{!=JS::import("form")}
<link type="text/css" rel="stylesheet" href="{url:#css/product.css}" />
<!-- S 面包屑 -->
<div class="bread-crumb">
    <ol class="container">
        {list:items=$category_nav}
        <li><a class="category-{$key}" href="{url:/index/category/cid/$item[id]}">{$item['name']} {if:$item!=end($category_nav)}{/if}</a></li>
        {/list}
    </ol>
</div>

<!-- E 面包屑 -->

<div class="container">
    <!--S 产品展示-->
    <div id="product-intro">
        <div class="sub-1" id="gallery">
            <div style="position: absolute;height:800px;">
                {list:items=unserialize($goods['imgs']) item=$img }
                {if:$key < 5 } <a class="small-img" href="javascript:;"><img src="{echo:Common::thumb($img,367)}" source="{url:@$img}" width="60"></a>
                {/if}
                {/list}
            </div>
        </div>
        <div class="sub-2">
            <div id="preview">
                <div id="imgmini" style="width: 420px;height:420px;"><img class="big-pic" width="420" src="{echo:Common::thumb($goods['img'],420)}" source="{url:@$goods[img]}"></div>
            </div>
        </div>
        <div class="sub-3">
            <ul class="product-info">
                <li class="product-title">{echo:TString::msubstr($goods['name'],0,22)}</li>
                <li class="product-no">
                    <label>货号：</label><span id="pro-no">{$goods['goods_no']}</span></li>
                <li class="red">
                    {query:name=flash_sale where=goods_id eq $goods[id] and is_end eq 0}
                    <span>正在进行抢购活动</span> &gt;&gt;<a style="margin-right: 100px;" href="{url:/index/flashbuy/id/$item[id]}">立即抢购</a> {/query} {query:name=groupbuy where=goods_id eq $goods[id] and is_end eq 0}
                    <span>正在进行团购活动</span> &gt;&gt; <a href="{url:/index/groupbuy/id/$item[id]}"> 立即团购</a> {/query}
                </li>
                {if:!empty($prom)} {if:isset($user['group_id'])} {set:$group_id = ','.$user['group_id'].',';} {/if}
                <li class="product-price "><span id="prom_price" class="price" formula="{$prom['parse']['minus']}">{$prom['parse']['real_price']} {$currency_unit}</span><i class="promo-type">{$prom['name']}{if:$prom['parse']['note']!=''}{/if}</i><i class="icon-clock ie6png"></i></li>
                <li>
                    {if:isset($group_id)} {if:stripos(','.$prom['group'].',',$group_id)===false} 你的会员级别，无法享受此活动。 {else:} {$prom['parse']['note']} /
                    <i class="icon-clock ie6png"></i>结束时间：<span id="countdown1" style="color:#333; "></span>
                    <script type="text/javascript">
                    $("#countdown1").countdown({
                        end_time: "{echo:date('Y/m/d H:i:s',strtotime($prom['end_time']))}"
                    });
                    </script>
                    {/if} {else:} 登录后查看是否享受此活动。 {/if}
                </li>
                {else:}
                <li class="product-price"><span id="sell_price" class="price">{$goods['sell_price']}{$currency_unit}</span></li>
                {/if} {if:$goods['store_nums']>0}
                <!-- <li class=""><label></label><span>库存&nbsp;&nbsp;</span><span id="goods_nums">({$goods['store_nums']})</span></li> -->
                {else:}
                <li class="">
                    <label><b class="f16">无货</b></label><span>此商品暂时售完</span> <span class="btn btn-gray btn-mini" id="goods-notify">到货通知</span></li>
                {/if}
            </ul>
            {set:$specs_array = unserialize($goods['specs']);} {if:count($specs_array)>0}
            <fieldset class="line-title">
                <legend align="center" class="txt">商品规格</legend>
            </fieldset>
            {else:}
            <fieldset class="line-title">
            </fieldset>
            {/if}
            <div class="spec-info">
                <div class="spec-close"></div>
                {list:items=unserialize($goods['specs']) item=$spec}
                <dl class="spec-item ">
                    <dt>{$spec['name']}</dt>
                    <dd>
                        <ul class="spec-values " spec_id="{$spec['id']}">
                            {list:items=$spec['value'] item=$value}
                            <li data-value="{$spec['id']}:{$value['id']}">{if:$value['img']==''}<span>{$value['name']}</span>{else:}<img src="{echo:Common::thumb($value['img'],100)}" width="36" height="36">
                                <label>{$value['name']}</label>{/if}<i></i></li>
                            {/list}
                        </ul>
                    </dd>
                </dl>
                {/list}
                <dl class="spec-item ">
                    <dt>购买量</dt>
                    <dd class="buy-num" id="buy-num-bar"><a href="javascript:;"><i class="icon-minus-16"></i></a>
                        <input id="buy-num" name="buy_num" value="1" maxlength=5><a href="javascript:;"><i class="icon-plus-16"></i></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="vm">库存：<b id="store_nums" class="red">{$goods['store_nums']}</b></span></dd>
                </dl>
                <dl id="spec-msg" class="spec-item " style="display: none;">
                    <dt></dt>
                    <dd>
                        <p class="msg"><i class="icon icon-alert-16"></i><span>请选择您要购买的商品规格</span></p>
                    </dd>
                </dl>
                <dl class="spec-item ">
                    <dd class="product-btns" id="product-buttons">
                        <a href="javascript:;" class="buy-now btn btn-warning"><i class="icon-basket-32 ie6png"></i><span>立即购买</span></a>&nbsp;&nbsp;&nbsp;&nbsp;
                        <a href="javascript:;" class="add-cart btn btn-main"><i class="icon-cart-1-32 ie6png"></i><span>加入购物车</span></a>&nbsp;&nbsp;&nbsp;&nbsp;
                        <a href="javascript:;" class=" attention btn btn-info"><i class="icon-hart-32 ie6png"></i><span>关注</span></a>
                    </dd>
                </dl>
            </div>
        </div>
    </div>
    <!--S 商品详情-->
    <div>
        {!$parseNum=array('一','二','三','四','五','六','七','八','九','十');}
        {query:name=bundling where=CONCAT(',',goods_id,',') like '%,$goods[id],%' and status eq 1 items=$bundling/} {if:$bundling}
                    <div class="tab ">
                        <ul class="tab-head">
                            {list:items=$bundling}
                            <li>优惠套装{!=isset($parseNum[$key])?$parseNum[$key]:$key+1}<i></i></li>
                            {/list}
                        </ul>
                        <div class="tab-body" style="min-height: 180px;">
                            <div class="bundling-list ">
                                {list:items=$bundling item=$bun} {set:$gids = $goods['id'].','.$bun['goods_id'];$total_price=0.00;}
                                <div class="sub-1">
                                <div class="col-1">
                                    <div class="item">
                                        <div class="header">
                                            <img src="{echo:Common::thumb($goods['img'],100,100);}" width="100">
                                        </div>
                                            <ul class="main">
                                                <li class="title">{echo:TString::msubstr($goods['name'],0,8)}</li>
                                                <li class="price"><b class="red price">{$goods['sell_price']}{$currency_unit}</b></li>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                                <div class="sub-2 group-item sub-list">
                                <ul class="row-6">
                                    {query:name=goods where=id in($gids) order=field(`id`,$gids)} {set:$total_price+=$item['sell_price'];}
                                    {if:$item['id'] != $goods['id']}
                                    <li class="product goods-item col-1">
                                        <div class="item">

                                        <div class="header">
                                            <i class="icon-add ie6png icon-plus-16"></i>
                                            <a href="{url:/index/product/id/$item[id]}"><img src="{echo:Common::thumb($item['img'],100,100);}" width="100"></a>
                                        </div>
                                            <ul class="main">
                                                <li class="title"><a href="{url:/index/product/id/$item[id]}">{echo:TString::msubstr($item['name'],0,8)}</a></li>
                                                <li class="price"><b class="red price">{$item['sell_price']}{$currency_unit}</b></li>
                                            </ul>
                                        </div>
                                    </li>
                                    {/if}
                                    {/query}
                                    </ul>
                                </div>
                                <div class="sub-3 group-item">
                                    <div class="item">
                                        <div class="header">
                                        <i class="icon-add ie6png icon-equal-16"></i>
                                        </div>
                                        <div class="main" style="padding-left: 20px;">
                                            <div>{$bun['title']}</div>
                                        <div>套&nbsp;&nbsp;装&nbsp;&nbsp;价： {$currency_symbol}{$bun['price']}</div>
                                        <div>原　　价：
                                            <del>{$currency_symbol}{$total_price}</del>
                                        </div>
                                        <div>立即节省： {$currency_symbol}{echo:$total_price-$bun['price']}</div>
                                        <div class="mt10"><a href="{url:/index/bundbuy/id/$bun[id]}" class="btn btn-main">购买套装</a></div>
                                        </div>
                                    </div>
                                </div>
                                {/list}
                            </div>
                        </div>
                    </div>
                    {/if}
                    <!--S 捆绑销售 -->
    </div>
    <div class="product-main">
        <div class="sub-1">
            <fieldset class="line-title">
                <legend align="center" class="txt">同类商品推荐</legend>
            </fieldset>
            <ul class="list">
                {set:$path_like = "like '$goods[path]%'";} {query:name=goods where= is_online eq 0 and category_id in (select id from tiny_goods_category where path $path_like) order=sort desc limit=10} {if:$goods['id']!=$item['id']}
                <li class="item">
                    <div class="header">
                    <a href="{url:/index/product/id/$item[id]}"><img src="{echo:Common::thumb($item['img'],220,220)}" width=200></a>
                    </div>
                    <ul class="main">
                        <li><a href="{url:/index/product/id/$item[id]}">{echo:TString::msubstr($item['name'],0,14)}</a></li>
                        <li><span class="price">售价：<b class="red">{$currency_symbol}{$item['sell_price']}</b></span></li>
                    </ul>
                </li>
                {/if} {/list}
            </ul>
        </div>
        <div class="sub-2">
            <div class="goods-detail">
                <div class="content">
                    <!--S 捆绑销售 -->

                    <div class="tab ">
                        <ul class="tab-head">
                            <li>商品详情<i></i></li>
                            <li>商品评价<i></i></li>
                            <li>商品咨询<i></i></li>
                            <li>售后服务<i></i></li>
                        </ul>
                        <div class="tab-body" style="min-height: 200px;">
                            <!--S 商品详情-->
                            <div class=" ">
                                <div class="list">
                                    <ul class="row-4">
                                        <li class="col-1">商品名称：{$goods['name']}</li>
                                        <li class="col-1">商品编号：{$goods['pro_no']}</li>
                                        <li class="col-1">商品重量：{$goods['weight']}g</li>
                                        <li class="col-1">上架时间：{$goods['create_time']}</li>
                                        {list:items=$goods_attrs}
                                        <li class="col-1">{$item['name']}：{$item['vname']}</li>
                                        {/list}
                                    </ul>
                                </div>
                                <div class="description  ">
                                    {$goods['content']}
                                </div>
                            </div>
                            <!--E 商品详情-->
                            <!--S 商品评价-->
                            <div class="comment-list">
                                <div class="comment-top ">
                                    <ul>
                                        <li>
                                            <div class="comment-score"><em class="circle ">{$comment['a']['percent']}<i style="font-size: 18px;">%</i></em>- 好评度 -</div>
                                            <div class="mt10 score ie6png"><i style="width:{$comment['a']['percent']}%"></i></div>
                                        </li>
                                        <li class="comment-grade">
                                            <div>
                                                <h1>共有({$comment['total']})人参考评价</h1>
                                                <dl class="comment-percent">
                                                    <dt>很好</dt>
                                                    <dd class="bar"><i style="width:{$comment['a']['percent']}%"></i></dd>
                                                    <dd class="percent">{$comment['a']['percent']}%</dd>
                                                    <dt>较好</dt>
                                                    <dd class="bar"><i style="width:{$comment['b']['percent']}%"></i></dd>
                                                    <dd class="percent">{$comment['b']['percent']}%</dd>
                                                    <dt>一般</dt>
                                                    <dd class="bar"><i style="width:{$comment['c']['percent']}%"></i></dd>
                                                    <dd class="percent">{$comment['c']['percent']}%</dd>
                                                </dl>
                                            </div>
                                        </li>
                                        <li class="comment-action">
                                            <div>
                                                {set:$uid = isset($user['id'])?$user['id']:0;} {query:name=review where=goods_id eq $id and user_id eq $uid and status eq 0 limit=1 /} {if:$items} {list:}
                                                <a href="{url:/index/review/id/$item[id]}" class="btn btn-main">我要评论</a> {/list} {else:}
                                                <a href="javascript:;" class="btn btn-gray  disabled">我要评论</a> {/if}
                                                <p class="mt10">仅对购买过该商品的用户开放！</p>
                                            </div>
                                        </li>
                                    </ul>
                                </div>
                                <div class="comment tab" id="comment">
                                    <ul class="tab-head">
                                        <li>全部({$comment['total']})<i></i></li>
                                        <li>很好({$comment['a']['num']})<i></i></li>
                                        <li>较好({$comment['b']['num']})<i></i></li>
                                        <li>一般({$comment['c']['num']})<i></i></li>
                                    </ul>
                                    <div class="tab-body">
                                        <div id="comment-all" class="js-template">
                                            <div class="page-content">
                                                <div class="comment-item">
                                                    <div class="consult-q">
                                                        <div class="head">
                                                            <img src="" src-data="{head_pic}" width="80" height="80">
                                                            <strong cla>{uname}</strong>
                                                            <i class="arrow"><b></b></i>
                                                        </div>
                                                        <div class="comment-content">
                                                            <p class="top"><span class="score "><i style="width:{point}%"></i></span><span class="fr">{comment_time|今天}</span></p>
                                                            <p>{content|默认评论}</p>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="page-nav"></div>
                                        </div>
                                        <div id="comment-a" class="js-template">
                                            <div class="page-content">
                                                <div class="comment-item">
                                                    <div class="consult-q">
                                                        <div class="head">
                                                            <img src="" src-data="{head_pic}" width="80" height="80">
                                                            <strong>{uname}</strong>
                                                            <i class="arrow"><b></b></i>
                                                        </div>
                                                        <div class="comment-content">
                                                            <p class="top"><span class="score "><i style="width:{point}%"></i></span><span class="fr">{comment_time|今天}</span></p>
                                                            <p>{content|默认好评}</p>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="page-nav"></div>
                                        </div>
                                        <div id="comment-b" class="js-template">
                                            <div class="page-content">
                                                <div class="comment-item">
                                                    <div class="consult-q">
                                                        <div class="head">
                                                            <img src="" src-data="{head_pic}" width="80" height="80">
                                                            <strong>{uname}</strong>
                                                            <i class="arrow"><b></b></i>
                                                        </div>
                                                        <div class="comment-content">
                                                            <p class="top"><span class="score "><i style="width:{point}%"></i></span><span class="fr">{comment_time|今天}</span></p>
                                                            <p>{content|默认中评}</p>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="page-nav"></div>
                                        </div>
                                        <div id="comment-c" class="js-template">
                                            <div class="page-content">
                                                <div class="comment-item">
                                                    <div class="consult-q">
                                                        <div class="head">
                                                            <img src="" src-data="{head_pic}" width="80" height="80">
                                                            <strong>{uname}</strong>
                                                            <i class="arrow"><b></b></i>
                                                        </div>
                                                        <div class="comment-content">
                                                            <p class="top"><span class="score "><i style="width:{point}%"></i></span><span class="fr">{comment_time|今天}</span></p>
                                                            <p>{content|默认差评}</p>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="page-nav"></div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!--E 商品评价-->
                            <!--S 商品咨询-->
                            <div class="consult ">
                                <form class="tiny-form">
                                    <div>
                                        <div class="line textarea">
                                            <label class="caption" style="width:968px;">咨询内容：</label>
                                            <textarea id="consult-content" style="width:958px;"></textarea>
                                        </div>
                                        <div class="line" style="text-align:right;"><span><input type="text" name="verifyCode" id="verifyCode" class="field" style="width: 80px;" ><img id="captcha_img"  src="{url:/simple/captcha/h/40/w/120}"><a href="javascript:void(0)" class="red" onclick="document.getElementById('captcha_img').src='{url:/simple/captcha/h/40/w/120/random/}'+Math.random()" id="change-img">换一张</a></span>
                                            <span >
                                                <input type="reset" value="取消" class="btn btn-gray"> <input type="submit" id="consult" value="咨询" class="btn btn-main">
                                            </span>
                                        </div>
                                    </div>
                                </form>
                                <div id="goods-consult" class="js-template">
                                    <div class="page-content" id="page-content">
                                        <div class="consult-item">
                                            <div class="consult-q">
                                                <div class="head">
                                                    <img src="" src-data="{head_pic}" width="80" height="80">
                                                    <strong>{uname|网友}</strong>
                                                    <i class="arrow"><b></b></i>
                                                </div>
                                                <div class="consult-content">{question}
                                                    <p class="tr">{ask_time}</p>
                                                </div>
                                            </div>
                                            <div class="consult-a {content||hidden}">
                                                <div class="head">
                                                    <img src="{url:@static/images/no-img.png}" width="80" height="80">
                                                    <strong>商城客服</strong>
                                                    <i class="arrow"><b></b></i>
                                                </div>
                                                <div class="consult-content">{content}
                                                    <p class="tl">{reply_time|今天}</p>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="page-nav"></div>
                                </div>
                            </div>
                            <!--E 商品咨询-->
                            <!--S 售后保障-->
                            <div class="">
                                {if:$goods['sale_protection']}
                                <div class="mb20">
                                    {$goods['sale_protection']}
                                </div>
                                {/if}
                                <div>
                                    {$sale_protection}
                                </div>
                            </div>
                            <!--E 售后保障-->
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--E 商品详情-->

    <!-- S 悬停快速购物 -->
    <div class="goods-top-fixed-bar">
        <div id="fixed-wrap">
            <div  class="container">
                <div class="list">
                    <div class="row-4">
                        <div class="col-1"><a href="javascript:;" class="attention btn btn-info"><i class="icon-hart-32 ie6png"></i><span>关注</span></a></div>
                        <div class="col-1 selected-spec"><span id="goods-selected-spec">&nbsp;</span></div>
                        <div class="col-1 tr goods-count">
                            <span>合计：</span><span id="selected-price">{$goods['sell_price']}{$currency_unit}</span>
                        </div>
                        <div class="col-1 " style="text-align:right"><a href="javascript:;"  class="buy-now btn btn-warning"><i class="icon-basket-32 ie6png"></i><span>立即购买</span></a>
                        <a href="javascript:;" class="add-cart btn btn-main"><i class="icon-cart-1-32 ie6png"></i><span>加入购物车</span></a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- E 悬停快速购物 -->
    <div id="notify-dialog" style="display:none;padding:10px 20px;">
        <form id="notify_form" method="post" class="tiny-form" callback="submit_notify" >
            <ul>
                <li class="line"><h1>订阅到货通知：</h1></li>
                <li class="line caption">
                    <label class="caption">邮箱地址：</label><input type="text" class="field" id="n_email" name="email" pattern="email">
                </li>
                <li class="line caption">
                    <label class="caption">手机号码：</label><input type="text" class="field" id="n_mobile" empty name="mobile" pattern="mobi">
                </li>
                <li class="line">
                    <input type="submit" class="btn" value="到货通知">
                </li>
            </ul>
        </form>
    </div>
