<template>
  <a-form v-bind="formLayout" :form="form">
    <a-form-item label="充值金额">
      <a-input
        v-decorator="[
          'amount',
          {
            rules: [{ required: true, message: '请输入充值金额' }],
          },
        ]"
      />
    </a-form-item>
    <a-form-item label="用户ID">
      <a-input
        v-decorator="[
          'login_id',
          {
            rules: [{ required: true, message: '请输入用户ID' }],
          },
        ]"
      />
    </a-form-item>
    <a-form-item label="充值方式">
      <a-select
        placeholder="请选择充值方式"
        v-decorator="[
          'recharge_method_uuid',
          {
            rules: [{ required: true, message: '请选择充值方式' }],
          },
        ]"
        :options="payMethods"
      />
    </a-form-item>
    <a-form-item label="资产类型">
      <a-row :gutter="10">
        <a-col :span="property_type ? 12 : 24">
          <a-select
            placeholder="请选择资产类型"
            v-model="property_type"
            v-decorator="[
              'property_type',
              {
                rules: [{ required: true, message: '请选择资产类型' }],
              },
            ]"
            :options="
              property_type_cas.map((v) => {
                return { label: v.name, value: v.code }
              })
            "
          />
        </a-col>
        <a-col :span="12" v-if="property_type">
          <a-select
            placeholder="请选择资产币种"
            v-decorator="[
              'property_coin_type',
              {
                rules: [{ required: true, message: '请选择资产币种' }],
              },
            ]"
            :options="
              property_coin_type_cas.map((v) => {
                return { label: v.name, value: v.code }
              })
            "
          />
        </a-col>
      </a-row>
    </a-form-item>
    <a-form-item label="留言备注">
      <a-textarea v-decorator="['memo']" />
    </a-form-item>
  </a-form>
</template>
<script>
import common from '../mixins/common'
import store from '../store'
import mix from './mixins'
import finance from '../mixins/finance'
export default {
  mixins: [mix,common, finance()],
  data() {
    return {
      formLayout: {
        labelCol: { span: 6 },
        wrapperCol: { span: 18 }
      },
      payMethods: [],
      property_type: ''
    }
  },
  computed: {
    property_type_cas(){
      return store.state.property_type_cas
    },
    successMessage() {
      return '添加成功'
    },
    property_coin_type_cas() {
      let property_coin_type_cas = this.property_type_cas.filter(
        (v) => v.code === this.property_type
      )
      if (property_coin_type_cas.length)
        return property_coin_type_cas[0].children
      return []
    }
  },
  mounted(){
    this.getPayMethods()
  },
  methods: {
    async getPayMethods(){
      let res = await this.request_api.finance_recharge_method.get({
        page_size: 200,
        page_index: 1,
        is_enable: 1,
        type: 2
      })
      if (res.err) return
      if(!res.data) res.data=[]
      this.payMethods=res.data.map(vv => ({
        value: vv.uuid,
        label: vv.rec_method_name||vv.bank_name
      }))
    },
    async submit(values) {
      let res = await this.request_api.finance_recharge.add({
        ...values,
        login_id: Number(values.login_id),
        amount: Number(values.amount)
      })
      return res
    }
  }
}
</script>
