<link type="text/css" rel="stylesheet" href="{url:#css/simple.css}" /> {set:$items=array("购物车","确认订单信息","选择支付","订购完成");} {widget:name=sub_navs action=crumbs items=$items step=4 current=1}
<div class="container blank">
<div class="blank clearfix"></div>
    {if:$cart}
    <table class="table table-line">
        <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;$trNum=0;} {list:items=$cart} {set:$total+=$item['amount'];}
        <tr class="{if:$trNum%2==1}odd{else:}even{/if}" id="{$item['id']}">
            <td>
                <a href="{url:/index/product/id/$item[goods_id]}" target="_blank"><img src="{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:;"><i class="icon-minus-16"></i></a>
                    <input name="buy_num" value="{$item['num']}" maxlength=5><a class="btn-add" href="javascript:;"><i class="icon-plus-16"></i></a></div>
            </td>
            <td class="goods-prom">{$item['prom']}</td>
            <td class="amount red">{$item['amount']}</td>
            <td class="tc">
                <a href="#" class="icon-close-16"></a>
            </td>
        </tr>
        {set:$trNum++;} {/list}
    </table>
    <div class="blank clearfix" 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 class="mt10 clearfix">
        <p class="fr"><a class="btn btn-gray" href="{url:/index/index}">继续购物</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class="btn btn-main" href="{url:/simple/order/cart_type/$cart_type}">立即结算</a></p>
    </div>
</div>
{else:}
<div class="mt20 mb20 p20 box">
    <p class="cart-empty ie6png">购物车内暂时没有商品，<a href="{url:/index/index}">去首页</a> 挑选喜欢的商品。</p>
</div>
<div class="mt10 clearfix">
    <p class="fr">
        <a class="btn btn-main" href="{url:/index/index}">
            < 继续购物</a>
    </p>
</div>
{/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-16").on("click",function(){
     var parent = $(this).parent();
     var id = $(this).parent().parent().attr("id");
     $.post("{url:/index/cart_del/cart_type/$cart_type}",{id:id},function(data){
      if(data['status']=='success')location.reload();
    },'json');
   })

   function changeInfo(id,num){
     $.post("{url:/index/cart_num/cart_type/$cart_type}",{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(".goods-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(".alert-min").size()==0)parent.append("<div class='alert alert-fail alert-min'>最多购买"+data[id]['store_nums']+"件</div>");
      }else{
        $("#"+id).find("input").val(data[id]['num']);
        $("#"+id).find("input").parent().parent().find(".alert-min").remove();
      }
      $(".cart-total").text(total.toFixed(2));
    },"json");
   }
 </script>