</div>
<script type="text/javascript">

$(window).scroll(function() {
    var a = $('.goods-top-fixed-bar');
    var top = $(".goods-detail").offset().top;
    var e = $(window).scrollTop();
    e >= top ? (a.addClass("fixed"), setTimeout(function() {
        a.addClass("show")
    }, 100)) : (a.removeClass("fixed"), a.removeClass("show"));
});

function changeImg(id){
        id.find("img").each(function(){
            $(this).attr("src",$(this).attr("src-data"));
            $(this).removeAttr("src-data");
        });
    }
$("#goods-consult").Paging({
    url: '{url:/index/get_ask}',
    callback:changeImg,
    params: {
        id: {$goods['id']}
    }
});
$("#comment-all").Paging({
    url: '{url:/index/get_review}',
    callback:changeImg,
    params: {
        id: {$goods['id']}
    }
});
$("#comment-a").Paging({
    url: '{url:/index/get_review}',
    callback:changeImg,
    params: {
        id: {$goods['id']},
        score: 'a'
    }
});
$("#comment-b").Paging({
    url: '{url:/index/get_review}',
    callback:changeImg,
    params: {
        id: {$goods['id']},
        score: 'b'
    }
});
$("#comment-c").Paging({
    url: '{url:/index/get_review}',
    callback:changeImg,
    params: {
        id: {$goods['id']},
        score: 'c'
    }
});

