<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
        @change="idChange"
        v-decorator="[
          'login_id',
          {
            rules: [{ required: true, message: '请输入用户ID' }],
          },
        ]"
      />
    </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 }
      },
      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 []
    }
  },
  methods: {
    async submit(values) {
      let res = await this.request_api.finance_withdraw.add({
        ...values,
        login_id: Number(values.login_id),
        amount: Number(values.amount)
      })
      if(res.err&&res.data.code==='OUT_OF_RANGE') res.errorMessage='用户余额不足'
      return res
    }
  }
}
</script>
