cart.html 4.4 KB
<link type="text/css" rel="stylesheet" href="{url:@static/css/simple.css}" />
{set:$items=array("购物车","确认订单信息","选择支付","订购完成");}
{widget:name=sub_navs action=crumbs items=$items step=4 current=1}
<div class="mt20  clearfix">
    {if:$cart}
	<table width="100%" class="simple">
		<tr>
			<th style="width:60px;">商品</th>
			<th style="width:200px;">名称</th>
			<th style="width:160px;">规格</th>
			<th style="width:100px;">单价</th>
			<th style="width:120px;">数量</th>
			<th style="width:100px;">优惠</th>
			<th style="width:80px;">小计</th>
			<th style="width:40px;">操作</th>
		</tr>
		{set:$total=0.00;}
		{list:items=$cart}
		{set:$total+=$item['amount'];}
		<tr id="{$item['id']}"><td><a href="{url:/index/product/id/$item[goods_id]}" target="_blank"><img src="{url:@}{echo:Common::thumb($item['img'],100,100)}" width="50" height="50"></a></td><td><a href="{url:/index/product/id/$item[goods_id]}" target="_blank">{echo:TString::msubstr($item['name'],0,36)}</a></td> <td>{list:items=$item['spec'] item=$spec}
								<p title="{$spec['name']}:{$spec['value'][2]}">{$spec['name']}:{$spec['value'][2]}</p>
							{/list}</td> <td>{$item['price']}</td> <td><div  class="buy-num-bar buy-num clearfix"><a class="btn-dec" href="javascript:;">-</a><input  name="buy_num" value="{$item['num']}"  maxlength=5><a class="btn-add" href="javascript:;">+</a></div></td> <td class="prom">{$item['prom']}</td> <td class="amount red">{$item['amount']}</td> <td><a href="#" class="icon-close"></a></td></tr>
		{/list}
	</table>
<div class="mb10" style="padding:10px; background: #f0f0f0;"><span class="fr">商品总价(不含运费):<span style="font-size: 24px;font-family: tahoma"><span class="currency-symbol">{$currency_symbol}</span><b class="cart-total red" >{echo:sprintf("%01.2f",$total)}</b></span></span></div>
</div>
<div class="mt10 clearfix">
<p class="fr"><a class="btn btn-gray" href="{url:/index/index}">继续购物</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class="btn" href="{url:/simple/order}">去结算</a></p></div>
{else:}
<div class="mt20 mb20 p20 box">
    <p class="cart-empty ie6png">购物车内暂时没有商品,<a  href="{url:/index/index}">去首页</a> 挑选喜欢的商品。</p>

</div>
<p class="fr"><a class="btn " href="{url:/index/index}"> < 继续购物</a></p>
{/if}

<script type="text/javascript">
	$(".btn-dec").on("click",function(){
		var parent = $(this).parent().parent();
		var id = parent.parent().attr("id");
        var num = parent.find("input").val();
        if(num>1) num--;
        else num=1;
        if($("#"+id).find("input").val()!=num) changeInfo(id,num);
        parent.find("input").val(num);
    });
    $(".btn-add").on("click",function(){
    	var parent = $(this).parent().parent();
    	var id = parent.parent().attr("id");
        var num = parent.find("input").val();
        num++;
        if($("#"+id).find("input").val()!=num) changeInfo(id,num);
        parent.find("input").val(num);
    });

    $(".buy-num-bar input").on("change",function(){
        var num = parseInt($(this).val());
        var parent = $(this).parent().parent();
        var id = parent.parent().attr("id");
        changeInfo(id,num);
    })
    $(".icon-close").on("click",function(){
    	var parent = $(this).parent();
    	var id = $(this).parent().parent().attr("id");
    	$.post("{url:/index/cart_del}",{id:id},function(data){
    		if(data['status']=='success')location.reload();
    	},'json');
    })

    function changeInfo(id,num){
    	$.post("{url:/index/cart_num}",{id:id,num:num},function(data){
    		var total = 0.00;
    		for(var i in data) total += parseFloat(data[i]['amount']);
            $("#"+id).find(".amount").text(data[id]['amount']);
        	$("#"+id).find(".prom").text(data[id]['prom']);
        	if(parseInt($("#"+id).find("input").val())>data[id]['store_nums']){
        		$("#"+id).find("input").val(data[id]['store_nums']);
        		var parent = $("#"+id).find("input").parent().parent();
        		if(parent.find(".msg-simple-error").size()==0)parent.append("<div class='msg-simple-error'>最多购买"+data[id]['store_nums']+"件</div>");
        	}else{
        		$("#"+id).find("input").val(data[id]['num']);
        		$("#"+id).find("input").parent().parent().find(".msg-simple-error").remove();
        	}
        	$(".cart-total").text(total.toFixed(2));
        },"json");
    }
</script>