<!--{include file="<!--{$tplpath}-->top.tpl"}-->
<!-------------------------------------- 头部结束 -------------------------------------->
<title>我的购物车</title>
<style>
	.site-category{display: none;}
</style>
<!-------------------------------------- 主体开始 -------------------------------------->

		<div class="site-header site-mini-header">

			<div class="container">

				<div class="header-logo" style="width: auto;">

					<a class="" href="<!--{$urlpath}-->" title=""><img src="<!--{$config.logo}-->"  ></a>

				</div>

				<div class="header-title has-more" id="J_miniHeaderTitle">

					<h2>我的购物车</h2>

				</div>

			</div>

		</div>
<div class="page-main">
	<div class="container">
		<div class="cart-loading loading hide" id="J_cartLoading">
			<div class="loader"></div>
		</div>
		<div id="J_cartBox" class="">
		<!--{if !empty($data)}--> 
			<div class="cart-goods-list">
				<div class="list-head clearfix">
					<div class="col col-check"><i class="iconfont icon-checkbox icon-checkbox-selected" id="all_check">√</i>全选</div>
					<div class="col col-img">&nbsp;</div><div class="col col-name">商品名称</div>
					<div class="col col-price">单价</div>
					<div class="col col-num">数量</div>
					<div class="col col-total">小计</div>
					<div class="col col-action">操作</div>
				</div>
				<div class="list-body" id="J_cartListBody">
				<!--{foreach $data as $volist}-->
					<div class="item-box" good-id="<!--{$volist.productid}-->">
						<div class="item-table J_cartGoods">
							<div class="item-row clearfix goodThis">
								<div class="col col-check brandBuy top" total="<!--{$volist.bprice}-->" num="<!--{$volist.productnum}-->"  gid="<!--{$volist.productid}-->">
									<i class="iconfont icon-checkbox J_itemCheckbox icon-checkbox-selected" data-itemid="2152400007_0_buy" data-status="1">√</i>
								</div>
								<div class="col col-img">
									<a href="" target="_blank"><img alt="" src="<!--{$volist.uploadfiles}-->" height="80" width="80"></a>
								</div>
								<div class="col col-name">
									<div class="tags"></div>
									<h3 class="name"><a href="" target="_blank"><!--{$volist.productname}--></a></h3>
								</div>
								<div class="col col-price prdctprice"><!--{$volist.bprice}--></div>
								<div class="col col-num">
									<div class="change-goods-num clearfix J_changeGoodsNum">
										<a href="javascript:void(0)" class="decrease adjust-control">
											<i class="iconfont " style="cursor:pointer;">-</i>
										</a>
										<input tyep="text" name="" max="<!--{$volist.productnum}-->" min="1" value="<!--{if !empty($volist.productnum)}--><!--{$volist.productnum}--><!--{else}-->1<!--{/if}-->" class="goods-num J_goodsNum inputNum">
										<a href="javascript:void(0)" class="increase adjust-control">
											<i class="iconfont " style="cursor:pointer;">+</i>
										</a>
									</div>
								</div>
								<div class="col col-total subtotal"> <!--{if !empty($volist.productnum)}--><!--{$volist.bprice*$volist.productnum}--><!--{else}--><!--{$volist.bprice}--><!--{/if}--></div>
								<div class="col col-action">
									<a class="del J_delGoods delete" gid="<!--{$volist.productid}-->" style="cursor:pointer;"><i class="iconfont "></i></a>
								</div>
							</div>
						</div>
					</div>
				<!--{/foreach}-->
				</div>
				<div class="cart-bar clearfix" id="J_cartBar">
					<div class="section-left">
						<span class="cart-total">共 <i id="J_cartTotalNum"><!--{count($data)}--></i> 类商品</span>
					</div>
					<span class="total-price"> 合计（不含运费）<em id="J_cartTotalPrice" class="totalPrice"><!--{$djtotal}--></em>元</span>
				<!--{if !empty($check)}-->
					<a class="btn btn-a btn btn-primary" id="J_goCheckout" href="javascript:;">去结算</a>
				<!--{else}-->
				<a class="btn btn-primary" href="./index.php?c=user&a=login">去登录</a>
				<!--{/if}-->
				</div>
			</div>
		<!--{else}--> 
			<div  class="item-box">
				<div class="list-head clearfix">
					<p class='cart-not-title m-t-0 m-b-20 blue-grey-400'>购物车中还没有商品，赶紧选购吧！</p>
					<a href="./index.php" class="btn btn-lg btn-squared btn-outline btn-danger">马上去购物</a>
				</div>
			</div>
		<!--{/if}-->
		</div>
	</div>
</div>

