瀏覽代碼

fix:5364【库存台账】拆批操作,计量数量没法除以包装规格,下面的整包分配没法拆分,这里看怎么限制下

mlchen 3 天之前
父節點
當前提交
555a1e4ada
共有 2 個文件被更改,包括 63 次插入 和 30 次删除
  1. 60 27
      src/views/warehouseManagement/stockLedger/components/BatchChangeDialog.vue
  2. 3 3
      vue.config.js

+ 60 - 27
src/views/warehouseManagement/stockLedger/components/BatchChangeDialog.vue

@@ -200,7 +200,7 @@
           <el-table-column label="计量数量">
             <template slot-scope="{ row }">
               <el-input
-                v-if="!hasPacking && !isAutoMeasureTarget(row.target)"
+                v-if="!hasPacking"
                 v-model="row.target.measureQuantity"
                 maxlength="19"
                 :disabled="Boolean(pendingApproveId)"
@@ -595,6 +595,14 @@
     return decimal(value).decimalPlaces(6).toFixed(6);
   }
 
+  function formatDecimal(value) {
+    return decimal(value)
+      .decimalPlaces(6)
+      .toFixed(6)
+      .replace(/\.0+$/, '')
+      .replace(/(\.\d*?)0+$/, '$1');
+  }
+
   function isEmptyDecimal(value) {
     return value == null || String(value).trim() === '';
   }