$("#consult").on("click", function() {

    var content = $("#consult-content").val();
    var verifyCode = $("#verifyCode").val();
    if (!Tiny.user.online){
        loginMin();
    }
    else if (content == ''){
        layer.msg("内容不能为空！");
    }
    else if (verifyCode == ''){
        layer.msg("验证码不能为空！");
    }
    else {
        $.post("{url:/index/goods_consult}", {
            id: {$goods['id']},
            content: content,
            verifyCode: verifyCode
        }, function(data) {
            if (data['status'] == 'success') {
                $("#goods-consult").Paging({
                    url: '{url:/index/get_ask}',
                    params: {
                        id: {$goods['id']}
                    }
                });
                $("#consult-content").val('');
                $("#verifyCode").val('');
                FireEvent(document.getElementById('change-img'), "click");
                layer.msg("<p class='success'>发布成功!</p>");
            } else {
                layer.msg("<p class='fail'>" + data['msg'] + "</p>");
            }
        }, 'json')
    }

    return false;
})

$("#imgmini").enlarge({
    // 鼠标遮罩层样式
    shadecolor: "#FFF",
    shadeborder: "#FF8000",
    shadeopacity: 0.5,
    cursor: "move",

    // 大图外层样式
    layerwidth: 420,
    layerheight: 420,
    layerborder: "#FFF",
    fade: true
});
var skuMap = {echo: JSON::encode($skumap)};
//更新库存信息
var store_nums = 0;
for (i in skuMap) {
    store_nums += parseInt(skuMap[i]['store_nums']);
}
$("#store_nums").text(store_nums);
$("#goods_nums").text(store_nums);

