Sfoglia il codice sorgente

电子券选择逻辑优化

john 2 anni fa
parent
commit
141f19fd33

+ 20 - 4
src/api/mockData/checkout.qh8.response.json

@@ -27,6 +27,7 @@
     "coupons": [
       {
         "code": "sggsxqg614f_t",
+        "couponId": "1",
         "name": "首2小时停车券(测试)",
         "expirationDate": "2023-05-31 23:59:59",
         "discountFee": 20,
@@ -36,24 +37,27 @@
       },
       {
         "code": "jvfmu4ept17_t",
+        "couponId": "2",
         "name": "5元停车券(周末及法定节假日)",
         "expirationDate": "2023-05-31 23:59:59",
         "discountFee": 5,
-        "defaultSelected": false,
+        "defaultSelected": true,
         "superposition": "2",
         "limitCountPerOrder": 1000
       },
       {
         "code": "r43iz9fgt5i_t",
+        "couponId": "2",
         "name": "5元停车券(周末及法定节假日)",
         "expirationDate": "2023-05-31 23:59:59",
         "discountFee": 5,
-        "defaultSelected": false,
+        "defaultSelected": true,
         "superposition": "2",
         "limitCountPerOrder": 1000
       },
       {
         "code": "h4rosxr74om_t",
+        "couponId": "3",
         "name": "周末首2小时满赠停车券--001--001",
         "expirationDate": "2023-05-31 23:59:59",
         "discountFee": 20,
@@ -61,8 +65,19 @@
         "superposition": "2",
         "limitCountPerOrder": 1
       },
+      {
+        "code": "h5rosxr74om_t",
+        "couponId": "3",
+        "name": "周末首2小时满赠停车券--001--001",
+        "expirationDate": "2023-05-31 23:59:59",
+        "discountFee": 20,
+        "defaultSelected": true ,
+        "superposition": "2",
+        "limitCountPerOrder": 1
+      },
       {
         "code": "0wtk9cbu9g2_t",
+        "couponId": "4",
         "name": "首2小时免费停车优惠券",
         "expirationDate": "2023-05-31 23:59:59",
         "discountFee": 20,
@@ -72,12 +87,13 @@
       },
       {
         "code": "g2viqqia3hs_t",
+        "couponId": "5",
         "name": "停车电子券(金额券)",
         "expirationDate": "2023-05-31 23:59:59",
-        "discountFee": 5,
+        "discountFee": 40,
         "defaultSelected": false,
         "superposition": "2",
-        "limitCountPerOrder": 0
+        "limitCountPerOrder": 1
       }
     ]
   },

+ 112 - 0
src/api/mockData/checkout.qh9.response.json

