<{import file="mheader.html" title="收货地址"}>
<style type="text/css">  
.addtab{ width:100%; border-bottom:none; padding:0 0 12px 0; float:left; }
.addtab a{ border:1px solid #ddd; padding:7px 25px; font-size:12px; border-radius:2px; font-weight:100; background:#f8f8f8; color:#333; float:left; }
a.edit_font{ margin:0 12px 0 0; float:left; }
</style> 
<div class="tab"><span>收货地址</span></div>
<div class="lbox">
	<div class="addtab"> 
		<a href="javascript:;" onClick="edit('添加地址', '<{$__URI__}>address/edit')" id="add_address">新增收货地址</a>
	</div>
	<table class="ltable">
		<thead>
			<tr>
				<th width="65">姓名</th>
				<th width="100">电话</th>
				<th width="130">所在地</th>
				<th>地址</th>
				<th width="80">邮编</th>
				<th width="100">操作</td>
				<th width="80"></th>
			</tr>
		</thead>
		<tbody>
			<{uqcms m="address" v="add" c="get_all"}> 	
			<{if $add}> 	
				<{foreach item=i from=$add}>		
					<tr>
						<td><{$i.name}></td>
						<td><{$i.mobile}></td>
						<td><{$i.area}></td>
						<td><{$i.address}> </td> 
						<td><{$i.zip}> </td> 
						<td>
							<a href="javascript:;" class="edit_font" onClick="edit('修改地址','<{$__URI__}>address/edit?id=<{$i.id}>')">编辑</a>
							<a href="javascript:;" class="addr_del" data-id="<{$i.id}>">删除</a>
						</td>
						<td>
							<div class="dft_box">
								<{if $i.is_default == '1'}>
									<a style="color:#f00;">默认</a>
								<{else}>
									<a href="javascript:;" class="set_default" data-id="<{$i.id}>">设为默认</a>
								<{/if}>
							</div> 
						</td> 
					</tr>
				<{/foreach}>
			<{else}>
				<tr><td colspan="6" class="btm"><div class="nomsg"><i></i><span>您还没添加送货地址~</span></div></td></tr> 
			<{/if}>
		</tbody> 
	</table>
</div> 	 
<{import file="mfooter.html"}>
<script type="text/javascript"> 
function edit(name,url){ 
	ajax_dialog(name, url, 550); 
} 
// 设为默认 
$(document).on("click",".set_default",function(){ 
	$this = $(this);
	var id = $(this).attr('data-id');
	$.post(URI+'address/set_default',{id:id},function(result){
		var data = jQuery.parseJSON(result); 
		if(data.error == '0'){
			$.alert('设置成功', function(){
				location.reload();
			});
		}else{
			$.alert(data.msg);
		}
	});
});
// 删除地址
$(document).on("click",".addr_del",function(){ 
	if (!confirm("确认要删除？")) { 
		if(window.event){
			window.event.returnValue = false;
		}else{
			event.preventDefault();	//for firefox
		}
	}else{
		$this = $(this);
		var id = $this.attr('data-id');
		$.post(URI+'address/del', {id:id}, function(result){
			var data = jQuery.parseJSON(result);  
			if(data.error == '0'){ 
				$.alert('删除成功', function(){
					location.reload();
				});
			}else{
				alert(data.msg);
			}
		});	
	}
});
</script>