$("#gallery  .small-img").each(function(i) {
    if (i == 0) $(this).addClass("current");
    $(this).on("mouseenter", function() {
        $(this).parent().find("a").removeClass("current");
        $(this).addClass("current");
        $("#imgmini img").attr("src", $(this).find("img").attr("src"));
        $("#imgmini img").attr("source", $(this).find("img").attr("source"));
    })
});
$(".spec-values li").each(function() {
    $(this).on("click", function() {
        var disabled = $(this).hasClass('disabled');
        if (disabled) return;
        var flage = $(this).hasClass('selected');

        $(this).parent().find("li").removeClass("selected");
        if (!flage) {
            $(this).addClass("selected");
        }
        changeStatus();
        var selected_spec = new Array();
        $('.spec-values li.selected').each(function(){
            selected_spec.push($(this).text());
        });
        $('#goods-selected-spec').text(selected_spec.join(' , '));
        if ($(".spec-values").length == $(".spec-values .selected").length) {
            var sku = new Array();
            $(".spec-values .selected").each(function(i) {
                sku[i] = $(this).attr("data-value");
            })
            var sku_key = ";" + sku.join(";") + ";";
            if (skuMap[sku_key] != undefined) {
                var sku = skuMap[sku_key];
                $("#sell_price").text(sku['sell_price'] + "{$currency_unit}");
                $("#store_nums").text(sku['store_nums']);
                $("#goods_nums").text(sku['store_nums']);
                if ($("#prom_price").size() > 0) {
                    var formula = $("#prom_price").attr('formula');
                    var prom_price = eval(sku['sell_price'] + formula);
                    if (prom_price <= 0) prom_price = 0;
                    $("#prom_price").text(prom_price.toFixed(2) + " {$currency_unit}");
                    $("#selected-price").text(prom_price.toFixed(2) + " {$currency_unit}");
                }


                $("#market-price").text(sku['market_price']);

                $("#pro-no").text(sku['pro_no']);
            }
            $("#spec-msg").css("display", "none");
            specClose();
        } else {
            $("#store_nums").text("{$goods['store_nums']}");
        }
    })
})

