guhongwei 2 years ago
parent
commit
3a0a0cfca2
2 changed files with 33 additions and 1 deletions
  1. 32 1
      pages/index/index.js
  2. 1 0
      pages/index/index.wxml

+ 32 - 1
pages/index/index.js

@@ -7,6 +7,37 @@ Page({
         const { route } = e.currentTarget.dataset;
         if (route) wx.navigateTo({ url: `/pages/${route}` });
     },
+    // 重置
+    async toMoney() {
+        let obj = {
+            openid: 'oH0y05UqPfQYt7eBWGMzhkfDwMMA',
+            money: 0.1,
+            school_id: '6355f251cb0f85380e83520b',
+            student_id: '635629fecb0f85380e8354e5'
+        }
+        let res = await app.$post(`/payOrder/toCharge`, obj);
+        if (res.errcode == '0') {
+            // 调取支付窗口
+            let wxSign = res.data.wxSign;
+            console.log(wxSign);
+            wx.requestPayment({
+                timeStamp: wxSign.timestamp,
+                nonceStr: wxSign.nonceStr,
+                package: `prepay_id=${wxSign.prepay_id}`,
+                signType: wxSign.signType,
+                paySign: wxSign.paySign,
+                async success(payRes) {
+                    console.log('充值成功');
+                },
+                async fail(payErr) {
+                    console.log(payErr);
+                    wx.showToast({ title: '充值不成功', icon: 'none' })
+                }
+            })
+        } else {
+            wx.showToast({ title: res.errmsg, icon: 'none' })
+        }
+    },
     /**
      * 生命周期函数--监听页面加载
      */
@@ -17,7 +48,7 @@ Page({
         wx.getStorage({
             key: 'user',
             success: async res => {
-                if (res.data) wx.redirectTo({ url: '/pages/school/index' })
+                // if (res.data) wx.redirectTo({ url: '/pages/school/index' })
                 // /pages/school/index
                 // /pagesSchool/common/lessoninfo
                 // /pagesSchool/schAdmin/course/coachlist

+ 1 - 0
pages/index/index.wxml

@@ -7,6 +7,7 @@
                 <!-- <button type="primary" size="mini" bindtap="toCommon" data-route="school/index">系统首页</button> -->
                 <!-- <button type="primary" size="mini" bindtap="toCommon" data-route="test/index">组件页面</button> -->
                 <!-- <button type="primary" size="mini" bindtap="toCommon" data-route="login/index">去登陆</button> -->
+                <button bindtap="toMoney">充值</button>
             </view>
         </view>
     </view>