liujt пре 1 месец
родитељ
комит
ef3f956426
1 измењених фајлова са 31 додато и 43 уклоњено
  1. 31 43
      src/views/warehouseManagement/warehouseDefinition/add.vue

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

@@ -1274,7 +1274,7 @@
           const diff = newAllocationCount - oldAllocationCount;
 
           if (diff > 0) {
-            // 货位数量增加,从末尾添加新的货位
+            // 货位数量增加,在该货架已有货位后面插入新的货位
             const lastAllocation = existingAllocationList[existingAllocationList.length - 1];
             let startRow = 1, startCol = 1;
             if (lastAllocation) {
@@ -1292,12 +1292,20 @@
               }
             }
 
+            // 找到该货架最后一个货位在数组中的索引
+            let lastIndex = this.areaForm.allocationReqList.findIndex(
+              (item) => item.goodsShelvesCode === obj.code
+            );
+            if (lastIndex === -1) lastIndex = this.areaForm.allocationReqList.length - 1;
+
+            // 生成新货位
+            const newAllocations = [];
             for (let i = 0; i < diff; i++) {
               const rowNum = startRow + Math.floor((startCol + i - 1) / newCols);
               const colNum = ((startCol + i - 1) % newCols) + 1;
               const allocationCode = `${obj.code}-${rowNum}-${colNum}`;
 
-              this.areaForm.allocationReqList.push({
+              newAllocations.push({
                 warehouseAreaCode: obj.reservoirAreaCode,
                 warehouseAreaGoodsCode: obj.code,
                 goodsAllocationCode: allocationCode,
@@ -1325,6 +1333,9 @@
                 isEdit: true
               });
             }
+
+            // 在该货架最后一个货位后面插入
+            this.areaForm.allocationReqList.splice(lastIndex + 1, 0, ...newAllocations);
           } else if (diff < 0) {
             // 货位数量减少,从末尾删除货位
             let deleteCount = Math.abs(diff);
@@ -1480,29 +1491,6 @@
 
             let obj = this.areaForm.warehouseAreasSaveList[index];
 
-            // 获取最后一个货架的编号,计算下一个编号的起始值
-            const pre =
-              this.areaForm.areaGoodsshelvesList[
-                this.areaForm.areaGoodsshelvesList.length - 1
-              ];
-            let preCode = 0;
-            if (pre) {
-              preCode = +(pre.code?.substr(1) || 0);
-            }
-
-            let codeEng = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
-            let currentLetterIndex = preCode + 1;
-
-            if (ruleName.length > 0) {
-              // 计算初始索引
-              let multiplier = Math.pow(codeEng.length, ruleName.length - 1);
-              for (let i = 0; i < ruleName.length; i++) {
-                currentLetterIndex +=
-                  (codeEng.indexOf(ruleName[i]) + 1) * multiplier;
-                multiplier /= codeEng.length;
-              }
-            }
-
             // 获取该库区原有的货架数量
             const existingShelfList = this.areaForm.areaGoodsshelvesList.filter(
               (item) => item.reservoirAreaCode === obj.code
@@ -1513,29 +1501,31 @@
 
             // 货架数量增加,添加新的货架
             for (let i = 0; i < diff; i++) {
-              let idx = currentLetterIndex;
-              let dividend = codeEng.length;
-              let remainder;
-              let quotient;
               let code = '';
-
-              while (idx > 0) {
-                remainder = idx % dividend;
-                quotient = Math.floor(idx / dividend);
-
-                if (remainder === 0) {
-                  remainder = codeEng.length;
-                  quotient--;
+              if (this.hjForm.type === 1) {
+                // 字母规则:从输入的字母开始递增(A, B, C...)
+                let codeEng = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
+                let startIndex = codeEng.indexOf(ruleName.toUpperCase());
+                if (startIndex === -1) startIndex = 0;
+                let letterIndex = startIndex + i;
+                
+                if (letterIndex < codeEng.length) {
+                  code = codeEng[letterIndex];
+                } else {
+                  // 超过26个字母时使用 AA, AB...
+                  let quotient = Math.floor(letterIndex / codeEng.length);
+                  let remainder = letterIndex % codeEng.length;
+                  code = codeEng[quotient - 1] + codeEng[remainder];
                 }
-
-                code = codeEng[remainder - 1] + code;
-                idx = quotient;
+              } else {
+                // 数字规则:ruleName + 数字
+                code = ruleName + (i + 1);
               }
 
               let obj1111 = {
                 reservoirAreaCode: obj.code,
                 warehouseId: this.formData.id,
-                code: this.hjForm.type === 1 ? code : ruleName + (i + 1),
+                code: code,
                 type: 2,
                 extInfo: [
                   {
@@ -1553,8 +1543,6 @@
               };
 
               this.areaForm.areaGoodsshelvesList.push(obj1111);
-
-              currentLetterIndex++;
             }
 
             this.hjCodeFalg = false;