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 @@
-
+
+
+ 创建BOM
+
+
+ 创建中...
+
+
@@ -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() {