@@ -0,0 +1,112 @@
+{
+  "parkingRecord": {
+    "vehicleNo": "赣A45678",
+    "enterTime": "2023-04-17 18:14:19",
+    "serviceMin": 27217,
+    "totalFee": 16000,
+    "actualPayFee": 140,
+    "thirdPartyId": "6a61bf47dc324ccd9d9ae8e3c0b914ab",
+    "thirdParkOrderNo": "DgNwcrwdlHeIrBMLDpmWd2",
+    "createdByQrCode": false,
+    "totalFeeInYuan": 160
+  },
+  "discountInfo": {
+    "usingTotalDiscount": 20,
+    "memberLevelDiscount": false,
+    "points": [
+      {
+        "available": 5060,
+        "selected": false,
+        "pointsPerUnit": 50,
+        "unitAmount": 5,
+        "newMember": false,
+        "label": "已选择兑换28小时",
+        "memberGradeText": "金卡",
+        "discountFee": 0
+      }
+    ],
+    "coupons": [
+      {
+        "code": "sggsxqg614f_t",
+        "selected": true,
+        "name": "首2小时停车券(测试)",
+        "expirationDate": "2023-05-31 23:59:59",
+        "discountFee": 20,
+        "defaultSelected": true,
+        "superposition": "2",
+        "limitCountPerOrder": 1,
+        "disabled": false
+      },
+      {
+        "code": "jvfmu4ept17_t",
+        "selected": false,
+        "name": "5元停车券(周末及法定节假日)",
+        "expirationDate": "2023-05-31 23:59:59",
+        "discountFee": 5,
+        "defaultSelected": false,
+        "superposition": "2",
+        "limitCountPerOrder": 1000,
+        "disabled": true
+      },
+      {
+        "code": "r43iz9fgt5i_t",
+        "selected": false,
+        "name": "5元停车券(周末及法定节假日)",
+        "expirationDate": "2023-05-31 23:59:59",
+        "discountFee": 5,
+        "defaultSelected": false,
+        "superposition": "2",
+        "limitCountPerOrder": 1000,
+        "disabled": true
+      },
+      {
+        "code": "h4rosxr74om_t",
+        "selected": false,
+        "name": "周末首2小时满赠停车券--001--001",
+        "expirationDate": "2023-05-31 23:59:59",
+        "discountFee": 20,
+        "defaultSelected": false,
+        "superposition": "2",
+        "limitCountPerOrder": 1,
+        "disabled": true
+      },
+      {
+        "code": "0wtk9cbu9g2_t",
+        "selected": false,
+        "name": "首2小时免费停车优惠券",
+        "expirationDate": "2023-05-31 23:59:59",
+        "discountFee": 20,
+        "defaultSelected": false,
+        "superposition": "1",
+        "limitCountPerOrder": 1,
+        "disabled": true
+      },
+      {
+        "code": "g2viqqia3hs_t",
+        "selected": false,
+        "name": "停车电子券(金额券)",
+        "expirationDate": "2023-05-31 23:59:59",
+        "discountFee": 5,
+        "defaultSelected": false,
+        "superposition": "2",
+        "limitCountPerOrder": 0,
+        "disabled": true
+      }
+    ]
+  },
+  "parkingRule": {
+    "enableNewMemberPoints": false,
+    "enablePoints": true,
+    "enableCoupon": true,
+    "enablePaperCoupons": false,
+    "enableConsume": false,
+    "enableConsumeSplit": false,
+    "hourPrice": 5
+  },
+  "parkInfo": {
+    "parkName": "深圳前海湾停车场",
+    "description": "计费基础规则:\n15分钟内免费,首小时15元,其后每小时5元,全天封顶60元。\n嘉湾汇会员停车礼遇:\n银卡:每月可免费领取2张首2小时停车券\n金卡:每月可免费领取5张首2小时停车券\n铂金卡:每月可免费领取10张首2小时停车券\n*数量有限,领完即止\n仅限开具一个月内的停车费电子发票 ",
+    "parkMallCode": 5,
+    "buildingId": "QHKC-P1"
+  }
+}

+ 15 - 13
src/pages/parkingFee/mixins/parkingFeeCoupon.js

