<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>订单结算 - <{$UQCMS.site_name}></title>
<link rel="stylesheet" type="text/css" href="<{$__PUBLIC__}>css/common_uqcms.css">  
<link rel="stylesheet" type="text/css" href="<{$__APP__}>public/css/public.css">
<link rel="stylesheet" type="text/css" href="<{$__APP__}>public/css/settle.css">
</head> 
<body>
<{include file="default/top.html"}>
<{include file="default/cart/header.html"}>
<div class="main_bar">
	<div class="main"> 
	<form action="#" method="post" id="settle_form"> 
		<!-- 购买地址 --> 
		<div class="addr">
			<div class="name"><span>确认收货地址</span></div>  
			<{uqcms m="address" v="addr" c="get_all"}> 
			<{if $addr}>
				<div class="con"> 
					<{foreach item=i from=$addr}>
					<div class="addr_box add_con_<{$i.id}>">
						<label>
							<span>送至</span>
							<input type="radio" name="address_id" value="<{$i.id}>" <{if $i.is_default == '1'}>checked="checked"<{/if}>/>
							<p> <{$i.prov_cn}> <{$i.city_cn}> <{$i.dist_cn}> <{$i.address}> ( <{$i.name}> 收) <{$i.mobile}></p>
						</label>
						<div class="rt">
							<a href="javascript:;" addrid="<{$i.id}>" onClick="address_edit('修改地址','member.php?m=address&a=edit&type=1&id=<{$i.id}>')">编辑</a>
							<a href="javascript:;" addrid="<{$i.id}>" class="address_del">删除</a>	
						</div>	
					</div> 
					<{/foreach}> 
				</div>
			<{else}> 
				<div class="add_box"><span class="noaddr">请添加地址</span></div> 
			<{/if}>
			<div class="addr_add">
				<a href="javascript:;" onClick="address_edit('添加地址','member.php?m=address&a=edit&type=1')">添加新地址</a>
			</div>
		</div>
		
		<!------购物清单列表-------> 
		<div class="cart_name"><span>商品清单</span></div>
		<div class="cart">
		<{uqcms m="cart" v="cart" c="settle"}>
		<{if $cart}>	
			<{foreach item=i from=$cart.list}> 
				<div class="cart_box">
					<div class="name">
						<i class="sp_icon" style="background:url(<{$__PUBLIC__}>images/icon/shop.png)"></i>
						<a href="index.php?m=shop&a=show&id=<{$c.id}>" target="_blank">店铺：<{$i.name}></a>
						<{if $i.sps_reduce_name}>
							<span class="reduce_box"><{$i.sps_reduce_name}></span>
						<{/if}>
						<div class="ms">
							<div class="zd m2">单价</div>
							<div class="zd m3">数量</div>
							<div class="zd m4">小计</div>
							<div class="zd m5">状态</div>
						</div>	
					</div> 
					<!--产品购买列表-->
					<{foreach item=ii from=$i.goods}>
						<div class="desc cart_detail_<{$ii.id}>">
							<div class="gs_con">
								<div class="images">
									<a href="index.php?m=goods&a=detail&id=<{$ii.gid}>" target="_blank">
										<img src="<{$__IMG__}><{$ii.images|img_size:80x80}>" width="70"/>
									</a>
								</div>
								<div class="ttl">
									<div class="sttl"><a href="?m=goods&a=detail&id=<{$ii.gid}>" target="_blank" class="gttl"><{$ii.title}></a></div>
									<div class="sku">
										<{if $ii.sku_name}>
											<{foreach item=iii from=$ii.sku_name}>
												 <span style="color:#999999;"><{$iii.0}>：<{$iii.1}> &nbsp;&nbsp;&nbsp;</span>
											<{/foreach}>
										<{/if}>
									</div>
								</div>
							</div>
							<div class="cart_right">
								<div class="ct">
									<span> ¥ <{$ii.price}><{if $ii.act_status}><a class="cuxiao">促</a><{/if}></span>
									<s> ¥ <{$ii.market_price}></s>
								</div>
								<div class="ct"><{$ii.buy_num}> </div> 
								<div class="ct zs">¥<{$ii.goods_total_price}></div> 
								<div class="ct"><{if $ii.stock_status}>有货<{else}>无货<{/if}></div> 
							</div>
						</div> 
					<{/foreach}>
					<!--留言和金额部分-->
					<div class="ly">
						<div class="left">
							<span>留言：</span>
							<p><input type="text" name="message[<{$i.id}>]" size="50" placeholder="选填:填写内容已和卖家协商确认"/></p>
						</div>
						<div class="right">
							<div class="info"><span>商品费用</span> <strong><{$i.goods_price}></strong></div>  
							<div class="info express_price_<{$i.id}>"><span>运费</span><strong><{$i.express_price}></strong></div>
							<{if $i.reduce_name}>
								<div class="info"><span>优惠</span> <strong>-<{$i.reduce_price}> </strong></div>
							<{/if}> 
							<div class="info"><span>店铺合计(含运费)</span><strong>¥ <{$i.total_price}></strong></div> 
						</div>
					</div>
					 
				</div>
			<{/foreach}> 
		<{else}>
			<div class="cart_no_goods">提交的订单为空</div>
			<script type="text/javascript"> location.href="index.php?m=cart"; </script>
		<{/if}> 
		</div>
		<div class="total_div">
			<div class="total_price">
				<span>实付款：</span>
				<p><{$cart.total_price}></p>
				<span style="padding-left:5px;">元</span>
			</div> 
		</div> 
		<div class="submit_order">
			<div class="lft">
				<a href="index.php?m=cart&a=index">返回购物车修改</a>
				<{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}>"/>
				<input type="submit" name="submit" class="gopay" value="下单支付"/>
			</div>
		</div>
	</form>
	</div>
