<template>
  <a-form v-bind="formLayout" :form="form">
    <a-form-item label="产品">
      <a-select
        placeholder="请选择产品"
        :disabled="!isNew"
        v-decorator="[
          'product_uuid',
          {
            initialValue: modalData.product_uuid,
            rules: [{ required: true, message: '请选择产品' }]
          }
        ]"
        :options="product_options"
      />
    </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"
            :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
        :disabled="!isNew"
        placeholder="请输入产品编码"
        v-decorator="[
          'product_code',
          {
            initialValue: modalData.product_code,
            rules: [{ required: true, message: '请输入产品编码' }],
          }
        ]" />
    </a-form-item> -->
    <a-form-item label="成本价">
			<a-input-number
				:min="0"
				style="width:100%"
				v-decorator="[
					'cost_price',
					{ initialValue: modalData.cost_price || 0 }
				]" />
    </a-form-item>
    <a-form-item label="原定出售价">
			<a-input-number
				:min="0"
				style="width:100%"
				v-decorator="[
					'sell_price',
					{ initialValue: modalData.sell_price || 0 }
				]" />
    </a-form-item>
    <a-form-item label="实际出售价">
			<a-input-number
				:min="0"
				style="width:100%"
				v-decorator="[
					'actual_sell_price',
					{ initialValue: modalData.actual_sell_price || 0 }
				]" />
    </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 ? '添加成功' : '修改成功'
    },
    product_options() {
      return store.getters.product_options || []
    },
		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_product_price.add({
          ...values
        })
      } else {
        res = await this.request_api.finance_product_price.edit({
          uuid: this.modalData.uuid,
          version: this.modalData.version,
          ...values
        })
      }
      return res
    }
  }
}
</script>
