Browse Source

积分和电子券优惠计算

john 2 years ago
parent
commit
3678167ca2

+ 2 - 2
src/pages/parkingFee/components/base/parkingFeeDetail.vue

@@ -148,9 +148,9 @@
           <div>抵扣{{ orderDetail.parkInfo.parkMallCode === 5 ? '金额' : '时长' }}</div>
           <div>抵扣{{ orderDetail.parkInfo.parkMallCode === 5 ? '金额' : '时长' }}</div>
           <div class="popue_box_index" style="width: 325px">
           <div class="popue_box_index" style="width: 325px">
             <div class="popue_box_index4_xs">
             <div class="popue_box_index4_xs">
-              <div class="popue_box_index4_xs_index1" @click="$store.dispatch('order/pointsMath',{type: 'minus'})">-</div>
+              <div class="popue_box_index4_xs_index1" @click="$store.dispatch('order/pointsMath',{type: 'minus', callback: pointsMathCallback})">-</div>
               <div class="popue_box_index4_xs_index2">{{ pointsTime }}</div>
               <div class="popue_box_index4_xs_index2">{{ pointsTime }}</div>
-              <div class="popue_box_index4_xs_index3" @click="$store.dispatch('order/pointsMath',{type: 'add'})">+</div>
+              <div class="popue_box_index4_xs_index3" @click="$store.dispatch('order/pointsMath',{type: 'add', callback: pointsMathCallback})">+</div>
             </div>
             </div>
             <div style="color: #808080">
             <div style="color: #808080">
               {{ orderDetail.parkInfo.parkMallCode === 5 ? '元' : '小时' }}
               {{ orderDetail.parkInfo.parkMallCode === 5 ? '元' : '小时' }}

+ 3 - 2
src/pages/parkingFee/mixins/parkingFeeCoupon.js

@@ -28,6 +28,7 @@ export default {
       coupons: (state) => state.order.coupons,
       coupons: (state) => state.order.coupons,
       maxOneDayDiscountFee: (state) => state.order.maxOneDayDiscountFee, // 深圳单日单次使用上限
       maxOneDayDiscountFee: (state) => state.order.maxOneDayDiscountFee, // 深圳单日单次使用上限
       usingTotalDiscount: (state) => state.order.usingTotalDiscount, // 当前已使用优惠
       usingTotalDiscount: (state) => state.order.usingTotalDiscount, // 当前已使用优惠
+      availableDiscountFee: (state) => state.order.availableDiscountFee, // 当前已使用优惠
     }),
     }),
   },
   },
 
 