function changeStatus() {
    var specs_array = new Array();
    $(".spec-values").each(function(i) {
        var selected = $(this).find(".selected");
        if (selected.length > 0) specs_array[i] = selected.attr("data-value");
        else specs_array[i] = "\\\d+:\\\d+";

    });
    $(".spec-values").each(function(i) {
        var selected = $(this).find(".selected");
        $(this).find("li").removeClass("disabled");
        var k = i;
        $(this).find("li").each(function() {

            var temp = specs_array.slice();
            temp[k] = $(this).attr('data-value');
            var flage = false;
            for (sku in skuMap) {
                var reg = new RegExp(';' + temp.join(";") + ';');
                if (reg.test(sku) && skuMap[sku]['store_nums'] > 0) flage = true;


            }
            if (!flage) $(this).addClass("disabled");
        })

    });
}
$("#buy-num-bar a:eq(0)").on("click", function() {
    var num = $("#buy-num-bar input").val();
    if (num > 1) num--;
    else num = 1;
    $("#buy-num-bar input").val(num);
    btnNumStatus(num);
});
$("#buy-num-bar a:eq(1)").on("click", function() {
    var num = $("#buy-num-bar input").val();
    var max = parseInt($("#store_nums").text());
    if (num < max) num++;
    else num = max;
    $("#buy-num-bar input").val(num);
    btnNumStatus(num);
});
$("#buy-num-bar input").on("change", function() {
    var value = $(this).val();
    var max = parseInt($("#store_nums").text());
    if ((/^\d+$/i).test(value)) {
        value = Math.abs(parseInt(value));
        if (value < 1) value = 1;
        if (value > max) value = max;
    } else {
        value = 1;
    }
    $(this).val(value);
    btnNumStatus(value);
})

