bundbuy.html 8.3 KB
{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="bundling-bar clearfix">
    <div class="container">
        <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>
            <dd><span>节约:</span><span class="save-price"><b>{$currency_symbol}{echo:sprintf('%01.2f',$goods_price-$bund['price'])}</b></span></dd>
        </dl>
    </div>
</div>
<div class="container">
    <div class="clearfix mt20" style="position: relative;">
    <div class="content " style="overflow:visible">
            <ul class=" clearfix " style="position: relative;">
                {set:$sets_enable=true;}
                {list:items=$goods}
                <li class="clearfix" style="position: relative;background:#fff;border-bottom:#eee 1px solid;margin-top:20px;margin-left:10px;">
                    <div class="fl" style="height:240px;">
                        <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:250px;" 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" >
                            {list:items=$specs item=$spec}
                            <dl class="spec-item ">
                                <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 " style="display: none;">
                                <dt></dt>
                                <dd ><p class="msg"><i class="icon-alert-16"></i><span >请选择您要购买的商品规格</span></p>
                                </dd>
                            </dl>
                        </div>
                        {/if}
                    </div>
                </li>
                {/list}
            </ul>

        </div>
    </div>
</div>
<div class="bundling-bar clearfix">
    <div class="container">
        <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 btn-main 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;
        var goods_id = $(this).attr('goods_id');
        $(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(";")+';'+goods_id);
                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+"-16");
    }
</script>
<!--E 产品展示-->