import { ref, reactive } from 'vue'
import { USER_STATUS } from '@/utils/dictionary.js'
import { getDeptAll } from '@/api/system/dept/index'
import { dataToSelect } from '@/utils/handleData.js'
const departmentOptions = ref()

export const form = reactive({
  departmentForm: {
    code: '',
    name: '',
    sort: null,
    pid: null,
    note: ''
  },
  departmentRules: {
    code: [{ required: true, message: '请输入部门编号', trigger: 'blur' }],
    name: [{ required: true, message: '请输入部门名称', type: 'string', trigger: 'blur' }],
    sort: [{ required: true, type: 'number', message: '请输入排序号', trigger: 'blur' }]
  },
  formItem: [
    { type: 'input', key: 'code', label: '部门编号', props: { maxlength: '20', placeholder: '请输入部门编号', clearable: true }},
    { type: 'input', key: 'name', label: '部门名称', props: { maxlength: '20', placeholder: '请输入部门名称', clearable: true }},
    { type: 'select', key: 'pid', label: '所属部门', props: { options: departmentOptions, placeholder: '请选择所属部门' }},
    { type: 'number', key: 'sort', label: '排序号', props: { min: 0, placeholder: '请输入排序号', clearable: true }},
    { type: 'input', key: 'note', label: '备注', props: { type: 'textarea', autosize: { maxlength: '200', minRows: 3, maxRows: 3 }}}
  ]
})

export const getDeptOptions = async function() {
  const res = await getDeptAll()
  departmentOptions.value = dataToSelect(res.data, { label: 'name', value: 'id' })
}
