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