From a79792f777c19d6f10c4355f34f294c8c8c17a99 Mon Sep 17 00:00:00 2001 From: fengyuan_yang <1976974459@qq.com> Date: Fri, 8 May 2026 17:15:44 +0800 Subject: [PATCH] =?UTF-8?q?2026-05-08=20RoHs=E5=8A=9F=E8=83=BD=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/rohs/rohs.js | 3 + src/views/modules/rohs/rohsRecord.vue | 148 +++++++++++++++++++++++--- 2 files changed, 135 insertions(+), 16 deletions(-) diff --git a/src/api/rohs/rohs.js b/src/api/rohs/rohs.js index 98015b1..f1b9852 100644 --- a/src/api/rohs/rohs.js +++ b/src/api/rohs/rohs.js @@ -15,6 +15,9 @@ export const saveRohs = data => createAPI(`/rohs/save`, 'post', data); // 修改 export const updateRohs = data => createAPI(`/rohs/update`, 'post', data); +// 仅保存材料明细(编辑时即时保存) +export const updateRohsMaterials = data => createAPI(`/rohs/updateMaterials`, 'post', data); + // 下达 export const issueRohs = data => createAPI(`/rohs/issue`, 'post', data); diff --git a/src/views/modules/rohs/rohsRecord.vue b/src/views/modules/rohs/rohsRecord.vue index 44341bb..4cdb5a9 100644 --- a/src/views/modules/rohs/rohsRecord.vue +++ b/src/views/modules/rohs/rohsRecord.vue @@ -299,7 +299,7 @@ -
+
@@ -318,6 +318,24 @@ + + + + + +
@@ -398,6 +416,9 @@ + + 关闭 + @@ -446,7 +467,7 @@ 确定 - 取消 + 关闭 @@ -643,16 +664,34 @@ + + + + + +
-
+
@@ -761,7 +800,7 @@ export default { columnSortable: false, status: true, fixed: '', - columnWidth: 240 + columnWidth: 200 }, { columnProp: 'createDate', @@ -773,7 +812,7 @@ export default { columnSortable: false, status: true, fixed: '', - columnWidth: 140 + columnWidth: 150 }, { columnProp: 'createBy', @@ -785,7 +824,7 @@ export default { columnSortable: false, status: true, fixed: '', - columnWidth: 140 + columnWidth: 120 } ], @@ -1296,9 +1335,9 @@ export default { this.$set(this.modalData, 'commGroup1Desc', '') this.$set(this.modalData, 'commGroup2Desc', '') this.$set(this.modalData, 'commGroup3Desc', '') - // 编辑时允许重新选择客户和项目 - this.$set(this.modalData, 'endCustomerFlag', false) - this.$set(this.modalData, 'projectIdFlag', !this.modalData.endCustomer) + // 编辑时不允许修改最终客户和项目编码 + this.$set(this.modalData, 'endCustomerFlag', true) + this.$set(this.modalData, 'projectIdFlag', true) this.$set(this.modalData, 'createBy2', '') this.$set(this.modalData, 'isReject', 'Y') this.$set(this.modalData, 'tpProcessControl', 'N') @@ -1584,18 +1623,42 @@ export default { this.$message.warning('请至少选择一条项目物料') return } - this.appendMaterialRows(this.projectMaterialSelections) - this.projectMaterialDialogFlag = false + const appendResult = this.appendMaterialRows(this.projectMaterialSelections) + if (!appendResult.appendedCount) { + this.$message.warning('所选物料已存在,未新增数据') + return + } + if (!this.shouldPersistMaterialsImmediately()) { + this.$set(this.modalData, 'materialList', appendResult.materialList) + this.projectMaterialDialogFlag = false + this.$message.success('已加入材料列表,保存单据后写入数据库') + return + } + this.$confirm('确认新增选中材料?', '提示', { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: 'warning' + }).then(() => { + this.persistMaterialList(appendResult.materialList, '新增材料成功', () => { + this.projectMaterialDialogFlag = false + this.projectMaterialSelections = [] + if (this.$refs.projectMaterialTable) { + this.$refs.projectMaterialTable.clearSelection() + } + }) + }).catch(() => {}) }, appendMaterialRows (rows) { const materialList = Array.isArray(this.modalData.materialList) ? [...this.modalData.materialList] : [] const exists = new Set(materialList.map(item => item.testPartNo)) + let appendedCount = 0 rows.forEach(row => { const testPartNo = row.testPartNo || row.test_part_no if (!testPartNo || exists.has(testPartNo)) { return } exists.add(testPartNo) + appendedCount++ materialList.push({ site: this.modalData.site, referenceNo: this.modalData.referenceNo, @@ -1607,11 +1670,53 @@ export default { partSpec: row.partSpec || row.part_spec || '' }) }) - this.$set(this.modalData, 'materialList', materialList) + return { + materialList, + appendedCount + } }, materialSelectionChange (rows) { this.materialSelections = rows || [] }, + shouldPersistMaterialsImmediately () { + return this.modalTitle === 'RoHs 编辑' && this.modalData && this.modalData.referenceNo && !String(this.modalData.referenceNo).startsWith('TEMP-') + }, + normalizeMaterialListForSave (materialList) { + return (materialList || []).map((item, index) => { + return { + ...item, + lineNo: index + 1, + projectId: item.projectId || this.modalData.projectId || '' + } + }) + }, + persistMaterialList (materialList, successMsg, successCallback) { + const normalizedList = this.normalizeMaterialListForSave(materialList) + const payload = { + site: this.modalData.site, + referenceNo: this.modalData.referenceNo, + projectId: this.modalData.projectId, + materialList: normalizedList + } + api.updateRohsMaterials(payload).then(({data}) => { + if (data && data.code === 0) { + this.$set(this.modalData, 'materialList', normalizedList) + this.modalData.ifsPartNo = normalizedList.length > 0 ? normalizedList[0].testPartNo : '' + this.materialSelections = [] + if (this.currentRow && this.currentRow.referenceNo === this.modalData.referenceNo) { + this.$set(this.currentRow, 'materialList', normalizedList) + } + this.$message.success(successMsg || '保存成功') + if (typeof successCallback === 'function') { + successCallback() + } + } else { + this.$message.error((data && data.msg) || '保存失败') + } + }).catch(() => { + this.$message.error('保存失败') + }) + }, removeSelectedMaterialRows () { if (this.showModalFlag) { return @@ -1622,8 +1727,19 @@ export default { } const removeSet = new Set(this.materialSelections.map(item => item.testPartNo)) const materialList = (this.modalData.materialList || []).filter(item => !removeSet.has(item.testPartNo)) - this.$set(this.modalData, 'materialList', materialList) - this.materialSelections = [] + if (!this.shouldPersistMaterialsImmediately()) { + this.$set(this.modalData, 'materialList', materialList) + this.materialSelections = [] + this.$message.success('已删除材料,保存单据后写入数据库') + return + } + this.$confirm('确认删除选中材料?', '提示', { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: 'warning' + }).then(() => { + this.persistMaterialList(materialList, '删除材料成功') + }).catch(() => {}) }, // ======== chooseList相关方法 ======== // 获取基础数据列表 @@ -1733,7 +1849,7 @@ export default { if (data.rows && data.rows.length === 1) { const customer = data.rows[0] this.modalData.endCustomerName = customer.customerDesc || customer.Customer_desc || customer.customerName || '' - this.modalData.projectIdFlag = false + this.modalData.projectIdFlag = !!this.modalData.endCustomerFlag } else { this.modalData.endCustomerName = '' this.modalData.projectId = ''