Explorar o código

feat: 审批销售订单时添加单价调整功能,支持联动更新总金额和应付金额

xieyong hai 2 días
pai
achega
47d86bac2f

+ 87 - 2
src/BIZComponents/inventoryTableDetails.vue

@@ -63,6 +63,26 @@
           {{ scope.row[countObj.unitKey] || '' }}
         </el-form-item>
       </template>
+      <!-- 单价:允许调整,联动 totalPrice / discountSinglePrice / discountTotalPrice -->
+      <template v-slot:singlePrice="scope">
+        <el-form-item :prop="'datasource.' + scope.$index + '.singlePrice'">
+          <el-input
+            v-model="scope.row.singlePrice"
+            type="number"
+            placeholder="请输入"
+            @input="changeCount(scope.row, scope.$index)"
+          >
+            <template slot="append">元</template>
+          </el-input>
+        </el-form-item>
+      </template>
+      <template v-slot:headerSinglePrice="{ column }">
+        <span>{{ column.label }}</span>
+      </template>
+      <!-- 不含税单价:跟随 singlePrice + taxRate 自动计算 -->
+      <template v-slot:notaxSinglePrice="scope">
+        {{ scope.row.notaxSinglePrice }}
+      </template>
       <!-- <template v-slot:saleUnit="scope">
         <el-form-item
           :prop="'datasource.' + scope.$index + '.' + countObj.unitKey"
@@ -107,7 +127,8 @@
     getAllQuantity,
     formatPrice,
     getAllPrice,
-    getAllDiscountPrice
+    getAllDiscountPrice,
+    changeCount as changeCountUtil
   } from '@/BIZComponents/setProduct.js';
   import { getInventoryTotalAPI } from '@/api/bpm/components/wms';
 
@@ -212,7 +233,9 @@
         },
         columnsVersion: 1,
         tabMixinsInit: false,
-        quoteTypeOp
+        quoteTypeOp,
+        // 标记:用户在表格里是否手动修改过单价,仅当为 true 时审批前才需要落库
+        singlePriceChanged: false
       };
     },
     computed: {
@@ -896,6 +919,64 @@
       handleMethod(row) {
         this.$refs.timeDialogRef.open(row);
       },
+      // 修改单价后,联动更新行内的合计/折让字段与组件级总计
+      changeCount(row, index) {
+        if (!row) {
+          this.form.datasource.forEach((item, idx) => {
+            this.$set(
+              this.form.datasource,
+              idx,
+              changeCountUtil(item, this.countObj)
+            );
+          });
+        } else {
+          // 用户在 UI 上实际修改了某行的单价,置位"已改动"标记
+          this.singlePriceChanged = true;
+          this.$set(
+            this.form.datasource,
+            index,
+            changeCountUtil(row, this.countObj)
+          );
+        }
+        this.$nextTick(() => {
+          this.getNotaxSinglePrice();
+          this.changeAll();
+          this.$forceUpdate();
+        });
+      },
+      // 供父组件查询:用户在表格里是否手动调整过单价
+      isSinglePriceChanged() {
+        return this.singlePriceChanged;
+      },
+      // 刷新组件级总计
+      changeAll() {
+        this.allPrice = getAllPrice(this.form.datasource) || 0;
+        if (this.isDiscountTotalPrice) {
+          this.form.discountTotalPrice =
+            getAllDiscountPrice(this.form.datasource) || this.allPrice;
+        }
+        // 通知父组件刷新"订单总金额 / 应付金额"
+        this.$emit('price-change', {
+          totalAmount: this.allPrice,
+          payAmount: this.form.discountTotalPrice
+        });
+      },
+      // 不含税单价 = 单价 / (1 + 税率/100)
+      getNotaxSinglePrice() {
+        this.form.datasource.forEach((item, index) => {
+          if (item.singlePrice && item.taxRate) {
+            this.$set(
+              this.form.datasource[index],
+              'notaxSinglePrice',
+              parseFloat(
+                (item.singlePrice / (1 + Number(item.taxRate) / 100)).toFixed(2)
+              )
+            );
+          } else {
+            this.$set(this.form.datasource[index], 'notaxSinglePrice', '');
+          }
+        });
+      },
       // 返回列表数据
       getTableValue() {
         let comitDatasource = this.form.datasource;
@@ -1047,6 +1128,10 @@
             'productId'
           );
           this.$refs.table?.reload();
+          // 单价允许调整:回显后统一跑一次联动计算,保证 totalPrice / discountTotalPrice / notaxSinglePrice 与 singlePrice 一致
+          if (this.isChangeCount) {
+            this.changeCount();
+          }
         }
       }
     }

+ 22 - 0
src/views/bpm/handleTask/components/saleOrder/detailDialog.vue

@@ -244,6 +244,7 @@
         ref="inventoryTabledetailRef"
         :isCustomerMark="true"
         :isDiscountTotalPrice="true"
+        @price-change="handlePriceChange"
         :isArrivalWay="true"
         :isProductionRequirements="true"
         :isIncreaseTotalWeight="true"
@@ -362,6 +363,27 @@
               this.$refs.paymentCollectionPlanRef.putTableValue(data);
           });
         }
+      },
+      // 转发:用户在物品清单里是否手动改过单价(用于审批前按需落库)
+      isSinglePriceChanged() {
+        return (
+          this.$refs.inventoryTabledetailRef?.isSinglePriceChanged?.() || false
+        );
+      },
+      // 物品清单里的单价调整后,同步刷新订单总金额 / 应付金额
+      handlePriceChange({ totalAmount, payAmount }) {
+        if (totalAmount !== undefined) {
+          this.$set(this.form, 'totalAmount', totalAmount);
+        }
+        if (payAmount !== undefined) {
+          this.$set(this.form, 'payAmount', payAmount);
+        }
+      },
+      // 返回整体数据(form + 表格数据),供审批前落库使用
+      getTableValue() {
+        return Object.assign({}, this.form, {
+          productList: this.$refs.inventoryTabledetailRef?.getTableValue?.() || []
+        });
       }
     }
   };

+ 7 - 7
src/views/bpm/handleTask/components/saleOrder/submit.vue

@@ -120,13 +120,13 @@
       async handleAudit(status) {
         const loading = this.$loading({ lock: true, text: '正在处理,请稍候...' });
         try {
-          //发起人补充
-          if (this.taskDefinitionKey === 'starter') {
-            let arr = await this.getTableValue();
-            if (!arr) {
-              loading.close();
-              return;
-            }
+          // 仅当用户在表格里实际修改过单价时才落库,避免无意义请求
+          const [arr, singlePriceChanged] = await new Promise((resolve, reject) => {
+            this.$emit('getTableValue', async (data, changed) => {
+              resolve([await data, changed]);
+            });
+          });
+          if (singlePriceChanged && arr) {
             let data = await UpdateInformation(arr);
             if (data.code != '0') {
               loading.close();

+ 5 - 1
src/views/bpm/handleTask/index.vue

@@ -909,7 +909,11 @@
         this.dialogVisible = false;
       },
       getTableValue(fn) {
-        fn(this.$refs.bziRef.getTableValue());
+        // 第二个参数告诉审批组件:用户在表格里是否手动改过单价(用于决定是否需要落库)
+        fn(
+          this.$refs.bziRef.getTableValue(),
+          this.$refs.bziRef.isSinglePriceChanged?.()
+        );
       }
     }
   };