Преглед изворни кода

收款计算优化,收款合并2个费翔

gqx пре 2 година
родитељ
комит
522bf2a770
1 измењених фајлова са 256 додато и 65 уклоњено
  1. 256 65
      src/views/room/modules/checkIn/BillRoomForm.vue

+ 256 - 65
src/views/room/modules/checkIn/BillRoomForm.vue

@@ -1203,29 +1203,30 @@ export default {
         });
         this.model.orderFees = [...list, ...list2];
       } else {
-        var list2 = this.model.orderFees.filter(
-          (t) => t.subjectType == 2 && (!t.add || t.add != 1)
-        );
-        var list1 = [];
+        // var list2 = this.model.orderFees.filter(
+        //   (t) => t.subjectType == 2 && (!t.add || t.add != 1)
+        // );
+        // var list1 = [];
 
-        var list = this.model.orderFees.filter(
-          (t) =>
-            (t.subjectType != 1 && t.subjectType != 2) || (t.add && t.add == 1)
-        );
-        list2.forEach((t) => {
-          if (t.yajing && t.yajing > 0) {
-            t.money -= t.yajing;
-            t.receivable = t.money;
-            var item = JSON.parse(JSON.stringify(t));
-            item.subjectType = 1;
-            item.money = t.yajing;
-            item.yajing = 0;
-            item.receivable = item.money;
-            list1.push(item);
-          }
-        });
-        list = [...list, ...list1];
-        this.model.orderFees = [...list, ...list2];
+        // var list = this.model.orderFees.filter(
+        //   (t) =>
+        //     (t.subjectType != 1 && t.subjectType != 2) || (t.add && t.add == 1)
+        // );
+        // list2.forEach((t) => {
+        //   if (t.yajing && t.yajing > 0) {
+        //     t.money -= t.yajing;
+        //     t.receivable = t.money;
+        //     var item = JSON.parse(JSON.stringify(t));
+        //     item.subjectType = 1;
+        //     item.money = t.yajing;
+        //     item.yajing = 0;
+        //     item.receivable = item.money;
+        //     list1.push(item);
+        //   }
+        // });
+        // list = [...list, ...list1];
+        // this.model.orderFees = [...list, ...list2];
+        this.loadOrderFees();
       }
     },
     // "model.roomIds": {
