From ae33b44468e8306f9c071d8f0b0e6ba34a13ef68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A0=82=E7=B3=96?= Date: Tue, 29 Jul 2025 15:22:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BABOM=E9=98=B2=E6=AD=A2?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E7=82=B9=E5=87=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/views/wms/bom/components/BomPanel.vue | 72 ++++++++++++------- 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/klp-ui/src/views/wms/bom/components/BomPanel.vue b/klp-ui/src/views/wms/bom/components/BomPanel.vue index bb845b51..f8f1e349 100644 --- a/klp-ui/src/views/wms/bom/components/BomPanel.vue +++ b/klp-ui/src/views/wms/bom/components/BomPanel.vue @@ -2,9 +2,20 @@
- + + + +
@@ -56,7 +67,8 @@ export default { loading: false, error: null, data: null, - info: {} + info: {}, + createLoading: false, }; }, watch: { @@ -96,33 +108,41 @@ export default { } }, - handleCreate() { - // 触发自定义事件 - addBom({ - bomName: (this.type == 'product' ? '产品BOM' : '原材料BOM') + new Date().getTime(), - bomCode: (this.type == 'product' ? 'P' : 'R') + new Date().getTime() - }).then(bom => { + async handleCreate() { + // 防止重复点击 + if (this.createLoading) return; + + try { + this.createLoading = true; + const bomResponse = await addBom({ + bomName: (this.type == 'product' ? '产品BOM' : '原材料BOM') + new Date().getTime(), + bomCode: (this.type == 'product' ? 'P' : 'R') + new Date().getTime() + }); + this.$message.success('创建BOM成功'); - console.log(bom, this.itemId) - if (this.type == 'product') { - updateProduct({ + const bomData = bomResponse.data; + + // 根据类型更新产品/原材料 + if (this.type == 'product' && this.itemId) { + await updateProduct({ productId: this.itemId, - bomId: bom.data.bomId - }).then(_ => { - this.$emit('addBom', bom.data); - }) - } - else if (this.type == 'raw_material') { - updateRawMaterial({ + bomId: bomData.bomId + }); + } else if (this.type == 'raw_material' && this.itemId) { + await updateRawMaterial({ rawMaterialId: this.itemId, - bomId: bom.data.bomId - }).then(_ => { - this.$emit('addBom', bom.data); - }) + bomId: bomData.bomId + }); } - }) - console.log('创建BOM操作'); + // 触发事件 + this.$emit('addBom', bomData); + } catch (error) { + console.error('创建失败:', error); + this.$message.error(`创建失败: ${error.message || '未知错误'}`); + } finally { + this.createLoading = false; + } }, handleUpdateBom() {