Просмотр исходного кода

feat: 更新应收金额计算逻辑,使用勾选明细的折让合计,并回填已收/未收金额

xieyong 11 часов назад
Родитель
Сommit
910f027f7e

+ 29 - 9
src/views/financialManage/receivableManage/components/collectionDialog.vue

@@ -12,7 +12,7 @@
     :resizable="true"
   >
     <div style="margin: 10px 0; font-size: 14px; color: #606266;">
-      <span>应收金额:{{ row.receivableTotalPrice || 0 }} 元</span>
+      <span>应收金额:{{ selectedReceivableAmount }} 元</span>
       <span style="margin-left: 20px;">已收金额:{{ receivedAmount }} 元</span>
       <span style="margin-left: 20px;">未收金额:{{ unreceivedAmount }} 元</span>
     </div>
@@ -138,19 +138,21 @@ export default {
     isView() {
       return this.dialogType === 'view';
     },
-    // 已收金额 = 勾选的应收明细「本次对账金额」之和
-    receivedAmount() {
+    // 应收金额 = 勾选的应收明细「折让合计」之和
+    selectedReceivableAmount() {
       const sum = this.selection.reduce((pre, item) => {
         const val = parseFloat(item.statementAmount);
         return pre + (isNaN(val) ? 0 : val);
       }, 0);
       return sum.toFixed(2);
     },
-    // 未收金额 = 应收金额 - 已收金额
+    // 已收金额 = 接口下发的 row.receivedTotalPrice
+    receivedAmount() {
+      return this.row.receivedTotalPrice || 0;
+    },
+    // 未收金额 = 接口下发的 row.unreceiveTotalPrice
     unreceivedAmount() {
-      const total = parseFloat(this.row.receivableTotalPrice) || 0;
-      const received = parseFloat(this.receivedAmount) || 0;
-      return (total - received).toFixed(2);
+      return this.row.unreceiveTotalPrice || 0;
     },
     queryDimension() {
       return this.form.queryDimension != null ? this.form.queryDimension : 1;
@@ -397,6 +399,12 @@ export default {
       const data = await getProductListForReceiptAPI(id);
       // 新接口只返回产品列表
       this.datasource = Array.isArray(data) ? data : (data.productList || []);
+      // 把接口返回的已收/未收金额回填到 row,供顶部汇总和表单展示
+      this.row = {
+        ...this.row,
+        receivedTotalPrice: data?.receivedTotalPrice ?? this.row.receivedTotalPrice ?? 0,
+        unreceiveTotalPrice: data?.unreceiveTotalPrice ?? this.row.unreceiveTotalPrice ?? 0
+      };
       this.form = {
         ...this.form,
         id: data?.id || '',
@@ -511,12 +519,24 @@ export default {
 
       this.loading = true;
       // 3. 提交:收款信息 + 勾选的应收明细(已收金额 = 勾选行本次对账金额之和)
+      const statementAmount = this.selection.reduce(
+        (pre, item) => pre + (+item.statementAmount || 0),
+        0
+      );
+      // productList 里每一行需要补一个 receivedTotalPrice 字段(值取本次录入的 statementAmount)
+      const productList = this.selection.map((item) => ({
+        ...item,
+        receivedTotalPrice: +(item.statementAmount || 0)
+      }));
       const params = {
         ...this.form,
-        receivedTotalPrice: this.receivedAmount,
+        statementAmount,
+        receivableTotalPrice: Number(this.selectedReceivableAmount),  // 应收金额(勾选行折让合计之和)
+        receivedTotalPrice: this.row.receivedTotalPrice,      // 历史已收总额(接口下发)
+        unreceiveTotalPrice: this.row.unreceiveTotalPrice,    // 历史未收金额(接口下发)
         receivableId: this.row.id,
         receivableCode: this.row.code,
-        productList: selection
+        productList
       };
       finReceivableSaveAPI(params)
         .then(() => {