<template>
  <a-form v-bind="formLayout" :form="form">
    <a-form-item label="资产类型">
			<a-row :gutter="10">
				<a-col :span="property_type ? 12 : 24">
					<a-select
						placeholder="请选择资产类型"
						v-model="property_type"
            :disabled="!isNew"
						v-decorator="[
							'property_type',
							{
								initialValue: modalData.property_type,
								rules: [{ required: true, message: '请选择资产类型' }]
							}
						]"
						:options="property_type_cas.map((v) => ({ label: v.name, value: v.code }))"
					/>
				</a-col>
				<a-col :span="12" v-if="property_type">
					<a-select
						placeholder="请选择资产币种"
            :disabled="!isNew"
						v-decorator="[
							'property_coin_type',
							{
								initialValue: modalData.property_coin_type,
								rules: [{ required: true, message: '请选择资产币种' }]
							}
						]"
						:options="property_coin_type_cas.map((v) => ({ label: v.name, value: v.code }))"
					/>
				</a-col>
			</a-row>
    </a-form-item>
    <a-form-item label="限制数量">
			<a-input-number
				:min="0"
				style="width:100%"
				v-decorator="[
					'recharge_online_limit_count',
					{ initialValue: modalData.recharge_online_limit_count || 0 }
				]" />
    </a-form-item>
    <a-form-item label="是否主币种">
			<a-radio-group
				v-decorator="[
					'is_main',
					{ initialValue: modalData.is_main || 0 }
				]">
				<a-radio :value="1">是</a-radio>
				<a-radio :value="0">否</a-radio>
			</a-radio-group>
    </a-form-item>
    <a-form-item label="备注">
      <a-textarea placeholder="请输入备注" v-decorator="['memo', { initialValue: modalData.memo }]" />
    </a-form-item>
  </a-form>
</template>
<script>
import mix from './mixins'
import common from '../mixins/common'

import store from '../store'
export default {
  mixins: [mix, common],
  data () {
    return {
			// 选中的类型
      property_type: this.modalData.property_type
    }
  },
  computed: {
    // 是否新增
    isNew() {
      return !this.modalData.uuid
    },
    successMessage() {
      return this.isNew ? '添加成功' : '修改成功'
    },
		property_type_cas() {
			return store.state.property_type_cas || []
		},
    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
      // 有id表示编辑
      if (this.isNew) {
        res = await this.request_api.finance_currency.add({
          ...values
        })
      } else {
        res = await this.request_api.finance_currency.edit({
          uuid: this.modalData.uuid,
          version: this.modalData.version,
          ...values
        })
      }
      return res
    }
  }
}
</script>
