From 4625705ce124cc75969de0996f8244b57f2be812 Mon Sep 17 00:00:00 2001 From: zxy Date: Tue, 7 Apr 2026 09:08:37 +0800 Subject: [PATCH] =?UTF-8?q?feat(xzdstoragelog):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=87=BA=E5=85=A5=E5=BA=93=E5=8D=95=E6=8D=AE=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/views/heli/xzdstoragelog/index.vue | 76 ++++++++++++++++++- 1 file changed, 72 insertions(+), 4 deletions(-) diff --git a/mes-ui/mes-ui-admin-vue3/src/views/heli/xzdstoragelog/index.vue b/mes-ui/mes-ui-admin-vue3/src/views/heli/xzdstoragelog/index.vue index 4c66d5d1..c9a23e83 100644 --- a/mes-ui/mes-ui-admin-vue3/src/views/heli/xzdstoragelog/index.vue +++ b/mes-ui/mes-ui-admin-vue3/src/views/heli/xzdstoragelog/index.vue @@ -171,6 +171,7 @@ style="width: 100%" filterable clearable + @focus="handleMatSelectFocus(scope.row)" @change="(val) => handleMatIdChange(val, scope.row)" > { // 更新 materialDOList row.materialDOList = newRow.materialDOList - // 检查当前 matId 是否在新选项列表中(用 == 避免类型不匹配) - if (row.matId != null && row.matId !== '') { + if (row.matId == null || row.matId === '') { + // matId 为空:物料编码 == 1 默认选中,> 1 不选择 + if (newRow.materialDOList.length === 1) { + const mat = newRow.materialDOList[0] + row.matId = mat.id + row.matCode = mat.code + row.matName = mat.name + row._autoSelectMatId = true // 标记为自动选中 + } + } else if (row._autoSelectMatId && newRow.materialDOList.length > 1) { + // 之前是自动选中的,现在变成多条,清空 + row.matId = undefined + row.matCode = '' + row.matName = '' + row._autoSelectMatId = false + } else { + // matId 不为空:保持当前选中,检查是否仍在新列表中 const mat = newRow.materialDOList.find((m) => m.id == row.matId) if (mat) { - // 编码仍存在,重新设置对应字段 row.matId = mat.id row.matCode = mat.code row.matName = mat.name } else { - // 编码不存在了,清空 row.matId = undefined row.matCode = '' row.matName = '' @@ -391,6 +405,7 @@ const getMatCode = async () => { row.matId = undefined row.matCode = '' row.matName = '' + row._autoSelectMatId = false } }) @@ -403,6 +418,55 @@ const getMatCode = async () => { } } +/** 点击物料编码下拉框时,请求当前行的物料编码列表 */ +const handleMatSelectFocus = async (row) => { + // 避免重复请求 + if (row._loadingMatList) return + row._loadingMatList = true + try { + queryParams.ids = [row.id] + const data = await StorageLogApi.getStorageLogPage(queryParams) + const newRow = data.list?.find((r) => r.id == row.id) + if (newRow && newRow.materialDOList) { + row.materialDOList = newRow.materialDOList + + if (row.matId == null || row.matId === '') { + // matId 为空:物料编码 == 1 默认选中,> 1 不选择 + if (newRow.materialDOList.length === 1) { + const mat = newRow.materialDOList[0] + row.matId = mat.id + row.matCode = mat.code + row.matName = mat.name + row._autoSelectMatId = true // 标记为自动选中 + } + } else if (row._autoSelectMatId && newRow.materialDOList.length > 1) { + // 之前是自动选中的,现在变成多条,清空 + row.matId = undefined + row.matCode = '' + row.matName = '' + row._autoSelectMatId = false + } else { + // matId 不为空:保持当前选中,检查是否仍在新列表中 + const mat = newRow.materialDOList.find((m) => m.id == row.matId) + if (mat) { + row.matId = mat.id + row.matCode = mat.code + row.matName = mat.name + } else { + row.matId = undefined + row.matCode = '' + row.matName = '' + } + } + } + queryParams.ids = [] + } catch (error) { + console.error('获取物料编码失败:', error) + } finally { + row._loadingMatList = false + } +} + const generateBill = async () => { // 1. 检查是否选择了数据 if (multipleSelection.value.length === 0) { @@ -612,6 +676,9 @@ const getDefaultDateRange = () => { /** 物料编码变更处理 */ const handleMatIdChange = (val, row) => { + // 用户手动选择,清除自动选中标记 + row._autoSelectMatId = false + if (val && queryParams.isSameMat) { // 当勾选了"相同物料"选项时,更新所有选中行的物料编码 const selectedIds = multipleSelection.value.map((item) => item.id) @@ -620,6 +687,7 @@ const handleMatIdChange = (val, row) => { if (selectedIds.includes(item.id)) { // 更新物料 ID item.matId = val + item._autoSelectMatId = false // 手动选择 // 自动设置价格类型为"1|临时暂估价" if (!item.priceType) { item.priceType = '1|临时暂估价'