// Generated by CoffeeScript 1.8.0
(function() {
  $(function() {
    $(".toast").hide();
    $("#text").html("编辑银行卡");
    var id =GetQueryString("id");
    this.Ajax({
    	url: baseUrl + '/api/user/get_bankcard_by_card_id.do',
    	data:{cardId: id},
    	callback:function(data){
    		if(data.status==200){
    			var ref=data.data.bankcard;
    			$("#name").val(ref.openName);
    			$("#cardno").val(ref.openCardno);
        		$("#bank").val(ref.openBank);
        	}else {
        		wrongMsg(data.message);
        	}
    	}
    });
    
     $("#confirm").on("click",function() {
    	 if (!isNotNull($("#bank")[0], "开户银行")) {
             return;
           }else if(!isNotNull($("#name")[0], "开户人姓名")){
           	return;
           }else if(!isBankCard($("#cardno")[0], "银行卡卡号")){
           	return;
           }
        return Ajax({
          url: baseUrl + '/api/user/update_bankcard.do?cardId='+id,
          data: $("#bankcard").serialize(),
          success: function(data) {
            if (data.status === 200) {
            	var orderId=localStorage.getItem("orderId");
              	if(orderId!=null&&orderId!="null"){
                    	localStorage.clear();
                    	return location.href ="./bankCard.html?id="+orderId;
                    }else{
                  	return location.href ="./bankCard.html";
                    }
            }else{
          	  wrongMsg(data.message);
            }
          }
        });
      });
     $("#dele").on("click",function() {
        $("#mask").show();
      });
     $("#cancle").on("click",function(){
    	$("#mask").hide(); 
     });
     $("#sure").on("click",function(){
    	 return Ajax({
             url: baseUrl + '/api/user/del_bankcard.do',
             data: {id:id},
             success: function(data) {
               if (data.status == 200) {
            	   var orderId=localStorage.getItem("orderId");
                  	if(orderId!=null&&orderId!="null"){
                        	localStorage.clear();
                        	return location.href ="./bankCard.html?id="+orderId;
                        }else{
                      	return location.href ="./bankCard.html";
                        }
               }else{
             	  wrongMsg(data.message);
               }
             }
           });
     });
  
  });
  
}).call(this);
