<!--{include file="<!--{$mpath}-->block_header.tpl"}-->
<!--loading页开始-->
<div class="loading">
	<div class="loader">
		<div class="loader-inner pacman">
			<div></div>
			<div></div>
			<div></div>
			<div></div>
			<div></div>
		</div>
	</div>
</div>
<!--loading页结束-->
<body>
<header class="mui-bar mui-bar-nav" id="header">
	<div class="header-left fl">
		购物车
	</div>
	<div class="header-right fr">
		<a href="javascript:void(0);" class="edit">
			编辑
		</a>
		<a href="javascript:void(0);" class="guan" style="display: none;">
			关闭
		</a>
	</div>
</header>
<div id="main" class="mui-clearfix" style="padding-top: 53px; padding-bottom: 67px;">
	<div class="contaniner fixed-contb">
		<!--{if !empty($data)}-->
				<!--{foreach $data as $volist}-->
				<section class="shopcar">
					<div class="shopcar-checkbox" id="top" total="<!--{$volist.bprice}-->" num="<!--{$volist.productnum}-->"  gid="<!--{$volist.productid}-->">
						<!--{if <!--{$volist.selected}-->=='1'}-->
						<label for="shopcar" onselectstart="return false" class="dancheck shopcar-checkd"></label>
						<!--{else}-->
						<label for="shopcar" onselectstart="return false" class="dancheck"></label>
						<!--{/if}-->
						<input type="checkbox" id="shopcar"/>
					</div>
					<figure><img src="<!--{$volist.uploadfiles}-->"  height="80" width="80"/></figure>
					<div class="shopclist clearfloat fl">
						<p class="tit"><!--{$volist.productname}--></p>
						<p class="fu-tit">
							商品分类：<!--{$volist.catname}-->
						</p>
						<div class="bottom clearfloat">
							<span class="fl hicon">￥<!--{$volist.bprice}--></span>
							<!--<span class="fl huicon">￥308</span>
							<span class="fl sjzx">手机专享价</span>-->
								<ul class="shuliang" style="float: right;margin-bottom: 2px;"s>
								<li class="fuhao decrease"  style="float: left;padding: .05rem .05rem 0 .05rem;
    margin-left: .2rem;
    text-align: center;
    border: 2px solid #dcdad3;
    border-color: #dcdad3;"><i class="iconfont icon-jian" style="font-size: 0.6rem;"></i></li>
								<li style="float: left;" class="goodThis"><input type="text" name="inputNum" class="inputNum"  value="<!--{$volist.productnum}-->" style="width: 20px;height: 4px;font-size: 17px;text-align: center; margin-left: 7%;"/></li>
								<li class="fuhao increase"   style="float: left;padding: .05rem .05rem 0 .05rem;
    margin-left: .2rem;
    text-align: center;
    border: 2px solid #dcdad3;
    border-color: #dcdad3; margin-right: 0.4rem;"><i class="iconfont icon-jia-copy" style="font-size: 0.6rem;"></i></li>
								</ul>
						     	<span class="fr shu del" style="display: none; font-size: 0.5rem;" gid="<!--{$volist.productid}-->">删除</span>
						</div>
					</div>
				</section>
				<!--{/foreach}-->
		<!--{else}-->
        <section class="shopcar">
            <div class="shopcar-checkbox">
				<img src="<!--{$mpath}-->images/cart.gif" style="margin-left: 1.5rem;"/>
				<div style="width: 60rem; margin-left:2.5rem;"><p style=" color: red;font-size: 0.5rem;">当前购物是空的，快去购物吧！</p></div>
            </div>
        </section>
		<!--{/if}-->
		<section class="shopcar shopcartwo">
			<div class="shopcar-checkbox">
				<label for="shopcar" onselectstart="return false" class="allcheck"></label>
				<input type="checkbox" id="shopcar"/>
			</div>
			<span class="fl qxuan">全选</span>
			<a href="javascript:void(0);" class="jiesuan clearfloat fr box-s" id="J_goCheckout">
				去结算
			</a>
			<p class="fr heji"><span>合计：￥</span><span id="J_cartTotalPrice">0</span></p>
		</section>
		<!--去结算-->

	</div>
	<script type="text/javascript">
		$(".allcheck").on('touchstart',function(){
			if($(this).hasClass('shopcar-checkd1')){
				$(".dancheck").removeClass("shopcar-checkd");
                $(this).removeClass('shopcar-checkd1');
			}else{
				$(".dancheck").addClass("shopcar-checkd");
                $(this).addClass('shopcar-checkd1');
			}
			// 更新总价
			alltotalfun();
		})
		$('.dancheck').on('touchstart',function(){
			if($(this).hasClass('shopcar-checkd')){
				$(this).removeClass('shopcar-checkd');
			}else{
				$(this).addClass('shopcar-checkd');
			}

			if($('.dancheck').length == $('.shopcar-checkd').length){
				$(".allcheck").addClass('shopcar-checkd1');
			}else{
				//alert(123)
				$(".allcheck").removeClass('shopcar-checkd1');
			}
			// 更新总价
			alltotalfun();
		});
		$('.decrease').click(function(){
			var inputNum = $(this).next('.goodThis').find('.inputNum').val();
			if(inputNum <= 1){
				alert('请正确填写商品数');
				return false;
			}
			inputNum = inputNum-1;
			$(this).next('.goodThis').find('.inputNum').val(inputNum);
			$(this).parent().parent().parent().prevAll('.shopcar-checkbox').attr('num',inputNum)
			alltotalfun();
		});
		//点击增加
		$('.increase').click(function(){
			var inputNum = $(this).prev('.goodThis').find('.inputNum').val();
			var sum = parseInt($('#stock').attr('stock'));
			if(inputNum>=sum){
				alert('库存仅'+sum);
				return false;
			}
			inputNum=parseInt(inputNum);
			inputNum = inputNum+1;
			$(this).prev('.goodThis').find('.inputNum').val(inputNum);
			$(this).parent().parent().parent().prevAll('.shopcar-checkbox').attr('num',inputNum)
			alltotalfun();
		});
		// 更新总价
		alltotalfun();
		function alltotalfun(){
			var total = 0;
			// 当前所有已选中
			$("#top .shopcar-checkd").each(function(k, v) {
				//更新总价
              //  alert();
				total += parseFloat($(v).parent('.shopcar-checkbox').attr('total')).toFixed(2) * $(v).parent('.shopcar-checkbox').attr('num');
				//alert(total);
				$('#J_cartTotalPrice').html(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));
			});
		//	$('#J_cartTotalPrice').text(total.toFixed(2));
			// 结算按钮
			if ($(".shopcar-checkd").length > 0) {
				$("#J_goCheckout").removeClass('btn-disabled');
			} else {
				$("#J_goCheckout").addClass('btn-disabled');
				//清空总价
				$('#J_cartTotalPrice').text('');
				//移除 全选 的选中事件

			}
		}
		if ($(".shopcar-checkd").length > 0) {
			$("#J_goCheckout").removeClass('btn-disabled');
		} else {
			$("#J_goCheckout").addClass('btn-disabled');
			//清空总价
			$('#J_cartTotalPrice').text('');
			//移除 全选 的选中事件

		}
		// 提交订单更新
		$("#J_goCheckout").click(function(event){ //提交
				if ($(".shopcar-checkd").length <= 0) {
					layer.open({
						content: '请先选择商品'
						,skin: 'msg'
						,time: 2 //2秒后自动关闭
					});
					return false;
				}
				var prarr=new Array();
				$("#top .shopcar-checkd").each(function(k, v) {
				prarr.push({
					'pcid' : $(v).parent('.shopcar-checkbox').attr("gid"),
					'bynm' : $(v).parent('.shopcar-checkbox').attr('num')
				})
			});

				$.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'){
							window.location.href=tourl;
						}else{
							layer.open({
								content: json.result
								,skin: 'msg'
								,time: 2 //2秒后自动关闭
							});
							return false;
						}
					}
				});

		});

		$(".edit").on('click',function(){
			$('.shuliang').hide();
			$('.del').show();
			$('.edit').hide();
			$('.guan').show();
		})
		$(".guan").on('click',function(){
			$('.shuliang').show();
			$('.del').hide();
			$('.edit').show();
			$('.guan').hide();
		})
		//删除信息
		$('.del').click(function(){
			var gid = $(this).attr('gid');
			//询问框
			layer.open({
				content: '你确定要删除吗？'
				,btn: ['确定', '不要']
				,yes: function(index){
					$.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.open({
									content: json.result
									,skin: 'msg'
									,time: 2 //2秒后自动关闭
								});
								window.location.reload();
							}else{
								layer.open({
									content: json.result
									,skin: 'msg'
									,time: 2 //2秒后自动关闭
								});
							}
						}
					});
				}
			});


		})
	</script>
</div>

<!--{include file="<!--{$mpath}-->block_button.tpl"}-->
<script type="text/javascript">
	jQuery(".sideMenu").slide({
		titCell:"h3",
		targetCell:".slist",
		effect:"slideDown",
		delayTime:300 ,
		triggerTime:150,
		defaultPlay:true,
		returnDefault:false,
		trigger:"click"
	});
</script>
</html>