feat(mes): 优化条件值校验逻辑,调整 valueId 处理方式

pull/871/MERGE
YunaiV 2026-03-31 18:47:57 +08:00
parent 55ca892c9c
commit 134cddc54c
2 changed files with 19 additions and 6 deletions

View File

@ -4,7 +4,7 @@ export interface StockTakingPlanParamVO {
id?: number id?: number
planId?: number planId?: number
type?: number type?: number
valueId?: number | string valueId?: number
valueCode?: string valueCode?: string
valueName?: string valueName?: string
remark?: string remark?: string

View File

@ -154,7 +154,7 @@ import { DICT_TYPE, getIntDictOptions, getStrDictOptions } from '@/utils/dict'
import { import {
StockTakingPlanParamApi, StockTakingPlanParamApi,
type StockTakingPlanParamVO type StockTakingPlanParamVO
} from '@/api/mes/wm/stocktaking/plan/param/index' } from '@/api/mes/wm/stocktaking/plan/param'
import { MesWmStockTakingParamTypeEnum } from '@/views/mes/utils/constants' import { MesWmStockTakingParamTypeEnum } from '@/views/mes/utils/constants'
import WmWarehouseSelect from '@/views/mes/wm/warehouse/components/WmWarehouseSelect.vue' import WmWarehouseSelect from '@/views/mes/wm/warehouse/components/WmWarehouseSelect.vue'
import WmWarehouseLocationSelect from '@/views/mes/wm/warehouse/components/WmWarehouseLocationSelect.vue' import WmWarehouseLocationSelect from '@/views/mes/wm/warehouse/components/WmWarehouseLocationSelect.vue'
@ -223,7 +223,19 @@ const formData = ref<StockTakingPlanParamVO>({
}) })
const formRules = reactive({ const formRules = reactive({
type: [{ required: true, message: '请选择条件类型', trigger: 'change' }], type: [{ required: true, message: '请选择条件类型', trigger: 'change' }],
valueId: [{ required: true, message: '条件值不能为空', trigger: 'change' }] valueId: [
{
validator: (_rule: any, _value: any, callback: any) => {
// 使 valueId valueCode
if (formData.value.type === MesWmStockTakingParamTypeEnum.QUALITY_STATUS) {
callback(formData.value.valueCode ? undefined : new Error('请选择质量状态'))
} else {
callback(formData.value.valueId ? undefined : new Error('条件值不能为空'))
}
},
trigger: 'change'
}
]
}) })
const formRef = ref() const formRef = ref()
@ -324,7 +336,7 @@ const handleBatchChange = (batch?: any) => {
const handleQualityStatusChange = (val: string) => { const handleQualityStatusChange = (val: string) => {
const dictOptions = getStrDictOptions(DICT_TYPE.MES_WM_QUALITY_STATUS) const dictOptions = getStrDictOptions(DICT_TYPE.MES_WM_QUALITY_STATUS)
const selected = dictOptions.find((d) => d.value === val) const selected = dictOptions.find((d) => d.value === val)
formData.value.valueId = val // ID valueCode formData.value.valueId = undefined // ID
formData.value.valueCode = val formData.value.valueCode = val
formData.value.valueName = selected?.label || '' formData.value.valueName = selected?.label || ''
} }
@ -358,16 +370,17 @@ const loadCascadeData = async () => {
return return
} }
try { try {
const vid = formData.value.valueId as number
// ID // ID
if (formData.value.type === MesWmStockTakingParamTypeEnum.LOCATION) { if (formData.value.type === MesWmStockTakingParamTypeEnum.LOCATION) {
const location = await WmWarehouseLocationApi.getWarehouseLocation(formData.value.valueId) const location = await WmWarehouseLocationApi.getWarehouseLocation(vid)
if (location?.warehouseId) { if (location?.warehouseId) {
locationWarehouseId.value = location.warehouseId locationWarehouseId.value = location.warehouseId
} }
} }
// IDID // IDID
else if (formData.value.type === MesWmStockTakingParamTypeEnum.AREA) { else if (formData.value.type === MesWmStockTakingParamTypeEnum.AREA) {
const area = await WmWarehouseAreaApi.getWarehouseArea(formData.value.valueId) const area = await WmWarehouseAreaApi.getWarehouseArea(vid)
if (area?.warehouseId) { if (area?.warehouseId) {
areaWarehouseId.value = area.warehouseId areaWarehouseId.value = area.warehouseId
} }