function btnNumStatus(value) {
    var max = parseInt($("#store_nums").text());
    if (value <= 1) {
        $("#buy-num-bar a:eq(0)").addClass('disable');
    } else {
        $("#buy-num-bar a:eq(0)").removeClass('disable');
    }
    if (value >= max) {
        $("#buy-num-bar a:eq(1)").addClass('disable');
    } else {
        $("#buy-num-bar a:eq(1)").removeClass('disable');
    }
}
//立即购买
$(".buy-now").on("click", function() {
    var product = currentProduct();
    if (product) {
        var id = product["id"];
        var num = parseInt($("#buy-num").val());
        var max = parseInt($("#store_nums").text());
        if (num > max) {
            $("#spec-msg").css("display", "");
            showMsgBar('stop', "购买商品数量，超出了允许购买的最大量！");
            return false;
        } else if (max <= 0) {
            $("#spec-msg").css("display", "");
            showMsgBar('stop', "库存不足！");
            return false;
        } else {
            $("#spec-msg").css("display", "none");
        }
        var url = "{url:/index/goods_add/id/__id__/num/__num__}";
        url = url.replace("__id__", id);
        url = url.replace("__num__", num);
        window.location.href = url;
    } else {
        $("#spec-msg").css("display", "");
        showMsgBar('alert', "请选择您要购买的商品规格！");
        $(window).scrollTop(0);
    }
});
//添加到购物车
$(".add-cart").on("click", function() {
    var product = currentProduct();
    if (product) {
        var id = product["id"];
        var num = parseInt($("#buy-num").val());
        var max = parseInt($("#store_nums").text());
        var cart_num = parseInt($("#" + id).find(".num").text());
        if ((num + cart_num) > max) {
            $("#spec-msg").css("display", "");
            showMsgBar('stop', "连同购物车里的商品数量，超出了允许购买的最大量！");
            return false;
        } else if (max <= 0) {
            $("#spec-msg").css("display", "");
            showMsgBar('stop', "库存不足！");
            return false;
        } else {
            $("#spec-msg").css("display", "none");
        }
        $.post("{url:/index/cart_add}", {id: id,num: num}, function(data){
            var tmp = $($("#imgmini img").get(0).cloneNode(true));
            tmp.css({
                position: 'absolute',
                'z-index': '9998',
                border: 'solid 1px #ccc',
                background: '#aaf',
                'overflow': 'hidden',
                background: '#fff'
            });
            var imgView = $("#imgmini").offset();
            tmp.css(imgView);
            tmp.appendTo($('body'));
            var end = $(".shopping").offset();
            step1 = {
                top: end.top + 160,
                left: end.left + 30,
                width: 100,
                height: 100,
                opacity: 0.8
            };
            step2 = {
                top: end.top,
                left: end.left + 30,
                width: 100,
                height: 100,
                opacity: 0
            };

            $(tmp).animate(step1, "slow").animate(step2, "slow", function() {
                tmp.remove();
            });
            layer.msg("<p class='success'>商品已成功加入购物车</p>");
        }, "json");
    } else {
        $("#spec-msg").css("display", "");
        showMsgBar('alert', "请选择您要购买的商品规格！");
        $(window).scrollTop(0);
    }
});
//关闭信息提示
$(".spec-close").on("click", function() {
    specClose();
});

