{echo:JS::import('dialog?skin=brief');}
{echo:JS::import('dialogtools');}
{echo:JS::import('form');}
<!--S 产品展示-->
<link type="text/css" rel="stylesheet" href="{url:#css/product.css}" />
<script type='text/javascript' src="{url:#js/jquery.enlarge.js}"></script>

<div class="clearfix mt10" style="position: relative;">
<div class="content box" style="overflow:visible">
<div class="bundling-bar clearfix">
    <dl class="bund-info">
        <dt>优惠套餐：</dt>
        <dd><div>原价：<del>{$currency_symbol}{$goods_price}</del></div></dd>
        <dd><span class="price-caption">套餐价：</span></dd>
        <dd><span class="price"><b>{$currency_symbol}{$bund['price']}</b></span></dd>
    </dl>
    <div class="save-top ie6png">
        <div class="save-price">{$currency_symbol}{echo:sprintf('%01.2f',$goods_price-$bund['price'])}</div>
    </div>
</div>
    <h3 class="bundling-spec">请选择商品规格：</h3> 
    <ul class=" clearfix " style="position: relative;margin-top:28px;">
        {set:$sets_enable=true;}
        {list:items=$goods}
        <li class=" p10 clearfix" style="position: relative;background:#fff;border-bottom:#eee 1px solid;margin-top:20px;">
        <div class="fl" style="height:210px;">
            <a href="{url:/index/product/id/$item[id]}" target="_blank"><img class="big-pic" src="{echo:Common::thumb($item['img'],220,220)}" width=220></a>
        </div>
        <div class="product-info" style="margin-left:230px;" gid="{$item['id']}">
            <ul>
                <li ><h1 class="f18">{$item['name']}</h1></li>
                <li class="product-price"><label>销售价：</label><span id="sell_price" class="price">{$currency_symbol}{$item['sell_price']}</span></li>
                {if:$item['store_nums']<=0}{set:$sets_enable=false;}{/if}
                <li class="product-price"><label>库存：</label>(<span>{$item['store_nums']}</span>)</li>
            </ul>
                {set:$specs = unserialize($item['specs']);}
                {if:!empty($specs)}

                <div class=" mt10 p10 spec-info box" >
                {list:items=$specs item=$spec}
                <dl class="spec-item clearfix">
                    <dt>{$spec['name']}：</dt>
                    <dd>
                        <ul class="spec-values" spec_id="{$spec['id']}" goods_id="{$item['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'],36,36)}" width="36" height="36"><label>{$value['name']}</label>{/if}<i></i></li>
                        {/list}
                        </ul>
                    </dd>
                </dl>
                {/list}
                <dl class="spec-msg" class="spec-item clearfix" style="display: none;">
                    <dt></dt>
                    <dd ><p class="msg"><i class="icon icon-alert"></i><span >请选择您要购买的商品规格</span></p>
                    </dd>
                </dl>
                </div>
                {/if}
                </div>
    </li>
    {/list}
    </ul>
    <div class="bundling-bbar clearfix">
        <dl class="bund-info">
            <dt>优惠套餐：</dt>
            <dd><div>原价：<del>{$currency_symbol}{$goods_price}</del></div></dd>
            <dd><span class="price-caption">套餐价：</span></dd>
            <dd><span class="price"><b>{$currency_symbol}{$bund['price']}</b></span></dd>
        </dl>{if:$sets_enable}<a href="javascript:;" id="buy-now" class="btn fr">立即购买</a>
        {else:}
        <a href="javascript:;"  class="btn btn-disable fr">库存不足</a>
        {/if}
    </div>
</div>
</div>
<script type="text/javascript">

    var skuMap = {echo:JSON::encode($skumap)};

    $(".product-info").each(function(){
        var spec = $(this);
        $(".spec-values li",spec).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(spec);
             if($(".spec-values",spec).length == $(".spec-values .selected",spec).length){
                var sku = new Array();
                $(".spec-values .selected",spec).each(function(i){
                    sku[i]= $(this).attr("data-value");
                })
                var sku_key = ";"+sku.join(";")+";";
                if(skuMap[sku_key]!=undefined){
                    var sku = skuMap[sku_key];
                }
                $(".spec-msg",spec).css("display","none");
             }
        })
    })
    });
    function changeStatus(spec){
        var specs_array = new Array();
        $(".spec-values",spec).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",spec).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-now").on("click",function(){
        var product = currentProduct();
        var error_flag = false;
        var ids = new Array();
        
        for(i in product){

            if(product[i]){
                ids[i] = product[i]['id'];
            }
            else{
                error_flag = true;
                $(".spec-msg:eq("+i+")").css("display","");
                showMsgBar('alert',"请选择您要购买的商品规格！");
            }
        }
        if(!error_flag){
            ids = ids.join('-');
            var url = "{url:/simple/order_info/type/bundbuy/id/$id/pid/}"+ids;
            window.location.href = url;
        }
        return false;
    });
    
    //取得当前商品
    function currentProduct(){
        var result = new Array();
        $(".product-info").each(function(i){
            var spec = $(this);
            if($(".spec-values",spec).length==0){
                result[i] = skuMap[spec.attr("gid")];
            }else if($(".spec-values",spec).length == $(".spec-values .selected",spec).length){
                var sku = new Array();
                $(".spec-values .selected",spec).each(function(i){
                    sku[i]= $(this).attr("data-value");
                })
                var sku_key = ";"+sku.join(";")+";"+spec.attr("gid");
                if(skuMap[sku_key]!=undefined){
                    result[i] = skuMap[sku_key];
                }else result[i] = null;
             }
             else result[i] = null;
        });
        return result;
    }
    //展示信息
    function showMsgBar(type,text){
        $(".msg").find("span").text(text);
        $(".msg").find("i").attr("class","icon icon-"+type);
    }
    </script>
<!--E 产品展示-->