fix: BomManage 修复外部跳转时查重逻辑 - 遍历分组 items 查找 parent_id,并主动触发背景列表刷新

This commit is contained in:
DXC
2026-05-15 09:48:52 +08:00
parent 950b8dd671
commit 33879c33f7

View File

@ -818,28 +818,36 @@ const submitForm = async () => {
} }
onMounted(() => { onMounted(() => {
fetchBomList() // 处理外部跳转自动打开 BOM带查重保护
// 【新增】:处理外部跳转自动打开 BOM带查重保护
if (route.query.create_for_id) { if (route.query.create_for_id) {
const parentId = Number(route.query.create_for_id); const parentId = Number(route.query.create_for_id);
const parentName = (route.query.parent_name as string) || ''; const parentName = (route.query.parent_name as string) || '';
const parentSpec = (route.query.parent_spec as string) || ''; const parentSpec = (route.query.parent_spec as string) || '';
// 把名称填入背景搜索框,让背后的表格也只显示相关的BOM // 1. 把名称填入背景搜索框,并真正触发一次列表搜索,让背景列表也只显示该物料
searchKeyword.value = parentName; searchKeyword.value = parentName;
fetchBomList();
// 延迟等待基础渲染 // 2. 延迟等待基础渲染后进行查重
setTimeout(() => { setTimeout(() => {
// 1. 先用 keyword 查询是否已有该父件的 BOM
getBomList({ keyword: parentName }).then((res: any) => { getBomList({ keyword: parentName }).then((res: any) => {
const rows = res.data || []; const groups = res.data || [];
// 严格校验 parent_id let existingBom = null;
const existingBom = rows.find((b: any) => b.parent_id === parentId);
// ★ 修复点:遍历分组 (groups) 里的 items 来查找正确的 parent_id
for (const group of groups) {
if (group.items && group.items.length > 0) {
const found = group.items.find((b: any) => b.parent_id === parentId);
if (found) {
existingBom = found;
break; // 找到了就跳出循环
}
}
}
if (existingBom) { if (existingBom) {
// ★ 情况 A已经有BOM了直接打开编辑弹窗并拉取历史数据 // ★ 情况 A已经有BOM了直接打开编辑(查看)弹窗
ElMessage.success('检测到该物料已有 BOM已自动为您打开编辑'); ElMessage.success('检测到该物料已有 BOM已自动为您打开');
handleEdit(existingBom); handleEdit(existingBom);
} else { } else {
// ★ 情况 B还没建过BOM打开新建并注入父件 // ★ 情况 B还没建过BOM打开新建并注入父件
@ -862,11 +870,11 @@ onMounted(() => {
}, 100); }, 100);
} }
} }
}).catch(err => {
console.error('BOM 查重失败', err);
ElMessage.error('获取 BOM 状态失败,请手动操作');
}); });
}, 300); }, 300);
} else {
// 如果不是从其他页面跳转过来的,直接正常加载全部列表
fetchBomList();
} }
}) })
</script> </script>