Переглянути джерело

fix:5027【退货单】进行退货处理,修改退货的数量跟金额后,包装规格没有根据退货的数量变动,导致信息不协调

mlchen 2 днів тому
батько
коміт
265ef52dd3

+ 1 - 0
src/BIZComponents/outdetails.vue

@@ -687,6 +687,7 @@
                     categoryCode: productItem.categoryCode,
                     bizNo: productItem.bizNo,
                     deliveryDetailId: productItem.deliveryDetailId,
+                    minPackingQuantity: productItem.minPackingQuantity,
                     materialDetailList: packingItem.materialDetailList.map(
                       (materialItem) => {
                         return {

+ 31 - 0
src/views/bpm/handleTask/components/saleOrder/returnGoods/addReturnGoodsDialog.vue

@@ -154,6 +154,7 @@
   // import inventoryTable1 from './inventoryTableReturn.vue';
   import inventoryTable1 from '@/BIZComponents/inventoryTable.vue';
   import { contactDetail } from '@/api/bpm/components/saleManage/contact';
+  import warehouseApi from '@/api/warehouseManagement/index.js';
 
   import sendListDialog from './sendListDialog.vue';
   import { copyObj } from '@/utils/util';
@@ -581,6 +582,33 @@
             this.customerMark = base.serialNo;
           }
 
+          // 回显只保存退货数,按原发货明细及包装 ID 取回源包装规格。
+          if (data.sendNo && data.productList?.some((row) => row.sendProductId)) {
+            try {
+              const outbound = await warehouseApi.getInfoBySourceBizNoAll(data.sendNo);
+              const details = (outbound || []).flatMap((item) => item.outInDetailList || []);
+              data.productList.forEach((row) => {
+                const source = details.find((detail) =>
+                  detail.deliveryDetailId != null &&
+                  String(detail.deliveryDetailId) === String(row.sendProductId) &&
+                  (!row.packageId || (detail.outInDetailRecordRequestList || []).some(
+                    (record) => String(record.id) === String(row.packageId)
+                  ))
+                );
+                if (!source) return;
+                const packing = row.packageId
+                  ? source.outInDetailRecordRequestList.find((record) => String(record.id) === String(row.packageId))
+                  : source;
+                this.$set(row, '_sourceMeasureQuantity', packing.measureQuantity);
+                this.$set(row, '_sourcePackingQuantity', packing.packingQuantity);
+                this.$set(row, '_sourceMeasureUnit', packing.measureUnit);
+                this.$set(row, '_minPackingQuantity', source.minPackingQuantity);
+              });
+            } catch (error) {
+              // 来源暂不可用时允许按实际包装数手工填写,避免沿用旧包装数。
+            }
+          }
+
           this.$nextTick(() => {
             this.$refs.inventoryTableref &&
               this.$refs.inventoryTableref.putTableValue(data.productList);
@@ -734,6 +762,9 @@
           item['singlePrice'] = priceSource.singlePrice;
           item['clientCode'] = item.clientCode || priceSource.customerMark;
           item['pricingWay'] = item.pricingWay || priceSource.pricingWay;
+          if (item.pricingWay == 1) {
+            item['totalPrice'] = (Number(item.singlePrice) * Number(item.totalCount)).toFixed(2);
+          }
         });
         this.$refs.inventoryTableref &&
           this.$refs.inventoryTableref.putTableValue(data);

+ 70 - 15
src/views/bpm/handleTask/components/saleOrder/returnGoods/inventoryTable.vue

@@ -137,8 +137,7 @@
           style="margin-bottom: 20px"
           :prop="'datasource.' + scope.$index + '.totalCount'"
           :rules="[
-            { required: true, message: '请输入数字', trigger: 'blur' },
-            { validator: validateTotalCount(scope.row), trigger: 'blur' }
+            { validator: validateTotalCount(scope.row), trigger: ['blur', 'change'] }
           ]"
         >
           <el-input
@@ -147,6 +146,16 @@
           ></el-input>
         </el-form-item>
       </template>
+      <template v-slot:packingQuantity="{ row, $index }">
+        <el-form-item
+          v-if="row.packageId || row.packingUnit"
+          :prop="'datasource.' + $index + '.packingQuantity'"
+          :rules="{ validator: validatePackingQuantity(row), trigger: ['blur', 'change'] }"
+        >
+          <el-input v-model="row.packingQuantity" placeholder="请输入包装数量"></el-input>
+        </el-form-item>
+        <span v-else>{{ row.packingQuantity }}</span>
+      </template>
       <template v-slot:headerTotalCount="{ column }">
         <span class="is-required">{{ column.label }}</span>
       </template>
@@ -320,6 +329,7 @@
           {
             minWidth: 100,
             prop: 'packingQuantity',
+            slot: 'packingQuantity',
             align: 'center',
             label: '包装数量',
             showOverflowTooltip: true
@@ -334,7 +344,9 @@
           {
             minWidth: 100,
             prop: 'totalCount',
-            label: '计量数量',
+            slot: 'totalCount',
+            headerSlot: 'headerTotalCount',
+            label: '退货数量',
             showOverflowTooltip: true,
             align: 'center'
           },
@@ -505,15 +517,7 @@
     computed: {
       totalAmount() {
         let num = 0;
-        this.form.datasource.forEach((item, index) => {
-          if (item.pricingWay == 1) {
-            this.$set(
-              this.form.datasource[index],
-              'totalPrice',
-              item.singlePrice * item.totalCount || 0
-            );
-          }
-      
+        this.form.datasource.forEach((item) => {
           if (item.totalPrice) {
             num += Number(item.totalPrice);
           }
@@ -527,6 +531,47 @@
       }
     },
     methods: {
+      // 退货数量变化时按已选出库包装的最小包装单元预填卷数,仍允许按实际退回包装修改。
+      changeNum(value, index) {
+        const row = this.form.datasource[index];
+        const count = Number(value);
+        const unit = Number(row._minPackingQuantity);
+        if (value !== '' && Number.isFinite(count) && count > 0 && Number.isFinite(unit) && unit > 0 && row.packingUnit && row.measuringUnit === row._sourceMeasureUnit) {
+          this.$set(row, 'packingQuantity', Math.ceil(count / unit));
+        } else if (row._sourceMeasureQuantity != null && value !== '' && Number.isFinite(count) && count > 0 && Number(row._sourceMeasureQuantity) === count) {
+          this.$set(row, 'packingQuantity', row._sourcePackingQuantity);
+        } else if (row.packageId || row.packingUnit) {
+          this.$set(row, 'packingQuantity', '');
+        }
+        if (row.pricingWay == 1) {
+          this.$set(row, 'totalPrice', Number.isFinite(count) && count > 0
+            ? (Number(row.singlePrice) * count).toFixed(2) : '');
+        }
+      },
+      validateTotalCount(row) {
+        return (_rule, value, callback) => {
+          const count = Number(value);
+          if (value === '' || value == null || !Number.isFinite(count) || count <= 0) {
+            return callback(new Error('退货数量必须大于0'));
+          }
+          if (row._sourceMeasureQuantity != null && count > Number(row._sourceMeasureQuantity)) {
+            return callback(new Error('退货数量不能超过所选出库明细数量'));
+          }
+          callback();
+        };
+      },
+      validatePackingQuantity(row) {
+        return (_rule, value, callback) => {
+          const count = Number(value);
+          if (value === '' || value == null || !Number.isFinite(count) || count <= 0) {
+            return callback(new Error('包装数量必须大于0'));
+          }
+          if (row._sourcePackingQuantity != null && count > Number(row._sourcePackingQuantity)) {
+            return callback(new Error('包装数量不能超过所选出库包装数量'));
+          }
+          callback();
+        };
+      },
       //出库单详情
       handleOutBound(e, rows, index) {
         this.curIndex = index;
@@ -647,13 +692,17 @@
 
       // 返回列表数据
       getTableValue() {
-        let comitDatasource = this.form.datasource;
-        if (comitDatasource.length === 0) return { productList: [] };
-        comitDatasource.forEach((v) => {
+        if (this.form.datasource.length === 0) return { productList: [] };
+        const comitDatasource = this.form.datasource.map((row) => {
+          const { _sourceMeasureQuantity, _sourcePackingQuantity, _minPackingQuantity, _sourceMeasureUnit, ...v } = row;
           v.totalCount = Number(v.totalCount);
+          if (v.packingQuantity !== '' && v.packingQuantity != null) {
+            v.packingQuantity = Number(v.packingQuantity);
+          }
           v.technicalDrawings = Array.isArray(v.technicalDrawings)
             ? v.technicalDrawings
             : [];
+          return v;
         });
         return { productList: comitDatasource, payAmount: this.payAmount };
       },
@@ -665,6 +714,12 @@
       putTableValue(data) {
         if (data && data?.length) {
           data.forEach((v) => {
+            if (v.measureQuantity != null && v._sourceMeasureQuantity == null) {
+              this.$set(v, '_sourceMeasureQuantity', v.measureQuantity);
+              this.$set(v, '_sourcePackingQuantity', v.packingQuantity);
+              this.$set(v, '_sourceMeasureUnit', v.measureUnit);
+              this.$set(v, '_minPackingQuantity', v.minPackingQuantity);
+            }
             v.returnReason = v.returnReason || '';
             v.returnType = v.returnType || '';
             v.sendTotalCount = v.sendTotalCount || v.totalCount;