姜永辉 1 жил өмнө
parent
commit
65f6bffd84
1 өөрчлөгдсөн 62 нэмэгдсэн , 4 устгасан
  1. 62 4
      pages/welcome/welcome.js

+ 62 - 4
pages/welcome/welcome.js

@@ -36,7 +36,7 @@ Page({
             })
         }
         // 从员工一览购买授权过来
-        if(options.buy){
+        if (options.buy) {
             this.setData({
                 buy: options.buy,
             })
@@ -139,7 +139,8 @@ Page({
                 // 说明注册未支付
                 if (!data.company.license) {
                     // 成功后跳转支付
-                    // this.toPay(res.data.data);
+                    _this.toPay(res.data.data);
+                    return
                 }
 
                 app.globalData.user = {
@@ -184,6 +185,63 @@ Page({
         })
     },
     /**
+     * @desc : 微信支付
+     * @date : 2022/5/12 13:49
+     * @author : 姜永辉
+     */
+    toPay(e) {
+        console.log("toPay", e);
+        let trade = e.company.trade
+        let wechatPayService = app.globalData['wechatPayService']
+        let params = {
+            openId: app.globalData.openid,
+            payFee: trade.tradeAmount,
+            paymentSn: trade.tradeNo,
+        }
+        api.request(wechatPayService.prefix + wechatPayService.unifiedOrder, 'POST', params).then(res => {
+            if (res.data.code === Constants.SUCESS_CODE) {
+                var appid = res.data.data.appId
+                var timeStamp = res.data.data.timeStamp
+                var nonce_str = res.data.data.nonceStr
+                var pk = res.data.data.pack
+                var paySign = res.data.data.paySign
+                let _this = this
+                //调用微信支付
+                wx.requestPayment({
+                    'appId': appid,
+                    'timeStamp': timeStamp,
+                    'nonceStr': nonce_str,
+                    'package': pk,
+                    'signType': 'MD5',
+                    'paySign': paySign,
+                    'success': function (res) {
+                        console.log('success', res);
+                        wx.showToast({
+                            title: '支付成功',
+                            image: '/static/image/success.png',
+                            duration: 2000
+                        })
+                        _this.setData({
+                            loading: false
+                        })
+                        //刷新当前页面
+                        _this.onShow()
+                    },
+                    'fail': function (res) {
+                        console.log('fail', res);
+                        _this.setData({
+                            loading: false
+                        })
+                    },
+                    'complete': function (res) {
+                        // console.log(res);
+                        console.log('complete', res);
+                    }
+                });
+            }
+        });
+    },
+    /**
     * @desc : 登录后获取数据
     * @date : 2022/5/12 13:49
     * @author : 周兴
@@ -197,7 +255,7 @@ Page({
             }).then(res => {
                 if (res.data.code === Constants.SUCESS_CODE) {
                     // 服务器的日期
-                    let nowDate =  res.data.data.nowDate
+                    let nowDate = res.data.data.nowDate
                     app.globalData.nowDate = nowDate
                     // 员工
                     let staff = res.data.data.staff
@@ -229,7 +287,7 @@ Page({
                         app.globalData.user.defaultWhName = staff.defaultWhName
                         app.globalData.user.defaultWhId = staff.defaultWhId
                         app.globalData.user.flgBusiness = staff.flgBusiness
-                        app.globalData.user.flgInit = !!staff.flgInit 
+                        app.globalData.user.flgInit = !!staff.flgInit
                         console.log('ffffffd', app.globalData.company);
 
                         // 调转主页--注意有场景值的情况