@@ -53,7 +54,7 @@ export default {
        * 2、superposition  叠加使用规则 (1不可叠加,2仅同类型可叠加,3可叠加);
        * 2、superposition  叠加使用规则 (1不可叠加,2仅同类型可叠加,3可叠加);
        * */
        * */
       this.couponList = [...this.coupons];
       this.couponList = [...this.coupons];
-      this.remainPrice = this.usingTotalDiscount * 1;
+      this.remainPrice = this.availableDiscountFee * 1;
       if (this.couponList.length) {
       if (this.couponList.length) {
         this.couponList = this.couponList.map((elm, index) => {
         this.couponList = this.couponList.map((elm, index) => {
           elm.disabled = true;
           elm.disabled = true;
@@ -313,7 +314,7 @@ export default {
        // });
        // });
        }*/
        }*/
       // 深圳超限处理
       // 深圳超限处理
-      if (parkMallCode === 5 && this.remainPrice  > actualPayFee) {
+      if (parkMallCode === 5 && this.remainPrice  <= actualPayFee) {
         return Toast({
         return Toast({
           message: `每日最高可抵扣${this.remainPrice}元`,
           message: `每日最高可抵扣${this.remainPrice}元`,
           icon: 'none',
           icon: 'none',

+ 7 - 0
src/pages/parkingFee/mixins/parkingFeeDetail.js

@@ -460,6 +460,13 @@ export default {
         pagePath = 'parkingFeeMsg?type=pay'
         pagePath = 'parkingFeeMsg?type=pay'
       }
       }
       return pagePath
       return pagePath
+    },
+    pointsMathCallback({type, message}) {
+      // console.log(465, type);
+      Toast({
+        message: message,
+        icon: 'none',
+      });
     }
     }
   },
   },
 };
 };

+ 19 - 3
src/store/order.js

@@ -361,30 +361,46 @@ const actions = {
   },
   },
 
 
   // 积分减免
   // 积分减免
-  pointsMath({ commit, dispatch, state }, { type }) {
+  pointsMath({ commit, dispatch, state }, { type, callback }) {
     /**
     /**
      * maxDiscountFee 单次最大可使用金额 
      * maxDiscountFee 单次最大可使用金额 
      * availableDiscountFee 当日剩余可使用优惠金额
      * availableDiscountFee 当日剩余可使用优惠金额
      * available 当前用户的剩余积分,也可以说是可以抵扣的积分,如果有积分抵扣自动勾选,那么这个值=这个值-已勾选积分
      * available 当前用户的剩余积分,也可以说是可以抵扣的积分,如果有积分抵扣自动勾选,那么这个值=这个值-已勾选积分
      */
      */
-
-    // console.log('289289289289289289289289', state.available / (state.pointsPerUnit / state.unitAmount) + state.pointsTime);
     // 计算用户当前的最大可使用积分的总数(单位:元)
     // 计算用户当前的最大可使用积分的总数(单位:元)
     let maxPointsTime = state.available / (state.pointsPerUnit / state.unitAmount) + state.pointsTime;
     let maxPointsTime = state.available / (state.pointsPerUnit / state.unitAmount) + state.pointsTime;
     if (maxPointsTime > state.maxDiscountFee) {
     if (maxPointsTime > state.maxDiscountFee) {
       maxPointsTime = state.maxDiscountFee
       maxPointsTime = state.maxDiscountFee
     }
     }
+    let msg = ''
     // 验证最大积分的总数(单位:元)
     // 验证最大积分的总数(单位:元)
     if (maxPointsTime > state.availableDiscountFee) {
     if (maxPointsTime > state.availableDiscountFee) {
       maxPointsTime = state.availableDiscountFee
       maxPointsTime = state.availableDiscountFee
     }
     }
+    if (type === 'add' && state.pointsTime >= maxPointsTime) {
+      // 以下是深圳积分上限规则
+      // 超出抵扣上限,每日最高可抵扣${this.parkFee.parkInfoEntity.maxOneDayHour}元 '优惠金额' >= '每日最高可抵扣'
+      if (state.usingTotalDiscount >= state.maxOneDayDiscountFee) {
+        msg = `超出抵扣上限,每日最高可抵扣${state.maxDiscountFee}元`
+      }
+      // 超出抵扣上限,每次最高可抵扣${this.integralMaxMoney}元 '积分兑换时长' >= '深圳前海停车积分上限'
+      if (state.pointsTime >= state.maxPointsTime) {
+        msg = `超出抵扣上限,每次最高可抵扣${state.maxDiscountFee}元`
+      }
+      callback({
+        message: msg
+      });
+      return
+    }
     if (type === 'add' && state.pointsTime < maxPointsTime) {
     if (type === 'add' && state.pointsTime < maxPointsTime) {
       const pointsTime = state.pointsTime + state.unitAmount;
       const pointsTime = state.pointsTime + state.unitAmount;
       const available = state.available - state.pointsPerUnit;
       const available = state.available - state.pointsPerUnit;
+      const usingTotalDiscount = usingTotalDiscount + state.unitAmount; // 重新计算已经使用的优惠逻辑
       if (available > -1) {
       if (available > -1) {
         // 如果是深圳车场
         // 如果是深圳车场
         commit('setAvailable', available);
         commit('setAvailable', available);
         commit('setPointsTime', pointsTime);
         commit('setPointsTime', pointsTime);
+        commit('setUsingTotalDiscount', usingTotalDiscount);
       }
       }
     }
     }
     if (type === 'minus' && state.pointsTime > 0) {
     if (type === 'minus' && state.pointsTime > 0) {