<template>
  <a-form v-bind="formLayout" :form="form">
    <a-form-item label="银行logo">
      <a-input
        v-decorator="[
          'bank_logo',
          {
            initialValue: modalData.bank_logo,
            rules: [{ required: true, message: '银行logo不能为空' }],
          }
        ]" />
    </a-form-item>
    <a-form-item label="银行名称">
      <a-input
        v-decorator="[
          'bank_name',
          {
            initialValue: modalData.bank_name,
            rules: [{ required: true, message: '银行名称不能为空' }],
          }
        ]" />
    </a-form-item>
    <a-form-item label="银行编码" v-if="isNew">
      <a-input
        v-decorator="[
          'bank_info_code',
          {
            initialValue: modalData.bank_info_code,
            rules: [{ required: true, message: '银行编码不能为空' }],
          }
        ]" />
    </a-form-item>
    <a-form-item label="类型" v-if="isNew">
      <a-select
        placeholder="请选择类型"
        v-decorator="[
          'bank_type',
          {
            initialValue: modalData.bank_type,
            rules: [{ required: true, message: '请选择类型' }],
          }
        ]"
        :options="bank_type_options" />
    </a-form-item>
    <a-form-item label="备注">
      <a-textarea v-decorator="['memo', { initialValue: modalData.memo }]" />
    </a-form-item>
  </a-form>
</template>
<script>
import mix from './mixins'
import finance from '../mixins/finance'
import common from '../mixins/common'
export default {
  mixins: [mix, finance(), common],
  data() {
    return {
      formLayout: {
        labelCol: { span: 6 },
        wrapperCol: { span: 18 }
      }
    }
  },
  computed: {
    // 是否新增
    isNew() {
      return !this.modalData.uuid
    },
    successMessage() {
      return this.isNew ? '添加成功' : '修改成功'
    }
  },
  methods: {
    async submit(values) {
      let res
      // 有id表示编辑
      if (this.isNew) {
        res = await this.request_api.finance_bank_info.add({
          ...values
        })
      } else {
        res = await this.request_api.finance_bank_info.edit({
          uuid: this.modalData.uuid,
          version: this.modalData.version,
          ...values
        })
      }
      return res
    }
  }
}
</script>
