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

<script>
import FormList from '@/components/Form/list'
export default {
  name: 'edit-page',
  components: { FormList },
  props: {
    itemData: {
      type: Object,
      default: () => {}
    }
  },
  data () {
    return {
      formItems: {
        options: [
          {
            type: 'text',
            key: 'name',
            value: null,
            label: '请输入路由名称 *',
            outlined: true,
            dense: true,
            rules: [v => !!v || '请输入路由名称']
          },
          {
            type: 'text',
            key: 'label',
            value: null,
            label: '请输入标题 *',
            outlined: true,
            dense: true,
            rules: [v => !!v || '请输入标题']
          },
          {
            type: 'text',
            key: 'enName',
            value: null,
            label: '请输入英文标题 *',
            outlined: true,
            dense: true,
            rules: [v => !!v || '请输入英文标题']
          },
          {
            type: 'number',
            key: 'sort',
            value: 0,
            label: '请输入排序序号 *',
            outlined: true,
            dense: true,
            rules: [v => typeof +v === 'number' || '请输入排序序号']
          },
          {
            type: 'ifRadio',
            key: 'active',
            value: null,
            label: '是否激活 *',
            items: [
              { label: '是', value: '1' },
              { label: '否', value: '0' }
            ]
          }
        ]
      }
    }
  },
  created () {
    // console.log(this.itemData)
    this.formItems.options.forEach(e => {
      e.value = this.itemData[e.key]
    })
  },
  methods: {
    getValue () {
      if (!this.$refs.form.validate()) return
      return this.formItems.options.reduce((res, item) => {
        res[item.key] = item.value
        return res
      }, {})
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
