From d35fe1760e4c85045a9c22bb27254ad146526ebd Mon Sep 17 00:00:00 2001 From: "han\\hanst" Date: Fri, 28 Nov 2025 09:32:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=B9=E9=87=8F=E4=BF=AE=E6=94=B9=E4=BC=A0?= =?UTF-8?q?=E5=8F=82=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/modules/part/bom_create.vue | 42 +++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/src/views/modules/part/bom_create.vue b/src/views/modules/part/bom_create.vue index 3e69ea7..7f1f8ec 100644 --- a/src/views/modules/part/bom_create.vue +++ b/src/views/modules/part/bom_create.vue @@ -548,7 +548,7 @@
@@ -1017,6 +1017,7 @@ export default { checkedDetail: [], detailDataList: [], subDetailList: [], + batchUpdateList: [], // 批量修改临时数据,避免直接修改原数据 componentPartList: [], componentPartList1: [], batchComponentPartList: [], @@ -3944,21 +3945,32 @@ export default { this.getDataList() }, + /** + * 打开批量修改弹窗 + * 深拷贝 subDetailList 到 batchUpdateList,避免修改时影响原数据 + */ batchUpdateComponents() { + // 深拷贝数据,确保修改时不影响原表格 + this.batchUpdateList = JSON.parse(JSON.stringify(this.subDetailList)) this.batchUpdateComponentsFlag = true }, + /** + * 保存批量修改 + * 使用 batchUpdateList 临时数据进行修改和保存 + * 成功后同步回 subDetailList + */ async batchUpdateComponentsSave() { // 开启loading this.batchUpdateSaveLoading = true let flag = true // 保存原始列表长度 - const listLength = this.subDetailList.length + const listLength = this.batchUpdateList.length for (let i = 0; i < listLength; i++) { // 每次从最新的列表中获取数据,因为前面的计算可能已经更新了列表 - let row = this.subDetailList[i] + let row = this.batchUpdateList[i] this.componentData = { flag: '2', site: row.site, @@ -4050,8 +4062,25 @@ export default { try { const {data} = await computeQtyPerAssemblyEdit(this.componentData) if (data && data.code === 0) { - // 更新列表数据 - this.subDetailList = data.rows.subDetailList + // 从后端返回的列表中找到当前行(通过 componentPart 和 lineSequence 匹配) + // 然后只更新该行的计算字段,保留用户在弹窗中修改的其他行数据 + const returnedList = data.rows.subDetailList || [] + const currentRow = this.batchUpdateList[i] + + // 在返回的列表中找到对应的行 + const updatedRow = returnedList.find(item => + item.componentPart === currentRow.componentPart && + item.lineSequence === currentRow.lineSequence + ) + + if (updatedRow) { + // 只更新计算相关的字段,保留用户修改的其他字段 + this.$set(this.batchUpdateList, i, { + ...this.batchUpdateList[i], + qtyPerAssembly: updatedRow.qtyPerAssembly, // 单位用量(存储过程计算) + formula: updatedRow.formula, // 计算公式(setFormula方法设置) + }) + } } else if (data && data.code !== 0) { flag = false this.batchUpdateSaveLoading = false @@ -4074,6 +4103,9 @@ export default { this.batchUpdateSaveLoading = false if(flag) { + // 保存成功后,将修改后的数据同步回原数据 + this.subDetailList = JSON.parse(JSON.stringify(this.batchUpdateList)) + this.$message({ message: '批量修改并计算完成', type: 'success',