Browse Source

scanQRCode

John-Hong 2 years ago
parent
commit
8d0e038fcf

+ 33 - 16
src/pages/parkingFee/parkingFeeDetail.vue

@@ -269,6 +269,8 @@ import { compare } from '@/utils/location.js';
 import uni from '@/utils/uniHooks';
 import { initWxJsSdkConfig } from '@/utils/login';
 import { isInWeixinH5, getPlatform } from '@/utils/index';
+import { Dialog } from 'vant';
+import { json } from 'body-parser';
 
 export default {
   data() {
@@ -534,18 +536,18 @@ export default {
           this.refreshTime = countDownTime;
         }
       }
-      return;
+      // return;
 
       // 优惠减免(首停、会员、消费)
       this.checkedTotal = uni.getStorageSync('checkedTotal');
       this.discountTotal = uni.getStorageSync('discountTotal');
 
       // 电子券减免(停车券)
-      this.couponInfo = uni.getStorageSync('couponInfo');
-      this.checkedCouponCount = uni.getStorageSync('checkedCouponList').length;
+      this.couponInfo = JSON.parse(uni.getStorageSync('couponInfo'));
+      this.checkedCouponCount = JSON.parse(uni.getStorageSync('checkedCouponList')).length;
 
       // 纸质优惠券
-      this.paperCouponInfo = uni.getStorageSync('paperCouponInfo');
+      this.paperCouponInfo = JSON.parse(uni.getStorageSync('paperCouponInfo'));
     }
   },
   onHide() {
@@ -1873,6 +1875,7 @@ export default {
               window.subscribe('wxPayOver', (options) => {
                 console.log('微信支付结束之后的返回参数', options);
                 if (options?.wxPayOver === 'fail') {
+                  console.log('支付失败');
                   this.failedParkOrder();
                 } else {
                   this.$router.replace({
@@ -1924,14 +1927,23 @@ export default {
 
     // 支付失败弹框 重新创建订单
     reCreateParkOrder() {
-      uni.showModal({
-        showCancel: false,
+      console.log('支付失败弹框 重新创建订单');
+      Dialog.alert({
         title: '提示',
-        content: '支付失败',
-        complete: (r) => {
-          this.createParkOrder();
-        },
+        message: '支付失败',
+        confirmButtonColor: '#333',
+      }).then(() => {
+        // on confirm
+        this.createParkOrder();
       });
+      // uni.showModal({
+      //   showCancel: false,
+      //   title: '提示',
+      //   content: '支付失败',
+      //   complete: (r) => {
+      //     this.createParkOrder();
+      //   },
+      // });
     },
 
     // 支付失败后返还优惠券
@@ -1939,17 +1951,22 @@ export default {
       const param = {
         orderno: this.parkInfo.orderno,
       };
+      console.log(1943, '支付失败后返还优惠券');
       this.$md(param);
-      this.$request({
-        path: this.$baseURL + 'api/1.0/park/failedParkOrder',
-        data: param,
-        method: 'POST',
-        header: JSON.parse(uni.getStorageSync('handleUser')),
-      })
+      console.log(1946, this.$baseURL + 'api/1.0/park/failedParkOrder');
+      uni
+        .request({
+          url: this.$baseURL + 'api/1.0/park/failedParkOrder',
+          data: param,
+          method: 'POST',
+          header: JSON.parse(uni.getStorageSync('handleUser')),
+        })
         .then((res) => {
+          console.log(1954, 'reCreateParkOrder then');
           this.reCreateParkOrder();
         })
         .catch((err) => {
+          console.log(1958, 'reCreateParkOrder catch');
           this.reCreateParkOrder();
         });
     },

+ 43 - 9
src/pages/parkingFee/parkingFeePaperCoupon.vue

@@ -79,13 +79,17 @@ const app = {};
 import { mapState } from 'vuex';
 import fuiToast from '@/components/fui-toast/fui-toast.vue';
 import { initWxJsSdkConfig } from '@/utils/login';
+import { getPlatform } from '@/utils/index';
 
 export default {
   components: {
     fuiToast,
   },
   created() {
-    initWxJsSdkConfig(['scanQRCode', 'checkJsApi']);
+    const platform = getPlatform();
+    if (platform === 'micromessenger') {
+      initWxJsSdkConfig(['scanQRCode']);
+    }
     this.servicefee = uni.getStorageSync('servicefee'); // 应缴金额
     this.parkDiscountTotal = uni.getStorageSync('parkingTotal'); // 总停车优惠
     if (uni.getStorageSync('parkFee')) {
@@ -182,14 +186,44 @@ export default {
     },
     // 扫码
     scanCode() {
-      this.$wx.scanQRCode({
-        needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
-        scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码,默认二者都有
-        success: (res) => {
-          console.log(187, res);
-          // this.formMsg.deviceCode = res.resultStr;
-        },
-      });
+      const runScanFn = (res) => {
+        if (res.scanType == 'QR_CODE' && res.scanType) {
+          console.log(res.result);
+          const url = res.result;
+          if (url.indexOf('auth/') === -1) {
+            this.getPaperCouponInfo(res.result);
+          } else {
+            const start = url.indexOf('auth/');
+            const end = url.indexOf('?');
+            const params = url.slice(start, end).split('/');
+            if (params && params.length) {
+              const couponCode = params[1];
+              this.getPaperCouponInfo(couponCode);
+            }
+          }
+        }
+      };
+      // 微信小程序
+      const platform = getPlatform();
+      if (platform === 'miniprogram') {
+        window.toWXSendMsg({
+          type: 'scanQRCode',
+        });
+        window.subscribe('scanQRCodeOver', (options) => {
+          console.log('微信扫码结束之后的返回参数', options);
+          runScanFn(options)
+        });
+      } else {
+        this.$wx.scanQRCode({
+          needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
+          scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码,默认二者都有
+          success: (res) => {
+            // console.log(187, res);
+            runScanFn(res)
+            // this.formMsg.deviceCode = res.resultStr;
+          },
+        });
+      }
 
       /* uni.scanCode({
         onlyFromCamera: false,