<script>

				$("#all_check").live("click" ,function() {
					if($(this).hasClass('icon-checkbox-selected')){
						$(this).removeClass('icon-checkbox-selected');
						$('.J_itemCheckbox').removeClass('icon-checkbox-selected');
					}else{
						$(this).addClass('icon-checkbox-selected');
						$('.J_itemCheckbox').addClass('icon-checkbox-selected');
					}
					// 更新总价
					alltotalfun();
				})
				$('.item-box .J_itemCheckbox').live('click',function(){
					if($(this).hasClass('icon-checkbox-selected')){
						$(this).removeClass('icon-checkbox-selected');
					}else{
						$(this).addClass('icon-checkbox-selected');
					}
					if($('.J_cartGoods .col-check .icon-checkbox-selected').length == $('.item-box .J_itemCheckbox').length){
						$("#all_check").addClass('icon-checkbox-selected');
					}else{
						$("#all_check").removeClass('icon-checkbox-selected');
					}
					// 更新总价
					alltotalfun();
				});
				$('.increase').live('click',function(){
					var inputNum = $(this).parents('.goodThis').find('.inputNum').val();
					inputNum = parseInt(inputNum);
					inputNum = inputNum+1;
					$(this).parents('.goodThis').find('.inputNum').val(inputNum);
					//更新总价
					alltotalfun();
				});
				$('.decrease').live('click',function(){
					var inputNum = $(this).parents('.goodThis').find('.inputNum').val();
					inputNum = parseInt(inputNum);
					
					if(inputNum == 1){
						$(this).parents('.goodThis').find('.inputNum').val(1);
					}else{
						inputNum = inputNum-1;
						$(this).parents('.goodThis').find('.inputNum').val(inputNum);
					}
					//更新总价
					alltotalfun();
				});

	// 更新总价
	alltotalfun();
function alltotalfun(){
	var total = 0;
	// 当前所有已选中
	$(".J_cartGoods .col-check .icon-checkbox-selected").each(function(k, v) {
		//更新总价
		total += parseFloat($(v).parents(".brandBuy").attr('total')).toFixed(2) * $(v).parents('.goodThis').find('.inputNum').val();
        $('#J_cartTotalPrice').text(total.toFixed(2));
        // 小计更新
        $(v).parents('.goodThis').find('.subtotal').text((parseFloat($(v).parents(".brandBuy").attr('total')).toFixed(2) * $(v).parents('.goodThis').find('.inputNum').val()).toFixed(2));
	});
	// 结算按钮
	if ($(".J_cartGoods .col-check .icon-checkbox-selected").length > 0) {
		$("#J_goCheckout").removeClass('btn-disabled');
	} else {
		$("#J_goCheckout").addClass('btn-disabled');
		//清空总价
		$('#J_cartTotalPrice').text('');
		//移除 全选 的选中事件
		$("#all_check").removeClass('icon-checkbox-selected');
	}
}
//

//删除信息
$('.delete').click(function(){
	//询问框
	layer.confirm('你确定要删除吗？', {
	  btn: ['确定','误点'] //按钮
	}, function(){
		var gid = $('.delete').attr('gid');
		$.ajax({
	        type: "POST",
	        url: "index.php?c=index&a=delshous",
	        data: {gid:gid},
	        dataType: "json",
	         success: function(data) {
	             var json = eval(data);
	               var response = json.response;
	               var result = json.result; 
	               if(response=='1'){
	               	layer.msg(result, {icon: 1});
	                window.location.reload();
	               }else{
	               	layer.msg(result, {icon: 5});
	               }
	        }
	    });
	}, function(){
	  layer.msg('未操作', {icon: 5});
	});

})

// 提交订单更新         
       $("#J_goCheckout").click(function(event){ //提交
	       	if ($(this).attr("disabled")=='disabled') {
	       		event.preventDefault();
	       	} else {
	       		var prarr=new Array();
			    $(".top .icon-checkbox-selected").each(function (i,v) {
			        prarr.push({
					    'pcid' : $(this).parent('.top').attr("gid"),
					    'bynm' : $(this).parents('.goodThis').find('.inputNum').val()
					})
			    });

	            $.ajax({
	                type: "POST",
	                url: "index.php?c=user&a=usupdateorder",
	                cache: false,
	                data: {prarr:prarr},
	                dataType: "json",
	                success: function(data) {
	                   var json = eval(data);
	                   var response = json.response;
	                   var result = json.result;
	                   var tourl = json.jumpurl;
	                   if(response=='1'){
	                        layer.msg(result);
	                        window.location.href=tourl;
	                   }else{
						   alert(result);
	                     //  layer.msg(result, function(){});  
	                   }
	                }	
	            });
	       	}
        });

</script>



<!--{include file="<!--{$tplpath}-->botton.tpl"}-->