From 78eac2f24297dd193e7d167dfa7e95e910e4e166 Mon Sep 17 00:00:00 2001 From: "han\\hanst" Date: Tue, 4 Nov 2025 21:58:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=8C=E5=87=BB=E7=BC=96=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inquiryTechnicalMaterialsNoBuilt.vue | 6 +- src/views/modules/part/quicklyCreateBom.vue | 207 +++++++++++++++++- 2 files changed, 203 insertions(+), 10 deletions(-) diff --git a/src/views/modules/inquiry/inquiryTechnicalMaterialsNoBuilt.vue b/src/views/modules/inquiry/inquiryTechnicalMaterialsNoBuilt.vue index 0bf48d4..eba4b36 100644 --- a/src/views/modules/inquiry/inquiryTechnicalMaterialsNoBuilt.vue +++ b/src/views/modules/inquiry/inquiryTechnicalMaterialsNoBuilt.vue @@ -412,7 +412,7 @@
@@ -562,6 +562,8 @@ export default { }, data() { return { + // 本地height副本(用于替代prop,避免直接修改prop) + localHeight: this.height || 200, userBuList: [], copyPriceCheckDetail:{}, loading:false, @@ -1555,7 +1557,7 @@ export default { mounted() { this.$nextTick(() => { /*第二个表格高度的动态调整*/ - this.height = window.innerHeight - 210; + this.localHeight = window.innerHeight - 210; }) EventBus.$on('refreshInquiryOneDetail2', () => { this.refreshCurrentTabTable(); diff --git a/src/views/modules/part/quicklyCreateBom.vue b/src/views/modules/part/quicklyCreateBom.vue index 6e9f860..0f3a592 100644 --- a/src/views/modules/part/quicklyCreateBom.vue +++ b/src/views/modules/part/quicklyCreateBom.vue @@ -16,15 +16,12 @@ 维护 - - - 物料属性批量维护 - @@ -1821,6 +1827,12 @@ export default { ] }, dataList: [{}], + editingCell: { + rowIndex: -1, + columnProp: null, + value: '', + isSaving: false + }, currentNode: {}, partCurrentRow: {}, bomCurrentRow: {}, @@ -5343,6 +5355,171 @@ export default { } }, + // 双击单元格开始编辑 + startEditCell(rowIndex, columnProp, value) { + this.editingCell.rowIndex = rowIndex + this.editingCell.columnProp = columnProp + this.editingCell.value = value || '' + + // 下一帧聚焦输入框 + this.$nextTick(() => { + if (this.$refs.editInput && this.$refs.editInput[0]) { + this.$refs.editInput[0].focus() + } + }) + }, + + // 保存单元格编辑 + async saveEditCell(rowIndex, columnProp, columnLabel) { + // 防止重复保存 + if (this.editingCell.isSaving) { + return + } + + const newValue = this.editingCell.value + const oldValue = this.dataList[rowIndex][columnProp] + + // 值未改变,直接取消编辑 + if (newValue === oldValue) { + this.cancelEditCell() + return + } + + this.editingCell.isSaving = true + + // 显示loading + const loading = this.$loading({ + lock: true, + text: '保存中...', + spinner: 'el-icon-loading', + background: 'rgba(0, 0, 0, 0.5)' + }) + + try { + // 更新本地显示 + this.$set(this.dataList[rowIndex], columnProp, newValue) + + // 先获取当前属性的完整信息 + let itemTemplate = null + await getPartItem({ + site: this.$store.state.user.site, + buNo: this.searchData.buNo, + partNo: this.searchData.partNo, + codeNo: this.searchData.codeNo, + recordType: 'IP' + }).then(({data}) => { + if (data && data.code === 0 && data.rows) { + itemTemplate = data.rows.find(item => item.itemDesc === columnLabel) + } + }) + + if (!itemTemplate) { + loading.close() + this.$message.error('未找到属性配置') + this.$set(this.dataList[rowIndex], columnProp, oldValue) + this.editingCell.isSaving = false + this.cancelEditCell() + return + } + + // 根据属性类型更新对应的值 + if (itemTemplate.valueTypeDb === 'N') { + // 数值类型 + const parsedValue = parseFloat(newValue) + if (newValue !== '' && isNaN(parsedValue)) { + loading.close() + this.$message.error('请输入有效的数值') + this.$set(this.dataList[rowIndex], columnProp, oldValue) + this.editingCell.isSaving = false + this.cancelEditCell() + return + } + itemTemplate.numValue = newValue === '' ? null : parsedValue + itemTemplate.textValue = '' + } else { + // 文本类型 + itemTemplate.textValue = newValue || '' + itemTemplate.numValue = null + } + + // 准备保存到后端 + let tempData = { + site: this.$store.state.user.site, + buNo: this.searchData.buNo, + partNo: this.searchData.partNo, + codeNo: this.searchData.codeNo + } + + // 获取所有物料 + await partInfoByMainPart(tempData).then(({data}) => { + if (data && data.code === 0) { + this.$set(this, 'partList1', data.rows) + } + }) + + // 构建保存数据 + let list = [] + let partList = this.partList1.filter(item => item.buNo === this.searchData.buNo) + + for (let i = 0; i < partList.length; i++) { + if (partList[i].partNo && partList[i].partNo !== '' && partList[i].buNo) { + // 克隆item对象并更新部分字段 + let itemCopy = JSON.parse(JSON.stringify(itemTemplate)) + itemCopy.site = partList[i].site + itemCopy.buNo = partList[i].buNo + itemCopy.partNo = partList[i].partNo + itemCopy.codeNo = partList[i].codeNo + itemCopy.recordType = 'IP' + + list.push({ + site: partList[i].site, + buNo: partList[i].buNo, + partNo: partList[i].partNo, + codeNo: partList[i].codeNo, + recordType: 'IP', + itemList: [itemCopy] + }) + } + } + + // 调用保存接口 + commitItemsValue(list).then(({data}) => { + loading.close() + if (data && data.code === 0) { + this.$message.success('保存成功') + this.editingCell.isSaving = false + this.cancelEditCell() + } else { + this.$message.error(data.msg || '保存失败') + this.$set(this.dataList[rowIndex], columnProp, oldValue) + this.editingCell.isSaving = false + this.cancelEditCell() + } + }).catch(error => { + loading.close() + this.$message.error('保存异常') + this.$set(this.dataList[rowIndex], columnProp, oldValue) + this.editingCell.isSaving = false + this.cancelEditCell() + }) + + } catch (error) { + loading.close() + this.$message.error('操作失败') + this.$set(this.dataList[rowIndex], columnProp, oldValue) + this.editingCell.isSaving = false + this.cancelEditCell() + } + }, + + // 取消单元格编辑 + cancelEditCell() { + this.editingCell.rowIndex = -1 + this.editingCell.columnProp = null + this.editingCell.value = '' + this.editingCell.isSaving = false + }, + openColumnModal(desc, prop) { this.partItemList1 = [] this.itemProp = prop @@ -5856,6 +6033,20 @@ export default { width: 100%; min-width: 320px; } +// 单元格编辑样式 +::v-deep .el-table__body-wrapper { + .el-table__row { + .cell { + div[style*="cursor: pointer"] { + &:hover { + background-color: #f5f7fa; + border-radius: 2px; + transition: background-color 0.2s; + } + } + } + } +} .structure-tree { .el-scrollbar .el-scrollbar__wrap { overflow-x: hidden;