import { genNameValidator } from '@/utils/validator'

export const defaultFormData = {
  // 表单初始数据
  id: '',
  parentId: 0,
  parentName: '作为一级组织',
  name: '',
  remark: ''
}

export default {
  data() {
    return {
      defaultFormData: { ...defaultFormData }, // 表单初始数据（打开编辑框时传入）
      formData: { ...defaultFormData }, // 表单数据
      formOptions: [ // 表单配置
        {
          type: 'hidden',
          key: 'id',
          mode: ['edit']
        },
        {
          type: 'slot',
          slotName: 'parentId',
          label: '上级组织',
          key: 'parentName',
          rules: [
            { required: true, message: '请选择上级组织', trigger: 'blur' }
          ],
          labelWidth: '100px'
        },
        {
          type: 'input',
          label: '组织名称',
          key: 'name',
          rules: [
            { required: true, message: '请输入组织名称', trigger: 'blur' },
            { validator: genNameValidator([2, 50]), trigger: 'blur' }
          ],
          labelWidth: '100px'
        },
        {
          type: 'textarea',
          label: '备注',
          key: 'remark',
          labelWidth: '100px'
        },
        {
          type: 'hidden',
          key: 'parentId',
          rules: [
            { required: true, message: '请选择上级组织', trigger: 'blur' }
          ]
        }
      ]
    }
  },
  methods: {
    resetFormData() {
      console.log(`output->defaultFormData`, defaultFormData)
      this.defaultFormData = { ...defaultFormData }
      this.formData = { ...defaultFormData }
    }
  }
}
