<template>
|
<ElDialog
|
:title="dialogTitle"
|
: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="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'
|
import {
|
getWhMatFlagCheckOptions,
|
getWhMatStatusOptions,
|
getWhMatStockLevelOptions
|
} from '../whMatPage.helpers'
|
|
const props = defineProps({
|
visible: { type: Boolean, default: false },
|
actionType: { type: String, default: 'status' }
|
})
|
|
const emit = defineEmits(['update:visible', 'submit'])
|
const { t } = useI18n()
|
|
const formRef = ref()
|
const form = reactive(createFormState())
|
|
function createFormState() {
|
return {
|
status: '',
|
stockLevel: '',
|
validWarn: null,
|
valid: null,
|
flagCheck: ''
|
}
|
}
|
|
const dialogTitle = computed(() =>
|
t(`pages.basicInfo.whMat.batchDialog.titles.${props.actionType}`)
|
)
|
|
const formItems = computed(() => {
|
if (props.actionType === 'status') {
|
return [
|
{
|
label: t('table.status'),
|
key: 'status',
|
type: 'select',
|
span: 24,
|
props: {
|
clearable: true,
|
placeholder: t('pages.basicInfo.whMat.search.statusPlaceholder'),
|
options: getWhMatStatusOptions(t)
|
}
|
}
|
]
|
}
|
|
if (props.actionType === 'stockLevel') {
|
return [
|
{
|
label: t('pages.basicInfo.whMat.batchDialog.fields.stockLevel'),
|
key: 'stockLevel',
|
type: 'select',
|
span: 24,
|
props: {
|
clearable: true,
|
placeholder: t('pages.basicInfo.whMat.batchDialog.placeholders.stockLevel'),
|
options: getWhMatStockLevelOptions()
|
}
|
}
|
]
|
}
|
|
if (props.actionType === 'validWarn') {
|
return [
|
{
|
label: t('pages.basicInfo.whMat.dialog.fields.validWarn'),
|
key: 'validWarn',
|
type: 'number',
|
props: {
|
min: 0,
|
controlsPosition: 'right',
|
valueOnClear: null,
|
placeholder: t('pages.basicInfo.whMat.batchDialog.placeholders.validWarn')
|
}
|
},
|
{
|
label: t('pages.basicInfo.whMat.dialog.fields.valid'),
|
key: 'valid',
|
type: 'number',
|
props: {
|
min: 0,
|
controlsPosition: 'right',
|
valueOnClear: null,
|
placeholder: t('pages.basicInfo.whMat.batchDialog.placeholders.valid')
|
}
|
}
|
]
|
}
|
|
return [
|
{
|
label: t('pages.basicInfo.whMat.dialog.fields.flagCheck'),
|
key: 'flagCheck',
|
type: 'select',
|
span: 24,
|
props: {
|
clearable: true,
|
placeholder: t('pages.basicInfo.whMat.batchDialog.placeholders.flagCheck'),
|
options: getWhMatFlagCheckOptions(t)
|
}
|
}
|
]
|
})
|
|
const rules = computed(() => {
|
if (props.actionType === 'status') {
|
return {
|
status: [
|
{
|
required: true,
|
message: t('pages.basicInfo.whMat.batchDialog.validation.status'),
|
trigger: 'change'
|
}
|
]
|
}
|
}
|
|
if (props.actionType === 'stockLevel') {
|
return {
|
stockLevel: [
|
{
|
required: true,
|
message: t('pages.basicInfo.whMat.batchDialog.validation.stockLevel'),
|
trigger: 'change'
|
}
|
]
|
}
|
}
|
|
if (props.actionType === 'validWarn') {
|
return {
|
validWarn: [
|
{
|
required: true,
|
message: t('pages.basicInfo.whMat.batchDialog.validation.validWarn'),
|
trigger: 'blur'
|
}
|
],
|
valid: [
|
{
|
required: true,
|
message: t('pages.basicInfo.whMat.batchDialog.validation.valid'),
|
trigger: 'blur'
|
}
|
]
|
}
|
}
|
|
return {
|
flagCheck: [
|
{
|
required: true,
|
message: t('pages.basicInfo.whMat.batchDialog.validation.flagCheck'),
|
trigger: 'change'
|
}
|
]
|
}
|
})
|
|
function resetForm() {
|
Object.assign(form, createFormState())
|
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>
|