Эх сурвалжийг харах

refactor(warehouse): 优化仓库管理删除逻辑,增加删除前的货架数量统计和更新逻辑。

liujt 1 сар өмнө
parent
commit
485532fd55

+ 10 - 3
src/api/warehouseManagement/warehouseDefinition.js

@@ -99,9 +99,16 @@ export default {
       return res.data.message;
     }
   },
-  //删除
-  isDelete: async (id) => {
-    const res = await request.get('/wms/warehouse/isDelete/' + id);
+  //判断库区是否可删除
+  isAreaCanDelete: async (id) => {
+    const res = await request.get(`/wms/warehousearea/isCanDelete/${id}`);
+    if (res.data.code == 0) {
+      return res.data.data;
+    }
+  },
+  //判断货架是否可删除
+  isGoodsshelvesCanDelete: async (id) => {
+    const res = await request.get(`/wms/warehouseareagoodsshelves/isCanDelete/${id}`);
     if (res.data.code == 0) {
       return res.data.data;
     }

+ 43 - 8
src/views/warehouseManagement/warehouseDefinition/add.vue

@@ -302,6 +302,11 @@
                   <el-button type="text" v-else @click="addShelf(row, $index)"
                     >添加货架</el-button
                   >
+
+                  <!-- <el-button type="text" v-if="!row.isEdit" @click="editArea(row, $index)"
+                    >编辑</el-button
+                  > -->
+
                   <el-button type="text" @click="remove1($index, row)"
                     >删除库区</el-button
                   >
@@ -826,6 +831,7 @@
       };
 
       return {
+        editType: '',
         warehouseDefinition_isRegular,
         warehouseDefinition_areaType,
         warehouseDefinition_areaAttribute,
@@ -994,9 +1000,10 @@
         let kqArr = [];
         for (const key in warehouseAreasSaveList) {
           kqArr.push({
-            // id: warehouseAreasSaveList[key].id,
+            id: warehouseAreasSaveList[key].id,
             name: warehouseAreasSaveList[key].name,
             code: warehouseAreasSaveList[key].code,
+            isEdit: false,
             extInfo: [
               {
                 areaType: warehouseAreasSaveList[key].type,
@@ -1524,9 +1531,14 @@
         }
 
         this.$confirm(`是否删除这个货架?`).then(async () => {
+          // 删除前统计该库区的货架数量
+          const beforeCount = this.areaForm.areaGoodsshelvesList.filter(
+            (item) => item.reservoirAreaCode === reservoirAreaCode
+          ).length;
+
           if (id) {
-            const res = await warehouseDefinition.isDelete(id);
-            if (res == 1) {
+            const res = await warehouseDefinition.isGoodsshelvesCanDelete(id);
+            if (res) {
               this.areaForm.areaGoodsshelvesList =
                 this.areaForm.areaGoodsshelvesList.filter(
                   (item) => item.code !== code
@@ -1535,9 +1547,11 @@
                 this.areaForm.allocationReqList.filter(
                   (item) => item.goodsShelvesCode !== code
                 );
+              // 更新对应库区的货架数量
+              this.updateAreaSubCount(reservoirAreaCode, beforeCount);
               this.$message.warning('已在本地删除,保存之后生效!');
             } else {
-              this.$message.warning('此数据可能有关联数据,暂时无法删除!');
+              this.$message.warning('该货架已上架产品,无法删除。');
             }
           } else {
             this.areaForm.areaGoodsshelvesList =
@@ -1548,18 +1562,38 @@
               this.areaForm.allocationReqList.filter(
                 (item) => item.goodsShelvesCode !== code
               );
-
+            // 更新对应库区的货架数量
+            this.updateAreaSubCount(reservoirAreaCode, beforeCount);
             this.$message.success('删除成功!');
           }
         });
       },
+      updateAreaSubCount(reservoirAreaCode, beforeCount) {
+        // 删除后统计该库区的货架数量
+        const afterCount = this.areaForm.areaGoodsshelvesList.filter(
+          (item) => item.reservoirAreaCode === reservoirAreaCode
+        ).length;
+        // 更新库区的货架数量
+        const areaIndex = this.areaForm.warehouseAreasSaveList.findIndex(
+          (item) => item.code === reservoirAreaCode
+        );
+        if (areaIndex !== -1) {
+          this.areaForm.warehouseAreasSaveList[areaIndex].subCount = afterCount;
+        }
+      },
+      editArea(row, index) {
+        this.editType = 'edit';
+        row.isEdit = true;
+        this.$set(this.areaForm.warehouseAreasSaveList[index], 'isEdit', true);
+        console.log('editArea~~', row, index, this.areaForm.warehouseAreasSaveList[index]);
+      },
       remove1(index, { id, code }) {
         console.log('remove1~~', index, id, code);
         this.$confirm(`是否删除这个库区`)
           .then(async () => {
             if (id) {
-              const res = await warehouseDefinition.isDelete(id);
-              if (res == 1) {
+              const res = await warehouseDefinition.isAreaCanDelete(id);
+              if (res) {
                 this.areaForm.warehouseAreasSaveList.splice(index, 1);
                 this.areaForm.areaGoodsshelvesList =
                   this.areaForm.areaGoodsshelvesList.filter(
@@ -1571,7 +1605,7 @@
                   );
                 this.$message.warning('已在本地删除,保存之后生效!');
               } else {
-                this.$message.warning('此数据可能有关联数据,暂时无法删除!');
+                this.$message.warning('该库区已上架产品,无法删除。');
               }
             } else {
               this.areaForm.warehouseAreasSaveList.splice(index, 1);
@@ -1628,6 +1662,7 @@
         this.areaForm.warehouseAreasSaveList.splice(index, 1);
       },
       addArea() {
+        this.editType = 'add';
         const pre =
           this.areaForm.warehouseAreasSaveList[
             this.areaForm.warehouseAreasSaveList.length - 1