</div>
<{include file="default/footer.html"}>
<script type="text/javascript">
var PUBLIC_PATH	= '<{$__PUBLIC__}>';
var APP_PATH	= '<{$__APP__}>';
var IMG_HOST 	= '<{$__IMG__}>'; 
</script>
<script type="text/javascript" src="<{$__PUBLIC__}>js/jquery.min.js"></script>
<script type="text/javascript" src="<{$__PUBLIC__}>js/common.js"></script>
<script type="text/javascript"> 
$(function(){  
	/* 地址删除 */
	$(document).on('click',".address_del",function(){ 
		$this = $(this);
		var id = $this.attr('addrid');
		$.post('member.php?m=address&a=del', {id:id}, function(result){
			data = jQuery.parseJSON(result); 
			if(data.error == '0'){
				$('.add_con_'+id).remove(); 
				var div_num = $('.add_con').length;
				if(div_num == '0'){ 
					$(".add_box").html('<span class="noaddr">请添加地址</span>');
				}		 
			}else{
			 	alert(data.msg); 
			}
		});
	});	
	// 设为默认
	$(document).on('click',".address_default",function(){ 
		$this = $(this);
		var id = $this.attr('addrid'); 
		$.post('member.php?m=address&a=ajax_address_only',{id:id},function(data){ 
			if(data == '1'){
				$(".add_con input:radio[name=address_id]").prop("checked",false);
				$('.add_con_'+id+' input:radio[name=address_id]').prop("checked",true);
			}else{
			 	alert(data);	
			}
		});
	});
	// 选择地址获取邮费
	$("input[name=address_id]").click(function(){
		$this = $(this);
		addr_id = $this.val();
		$.post('index.php?m=cart&a=get_express_price',{addr_id:addr_id}, function(result){ 
			data = jQuery.parseJSON(result); 
			if(data.error == '0'){
				$.each(data.list, function(k,v){ 
					$(".express_price_"+k+" strong").html(v);
				}); 
			} 
		});
	}); 
	// 支付默认第一个自动选择
	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"]:checked').val();
		if(address_id == '' || address_id == 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="member.php?m=account&a=pay&trade_no="+data.trade_no;
				}else{
					$.alert(data.msg); 
				}
			},error:function(){
				$.alert('系统超时');
			}
		});
		return false;
	}); 
}); 
function address_edit(name, url){
	ajax_dialog(name,url,'455'); 
}
function pay_status_box(){
	var dialog_con = '<div class="dg_bgcolor"></div><div class="dg_box_bar">'+
	 					'<div class="pay_status_box">'+
							'<div class="tishi"><p>付款提示,请您在新打开的页面进行支付，支付完成前请不要关闭此窗口。</p></div>'+
							'<div class="jguo">'+
								'<a href="index.php?m=news&a=help&id=6">支付遇到了问题</a>'+
								'<a href="member.php?m=buy">查看结果</a>'+
							'</div>'+
						'</div>'+
					'</div>'; 
	$("body").after(dialog_con).css({opacity:'0',marginTop:'-10px'}).animate({opacity:'1',marginTop:'0'},300); 
	showOverlay();
} 
</script>