feat(mes): 添加级联选择器数据加载逻辑

pull/871/MERGE
YunaiV 2026-03-07 18:07:13 +08:00
parent 715135fbb1
commit 4cbfd26da7
1 changed files with 38 additions and 0 deletions

View File

@ -204,6 +204,8 @@ import MdWorkshopSelect from '@/views/mes/md/workstation/components/MdWorkshopSe
import MdClientSelect from '@/views/mes/md/client/components/MdClientSelect.vue'
import TmToolSelect from '@/views/mes/tm/tool/components/TmToolSelect.vue'
import UserSelect from '@/views/system/user/components/UserSelect.vue'
import { WmWarehouseLocationApi } from '@/api/mes/wm/warehouse/location'
import { WmWarehouseAreaApi } from '@/api/mes/wm/warehouse/area'
defineOptions({ name: 'BarcodeForm' })
@ -238,6 +240,7 @@ const formRef = ref()
const locationWarehouseId = ref<number>() //
const areaWarehouseId = ref<number>() //
const areaLocationId = ref<number>() //
const isLoadingData = ref(false) // watch
/** 业务 Select 选中回调:自动填充 bizId、bizCode、bizName */
const handleBizSelect = async (item: any) => {
@ -291,10 +294,41 @@ const handleAreaLocationChange = () => {
formData.value.content = undefined
}
/** 加载级联选择器的数据(编辑时回填上级数据) */
const loadCascadeData = async () => {
if (!formData.value.bizType || !formData.value.bizId) {
return
}
try {
// ID
if (formData.value.bizType === BarcodeBizTypeEnum.LOCATION) {
const location = await WmWarehouseLocationApi.getWarehouseLocation(formData.value.bizId)
if (location?.warehouseId) {
locationWarehouseId.value = location.warehouseId
}
}
// IDID
else if (formData.value.bizType === BarcodeBizTypeEnum.AREA) {
const area = await WmWarehouseAreaApi.getWarehouseArea(formData.value.bizId)
if (area?.warehouseId) {
areaWarehouseId.value = area.warehouseId
}
if (area?.locationId) {
areaLocationId.value = area.locationId
}
}
} catch (error) {
console.error('加载级联数据失败:', error)
}
}
/** bizType 切换时,清空业务字段 */
watch(
() => formData.value.bizType,
() => {
//
if (isLoadingData.value) return
formData.value.bizId = undefined
formData.value.bizCode = undefined
formData.value.bizName = undefined
@ -314,10 +348,14 @@ const open = async (type: string, id?: number) => {
resetForm()
if (id) {
formLoading.value = true
isLoadingData.value = true
try {
formData.value = await WmBarcodeApi.getBarcode(id)
//
await loadCascadeData()
} finally {
formLoading.value = false
isLoadingData.value = false
}
}
}