$(function () {
  //保存
  function submitFunction(e){
      var postdata = new FormData();
      postdata.append('tradingPlatformId',$("[name=tradingPlatformId]").val());
      postdata.append('platformName',$("[name=platformName]").val());
      postdata.append('socialCreditCode',$("[name=socialCreditCode]").val());
      postdata.append('address',$("[name=address]").val());
      postdata.append('phoneNumber',$("[name=phoneNumber]").val());
      if(!$("[name=platformInvoiceId]").val() == false) {
        postdata.append('id',$("[name=platformInvoiceId]").val());
      }
      var url = '/platform/doEditInvoice',tip='提交';

      $.ajax({
          url:url,
          type:'post',
          data:postdata,
          processData:false,
          contentType:false,
          success:function(data){
              if( data.success ){
                  new $.zui.Messager( tip+'成功', {
                      type: 'success'
                  }).show();
                  $(".yk_rightcontent").load('/platform/platformList');
                  return false;
              }else{
                  new $.zui.Messager(tip+'失败:'+data.msg, {
                      type: 'danger'
                  }).show();
              }
          },
          error:function(status){
              new $.zui.Messager(tip+'时发生错误:'+status, {
                  type: 'danger'
              }).show();
          }
      });
      return false;
  };

  var formRules = {
      'socialCreditCode':{
          required:true,
      },
      'address':{
          required:true,
      },
      'phoneNumber':{
          required:true,
          number:true
      }
  };

  var formMessages = {
      'socialCreditCode':{
          required:'请输入纳税人识别号',
      },
      'address':{
          required:'请输入地址',
      },
      'phoneNumber':{
          required:'请输入电话',
      }
  };

  //表单验证
  function addNewCustomer(e){
      $("#businessAddForm").validate({
          promptPosition : "bottomLeft",
          submitHandler : function(form) {
              if( $('.error.shows').length>0 ){
                $('.error.shows:first').prev().focus();
                return;
              };
              submitFunction(e);
          },
          rules:formRules,
          messages : formMessages
      });
  };
  //提交按钮
  $(".yk_addNewMsg .submitBusiness").click(addNewCustomer);

  //关闭按钮
  $(".yk_addNewMsg .btn-cancel, .newBackBtn").click(function(){
      $(".yk_rightcontent").load('/platform/platformList');
      return false;
  });


})
