<template>
|
<ElDialog
|
:title="t('pages.basicInfo.whMat.batchGroupDialog.title')"
|
:model-value="visible"
|
width="640px"
|
align-center
|
destroy-on-close
|
@update:model-value="handleCancel"
|
@closed="handleClosed"
|
>
|
<ArtForm
|
ref="formRef"
|
v-model="form"
|
:items="formItems"
|
:rules="rules"
|
:span="24"
|
:gutter="20"
|
label-width="120px"
|
: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 { computed, nextTick, reactive, ref, watch } from 'vue'
|
import { useI18n } from 'vue-i18n'
|
import ArtForm from '@/components/core/forms/art-form/index.vue'
|
|
const props = defineProps({
|
visible: { type: Boolean, default: false },
|
groupOptions: { type: Array, default: () => [] }
|
})
|
|
const emit = defineEmits(['update:visible', 'submit'])
|
const { t } = useI18n()
|
|
const formRef = ref()
|
const form = reactive({ groupId: '' })
|
|
const formItems = computed(() => [
|
{
|
label: t('pages.basicInfo.whMat.dialog.fields.groupId'),
|
key: 'groupId',
|
type: 'treeselect',
|
props: {
|
data: props.groupOptions,
|
props: {
|
label: 'displayLabel',
|
value: 'value',
|
children: 'children'
|
},
|
placeholder: t('pages.basicInfo.whMat.dialog.placeholders.groupId'),
|
clearable: false,
|
checkStrictly: true,
|
defaultExpandAll: true
|
}
|
}
|
])
|
|
const rules = computed(() => ({
|
groupId: [
|
{
|
required: true,
|
message: t('pages.basicInfo.whMat.dialog.validation.groupId'),
|
trigger: 'change'
|
}
|
]
|
}))
|
|
function resetForm() {
|
form.groupId = ''
|
formRef.value?.clearValidate?.()
|
}
|
|
async function handleSubmit() {
|
if (!formRef.value) return
|
try {
|
await formRef.value.validate()
|
emit('submit', { ...form })
|
} catch {
|
return
|
}
|
}
|
|
function handleCancel() {
|
emit('update:visible', false)
|
}
|
|
function handleClosed() {
|
resetForm()
|
}
|
|
watch(
|
() => props.visible,
|
(visible) => {
|
if (visible) {
|
resetForm()
|
nextTick(() => {
|
formRef.value?.clearValidate?.()
|
})
|
}
|
},
|
{ immediate: true }
|
)
|
</script>
|