<!--{assign var="menu_id" value="cp"}-->
<!--{include file="<!--{$oetplpath}-->block_header.tpl"}-->
<div class="oe_ntop">
  <i class="iconfont" onclick="goBack();">&#xe616;</i>
  <p>编辑收货地址</p>
</div>
<div class="oe_address_add">
  <dl>
  	<dt>收 货 人</dt>
  	<dd><input type="text" name="contname" id="contname" placeholder="请输入收货人姓名" value="<!--{$address.contname}-->" /></dd>
  </dl>
  <dl>
  	<dt>联系电话</dt>
  	<dd><input type="text" name="contphone" id="contphone" placeholder="请输入联系电话" value="<!--{$address.contphone}-->" /></dd>
  </dl>
  <dl>
  	<dt>所在地区</dt>
  	<dd>
      <label>
		<!--{area type='select' name='area' depth='1' child='1' text='请选择' value=$address.area1}-->
		<span id="json_area2">
		  <!--{if $address.area1 > 0}-->
		  <!--{area type='select' name='area' depth='2' child='1' text='请选择' parentid=$address.area1 value=$address.area2}-->
		  <!--{else}-->
		  <select name="area2" id="area2"><option value="">请选择</option></select>
		  <!--{/if}-->
		</span>
		<span id="json_area3">
		  <!--{if $address.area2 > 0}-->
		  <!--{area type='select' name='area' depth='3' child='1' text='请选择' parentid=$address.area2 value=$address.area3}-->
		  <!--{else}-->
		  <select name="area3" id="area3"><option value="">请选择</option></select>
		  <!--{/if}-->
		</span>
	  </label>
      <i style="display:none;" class="iconfont">&#xe615;</i>
    </dd>
  </dl>
  <dl>
  	<dt>所在街道</dt>
  	<dd><input type="text" name="street" id="street" placeholder="街道详细地址" value="<!--{$address.street}-->" /></dd>
  </dl>
  <dl>
  	<dt>邮政编码</dt>
  	<dd><input type="text" name="zipcode" id="zipcode" placeholder="邮政编码" value="<!--{$address.zipcode}-->" /></dd>
  </dl>

  <div class="ge"></div>
  <dl f="but_select_default"<!--{if $address.isdefault == '1'}--> class='current'<!--{/if}-->>
  	<dt>设为默认地址</dt>
  	<dd><span class="iconfont">&#xe61b;</span></dd>
  </dl>

  <div class="oe_address_btn">
    <input type="hidden" name="isdefault" id="isdefault" value="<!--{$address.isdefault}-->" />
    <span f="but_submit" style="cursor:pointer;">编辑保存</span>
  </div>
  <p style="padding:10px;text-align:center;" id="tips_submit"></p>

</div>

<script type="text/javascript">
$(function(){
	
	//默认地址
	$("[f='but_select_default']").bind("click", function(){
		if ($(this).hasClass("current")) {
			$(this).removeClass("current");
			$("#isdefault").val(0);
		}
		else {
			$(this).addClass("current");
			$("#isdefault").val(1);
		}
	});

	//编辑保存
	$(document).on("click", "[f='but_submit']", function(){
		$tips_obj = $("#tips_submit");

		$contname = $("#contname").val();
		$contphone = $("#contphone").val();
		$area1 = $("#area1").val();
		$area2 = $("#area2").val();
		$area3 = $("#area3").val();
		$street = $("#street").val();
		$zipcode = $("#zipcode").val();
		$isdefault = $("#isdefault").val();

		if ($contname.length == 0) {
			$tips_obj.html("<font color='red'>请填写收货人</font>");
			return false;
		}
		if ($contphone.length == 0) {
			$tips_obj.html("<font color='red'>请填写联系方式</font>");
			return false;
		}
		if ($area1 <= 0) {
			$tips_obj.html("<font color='red'>请选择所在地区</font>");
			return false;
		}
		if ($area2 <= 0) {
			$tips_obj.html("<font color='red'>请选择所在地区</font>");
			return false;
		}
		if ($street.length == 0) {
			$tips_obj.html("<font color='red'>请填写所在街道</font>");
			return false;
		}

		$_urlitems = "&contname="+encodeURIComponent($contname)+"&contphone="+encodeURIComponent($contphone)+"&area1="+encodeURIComponent($area1)+"&area2="+encodeURIComponent($area2)+"&area3="+encodeURIComponent($area3)+"&street="+encodeURIComponent($street)+"&zipcode="+encodeURIComponent($zipcode)+"&isdefault="+encodeURIComponent($isdefault)+"";

		$_url = WAP_APPFILE + "&c=<!--{$c}-->&a=saveedit&id=<!--{$address.addrid}-->"+$_urlitems;
		$post_json = {"url":$_url, "success_text":"编辑成功", "fail_text":"编辑失败", "tips_box":"tips_submit"};
		_oemarryAjaxPost($post_json);

	});


});
</script>
</body>
</html>