@@ -86,12 +86,19 @@ export default {
       return Number.parseInt(i.replace(/coupon/g, ''));
     },
     checkboxItemChange(name, index) {
+      const coupon  = this.couponList[index];
+      if ( coupon.disabled ) {
+        setTimeout(() => {
+          // 根据电子券规则判断是否可选
+          this.isDisabledByRule(coupon, index);
+        }, 100)
+        return;
+      }
+      
       // 取消勾选时
       if (this.checkedCouponList.indexOf(name) > -1) {
         this.checkedCouponList = this.checkedCouponList.filter((i) => i !== name);
         setTimeout(() => {
-          // console.log(158, this.checkedCouponList);
-          // this.groupedCouponData();
           this.remainPrice = this.remainPrice - this.couponList[index].discountFee
           this.newGroupedCouponData()
         }, 100)
@@ -102,10 +109,6 @@ export default {
       this.remainPrice = this.remainPrice + this.couponList[index].discountFee
       if (!item.disabled) {
         this.checkedCouponList.push(`coupon${index}`);
-        setTimeout(() => {
-          // 根据电子券规则判断是否可选
-          this.isDisabledByRule(item, index);
-        }, 100)
       }
     },
     // 对不同类型的优惠券进行汇总统计
@@ -201,16 +204,18 @@ export default {
           })
           break;
         case '2': // 同类型可叠加
+          // 找到
           couponList = couponList.map((elm, i) => {
             elm.disabled = false; // 默认可选
-            const elmName = `coupon${i}`;
+            // 找到所以 superposition === 2 的同类型的券
             if (elm.superposition === superposition) {
+              const selectCouponIds = couponList.filter((iem, iemi) => iem.couponId === elm.couponId && this.checkedCouponList.indexOf(`coupon${iemi}`) > -1);
               if (elm.limitCountPerOrder > 1) { // 是否存在上限
-                if (this.checkedCouponList.length >= limitCountPerOrder) {
-                  elm.disabled = this.checkedCouponList.indexOf(elmName) < 0
+                if (selectCouponIds.length >= elm.limitCountPerOrder) {
+                  elm.disabled = selectCouponIds.findIndex(iem => iem.code === elm.code) < 0
                 }
               } else {
-                elm.disabled = this.checkedCouponList.indexOf(elmName) < 0 // 同类型可选的券,如果可选上限是1,就设为不可选择
+                elm.disabled = selectCouponIds.findIndex(iem => iem.code === elm.code) < 0 && selectCouponIds.length > 0 // 同类型可选的券,如果可选上限是1,就设为不可选择
               }
             } else {
               elm.disabled = true; // 非同批次的优惠券设置为不可选择
@@ -219,7 +224,6 @@ export default {
           })
           break;
       }
-      console.log(220, couponList)
       this.couponList = [...couponList];
     },
     // 根据电子券规则判断是否可选
@@ -343,10 +347,8 @@ export default {
     confirm() {
       // 重新计算兑换券优惠
       const checkedCouponList = this.checkedCouponList.map((i) => this.item2Number(i));
-      console.log(checkedCouponList);
       const couponList = this.couponList.map((elm, index) => {
         elm.selected = false;
-        console.log(checkedCouponList, index);
         if (this.checkedCouponList.indexOf(`coupon${index}`) > -1) {
           elm.selected = true;
         }

+ 1 - 1
src/pages/parkingFee/parkingFeeDetail.vue

@@ -18,7 +18,7 @@
         </div>
         <div class="info-item-box">
           <div class="label">已停车时长</div>
-          <div class="value">{{ orderDetail.parkingRecord.serviceMin }}</div>
+          <div class="value">{{ orderDetail.parkingRecord.serviceMin | parkingTime }}</div>
         </div>
         <div class="van-hairline--bottom hr"></div>
         <div class="info-item-box">

+ 4 - 4
src/store/order/index.js

@@ -1,4 +1,4 @@
-import checkOutQHResponse from "@/api/mockData/checkout.qh8.response.json";
+import checkOutQHResponse from "@/api/mockData/checkout.qh9.response.json";
 import { checkOut,calculateDiscount,ordersAndPrepay,currentUnlicensedPlate,unlicensedCarCheckIn,unlicensedCarCheckout } from '@/api/parking';
 import state from "@/store/order/state";
 import mutations from "@/store/order/mutations";
@@ -49,11 +49,11 @@ export default {
         }
         // console.log(vehicleNo, res);
         // 所有的优惠时间长转为金额
-        console.log(112,'所有的优惠时间长转为金额');
+        // console.log(112,'所有的优惠时间长转为金额');
         // dispatch('orderInitRule', checkOutQHResponse);
         dispatch('orderInitRule',res);
       } catch ( error ) {
-        console.log('151151151151151',error);
+        // console.log('151151151151151',error);
         /* if (/NOT_FOUND|PARKING_RECORD_NOT_FOUND/.test(error.code)) {
          callback && callback(error)
          } */
@@ -61,7 +61,7 @@ export default {
       }
     },
     orderInitRule( {commit,dispatch,state},checkOutResponse ) {
-      console.log(119,checkOutResponse);
+      // console.log(119,checkOutResponse);
       // 记录buildingId
       if ( checkOutResponse?.parkInfo?.buildingId ) {
         window.localStorage.setItem('buildingId',checkOutResponse.parkInfo.buildingId);

+ 1 - 1
src/store/order/state.js

@@ -34,7 +34,7 @@ export default  {
   // 无牌车逻辑
   unlicensedCar: '',
   // 车场相关
-  parkMallCode: '', // 车场唯一编号
+  parkMallCode: '', // 车场唯一编号 0静安 1浦东 2杭州 3北京 4沈阳 5深圳 6天津
   /* 纸质优惠券相关 */
   paperCoupons: [], // 可选纸质优惠券数量
   paperCouponCount: 0, // 已选纸质择优惠券

+ 3 - 3
src/store/order/utils.js

@@ -8,7 +8,7 @@ export function setSelected( types,orderDetail ) {
         if ( orderDetail.discountInfo?.memberGrade?.length ) {
           const [memberGrade] = orderDetail.discountInfo?.memberGrade;
           if ( !memberGrade?.discountFee ) {
-            memberGrade.discountFee = (memberGrade.hasOwnProperty('defaultDiscountTime')? memberGrade.defaultDiscountTime : memberGrade.discountTime ) * orderDetail.parkingRule.hourPrice
+            memberGrade.discountFee = (memberGrade.hasOwnProperty('defaultDiscountTime')? memberGrade.defaultDiscountTime : memberGrade.discountTime ) * orderDetail.parkingRule.hourPrice || 0
           }
           orderDetail.discountInfo.memberGrade = [{
             ...memberGrade,
@@ -21,7 +21,7 @@ export function setSelected( types,orderDetail ) {
         if ( orderDetail.discountInfo?.consume?.length ) {
           const [consume] = orderDetail.discountInfo?.consume;
           if ( !consume?.discountFee ) {
-            consume.discountFee = (consume.hasOwnProperty('defaultDiscountTime')? consume.defaultDiscountTime : consume.discountTime ) * orderDetail.parkingRule.hourPrice
+            consume.discountFee = (consume.hasOwnProperty('defaultDiscountTime')? consume.defaultDiscountTime : consume.discountTime ) * orderDetail.parkingRule.hourPrice || 0
           }
           orderDetail.discountInfo.consume = [{
             ...consume,
@@ -34,7 +34,7 @@ export function setSelected( types,orderDetail ) {
         if ( orderDetail.discountInfo?.points?.length ) {
           const [points] = orderDetail.discountInfo?.points;
           if ( !points?.discountFee ) {
-            points.discountFee = (points.hasOwnProperty('defaultDiscountTime')? points.defaultDiscountTime : points.discountTime ) * orderDetail.parkingRule.hourPrice
+            points.discountFee = (points.hasOwnProperty('defaultDiscountTime')? points.defaultDiscountTime : points.discountTime ) * orderDetail.parkingRule.hourPrice || 0
           }
           orderDetail.discountInfo.points = [{
             ...points,

+ 7 - 7
src/utils/index.js

@@ -173,12 +173,12 @@ export function initEnv() {
   const href = window.location.href;
   console.log('当前页面的url地址  ',href);
   if ( /dev-|8080/.test(href) ) {
-    window.env = 'qa';
-    window.profileApi = 'https://qa-apim.kerryplus.com/c/api';
-    window.api = 'qaApi';
-    // window.env = 'dev';
-    // window.profileApi = 'https://dev-gateway-kip.kerryonvip.com/api';
-    // window.api = 'devApi';
+    // window.env = 'qa';
+    // window.profileApi = 'https://qa-apim.kerryplus.com/c/api';
+    // window.api = 'qaApi';
+    window.env = 'dev';
+    window.profileApi = 'https://dev-gateway-kip.kerryonvip.com/api';
+    window.api = 'devApi';
     // window.env = 'prod';
     // window.profileApi = 'https://sl-apim.kerryplus.com/c/api';
     // window.api = 'api';
@@ -204,7 +204,7 @@ export function initEnv() {
 export function requestInit() {
   let baseURL = window.profileApi + '/temporary-parking/v1';
   if (window.location.href.indexOf('parking.') < 0) {
-    // baseURL = '/msApi';
+    baseURL = '/msApi';
   }
   window.requestms = createAxiosByinterceptors({
     // baseURL: `https://dev-kip-service-internal.kerryonvip.com/`,