// Generated by CoffeeScript 1.8.0
(function() {
  $(function() {
    $(".toast").hide();
    $("#text").html("编辑邮寄地址");
    var id =GetQueryString("id");
    this.Ajax({
    	url: baseUrl + '/api/user/get_address_by_address_id.do',
    	data:{addressId : id},
    	callback:function(data){
    		if(data.status==200){
    			var ref=data.data.address;
    			$("#addressId").val(id);
    			$("#name").val(ref.contact);
        		$("#phone").val(ref.phone);
        		$("#address").val(ref.address);
        	}else {
        		wrongMsg(data.message);
        	}
    	}
    });
    
     $("#confirm").on("click",function() {
        if (!isValidMobile($("#phone")[0], "手机号")) {
        	toast.hide();
          return;
        }
        return Ajax({
          url: baseUrl + '/api/user/update_address.do?addressId'+id,
          data: $("#emailAdd").serialize(),
          success: function(data) {
            if (data.status === 200) {
            	var orderId=localStorage.getItem("orderId");
            	if(orderId!=null){
                  	localStorage.clear();
                  	return location.href ="./email.html?id="+orderId;
                  }else{
                	return location.href ="./email.html";
                  }
            }else{
          	  wrongMsg(data.message);
          	  setTimeout(function(){
          		toast.hide();
          	  },500);
            }
          }
        });
      });
     $("#dele").on("click",function() {
        $("#mask").show();
      });
     $("#cancle").on("click",function(){
    	$("#mask").hide(); 
     });
     $("#sure").on("click",function(){
    	 return Ajax({
             url: baseUrl + '/api/user/del_address.do',
             data: {id:id},
             success: function(data) {
            	
               if (data.status == 200) {
            	   var orderId=localStorage.getItem("orderId");
               	if(orderId!=null){
                     	localStorage.clear();
                     	return location.href ="./email.html?id="+orderId;
                     }else{
                   	return location.href ="./email.html";
                     }
               }else{
             	  wrongMsg(data.message);
             	  setTimeout(function(){
                		toast.hide();
              	  },500);
               }
             }
           });
     });
  
  });
  
}).call(this);
