<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    :maskClosable="false"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
          
        <a-form-item label="开户行" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'bankName', validatorRules.bankName]" placeholder="请输入开户行"></a-input>
        </a-form-item>
          
        <a-form-item label="开户地" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'bankAddress', validatorRules.bankAddress]" placeholder="请输入开户地"></a-input>
        </a-form-item>
          
        <a-form-item label="账户" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'bankAccount', validatorRules.bankAccount]" placeholder="请输入账户" style="width: 100%"></a-input>
        </a-form-item>
          
        
      </a-form>
    </a-spin>

  </a-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'


  
  export default {
    name: "CompanyPayBankInformationModal",
    components: {


    },
    data () {
      return {
        addtype:0,
        index:0,
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        bankName:{rules: [{ required: true, message: '请输入开户行!' }]},
        bankAddress:{rules: [{ required: true, message: '请输入开户地!' }]},
        bankAccount:{rules: [{ required: true, message: '请输入账户!' },{ validator: this.validateAbbreviation }]},
        },
        url: {
          add: "/hlgsubcontractor/hlgSubcontractorBankInformation/add",
          edit: "/hlgsubcontractor/hlgSubcontractorBankInformation/edit",
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record,addtype,index) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.addtype=addtype
        this.index=index
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'bankName','bankAddress','bankAccount'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            let formData = Object.assign(this.model, values);
            this.$emit('ok',formData,this.addtype,this.index);
            this.close()
          }
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'bankName','bankAddress','bankAccount'))
      },



      //校验只能为数字
      validateAbbreviation(rule, value, callback) {
        if (!value) {
          callback()
        } else {
          if (new RegExp(/^[0-9]*$/).test(value)) {
            callback()
          } else {
            callback('请输入数字!')
          }
        }

      },


    }
  }
</script>