<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="账户姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'userName', validatorRules.userName]" placeholder="请输入账户姓名"></a-input>
        </a-form-item>

        <a-form-item label="身份证号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'idcardNumber', validatorRules.idcardNumber]" placeholder="请输入身份证号"></a-input>
        </a-form-item>

        <a-form-item label="银行卡号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'cardNumber', validatorRules.cardNumber]" placeholder="请输入银行卡号"></a-input>
        </a-form-item>

        <a-form-item label="是否招商银行" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-radio-group v-decorator="['bnkflg',validatorRules.bnkflg]">
            <a-radio value="Y">
              是
            </a-radio>
            <a-radio value="N">
              否
            </a-radio>
          </a-radio-group>
        </a-form-item>

        <a-form-item v-show="is_show" label="他行开户行" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'eacbnk', { rules: [{ required: is_show, message: '请输入他行开户行!' }] }]"
                   placeholder="请输入他行开户行"></a-input>
        </a-form-item>

        <a-form-item v-show="is_show" label="他行开户地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'rcveaa', { rules: [{ required: is_show, message: '请输入他行开户地址!' }] }]"
                   placeholder="请输入他行开户地址"></a-input>
        </a-form-item>

      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>

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

  export default {
    name: 'HlgPaymentReissueModal',
    components: {
      JDate
    },
    data() {
      return {
        form: this.$form.createForm(this),
        title: '操作',
        width: 800,
        visible: false,
        is_show: true,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        },

        confirmLoading: false,
        validatorRules: {
          userName: { rules: [{ required: true, message: '请输入账户姓名!' }] },
          idcardNumber: { rules: [{ required: true, message: '请输入身份证号!' }] },
          cardNumber: { rules: [{ required: true, message: '请输入银行卡号!' }] },
          bnkflg: { rules: [{ required: true, validator: this.checkBnkflg }] }
          // eacbnk: { rules: [{ required: is_show, message: '请输入他行开户行!' }] },
          // rcveaa: { rules: [{ required: is_show, message: '请输入他行开户地址!' }] }
        },
        url: {
          add: '/hlgpayment/hlgPaymentDetail/add',
          edit: '/hlgpayment/hlgPaymentDetail/edit'
        }

      }
    },
    created() {
    },
    methods: {
      add() {
        this.edit({})
      },
      edit(record) {
        this.form.resetFields()
        this.model = Object.assign({}, record)
        this.visible = true
        this.is_show = record.bnkflg === 'N'
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model, 'userId', 'userName', 'idcardNumber', 'cardNumber', 'bnkflg', 'eacbnk', 'rcveaa'))
        })
      },
      close() {
        this.$emit('close')
        this.$destroyAll()
        this.visible = false
      },
      handleOk() {
        const that = this
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            if (values.userName !== this.model.userName || values.idcardNumber !== this.model.idcardNumber) {
              this.$confirm({
                title: '提示',
                content: '姓名和身份证信息发生变动，将同步到绑定的需求下',
                okText: '确定',
                cancelText: '取消',
                centered: true,
                onOk: () => {
                  this.Reissue()
                },
                onCancel: () => {
                  this.$destroyAll()
                }
              })
            } else {
              this.Reissue()
            }
          }

        })
      },
      Reissue() {
        // that.confirmLoading = true
        // let httpurl = ''
        // let method = ''
        // if (!this.model.id) {
        //   httpurl += this.url.add
        //   method = 'post'
        // } else {
        //   httpurl += this.url.edit
        //   method = 'put'
        // }
        // let formData = Object.assign(this.model, values)
        // console.log('表单提交数据', formData)
        // httpAction(httpurl, formData, method).then((res) => {
        //   if (res.success) {
        //     that.$message.success(res.message)
        //     that.$emit('ok')
        //   } else {
        //     that.$message.warning(res.message)
        //   }
        // }).finally(() => {
        //   that.confirmLoading = false
        //   that.close()
        // })
        this.$message.success('已提交银行，等待银行返回结果')
      },
      checkBnkflg(rule, value, callback) {
        this.is_show = value === 'N'
        callback()
      },
      handleCancel() {
        this.close()
      },
      popupCallback(row) {
        this.form.setFieldsValue(pick(row, 'paymentId', 'userId', 'userName', 'idcardNumber', 'cardNumber', 'bnkflg', 'eacbnk', 'rcveaa', 'payment', 'paymentTime', 'paymentBy', 'paymentResultTime', 'createTime', 'createBy', 'updateTime', 'updateBy', 'sysOrgCode', 'status', 'isSupplementPayment', 'failureReason', 'delFlag'))
      }

    }
  }
</script>