<template>
  <a-form v-bind="formLayout" :form="form">
    <a-row>
      <a-col :span="12">
        <a-form-item label="收款人">
          <a-input
            v-decorator="[
              'payee',
              {
                initialValue: modalData.payee,
              }
            ]" />
        </a-form-item>
      </a-col>
      <a-col :span="12">
        <a-form-item label="收款账号">
          <a-input
            v-decorator="[
              'account',
              {
                initialValue: modalData.account,
              }
            ]" />
        </a-form-item>
      </a-col>
      <a-col :span="12">
        <a-form-item label="充值方式名称">
          <a-input
            v-decorator="[
              'rec_method_name',
              {
                initialValue: modalData.rec_method_name,
              }
            ]" />
        </a-form-item>
      </a-col>
      <a-col :span="12">
        <a-form-item label="充值方式logo">
          <a-input
            v-decorator="[
              'rec_method_logo',
              {
                initialValue: modalData.rec_method_logo,
              }
            ]" />
        </a-form-item>
      </a-col>
      <a-col :span="12">
        <a-form-item label="充值方式">
          <a-select
            placeholder="请选择充值方式"
            v-decorator="[
              'type',
              {
                initialValue: modalData.type,
                rules: [{ required: true, message: '请选择充值方式' }],
              }
            ]"
            :options="recharge_mode_options" />
        </a-form-item>
      </a-col>
      <a-col :span="12">
        <a-form-item label="充值方式编码">
          <a-input
            v-decorator="[
              'rec_method_code',
              {
                initialValue: modalData.rec_method_code,
              }
            ]" />
        </a-form-item>
      </a-col>
      <a-col :span="12">
        <a-form-item label="银行编码">
          <a-select
            placeholder="请选择开户行"
            v-decorator="[
              'bank_info_code',
              {
                initialValue: modalData.bank_info_code,
                rules: [{ required: true, message: '请选择银行编码' }],
              }
            ]"
            :options="bank_info_cas.map(v => ({ label: v.name, value: v.code }))" />
        </a-form-item>
      </a-col>
      <a-col :span="12">
        <a-form-item label="开户行">
          <a-input
            v-decorator="[
              'open_bank_name',
              {
                initialValue: modalData.open_bank_name,
              }
            ]" />
        </a-form-item>
      </a-col>
      <a-col :span="12">
        <a-form-item label="排序值">
          <a-input-number
            style="width: 100%"
            v-decorator="[
              'sequence',
              { initialValue: modalData.sequence || 0 }
            ]" />
        </a-form-item>
      </a-col>
      <a-col :span="12">
        <a-form-item label="银行编号">
          <a-input
            v-decorator="[
              'bank_code',
              {
                initialValue: modalData.bank_code,
              }
            ]" />
        </a-form-item>
      </a-col>
      <a-col :span="12">
        <a-form-item label="分行编号">
          <a-input
            v-decorator="[
              'branch_code',
              {
                initialValue: modalData.branch_code,
              }
            ]" />
        </a-form-item>
      </a-col>
      <a-col :span="12">
        <a-form-item label="国际SWIFT代码">
          <a-input
            v-decorator="[
              'swift_code',
              {
                initialValue: modalData.swift_code,
              }
            ]" />
        </a-form-item>
      </a-col>
    </a-row>
    <a-form-item label="是否启用" v-bind="blockLayout">
      <a-switch :defaultChecked="Boolean(modalData.is_enable)" v-decorator="['is_enable', { initialValue: Boolean(modalData.is_enable) }]" />
    </a-form-item>
    <a-form-item label="开户行地址" v-bind="blockLayout">
      <a-textarea v-decorator="['open_bank_address', { initialValue: modalData.open_bank_address }]" />
    </a-form-item>
    <a-form-item label="备注" v-bind="blockLayout">
      <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'
import store from '../store'
export default {
  mixins: [mix, finance(), common],
  data() {
    return {
      blockLayout: {
        labelCol: { span: 3 },
        wrapperCol: { span: 21 }
      },
      formLayout: {
        labelCol: { span: 6 },
        wrapperCol: { span: 18 }
      }
    }
  },
  computed: {
		bank_info_cas() {
			return store.state.bank_info_cas || []
		},
    // 是否新增
    isNew() {
      return !this.modalData.uuid
    },
    successMessage() {
      return this.isNew ? '添加成功' : '修改成功'
    }
  },
  mounted () {
		if (!this.bank_info_cas || !this.bank_info_cas.length) store.dispatch('getBankInfo')
  },
  methods: {
    async submit(values) {
      let is_enable=values.is_enable?1:0
      let res
      // 有id表示编辑
      if (this.isNew) {
        res = await this.request_api.finance_recharge_method.add({
          ...values,
          is_enable
        })
      } else {
        res = await this.request_api.finance_recharge_method.edit({
          uuid: this.modalData.uuid,
          version: this.modalData.version,
          ...values,
          is_enable
        })
      }
      return res
    }
  }
}
</script>
