<template>
  <a-form v-bind="formLayout" :form="form">
    <a-form-item label="产品名称">
      <a-input
        placeholder="请输入产品名称"
        v-decorator="[
          'product_name',
          {
            initialValue: modalData.product_name,
            rules: [{ required: true, message: '请输入产品名称' }],
          }
        ]" />
    </a-form-item>
    <a-form-item label="产品编码">
      <a-input
        placeholder="请输入产品编码"
        :disabled="!isNew"
        v-decorator="[
          'product_code',
          {
            initialValue: modalData.product_code,
            rules: [{ required: true, message: '请输入产品编码' }],
          }
        ]" />
    </a-form-item>
    <a-form-item label="描述">
      <a-textarea placeholder="请输入描述" v-decorator="['description', { initialValue: modalData.description }]" />
    </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'
export default {
  mixins: [mix, common],
  computed: {
    // 是否新增
    isNew() {
      return !this.modalData.uuid
    },
    successMessage() {
      return this.isNew ? '添加成功' : '修改成功'
    }
  },
  methods: {
    async submit(values) {
      let res
      // 有id表示编辑
      if (this.isNew) {
        res = await this.request_api.finance_product.add({
          ...values
        })
      } else {
        res = await this.request_api.finance_product.edit({
          uuid: this.modalData.uuid,
          version: this.modalData.version,
          ...values
        })
      }
      return res
    }
  }
}
</script>