function specClose() {
    $(".spec-info").removeClass("noselected");
}
//取得当前商品
function currentProduct() {
    if ($(".spec-values").length == 0) {
        return skuMap[''];
    }
    if ($(".spec-values").length == $(".spec-values .selected").not(".disabled").length) {
        var sku = new Array();
        $(".spec-values .selected").each(function(i) {
            sku[i] = $(this).attr("data-value");
        })
        var sku_key = ";" + sku.join(";") + ";";
        if (skuMap[sku_key] != undefined) {
            return skuMap[sku_key];
        } else return null;
    } else return null;
}
//展示信息
function showMsgBar(type, text) {
    $(".spec-info").addClass("noselected");
    $(".msg").find("span").text(text);
    $(".msg").find("i").attr("class", "icon icon-" + type + "-16");
}
//切换画廊图片
$(".turn-right,.turn-left").on("click", function() {
    var canvas = $(".show-list >div");
    var num = canvas.find("a").size();
    var flage = -1;
    var current = 0;
    var width = 66;
    var show_num = 5;
    var left = 0;
    current = Math.round((Math.abs(canvas.position().left) / width));
    if ($(this).hasClass("turn-left")) {
        current--;
    } else {
        current++;
    }
    if (num - current >= show_num && current >= 0) {
        left = current * flage * width;
        canvas.animate({
            left: left
        }, 200);
    }
})

$(".attention").on("click", function() {
        $.post("{url:/index/attention}", {
            goods_id: {$id}
        }, function(data) {
            if (data['status'] == 2) layer.msg("<p class='warning'>已关注过了该商品！</p>");
            else if (data['status'] == 1) layer.msg("<p class='success'>成功关注了该商品!</p>");
            else {
                loginMin();
            }
        }, 'json')
    })
    //到货通知
$("#goods-notify").on("click", function() {
    if (Tiny.user.online) {
        layer.open({
            type: 1,
            area: ['520px', '300px'], //宽高
            content: $('#notify-dialog')
        });
    } else {
        loginMin();
    }

})

function submit_notify(e) {
    if (e == null) {
        var email = $("#n_email").val();
        var mobile = $("#n_mobile").val();
        $.post("{url:/index/notify}", {
            goods_id: {$goods['id'] },
            email: email,
            mobile: mobile
        }, function(data) {
            if (data['status'] != undefined) {
                layer.closeAll();
                layer.msg('<p class="' + data['status'] + '">' + data['msg'] + '</p>');
            }
        }, 'json');
        return false;
    }
    return false;
}
</script>
<!--E 产品展示-->
