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

<script>
import FormList from '@/components/Form/list'
import {
  metadata
} from '@/utils/dataGovernance'
export default {
  name: 'data-label-edit',
  components: { FormList },
  props: {
    itemData: {
      type: Object,
      default: () => ({})
    }
  },
  data () {
    return {
      formItems: {
        options: [
          {
            type: 'text',
            key: 'name_zh',
            value: null,
            label: '请输入名称 *',
            outlined: true,
            dense: true,
            rules: [v => !!v || '请输入名称']
          },
          {
            type: 'autocomplete',
            key: 'category',
            value: null,
            label: '请输入分类 *',
            outlined: true,
            dense: true,
            items: metadata,
            rules: [v => !!v || '请输入分类']
          },
          // {
          //   type: 'text',
          //   key: 'group',
          //   value: null,
          //   label: '请输入分组',
          //   outlined: true,
          //   dense: true
          // },
          {
            type: 'text',
            key: 'scope',
            value: null,
            outlined: true,
            dense: true,
            label: '请输入适用范围'
          },
          {
            type: 'text',
            key: 'describe',
            value: null,
            label: '请输入描述',
            outlined: true,
            dense: true
          },
          {
            type: 'ifRadio',
            key: 'group',
            value: false,
            label: '标记为业务域',
            width: 120,
            items: [{ label: '是', value: true }, { label: '否', value: false }]
          },
          {
            type: 'ifRadio',
            key: 'status',
            value: true,
            label: '启用',
            width: 120,
            items: [{ label: '是', value: true }, { label: '否', value: false }]
          }
        ]
      }
    }
  },
  created () {
    if (!Object.keys(this.itemData).length) {
      return
    }
    this.formItems.options.forEach(item => {
      item.value = this.itemData[item.key]
    })
  },
  methods: {
    getValue () {
      if (!this.$refs.form.validate()) {
        return
      }

      const params = this.formItems.options.reduce((acc, cur) => {
        acc[cur.key] = cur.value
        return acc
      }, {})
      // 编辑带id
      if (this.itemData?.id) params.id = this.itemData.id

      return params
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
