index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. const app = getApp()
  2. Page({
  3. data: {
  4. frameStyle: { useTop: true, name: '系统', leftArrow: false, useBar: false },
  5. },
  6. toCommon: function (e) {
  7. const { route } = e.currentTarget.dataset;
  8. if (route) wx.navigateTo({ url: `/pages/${route}` });
  9. },
  10. async toRefund() {
  11. let obj = {
  12. lesson_id: '63563bbd8018a39220eca774',
  13. student_id: '635629fecb0f85380e8354e5'
  14. }
  15. let res = await app.$post(`/lessonStudent/toRefund`, obj);
  16. if (res.errcode == '0') {
  17. wx.showToast({
  18. title: '退课成功',
  19. icon: 'none'
  20. })
  21. } else {
  22. wx.showToast({
  23. title: res.errmsg,
  24. icon: 'none'
  25. })
  26. }
  27. },
  28. async toPay() {
  29. let obj = {
  30. id: '6357ad3bb78abf276d3ae74e'
  31. }
  32. let res = await app.$post(`/lessonStudent/toRePay`, obj);
  33. if (res?.data?.wxSign) {
  34. // 调取支付窗口
  35. let wxSign = res.data.wxSign;
  36. wx.requestPayment({
  37. timeStamp: wxSign.timestamp,
  38. nonceStr: wxSign.nonceStr,
  39. package: `prepay_id=${wxSign.prepay_id}`,
  40. signType: wxSign.signType,
  41. paySign: wxSign.paySign,
  42. async success(payRes) {
  43. wx.showToast({ title: '报名成功', icon: 'none' })
  44. },
  45. async fail(payErr) {
  46. wx.showToast({ title: '支付不成功', icon: 'none' })
  47. }
  48. })
  49. } else {
  50. wx.showToast({ title: '报名成功', icon: 'none' });
  51. }
  52. },
  53. /**
  54. * 生命周期函数--监听页面加载
  55. */
  56. onLoad: function (options) { },
  57. // 监听用户是否登录
  58. watchLogin: async function () {
  59. // 监听用户是否登录,
  60. wx.getStorage({
  61. key: 'user',
  62. success: async res => {
  63. if (res.data) wx.redirectTo({ url: '/pages/school/index' })
  64. // /pages/school/index
  65. // /pagesSchool/common/lessoninfo
  66. // /pagesSchool/schAdmin/course/coachlist
  67. // /pagesSchool/stuAdmin/money/list
  68. // /pagesSchool/stuAdmin/course/list
  69. },
  70. fail: async res => {
  71. wx.login({
  72. success: async (arr) => {
  73. if (app.globalData?.wxInfo?.openid) { await this.toLogin(app.globalData?.wxInfo?.openid); return; }
  74. const { code: js_code } = arr;
  75. const aee = await app.$get('/wechat/api/login/app', { js_code: js_code, config: 'newCourtApp' });
  76. if (aee.errcode === 0 && aee.data?.openid) {
  77. const openid = aee.data.openid;
  78. app.globalData.wxInfo = { openid };
  79. await this.toLogin(openid);
  80. } else {
  81. wx.showToast({ title: `${aee.errmsg}`, icon: 'fail', duration: 2000 });
  82. wx.redirectTo({ url: '/pages/register/index' });
  83. }
  84. },
  85. });
  86. }
  87. })
  88. },
  89. async toLogin(openid) {
  90. const res = await app.$post('/user/wxAppLogin', { openid });
  91. if (app.$checkRes(res)) {
  92. const { data } = res;
  93. // 没有用户,去注册
  94. if (!data) wx.redirectTo({ url: '/pages/register/index' });
  95. // 有用户,存起来,跳转
  96. else {
  97. wx.setStorageSync('user', data);
  98. wx.redirectTo({ url: '/pages/school/index' });
  99. }
  100. }
  101. },
  102. /**
  103. * 生命周期函数--监听页面初次渲染完成
  104. */
  105. onReady: function () {
  106. },
  107. /**
  108. * 生命周期函数--监听页面显示
  109. */
  110. onShow: function () {
  111. const that = this;
  112. // 监听用户是否登录
  113. that.watchLogin();
  114. },
  115. /**
  116. * 生命周期函数--监听页面隐藏
  117. */
  118. onHide: function () {
  119. },
  120. /**
  121. * 生命周期函数--监听页面卸载
  122. */
  123. onUnload: function () {
  124. },
  125. /**
  126. * 页面相关事件处理函数--监听用户下拉动作
  127. */
  128. onPullDownRefresh: function () {
  129. },
  130. /**
  131. * 页面上拉触底事件的处理函数
  132. */
  133. onReachBottom: function () {
  134. },
  135. /**
  136. * 用户点击右上角分享
  137. */
  138. onShareAppMessage: function () {
  139. }
  140. })