<template>
|
<ElDialog
|
:title="t('pages.basicInfo.whMat.bindLocDialog.title')"
|
:model-value="visible"
|
width="960px"
|
align-center
|
destroy-on-close
|
@update:model-value="handleCancel"
|
@closed="handleClosed"
|
>
|
<ArtForm
|
ref="formRef"
|
v-model="form"
|
:items="formItems"
|
:rules="rules"
|
:span="12"
|
: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 },
|
areaMatOptions: { type: Array, default: () => [] },
|
areaOptions: { type: Array, default: () => [] },
|
locOptions: { type: Array, default: () => [] }
|
})
|
|
const emit = defineEmits(['update:visible', 'submit'])
|
const { t } = useI18n()
|
|
const formRef = ref()
|
const form = reactive({
|
areaMatId: '',
|
areaId: '',
|
locId: []
|
})
|
|
const filteredAreaMatOptions = computed(() => {
|
const selectedAreaId =
|
form.areaId !== undefined && form.areaId !== null && form.areaId !== ''
|
? Number(form.areaId)
|
: void 0
|
if (selectedAreaId === void 0) {
|
return props.areaMatOptions
|
}
|
return props.areaMatOptions.filter(
|
(item) => item.areaId === void 0 || Number(item.areaId) === selectedAreaId
|
)
|
})
|
|
const filteredLocOptions = computed(() => {
|
const selectedAreaId =
|
form.areaId !== undefined && form.areaId !== null && form.areaId !== ''
|
? Number(form.areaId)
|
: void 0
|
if (selectedAreaId === void 0) {
|
return props.locOptions
|
}
|
return props.locOptions.filter(
|
(item) => item.areaId === void 0 || Number(item.areaId) === selectedAreaId
|
)
|
})
|
|
const formItems = computed(() => [
|
{
|
label: t('pages.basicInfo.whMat.bindLocDialog.fields.areaMatId'),
|
key: 'areaMatId',
|
type: 'select',
|
props: {
|
clearable: true,
|
filterable: true,
|
placeholder: t('pages.basicInfo.whMat.bindLocDialog.placeholders.areaMatId'),
|
options: filteredAreaMatOptions.value
|
}
|
},
|
{
|
label: t('pages.basicInfo.whMat.bindLocDialog.fields.areaId'),
|
key: 'areaId',
|
type: 'select',
|
props: {
|
clearable: true,
|
filterable: true,
|
placeholder: t('pages.basicInfo.whMat.bindLocDialog.placeholders.areaId'),
|
options: props.areaOptions
|
}
|
},
|
{
|
label: t('pages.basicInfo.whMat.bindLocDialog.fields.locId'),
|
key: 'locId',
|
type: 'select',
|
span: 24,
|
props: {
|
clearable: true,
|
filterable: true,
|
multiple: true,
|
collapseTags: true,
|
placeholder: t('pages.basicInfo.whMat.bindLocDialog.placeholders.locId'),
|
options: filteredLocOptions.value
|
}
|
}
|
])
|
|
const rules = computed(() => ({
|
areaMatId: [
|
{
|
required: true,
|
message: t('pages.basicInfo.whMat.bindLocDialog.validation.areaMatId'),
|
trigger: 'change'
|
}
|
],
|
areaId: [
|
{
|
required: true,
|
message: t('pages.basicInfo.whMat.bindLocDialog.validation.areaId'),
|
trigger: 'change'
|
}
|
],
|
locId: [
|
{
|
required: true,
|
message: t('pages.basicInfo.whMat.bindLocDialog.validation.locId'),
|
trigger: 'change'
|
}
|
]
|
}))
|
|
function resetForm() {
|
form.areaMatId = ''
|
form.areaId = ''
|
form.locId = []
|
formRef.value?.clearValidate?.()
|
}
|
|
async function handleSubmit() {
|
if (!formRef.value) return
|
try {
|
await formRef.value.validate()
|
emit('submit', {
|
areaMatId: form.areaMatId,
|
areaId: form.areaId,
|
locId: Array.isArray(form.locId) ? [...form.locId] : []
|
})
|
} 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>
|