|
|
|
|
@ -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}`, // 临时唯一标识 |
|
|
|
|
_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; |
|
|
|
|
|