<template>
|
<ElDialog
|
:title="dialogTitle"
|
:model-value="visible"
|
width="760px"
|
align-center
|
@update:model-value="handleCancel"
|
@closed="handleClosed"
|
>
|
<ArtForm
|
ref="formRef"
|
v-model="form"
|
:items="formItems"
|
:rules="rules"
|
:span="12"
|
:gutter="20"
|
label-width="110px"
|
:show-reset="false"
|
:show-submit="false"
|
/>
|
|
<template #footer>
|
<span class="dialog-footer">
|
<ElButton @click="handleCancel">{{ t('common.cancel') }}</ElButton>
|
<ElButton type="primary" @click="handleSubmit">{{ t('common.confirm') }}</ElButton>
|
</span>
|
</template>
|
</ElDialog>
|
</template>
|
|
<script setup>
|
import ArtForm from '@/components/core/forms/art-form/index.vue'
|
import { useI18n } from 'vue-i18n'
|
import { buildDeptDialogModel, createDeptFormState } from '../deptPage.helpers'
|
|
const props = defineProps({
|
visible: { required: false, default: false },
|
deptData: { required: false, default: () => ({}) },
|
deptTreeOptions: { required: false, default: () => [] }
|
})
|
|
const emit = defineEmits(['update:visible', 'submit'])
|
const { t } = useI18n()
|
const formRef = ref()
|
const form = reactive(createDeptFormState())
|
|
const isEdit = computed(() => Boolean(form.id))
|
const dialogTitle = computed(() =>
|
isEdit.value ? t('pages.system.dept.dialog.titleEdit') : t('pages.system.dept.dialog.titleCreate')
|
)
|
|
const rules = computed(() => ({
|
name: [{ required: true, message: t('pages.system.dept.validation.name'), trigger: 'blur' }]
|
}))
|
|
const formItems = computed(() => [
|
{
|
label: t('pages.system.dept.table.parent'),
|
key: 'parentId',
|
type: 'treeselect',
|
span: 24,
|
props: {
|
data: props.deptTreeOptions,
|
props: {
|
label: 'label',
|
value: 'value',
|
children: 'children'
|
},
|
placeholder: t('pages.system.dept.placeholders.parentId'),
|
clearable: false,
|
checkStrictly: true,
|
defaultExpandAll: true
|
}
|
},
|
{
|
label: t('pages.system.dept.table.name'),
|
key: 'name',
|
type: 'input',
|
props: {
|
placeholder: t('pages.system.dept.placeholders.name'),
|
clearable: true
|
}
|
},
|
{
|
label: t('pages.system.dept.table.fullName'),
|
key: 'fullName',
|
type: 'input',
|
props: {
|
placeholder: t('pages.system.dept.placeholders.fullName'),
|
clearable: true
|
}
|
},
|
{
|
label: t('pages.system.dept.table.leader'),
|
key: 'leader',
|
type: 'input',
|
props: {
|
placeholder: t('pages.system.dept.placeholders.leader'),
|
clearable: true
|
}
|
},
|
{
|
label: t('table.sort'),
|
key: 'sort',
|
type: 'number',
|
props: {
|
min: 0,
|
controlsPosition: 'right',
|
style: { width: '100%' }
|
}
|
},
|
{
|
label: t('table.status'),
|
key: 'status',
|
type: 'select',
|
props: {
|
placeholder: t('pages.system.dept.placeholders.status'),
|
options: [
|
{ label: t('common.status.normal'), value: 1 },
|
{ label: t('common.status.disabled'), value: 0 }
|
]
|
}
|
},
|
{
|
label: t('table.memo'),
|
key: 'memo',
|
type: 'input',
|
span: 24,
|
props: {
|
type: 'textarea',
|
rows: 3,
|
placeholder: t('pages.system.dept.placeholders.memo'),
|
clearable: true
|
}
|
}
|
])
|
|
const resetForm = () => {
|
Object.assign(form, createDeptFormState())
|
formRef.value?.clearValidate?.()
|
}
|
|
const loadFormData = () => {
|
Object.assign(form, buildDeptDialogModel(props.deptData))
|
}
|
|
const handleSubmit = async () => {
|
if (!formRef.value) return
|
try {
|
await formRef.value.validate()
|
emit('submit', { ...form })
|
} catch {
|
return
|
}
|
}
|
|
const handleCancel = () => {
|
emit('update:visible', false)
|
}
|
|
const handleClosed = () => {
|
resetForm()
|
}
|
|
watch(
|
() => props.visible,
|
(visible) => {
|
if (visible) {
|
loadFormData()
|
nextTick(() => {
|
formRef.value?.clearValidate?.()
|
})
|
}
|
},
|
{ immediate: true }
|
)
|
|
watch(
|
() => props.deptData,
|
() => {
|
if (props.visible) {
|
loadFormData()
|
}
|
},
|
{ deep: true }
|
)
|
</script>
|