From f1d4088555c5277d0a1b61f48c31bd4e9f153d28 Mon Sep 17 00:00:00 2001
From: zhangdi <1104545947@qq.com>
Date: Wed, 27 May 2026 18:27:49 +0800
Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E8=89=BA=E9=97=AE=E9=A2=98=E4=BF=AE?=
=?UTF-8?q?=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../processMainte/processPlanning.vue | 102 ++++++++++--------
.../productionTesting/InspectionTemplate.vue | 4 +-
.../zhgd-work/childWarehousing/index.vue | 69 +++++++-----
3 files changed, 102 insertions(+), 73 deletions(-)
diff --git a/src/views/processManagement/components/processMainte/processPlanning.vue b/src/views/processManagement/components/processMainte/processPlanning.vue
index 0124200d..8fb633d7 100644
--- a/src/views/processManagement/components/processMainte/processPlanning.vue
+++ b/src/views/processManagement/components/processMainte/processPlanning.vue
@@ -677,52 +677,64 @@ export default {
},
// 导入检验项目模板
importInspectionTemplate() {
+ // 1. 验证选择
+ if (!this.cascaderValue || this.cascaderValue.length === 0) {
+ return this.$message.warning('请选择模板');
+ }
+
+ const templateId = this.cascaderValue[this.cascaderValue.length - 1];
this.modelLevelLoading = true;
- getInspectionDetail({
- id: this.cascaderValue,
- })
+
+ getInspectionDetail({ id: templateId })
.then(res => {
this.modelLevelLoading = false;
- console.log('res--------------------------', res.data.data);
- const templateData = res.data.data.detailList;
+ const templateData = res.data.data?.detailList; // 确保路径正确
+
if (!templateData || !Array.isArray(templateData)) {
return this.$message.warning('模板数据为空');
}
- // 获取当前已有数据长度,用于生成新的 trialNo
+
+ // 2. 生成新数据
const existingLength = this.form2.tableData2.length;
- // 映射模板数据为表格所需格式,并生成 trialNo
const mappedData = templateData.map((item, index) => {
- // 生成项目编号:例如 P001, P002...
- const trialNo = `P${String(existingLength + index + 1).padStart(3, '0')}`;
+ // 生成项目编号 P001, P002...
+ const trialNo = this.treeNodes.processNo + '-' + this.getProcessNo(this.form2.tableData2);
- // 根据 projectCode 查找 projectName(如果需要)
+ // 获取项目名称
let projectName = '';
- if (item.projectCode) {
- const projectOption = this.projectOptions.find(p => p.id === item.projectCode);
+ if (item.inspectionItemId) {
+ const projectOption = this.projectOptions.find(p => p.id === item.inspectionItemId);
projectName = projectOption ? projectOption.name : '';
}
+ // 获取标准名称
+ let projectStandardName = '';
+ if (item.standardId) {
+ const standardOption = this.standardList.find(s => s.id === item.standardId);
+ projectStandardName = standardOption ? standardOption.name : '';
+ }
+
return {
- id: null, // 新增数据无 ID
- _tempId: `temp_${Date.now()}_${index}`, // 临时唯一标识
+ id: null, // 新增数据无ID
+ _tempId: `temp_project_${Date.now()}_${index}`,
trialNo: trialNo,
projectCode: item.inspectionItemId || '',
- projectName: projectName || item.projectName || '',
+ projectName: projectName,
projectStandard: item.standardId || '',
- projectStandardName: item.projectStandardName || '',
+ projectStandardName: projectStandardName,
proHours: item.proHours != null ? item.proHours : 0,
prepareHours: item.prepareHours != null ? item.prepareHours : 0,
};
});
- // ✅ 追加模式:不覆盖,而是拼接到现有数据后面
+ // 3. 追加到现有表格
this.form2.tableData2 = [...this.form2.tableData2, ...mappedData];
-
- this.$message.success('模板导入成功,请检查后保存');
- // this.form2.tableData2 = res.data.data;
+ this.$message.success('模板导入成功');
})
.catch(err => {
+ console.error('导入失败:', err);
this.modelLevelLoading = false;
+ this.$message.error('模板导入失败,请重试');
});
},
changeMtId(val, item, index) {
@@ -1023,16 +1035,17 @@ export default {
const findAndSelectNode = nodes => {
for (let node of nodes) {
if (node.id === this.cachedSelectedNodeId) {
- // 模拟点击事件恢复数据
- this.handleNodeClick(node, {
+ // 构造模拟的 node 对象(el-tree 需要 level 和 parent)
+ const mockNode = {
level: node.level,
parent: {
- data: this.getParentNode(this.data, node.id),
+ data: node.level === 1 ? null : this.getParentNode(this.data, node.id),
isRoot: node.level === 1,
},
- });
+ };
- // 视觉选中
+ // 恢复数据和视觉选中
+ this.handleNodeClick(node, mockNode);
this.$nextTick(() => {
if (this.$refs.tree) {
this.$refs.tree.setCurrentKey(node.id);
@@ -1048,20 +1061,33 @@ export default {
return false;
};
- findAndSelectNode(this.data);
+ // 如果找不到缓存节点(如被删除),则回退到根节点
+ if (!findAndSelectNode(this.data)) {
+ this.cachedSelectedNodeId = null;
+ if (this.data.length > 0) {
+ this.handleNodeClick(this.data[0], {
+ level: 1,
+ parent: { data: null, isRoot: true },
+ });
+ this.$refs.tree?.setCurrentKey(this.data[0].id);
+ }
+ }
},
// 辅助方法:获取父节点
getParentNode(nodes, targetId, parent = null) {
for (let node of nodes) {
- if (node.id === targetId) {
- return parent;
+ // 检查子节点是否包含目标ID
+ if (node.children && node.children.some(child => child.id === targetId)) {
+ return node;
}
+
+ // 递归查找
if (node.children && node.children.length > 0) {
- const found = this.getParentNode(node.children, targetId, node);
- if (found) return found;
+ const parent = this.getParentNode(node.children, targetId);
+ if (parent) return parent;
}
}
- return null;
+ return null; // 根节点无父节点
},
autoSelectFirstProcess() {
if (!this.data || this.data.length === 0) return;
@@ -1704,12 +1730,7 @@ export default {
.then(res => {
this.$message.success('保存成功');
this.craftLoading = false;
- // ✅ 更新工序节点下的项目数据
- if (this.treeLeave === 3) {
- this.treeNodes.rawData.projectList = this.form2.tableData2;
- this.updateTreeNodeProject();
- this.refreshTableData(); // ✅ 刷新右侧表格
- }
+ this.getDetails(true);
})
.catch(err => {
this.craftLoading = false;
@@ -1730,12 +1751,7 @@ export default {
.then(res => {
this.$message.success('保存成功');
this.craftLoading = false;
- // ✅ 更新工序节点下的量具数据
- if (this.treeLeave === 3) {
- this.treeNodes.rawData.measuringToolList = this.form3.tableData3;
- this.updateTreeNodeProject();
- this.refreshTableData(); // ✅ 刷新右侧表格
- }
+ this.getDetails(true); // 统一刷新逻辑
})
.catch(err => {
this.craftLoading = false;
diff --git a/src/views/productionTesting/InspectionTemplate.vue b/src/views/productionTesting/InspectionTemplate.vue
index 84c8ee2d..b23dee9e 100644
--- a/src/views/productionTesting/InspectionTemplate.vue
+++ b/src/views/productionTesting/InspectionTemplate.vue
@@ -759,8 +759,8 @@ export default {
this.tidList = res.data.data.detailList;
if (this.tidList.length > 0) {
this.tidList.map(item => {
- item.inspectionItemId = item.inspectionItemId+''
- item.inspectionTemplateId = item.inspectionTemplateId+''
+ item.inspectionItemId = item.inspectionItemId?item.inspectionItemId+'':item.inspectionItemId
+ item.standardId = item.standardId?item.standardId+'':item.standardId
});
}
this.showDialog = true;
diff --git a/src/views/zhgd-work/childWarehousing/index.vue b/src/views/zhgd-work/childWarehousing/index.vue
index 5368c80b..b5231ebc 100644
--- a/src/views/zhgd-work/childWarehousing/index.vue
+++ b/src/views/zhgd-work/childWarehousing/index.vue
@@ -16,19 +16,6 @@