<{import file="common.html" title="地址编辑"}>
<style type="text/css"> 
body{ background:#f8f8f8; } 
.addCon{ width:100%; background:#fff; margin:0 0 0.2rem 0; float:left; }
table.etable{ margin:0; }
table.etable tr td{ border-bottom:1px solid #efefef; }
table.etable tr td:first-child{ text-align:left; padding-left:10px; font-size:0.3rem; color:#333; }
table.etable tr td em{ font-style:inherit; padding:10px 0 0 10px; color:#FF0000; float:left;}
table.etable tr td input[type=text]{ width:100%; border:none; padding:10px 0; font-size:0.3rem; color:#888; float:left;} 
</style>
<body>
<div class="cnav">
	<a class="back">&nbsp;</a>编辑地址<a href="javascript:;" class="thome">主页</a>
</div>
<{uqcms m="address" v="row" c="get_one:id=smarty.get.id"}>
<div class="addCon">
	<table width="100%" class="etable">
		<tr>
			<td style="width:1.5rem;">收货人 </td>
			<td><input type="text" name="name" id="recive_name" size="38" value="<{$row.name}>" placeholder="收件人姓名"/></td>
		</tr>
		<tr>
			<td>手机号码 </td> 
			<td><input type="text" name="mobile" id="recive_mobile" size="38" value="<{$row.mobile}>" placeholder="收件人联系电话"/></td>
		</tr>
		<tr>
			<td>选择地区 </td> 
			<td><div class="area_box"></div></td>
		</tr>
		<tr>
			<td>详细地址 </td>
			<td><input type="text" name=""  id="recive_address" size="38" value="<{$row.address}>" placeholder="收件人详细地址"/></td>
		</tr>
		<tr>
			<td>区域邮编 </td>
			<td><input type="text" name="" id="recive_zip" size="38" value="<{$row.zip}>" placeholder="收件人邮编（选填）"/></td>
		</tr>
	</table> 
</div>
<div class="sbutton"><input type="submit" id="submit"  name="is_default" class="submit" value="保存"/></div>
<{import file="footer.html"}>
<script type="text/javascript" src="<{$__APP__}>public/js/area.js"></script>
<script type="text/javascript"> 
$(function(){  
	$(".area_box").area(<{if $row.prov && $row.city && $row.dist}>{'prov':<{$row.prov}>,'city':<{$row.city}>,'dist':<{$row.dist}>,'title':'<{$row.prov_cn}>/<{$row.city_cn}>/<{$row.dist_cn}>'}<{/if}>); 
	
	$(".submit").click(function(){
		var name = 		$("#recive_name").val(); 		if(name == '')	{ 	$.alert('姓名不能为空');	return false; }
		var mobile = 	$("#recive_mobile").val();		if(mobile == ''){ 	$.alert('电话不能为空');	return false; } 
		var prov = 		$("#prov").val();				if(dist == '0')	{ 	$.alert('选择省份');		return false; } 
		var city = 		$("#city").val();				if(city == '0')	{ 	$.alert('选择市区');		return false; } 
		var dist = 		$("#dist").val(); 				if(dist == '0')	{ 	$.alert('选择县级');		return false; } 
		var address = 	$("#recive_address").val();		if(address == ''){ 	$.alert('地址不能为空');	return false; } 
		var zip = 		$("#recive_zip").val(); 
		var is_default = $("#recive_is_default").is(':checked')?'1':'0'; 
		$.post('<{$__URI__}>address/edit_save',{<{if $smarty.get.id}>id:<{$smarty.get.id}>,<{/if}>name:name, mobile:mobile, prov:prov, city:city, dist:dist, address:address, zip:zip, is_default:is_default},function(result){
			var data = jQuery.parseJSON(result);  
			if(data.error == '0'){
				<{if $smarty.get.cart == '1'}>
					$.get('<{$__URI__}>cart/address_ch?id='+data.id, function(result){ 
						data = jQuery.parseJSON(result); 
						if(data.error == '0'){
							$.alert('保存成功', function(){
								location.href="<{$__WAP__}>cart/settle";
							}); 
						}else{
							$.alert(data.msg);
						}
					}); 
				<{else}>
					$.alert('保存成功',function(){
						location.href="<{$__WAP__}>address/index";
					});
					
				<{/if}>
			}else{
				$.alert(data.msg);
			} 
		});	
		
	});
}); 
</script>