<template>
  <form-list ref="form" class="mt-5" :items="formItems"></form-list>
</template>

<script>
import FormList from '@/components/Form/list'
const defaultOption = {
  value: null,
  outlined: true,
  dense: true
}
export default {
  name: 'data-asset-edit',
  components: { FormList },
  props: {
    itemData: {
      type: Object,
      default: () => ({})
    }
  },
  data () {
    return {
      formItems: {
        options: [
          {
            type: 'text',
            key: 'name',
            label: '请输入资产名称',
            ...defaultOption,
            rules: [v => !!v || '请输入资产名称']
          },
          {
            type: 'text',
            key: 'classify',
            label: '请输入分类',
            ...defaultOption,
            rules: [v => !!v || '请输入分类']
          },
          {
            type: 'text',
            key: 'institution',
            label: '请输入制作单位',
            ...defaultOption,
            rules: [v => !!v || '请输入制作单位']
          },
          {
            type: 'text',
            key: 'organization',
            label: '请输入评估机构',
            ...defaultOption,
            rules: [v => !!v || '请输入评估机构']
          },
          {
            type: 'text',
            key: 'amount',
            label: '请输入估值（万元）',
            ...defaultOption,
            rules: [v => !!v || '请输入估值（万元）']
          }
        ]
      }
    }
  },
  created () {
    if (!this.itemData.id) {
      return
    }
    this.formItems.options.forEach(item => {
      item.value = this.itemData[item.key]
    })
  },
  methods: {
    validate () {
      return this.$refs.form.validate()
    },
    getValue () {
      const id = this.itemData.id
      return this.formItems.options.reduce((res, item) => {
        res[item.key] = item.value
        return res
      }, { id })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
