<{import file="common.html" title="订单结算"}> 
<link rel="stylesheet" type="text/css" href="<{$__APP__}>public/css/settle.css?t=<{$smarty.now}>"> 
<div class="cnav">
	<a class="back">&nbsp;</a>订单结算<a href="javascript:;" class="thome">主页</a>
</div>
<form action="#" method="post" id="settle_form">
	<div class="addr_box">
		<{uqcms m="address" v="address_row" c="get_session_address"}>
		<{if $address_row}>
			<div class="addr_detail"> 
				<a href="?m=address&cart=1">
					<div class="addr_icon"><em class="addr_icon"></em></div>
					<div class="addr_info">
						<div class="name">
						 	<span><{$address_row.name}></span>
							<span><{$address_row.mobile}></span>
						</div>
						<div class="detail"><{$address_row.prov_cn}>，<{$address_row.city_cn}>，<{$address_row.dist_cn}>，<{$address_row.address}></div>
					</div> 
				</a> 
			</div>
			<input type="hidden" name="address_id" value="<{$address_row.id}>">
		<{else}>	
			<div class="addr_no">	
				<a href="?m=address&cart=1" class="chose_address"><span></span><em>请选择收货地址！</em></a>
			</div>	
		<{/if}>		
		<div class="address_line"></div>
	</div>  
	<{uqcms m="cart" c="settle" v="cart"}>
	<{if $cart}>
		<div class="cart_box"> 
			<{foreach item=i from=$cart.list}>
			<div class="cart_sp">
				<div class="cart_name"><em></em><span><{$i.name}></span></div> 
				<div class="cart_gds">
					<{foreach item=ii from=$i.goods}>
						<div class="cart_desc">
							<div class="images"><a href="index.php?m=goods&a=detail&id=<{$ii.gid}>"><img src="<{$__IMG__}><{$ii.images|img_size:200x200}>"/></a></div>
							<div class="ttl">
								<div class="sttl"><a href="?m=goods&a=detail&id=<{$ii.gid}>" class="gttl"><{$ii.title}></a></div>
								<div class="sku">
									<{if $ii.sku_name}>
										<{foreach item=s from=$ii.sku_name}>
											 <span><{$s.0}>：<{$s.1}> &nbsp;&nbsp;</span>
										<{/foreach}>
									<{/if}>
								</div>
								<div class="pr">
									<{if $ii.stock_status}>
										<span class="l">¥ <{$ii.price}></span> <span class="r">X<{$ii.buy_num}></span>
									<{else}>
										<span class="l">¥ <{$ii.price}></span> <span class="r">库存不足</span>
									<{/if}> 
								</div>
							</div>
						</div> 
					<{/foreach}>
					
					<div class="other_pirce"> 
						<div class="obox express_price_<{$i.id}>">
							<span>运费</span>
							<em><{$i.express_price}></em>
						</div> 
						<{if $c.reduce_name}> 
							<div class="obox">
								<span>优惠 </span> 
								<em>-<{$i.reduce_price}></em>
							</div>
						<{/if}>  
						<div class="ly">
							<span>买家留言 </span>
							<em><input type="text" name="message[<{$i.id}>]" placeholder="建议填写说明和要求"/></em>
						</div>  
					</div>
					
				</div> 
			</div> 
			<{/foreach}> 	
		</div> 
	<{else}>
		<script> location.href="wap.php?m=cart"; </script>
	<{/if}>
	<div class="payment">
		<label><input type="radio" name="payment" value="online" class="gopay" checked="checked"/><span>在线支付</span></label>
	</div>  
	<div class="bill_list">
		<div class="list_one">
			<span>支付价格</span> 
			<em><{$cart.total_price}></em>
		</div>
	</div> 
	<{if $cart.post_method == 'direct' || $cart.post_method == 'group'}>
		<!--直接提交需要传递 sku_id,buy_num -->
		<input type="hidden" name="post_method" value="<{$cart.post_method}>"/>
		<input type="hidden" name="sku_id" 	value="<{$cart.post_sku_id}>"/>
		<input type="hidden" name="buy_num" value="<{$cart.post_buy_num}>"/>
	<{/if}>
	<input type="hidden" name="share_id" value="<{$cart.share_id}>"/>
	<div class="sbutton"><input type="submit" value="支付订单" name="submit" class="gopay"/></div>
</form>
<{include file="default/footer.html"}>
<script type="text/javascript"> 
$(function(){  
	if($('input:radio[name="payment"]:checked').length == 0){
		$('input:radio[name="payment"]').eq(0).prop("checked",true);
	}
	$('form').submit(function(){ 
		var address_id = $('input[name="address_id"]').val();
		if(address_id == '' || address_id == undefined){ 
			$.alert("请选择一个地址");  return false; 
		}
		var payment = $('input:radio[name="payment"]:checked').val();
		if(payment == '' || payment == undefined){ 
			$.alert("请选择一个支付方式");  return false;   
		}
		$.ajax({
			type:'POST',
			url:'index.php?m=cart&a=create_order&jq_time='+new Date().getTime(),
			data:$("#settle_form").serialize(), 
			success:function(result){	// 支付成功，跳转到订单支付页面
				data = $.parseJSON(result);
				if(data.error == '0'){ 
					location.href = "wap.php?m=account&a=pay&trade_no="+data.trade_no; 
				}else{
					$.alert(data.msg); 
				}
			},error:function(){
				$.alert('系统超时');
			}
		});
		return false;
	});
	
}); 
</script>  