<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>购物车 - {wc:fun:_cfg("web_name")}</title>
<meta name="keywords" content="{wc:if isset($keywords)}{wc:$keywords}{wc:else}{wc:fun:_cfg("web_key")}{wc:if:end}" />
<meta name="description" content="{wc:if isset($description)}{wc:$description}{wc:else}{wc:fun:_cfg("web_des")}{wc:if:end}" />
<link rel="stylesheet" type="text/css" href="{G_TEMPLATES_STYLE}/css/Comm1.css"/>
<link rel="stylesheet" type="text/css" href="{G_TEMPLATES_STYLE}/css/CartList.css"/>
<script type="text/javascript" src="{G_GLOBAL_STYLE}/global/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="{G_TEMPLATES_STYLE}/js/jquery.cookie.js"></script>
</head>
<body>
<div class="logo">
	<div class="float">
		<span class="logo_pic"><a href="{G_WEB_PATH}" class="a" title="{wc:fun:_cfg("web_name")}">
			<img src="{G_UPLOAD_PATH}/{wc:fun:Getlogo()}"/>
		</a></span>
		<span class="tel"><a href="{G_WEB_PATH}" style="color:#999;">返回首页</a></span>
	</div>
</div>
<div class="shop_process">
	<ul class="process">
		<li class="first_step">第一步：提交订单</li>
		<li class="arrow_1"></li>
		<li class="secend_step">第二步：支付订单</li>
		<li class="arrow_2"></li>
		<li class="third_step">第三步：购买成功</li>
	</ul>
	<div class="i_tips"></div>
	<div class="submitted">
		<ul class="order">
			<li class="top">
				<span class="goods">商品</span>
				<span class="name">名称</span>
				<span class="moneys">&nbsp;</span>
				<span class="money">全额</span>
				<span class="num">购买数量</span>
				<span class="xj">小计</span>
				<span class="do">操作</span>
			</li>
			{wc:loop $shoplist $shops}
			<li class="end" id="shoplist{wc:$shops['id']}">
				<span class="goods">
					<a href="{WEB_PATH}/jf_goods/{wc:$shops['id']}">
                   	 <img src="{G_UPLOAD_PATH}/{wc:$shops['thumb']}" />
                    </a>
				</span>
				<span class="name">
					<a href="{WEB_PATH}/go/index/jf_item/{wc:$shops['id']}" >{wc:$shops['title']}</a>
					<p>库存<span class="gorenci">{wc:$shops['cart_shenyu']}</span> 件
                    </p>
				</span>
				<span class="moneys">&nbsp;</span>
				<span class="money"><span class="color">￥<b>{wc:$shops['yunjiage']}</b></span></span>
				<span class="num">
					<dl class="add">
					<dd><input type="type" val="{wc:$shops['id']}" onkeyup="value=value.replace(/\D/g,'')" value="{wc:$shops['cart_gorenci']}" class="amount" /></dd>
						<dd>
							<a href="JavaScript:;" val="{wc:$shops['id']}" class="jia"></a>
							<a href="JavaScript:;" val="{wc:$shops['id']}" class="jian"></a>
						</dd>
					</dl>
                    <p class="message"></p>
				</span>
				<span  class="xj">{wc:$shops['cart_xiaoji']}</span>
				<span class="do"><a href="javascript:;" onclick="delcart({wc:$shops['id']})"  class="delgood">删除</a></span>
			</li>
			{wc:loop:end}
			<li class="ts">
				<p class="right">购买总计:<span id="moenyCount">{wc:$MoenyCount}</span></p>
			</li>
		</ul>
	</div>
	<h5>
		<a href="{WEB_PATH}" id="but_on"></a>
		<input id="but_ok" type="button" value=""  name="submit"/>
	</h5>
</div>

<script type="text/javascript">
var info={wc:$Cartshopinfo};
var numberadd=$(".jia");
var numbersub=$(".jian");
var xiaoji=$(".xj");
var num=$(".amount");
var message=$(".message");
var moenyCount=$("#moenyCount");

$(function(){
	$("#but_ok").click(function(){
		var countmoney=parseInt(moenyCount.text());
		if(countmoney > 0){
			$.cookie('Cartlist_jf',$.toJSON(info),{expires:30,path:'/'});
			document.location.href='{WEB_PATH}/member/cart/jf_pay';
		}else{
			alert("购物车为空!");
		}
	});
});
function UpdataMoney(shopid,number,zindex){
		var number = parseInt(number);
		info['MoenyCount']=info['MoenyCount']-info[shopid]['money']*info[shopid]['num']+info[shopid]['money']*number;
		info[shopid]['num']=number;
		var xjmoney=xiaoji.eq(zindex+1);
			xjmoney.text(info[shopid]['money']*number+'.00');
			moenyCount.text(info['MoenyCount']+'.00');
}


function delcart(id){
	info['MoenyCount'] = info['MoenyCount']-info[id]['money']*info[id]['num'];
	$("#shoplist"+id).hide();
	$("#moenyCount").text(info['MoenyCount']+".00");
	delete info[id];
	$.cookie('Cartlist_jf',$.toJSON(info),{expires:30,path:'/'});
}

num.keyup(function(){
	var shopid=$(this).attr("val");
	var zindex=num.index(this);
	var ten_per = Math.floor(parseInt(info[shopid]['zongrenshu'])) || 1;
	var max_num = (ten_per > parseInt(info[shopid]['shenyu'])) ? parseInt(info[shopid]['shenyu']) : ten_per;
	if($(this).val() > max_num){
		message.eq(zindex).text("兑换数量不能超过"+max_num+"次");
		$(this).val(max_num);
		UpdataMoney(shopid,$(this).val(),zindex);
		return;
	}
	if($(this).val()<1){
		message.eq(zindex).text("兑换数量不能少于1次");
		$(this).val(1);
		UpdataMoney(shopid,$(this).val(),zindex);
		return;
	}
	UpdataMoney(shopid,$(this).val(),zindex);
});
numberadd.click(function(){
	var shopid=$(this).attr('val');
	var zindex=numberadd.index(this);
	var thisnum=num.eq(zindex);
	var ten_per = Math.floor(parseInt(info[shopid]['zongrenshu'])) || 1;
	var max_num = (ten_per > parseInt(info[shopid]['shenyu'])) ? parseInt(info[shopid]['shenyu']) : ten_per;
	if(info[shopid]['num'] >= max_num){
		message.eq(zindex).text("兑换数量不能超过"+max_num+"次");
		return;
	}
	var number=info[shopid]['num']+1;
		thisnum.val(number);
		UpdataMoney(shopid,number,zindex);
});
numbersub.click(function(){
	var shopid=$(this).attr('val');
	var zindex=numbersub.index(this);
	var thisnum=num.eq(zindex);
		if(info[shopid]['num'] <=1){
			message.eq(zindex).text("兑换数量不能少于1次");
			return;
		}
		var number=info[shopid]['num']-1;
			thisnum.val(number);
			UpdataMoney(shopid,number,zindex);
});

</script>