@@ -680,8 +688,8 @@
         return this.packingRows.length > 0;
       },
       mergeMeasureQuantity() {
-        return this.sources
-          .reduce(
+        return formatDecimal(
+          this.sources.reduce(
             (sum, source) =>
               sum.plus(
                 decimal(source.stockCountBase).minus(
@@ -690,7 +698,7 @@
               ),
             new BigNumber(0)
           )
-          .toFixed(6);
+        );
       },
       targetRows() {
         return this.targets.map((target) => {
@@ -921,7 +929,19 @@
           (max, target) => Math.max(max, target.targetDetailId),
           0
         );
-        this.targets.push(this.createTarget(maxId + 1));
+        const target = this.createTarget(maxId + 1);
+        this.targets.push(target);
+        if (this.hasPacking) {
+          this.syncTargetPackingMinimums();
+        } else {
+          this.handleMeasureQuantityInput(this.targets[0]);
+          const weightRemainder = decimal(this.sources[0].weight).minus(
+            this.sum(this.targets.slice(0, -1), 'weight')
+          );
+          target.weight = formatDecimal(
+            weightRemainder.isNegative() ? 0 : weightRemainder
+          );
+        }
       },
       removeTarget(targetDetailId) {
         if (this.targets.length <= 2)
@@ -937,6 +957,11 @@
         this.targets = this.targets.filter(
           (target) => target.targetDetailId !== targetDetailId
         );
+        if (this.hasPacking) {
+          this.syncTargetPackingMinimums();
+        } else {
+          this.handleMeasureQuantityInput(this.targets[0]);
+        }
         if (this.batchPackingTargetId === targetDetailId) {
           this.batchPackingTargetId = null;
         }
@@ -954,8 +979,8 @@
           row.targetDetailId = null;
         });
         const target = this.targets[0];
-        target.measureQuantity = this.sources
-          .reduce(
+        target.measureQuantity = formatDecimal(
+          this.sources.reduce(
             (sum, source) =>
               sum.plus(
                 decimal(source.stockCountBase).minus(
@@ -964,7 +989,7 @@
               ),
             new BigNumber(0)
           )
-          .toFixed(6);
+        );
         target.packageQuantity = this.sum(this.sources, 'packingQuantity');
         target.weight = this.sum(this.sources, 'weight');
         this.syncTargetPackingMinimums();
@@ -982,8 +1007,9 @@
       isAutoMeasureTarget(target) {
         return (
           this.mode === 'split' &&
-          this.targets.length === 2 &&
-          target.targetDetailId === this.targets[1].targetDetailId
+          this.targets.length > 1 &&
+          target.targetDetailId ===
+            this.targets[this.targets.length - 1].targetDetailId
         );
       },
       /** 将勾选的整包装一次分配到同一目标子批次。 */
@@ -1087,35 +1113,42 @@
           );
           const measureMinimum = decimal(this.sum(packages, 'measureQuantity'));
           const weightMinimum = decimal(this.sum(packages, 'weight'));
-          target.measureQuantity = measureMinimum.toFixed(6);
-          target.weight = weightMinimum.toFixed(6);
+          target.measureQuantity = formatDecimal(measureMinimum);
+          target.weight = formatDecimal(weightMinimum);
         });
         if (this.mode === 'split') {
           const lastTarget = this.targets[this.targets.length - 1];
           const assigned = this.targets.slice(0, -1);
-          lastTarget.measureQuantity = decimal(source.stockCountBase)
-            .minus(this.sum(assigned, 'measureQuantity'))
-            .max(0)
-            .toFixed(6);
-          lastTarget.weight = decimal(source.weight)
-            .minus(this.sum(assigned, 'weight'))
-            .max(0)
-            .toFixed(6);
+          const measureRemainder = decimal(source.stockCountBase).minus(
+            this.sum(assigned, 'measureQuantity')
+          );
+          const weightRemainder = decimal(source.weight).minus(
+            this.sum(assigned, 'weight')
+          );
+          lastTarget.measureQuantity = formatDecimal(
+            measureRemainder.isNegative() ? 0 : measureRemainder
+          );
+          lastTarget.weight = formatDecimal(
+            weightRemainder.isNegative() ? 0 : weightRemainder
+          );
         }
       },
       handleMeasureQuantityInput(target) {
         if (
           this.mode !== 'split' ||
-          this.targets.length !== 2 ||
           this.isAutoMeasureTarget(target) ||
           !this.sources.length
         ) {
           return;
         }
+        const lastTarget = this.targets[this.targets.length - 1];
+        const assigned = this.targets.filter((item) => item !== lastTarget);
         const remainder = decimal(this.sources[0].stockCountBase).minus(
-          decimal(target.measureQuantity)
+          this.sum(assigned, 'measureQuantity')
+        );
+        lastTarget.measureQuantity = formatDecimal(
+          remainder.isNegative() ? 0 : remainder
         );
-        this.targets[1].measureQuantity = remainder.max(0).toFixed(6);
       },
       validateTargetLimit(target, field) {
         if (this.mode !== 'split' || !this.sources.length) return;
@@ -1133,7 +1166,7 @@
         const label = field === 'measureQuantity' ? '计量数量' : '重量';
         target[field] = '';
         this.$message.warning(
-          `目标子批次${label}累计不能超过来源库存${label} ${limit.toFixed(6)}`
+          `目标子批次${label}累计不能超过来源库存${label} ${formatDecimal(limit)}`
         );
       },
       targetLabel(id) {
@@ -1151,9 +1184,9 @@
           .join('、');
       },
       sum(rows, key) {
-        return rows
-          .reduce((sum, row) => sum.plus(decimal(row[key])), new BigNumber(0))
-          .toFixed(6);
+        return formatDecimal(
+          rows.reduce((sum, row) => sum.plus(decimal(row[key])), new BigNumber(0))
+        );
       },
       total(key) {
         return this.sum(this.sources, key);

+ 3 - 3
vue.config.js

@@ -2,7 +2,7 @@
  * @Author: mlchen 374826075@qq.com
  * @Date: 2026-07-21 09:26:11
  * @LastEditors: mlchen 374826075@qq.com
- * @LastEditTime: 2026-09-29 15:53:40
+ * @LastEditTime: 2026-10-10 15:17:10
  * @FilePath: /kd-aiot-frontend-wms/vue.config.js
  * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  */
@@ -43,8 +43,8 @@ module.exports = {
         // target: 'http://124.71.68.31:50001',
         // target: 'http://192.168.1.132:18086',
         // target: 'http://192.168.1.105:18086', //开发
-        target: 'http://localhost:18090', //开发
-        // target: 'http://192.168.1.251:18086', //测试
+        // target: 'http://localhost:18090', //开发
+        target: 'http://192.168.1.251:18086', //测试
         // target: 'http://192.168.1.116:18086',
 
         // target: 'http://192.168.1.116:18086',