Parcourir la source

每天房价自定义后 各种场景计算

gqx il y a 2 ans
Parent
commit
d6b7e6b578
1 fichiers modifiés avec 197 ajouts et 94 suppressions
  1. 197 94
      src/views/room/modules/checkIn/BillRoomForm.vue

+ 197 - 94
src/views/room/modules/checkIn/BillRoomForm.vue

@@ -973,9 +973,9 @@ export default {
       PriceData: [],
       newTabIndex: 0,
       //调价弹窗
-      editPriceModal:false,
+      editPriceModal: false,
       //调价的索引
-      editPriceIndex:null,
+      editPriceIndex: null,
       selectedRowKeys: [],
       // data,
       columns,
@@ -1061,23 +1061,31 @@ export default {
     };
   },
   computed: {
-
-    editPriceData(){
-      let arr = []
-      arr.length = this.model.orderInfo.dayCount
+    editPriceData() {
+      let arr = [];
+      arr.length = this.model.orderInfo.dayCount;
       for (let i = 0; i < arr.length; i++) {
         arr[i] = {
-          day:this.addDate(this.model.orderInfo.arrivalTime2,i),
-          price: this.model.roomPrices[this.editPriceIndex] && this.model.roomPrices[this.editPriceIndex].prefPrice || 0
-        }
-        let idx = this.model.roomPrices[this.editPriceIndex] && this.model.roomPrices[this.editPriceIndex].editPriceTime && this.model.roomPrices[this.editPriceIndex].editPriceTime.findIndex( item => item == arr[i].day)
-        if ( idx > -1) {
-          console.log(idx)
-          arr[i].price = this.model.roomPrices[this.editPriceIndex].editPrice[idx]
+          day: this.addDate(this.model.orderInfo.arrivalTime2, i),
+          price:
+            (this.model.roomPrices[this.editPriceIndex] &&
+              this.model.roomPrices[this.editPriceIndex].prefPrice) ||
+            0,
+        };
+        let idx =
+          this.model.roomPrices[this.editPriceIndex] &&
+          this.model.roomPrices[this.editPriceIndex].editPriceTime &&
+          this.model.roomPrices[this.editPriceIndex].editPriceTime.findIndex(
+            (item) => item == arr[i].day
+          );
+        if (idx > -1) {
+          console.log(idx);
+          arr[i].price =
+            this.model.roomPrices[this.editPriceIndex].editPrice[idx];
         }
       }
-      this.PriceData = arr
-      return arr
+      this.PriceData = arr;
+      return arr;
     },
 
     formDisabled() {
@@ -1178,60 +1186,92 @@ export default {
     //  this.getcesRoomLayout();
   },
   methods: {
-
     //批量调价
-    batchPrice(e){
+    batchPrice(e) {
       console.log(e);
-      this.editPriceData.forEach(ele=>{
-        ele.price = e
-      })
+      this.editPriceData.forEach((ele) => {
+        ele.price = e;
+      });
     },
 
-
     //根据传入的数字将日期加上对应的天数
-		addDate(date,days){
-			console.log(date, days);
-			let time = new Date(date);
-			time.setDate(time.getDate() + days);
-			let m = time.getMonth() + 1;
-			let d = time.getDate();
-			if (m<10) {
-				m = '0' + m;
-			}
-			if (d<10) {
-				d = '0' + d;
-			}
-			return time.getFullYear() + '-' + m + '-' + d;
-		},
+    addDate(date, days) {
+      console.log(date, days);
+      let time = new Date(date);
+      time.setDate(time.getDate() + days);
+      let m = time.getMonth() + 1;
+      let d = time.getDate();
+      if (m < 10) {
+        m = "0" + m;
+      }
+      if (d < 10) {
+        d = "0" + d;
+      }
+      return time.getFullYear() + "-" + m + "-" + d;
+    },
     /**
      * 点击修改图标时
      */
-    onCellExpand(idx){
+    onCellExpand(idx) {
       console.log(idx);
-      this.editPriceIndex = idx
-      console.log('11111111111111111111111',this.model.roomPrices[this.editPriceIndex]);
+      this.editPriceIndex = idx;
+      console.log(
+        "11111111111111111111111",
+        this.model.roomPrices[this.editPriceIndex]
+      );
       this.editPriceModal = true;
     },
 
     /**
      * 修改完成
      */
-    editPriceOk(){
+    editPriceOk() {
       console.log(this.editPriceData);
-      this.model.roomPrices[this.editPriceIndex].editPriceTime = []
-      this.model.roomPrices[this.editPriceIndex].editPrice = []
-      this.editPriceData.forEach(ele=>{
-        this.model.roomPrices[this.editPriceIndex].editPriceTime.push(ele.day)
-        this.model.roomPrices[this.editPriceIndex].editPrice.push(ele.price)
-      })
+      this.model.roomPrices[this.editPriceIndex].editPriceTime = [];
+      this.model.roomPrices[this.editPriceIndex].editPrice = [];
+      this.editPriceData.forEach((ele) => {
+        this.model.roomPrices[this.editPriceIndex].editPriceTime.push(ele.day);
+        this.model.roomPrices[this.editPriceIndex].editPrice.push(ele.price);
+      });
       console.log(this.model.roomPrices);
-      this.model.roomPrices[this.editPriceIndex].prefPrice = this.editPriceData[0].price
-      this.onCellChange('prefPrice', this.editPriceIndex, this.editPriceData[0].price)
-      this.editPriceData.forEach(ele=>{
-        ele.prcie = 0
-      })
+      this.model.roomPrices[this.editPriceIndex].prefPrice =
+        this.editPriceData[0].price;
+      this.onCellChange(
+        "prefPrice",
+        this.editPriceIndex,
+        this.editPriceData[0].price
+      );
+      this.editPriceData.forEach((ele) => {
+        ele.prcie = 0;
+      });
       console.log(this.editPriceData);
-      this.editPriceModal = false
+      this.editPriceModal = false;
+
+      var sum = 0;
+      for (var i = 0; i < this.model.roomPrices.length; i++) {
+        var money = 0;
+        var item = this.model.roomPrices[i];
+        if (item.editPrice && item.editPrice.length > 0) {
+          item.editPrice.forEach((p) => {
+            money += p;
+          });
+          item.roomFee = money;
+          sum += money + item.deposit;
+        } else {
+          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;
+        }
+      }
+      this.amount = sum;
     },
 
     presetNumChange(e, record) {
@@ -1264,7 +1304,7 @@ export default {
     loadRooms() {
       // this.model.roomPrices = [];
       // this.model.roomIds = [];
-      this.amount = 0;
+      // this.amount = 0;
       getAction("/rooms/cesRooms/can-user-rooms", {
         startOf:
           this.model.orderInfo.arrivalTime2 +
@@ -1286,7 +1326,11 @@ export default {
             // });
             t.buildingRooms.forEach((b) => {
               b.floorRooms.forEach((f) => {
-                this.$set(f, "check", 0);
+                this.$set(
+                  f,
+                  "check",
+                  this.model.roomIds.some((r) => r.id == f.id) ? 1 : 0
+                );
               });
             });
           });
@@ -1354,7 +1398,19 @@ export default {
         .add(e, "days")
         .format("YYYY-MM-DD");
       this.loadRooms();
-      this.edit(this.modelDefault);
+
+      // this.modelDefault = Object.assign({}, this.modelDefault, {
+      //   roomPrices: this.model.roomPrices,
+      //   orderFees: this.model.orderFees,
+      // });
+      // this.edit(this.modelDefault);
+      var i = 0;
+      this.model.roomPrices.forEach((t) => {
+        t.day = this.model.orderInfo.dayCount;
+        this.editPriceIndex = i;
+        this.editPriceOk();
+        i++;
+      });
     },
     disabledDate(current) {
       return current && current < moment().add(-1, "days").endOf("day");
@@ -1474,12 +1530,12 @@ export default {
         this.model.roomPrices = dataSource;
       }
 
-      var sum = 0;
-      this.model.roomPrices.forEach(function (item) {
-        sum += item.roomFee + item.deposit;
-      });
-      this.amount = sum;
-      console.log("this.model.roomPrices", this.model.roomPrices);
+      // var sum = 0;
+      // this.model.roomPrices.forEach(function (item) {
+      //   sum += item.roomFee + item.deposit;
+      // });
+      // this.amount = sum;
+      // console.log("this.model.roomPrices", this.model.roomPrices);
     },
     // handleChange(value, index, column) {
     //   const newData = [...this.data2];
@@ -1535,6 +1591,25 @@ export default {
       console.log("editTabs", e);
       var index = this.model.roomIds.findIndex((t) => t.id == e);
       this.model.roomIds.splice(index, 1);
+      this.model.roomPrices = this.model.roomPrices.filter(
+        (t) => t.roomId != e
+      );
+      this.model.orderFees = this.model.orderFees.filter((t) => t.roomId != e);
+      var sum = 0;
+      for (var i = 0; i < this.model.roomPrices.length; i++) {
+        var money = 0;
+        var item = this.model.roomPrices[i];
+        if (item.editPrice && item.editPrice.length > 0) {
+          item.editPrice.forEach((p) => {
+            money += p;
+          });
+          item.roomFee = money;
+          sum += money + item.deposit;
+        } else {
+          sum += item.roomFee + item.deposit;
+        }
+      }
+      this.amount = sum;
     },
     tabClick(e) {
       console.log("tabClick", e);
@@ -1543,8 +1618,16 @@ export default {
     },
     modalFormOk(e) {
       console.log("e", e);
+      this.model.roomPrices = this.model.roomPrices.filter((t) =>
+        e.some((r) => r.id == t.roomId)
+      );
+      this.model.orderFees = this.model.orderFees.filter((t) =>
+        e.some((r) => r.id == t.roomId)
+      );
       this.modelDefault = Object.assign({}, this.modelDefault, {
         roomIds: e,
+        roomPrices: this.model.roomPrices,
+        orderFees: this.model.orderFees,
       });
       this.edit(this.modelDefault);
     },
@@ -1599,52 +1682,69 @@ export default {
           var roomLayout = this.roomLayoutList.find(
             (t) => (t.id = item.layoutId)
           );
-          roomPrices.push({
-            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.editPriceIndex = this.model.roomPrices.findIndex(
+            (t) => t.roomId == item.id
+          );
+          var find = this.model.roomPrices[this.editPriceIndex];
+          if (!find) {
+            var obj = {
+              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,
+            };
+            roomPrices.push(obj);
+          } else {
+            find.day = this.model.orderInfo.dayCount;
+            this.editPriceOk();
+          }
           var payType = this.payTypeList[0];
-
-          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) {
+          if (!this.model.orderFees.some((t) => t.roomId == item.id)) {
             orderFees.push({
-              subjectType: 1,
-              subjectTypeLabel: "押金",
+              subjectType: 2,
+              subjectTypeLabel: "预收房费",
               payType: payType ? payType.id : "",
               payTypeLabel: payType ? payType.name : "",
-              receivable: deposit,
-              money: deposit,
+              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;
+            // }
           }
         });
-        this.model.roomPrices = roomPrices;
+        this.model.roomPrices = [...this.model.roomPrices, ...roomPrices];
         var sum = 0;
         this.model.roomPrices.forEach(function (item) {
           sum += item.roomFee + item.deposit;
         });
         this.amount = sum;
-
-        this.model.orderFees = orderFees;
-        console.log("this.model", this.model);
+        console.log("orderFees", orderFees);
+        this.model.orderFees = [...this.model.orderFees, ...orderFees];
       }
-      // console.log("this.amount2", JSON.stringify(this.amount));
     },
     submitForm() {
       const that = this;
@@ -1657,9 +1757,12 @@ export default {
             .format("YYYY-MM-DD");
           that.model.livingRoomDayPrices.push({
             livingType: 1,
-            dayTime: t.editPriceTime? t.editPriceTime[b].toString() : dayTime,
+            dayTime: t.editPriceTime ? t.editPriceTime[b].toString() : dayTime,
             // price:  t.editPrice? t.editPrice[b].toString() : t.prefPrice,
-            price: ( t.editPrice && t.editPriceTime && t.editPriceTime[b]==dayTime ) ? t.editPrice[b].toString() : t.prefPrice,
+            price:
+              t.editPrice && t.editPriceTime && t.editPriceTime[b] == dayTime
+                ? t.editPrice[b].toString()
+                : t.prefPrice,
             // dayTime: dayTime,
             // price: t.prefPrice,
             roomLayoutId: t.layoutId,