@@ -1378,6 +1379,86 @@ export default {
     //  this.getcesRoomLayout();
   },
   methods: {
+    loadOrderFees() {
+      var orderFees = [];
+      var roomIndex = 0;
+      var payType = this.payTypeList[0];
+      // roomNo: item.name,
+      //         roomId: item.id,
+      //         marketPrice: item.marketPrice,
+      //         prefPrice: item.marketPrice,
+      //         day: this.model.orderInfo.dayCount,
+      //         roomFee: item.marketPrice * this.model.orderInfo.dayCount,
+      //         deposit: this.compuleDeposit(item.marketPrice),
+      //         layoutName: roomLayout ? roomLayout.name : "",
+      //         layoutId: item.layoutId,
+      this.model.roomPrices.forEach((item) => {
+        var money = item.roomFee;
+        var deposit = item.deposit;
+        if (!orderFees.some((t) => t.roomId == this.model.roomIds[0].id)) {
+          if (!this.paymentSplit) {
+            money = item.roomFee + deposit;
+          }
+          orderFees.push({
+            subjectType: 2,
+            subjectTypeLabel: "预收房费",
+            payType: payType ? payType.id : "",
+            payTypeLabel: payType ? payType.name : "",
+            receivable: money,
+            money: money,
+            roomId: this.model.roomIds[0].id,
+          });
+          if (this.paymentSplit) {
+            if (deposit > 0) {
+              orderFees.push({
+                subjectType: 1,
+                subjectTypeLabel: "押金",
+                payType: payType ? payType.id : "",
+                payTypeLabel: payType ? payType.name : "",
+                receivable: deposit,
+                money: deposit,
+                roomId: this.model.roomIds[0].id,
+              });
+            }
+          }
+        } else {
+          var find = orderFees.find(
+            (t) => t.subjectType == 2 && t.roomId == this.model.roomIds[0].id
+          );
+          if (find) {
+            if (roomIndex == 0) {
+              find.money = item.roomFee;
+              find.receivable = item.roomFee;
+            } else {
+              find.money += item.roomFee;
+              find.receivable += item.roomFee;
+            }
+            if (!this.paymentSplit) {
+              find.money += deposit;
+              find.receivable += deposit;
+            }
+          }
+          if (this.paymentSplit) {
+            var find2 = orderFees.find(
+              (t) => t.subjectType == 1 && t.roomId == this.model.roomIds[0].id
+            );
+            if (find2) {
+              if (deposit > 0) {
+                if (roomIndex == 0) {
+                  find2.money = deposit;
+                  find2.receivable = deposit;
+                } else {
+                  find2.money += deposit;
+                  find2.receivable += deposit;
+                }
+              }
+            }
+          }
+        }
+        roomIndex++;
+      });
+      this.model.orderFees = orderFees;
+    },
     readCardNo() {
       this.$message.error("接口程序未打开,请打开接口程序");
     },
@@ -1557,6 +1638,8 @@ export default {
       this.editPriceModal = false;
 
       var sum = 0;
+      var money2 = 0;
+      var deposit2 = 0;
       for (var i = 0; i < this.model.roomPrices.length; i++) {
         var money = 0;
         var item = this.model.roomPrices[i];
@@ -1570,16 +1653,36 @@ export default {
           sum += item.roomFee + item.deposit;
         }
 
-        var find = this.model.orderFees.find(
-          (t) =>
-            t.subjectType == 2 &&
-            t.roomId == this.model.roomPrices[this.editPriceIndex].roomId
-        );
-        if (find && find.roomId == item.roomId) {
-          find.money = money;
-          find.receivable = money;
+        money2 += item.roomFee;
+        deposit2 += item.deposit;
+        // var find = this.model.orderFees.find(
+        //   (t) =>
+        //     t.subjectType == 2 &&
+        //     t.roomId == this.model.roomPrices[this.editPriceIndex].roomId
+        // );
+        // if (find && find.roomId == item.roomId) {
+        //   find.money = money;
+        //   find.receivable = money;
+        // }
+      }
+      var find = this.model.orderFees.find(
+        (t) => t.subjectType == 2 && t.roomId == this.model.roomIds[0].id
+      );
+      if (find) {
+        find.money = money2;
+        find.receivable = money2;
+        if (!this.paymentSplit) {
+          find.money += deposit2;
+          find.receivable += deposit2;
         }
       }
+      var find2 = this.model.orderFees.find(
+        (t) => t.subjectType == 1 && t.roomId == this.model.roomIds[0].id
+      );
+      if (find2) {
+        find2.money = deposit2;
+        find2.receivable = deposit2;
+      }
       this.amount = sum;
     },
 
@@ -1823,7 +1926,7 @@ export default {
         payTypeLabel: payType ? payType.name : "",
         receivable: 0,
         money: 0,
-        roomId: this.model.orderFees[0].roomId,
+        roomId: this.model.roomIds[0].id,
       });
     },
     onCellChange(key, dataIndex, value) {
@@ -1913,8 +2016,15 @@ export default {
       this.model.roomPrices = this.model.roomPrices.filter(
         (t) => t.roomId != e
       );
-      this.model.orderFees = this.model.orderFees.filter((t) => t.roomId != e);
+      // this.model.orderFees = this.model.orderFees.filter((t) => t.roomId != e);
+      this.model.orderFees.forEach((t) => {
+        if (t.roomId == e) {
+          t.roomId = this.model.roomIds[0].id;
+        }
+      });
       var sum = 0;
+      var money2 = 0;
+      var deposit2 = 0;
       for (var i = 0; i < this.model.roomPrices.length; i++) {
         var money = 0;
         var item = this.model.roomPrices[i];
@@ -1927,6 +2037,22 @@ export default {
         } else {
           sum += item.roomFee + item.deposit;
         }
+        money2 += item.roomFee;
+        deposit2 += item.deposit;
+      }
+      var find = this.model.orderFees.find(
+        (t) => t.subjectType == 2 && t.roomId == this.model.roomIds[0].id
+      );
+      if (find) {
+        find.money = money2;
+        find.receivable = money2;
+      }
+      var find2 = this.model.orderFees.find(
+        (t) => t.subjectType == 1 && t.roomId == this.model.roomIds[0].id
+      );
+      if (find2) {
+        find2.money = deposit2;
+        find2.receivable = deposit2;
       }
       this.amount = sum;
     },
@@ -2041,6 +2167,7 @@ export default {
 
         var roomPrices = [];
         var orderFees = [];
+        var roomIndex = 0;
         this.model.roomIds.forEach((item) => {
           var roomLayout = this.roomLayoutList.find(
             (t) => (t.id = item.layoutId)
@@ -2067,37 +2194,99 @@ export default {
             this.editPriceOk();
           }
           var payType = this.payTypeList[0];
-          if (!this.model.orderFees.some((t) => t.roomId == item.id)) {
-            orderFees.push({
-              subjectType: 2,
-              subjectTypeLabel: "预收房费",
-              payType: payType ? payType.id : "",
-              payTypeLabel: payType ? payType.name : "",
-              receivable: item.marketPrice * this.model.orderInfo.dayCount,
-              money: item.marketPrice * this.model.orderInfo.dayCount,
-              roomId: item.id,
-            });
-            var deposit = this.compuleDeposit(item.marketPrice);
-            if (deposit > 0) {
-              orderFees.push({
-                subjectType: 1,
-                subjectTypeLabel: "押金",
-                payType: payType ? payType.id : "",
-                payTypeLabel: payType ? payType.name : "",
-                receivable: deposit,
-                money: deposit,
-                roomId: item.id,
-              });
-            }
-          } else {
-            // var find = this.model.orderFees.find(
-            //   (t) => t.subjectType == 2 && t.roomId == item.id
-            // );
-            // if (find) {
-            //   find.money = money;
-            //   find.receivable = money;
-            // }
-          }
+          // if (!this.model.orderFees.some((t) => t.roomId == item.id)) {
+          //   orderFees.push({
+          //     subjectType: 2,
+          //     subjectTypeLabel: "预收房费",
+          //     payType: payType ? payType.id : "",
+          //     payTypeLabel: payType ? payType.name : "",
+          //     receivable: item.marketPrice * this.model.orderInfo.dayCount,
+          //     money: item.marketPrice * this.model.orderInfo.dayCount,
+          //     roomId: item.id,
+          //   });
+          //   var deposit = this.compuleDeposit(item.marketPrice);
+          //   if (deposit > 0) {
+          //     orderFees.push({
+          //       subjectType: 1,
+          //       subjectTypeLabel: "押金",
+          //       payType: payType ? payType.id : "",
+          //       payTypeLabel: payType ? payType.name : "",
+          //       receivable: deposit,
+          //       money: deposit,
+          //       roomId: item.id,
+          //     });
+          //   }
+          // } else {
+          //   // var find = this.model.orderFees.find(
+          //   //   (t) => t.subjectType == 2 && t.roomId == item.id
+          //   // );
+          //   // if (find) {
+          //   //   find.money = money;
+          //   //   find.receivable = money;
+          //   // }
+          // }
+          // if (
+          //   !this.model.orderFees.some(
+          //     (t) => t.roomId == this.model.roomIds[0].id
+          //   )
+          // ) {
+          //   orderFees.push({
+          //     subjectType: 2,
+          //     subjectTypeLabel: "预收房费",
+          //     payType: payType ? payType.id : "",
+          //     payTypeLabel: payType ? payType.name : "",
+          //     receivable: item.marketPrice * this.model.orderInfo.dayCount,
+          //     money: item.marketPrice * this.model.orderInfo.dayCount,
+          //     roomId: this.model.roomIds[0].id,
+          //   });
+          //   var deposit = this.compuleDeposit(item.marketPrice);
+          //   if (deposit > 0) {
+          //     orderFees.push({
+          //       subjectType: 1,
+          //       subjectTypeLabel: "押金",
+          //       payType: payType ? payType.id : "",
+          //       payTypeLabel: payType ? payType.name : "",
+          //       receivable: deposit,
+          //       money: deposit,
+          //       roomId: this.model.roomIds[0].id,
+          //     });
+          //   }
+          // } else {
+          //   var deposit = this.compuleDeposit(item.marketPrice);
+          //   var find = this.model.orderFees.find(
+          //     (t) => t.subjectType == 2 && t.roomId == this.model.roomIds[0].id
+          //   );
+          //   if (find) {
+          //     if (roomIndex == 0) {
+          //       find.money = item.marketPrice * this.model.orderInfo.dayCount;
+          //       find.receivable =
+          //         item.marketPrice * this.model.orderInfo.dayCount;
+          //     } else {
+          //       find.money += item.marketPrice * this.model.orderInfo.dayCount;
+          //       find.receivable +=
+          //         item.marketPrice * this.model.orderInfo.dayCount;
+          //     }
+          //     if (!this.paymentSplit) {
+          //       find.money += deposit;
+          //       find.receivable += deposit;
+          //     }
+          //   }
+          //   var find2 = this.model.orderFees.find(
+          //     (t) => t.subjectType == 1 && t.roomId == this.model.roomIds[0].id
+          //   );
+          //   if (find2) {
+          //     if (deposit > 0) {
+          //       if (roomIndex == 0) {
+          //         find2.money = deposit;
+          //         find2.receivable = deposit;
+          //       } else {
+          //         find2.money += deposit;
+          //         find2.receivable += deposit;
+          //       }
+          //     }
+          //   }
+          // }
+          // roomIndex++;
         });
         this.model.roomPrices = [...this.model.roomPrices, ...roomPrices];
         if (this.model.roomPrices && this.model.roomPrices.length > 2) {
@@ -2114,8 +2303,10 @@ export default {
           sum += item.roomFee + item.deposit;
         });
         this.amount = sum;
-        console.log("orderFees", orderFees);
-        this.model.orderFees = [...this.model.orderFees, ...orderFees];
+        // console.log("orderFees", orderFees);
+        
+        this.loadOrderFees();
+        // this.model.orderFees = [...this.model.orderFees, ...orderFees];
       }
     },
     submitForm() {