share-power.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. // package-basic-data/pages/share-power/share-power.js
  2. const Constants = require('@/utils/Constants.js');
  3. const mixins = require('@/mixins/index.js');
  4. const app = getApp()
  5. const util = require('@/utils/util.js')
  6. const api = require('@/utils/api.js');
  7. Page({
  8. mixins: [mixins],
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. needHelpUserNumber: 5,
  14. powerModelShowFlag: true,
  15. menuButtonTop: 48,
  16. helpUserNumber: 0,
  17. params: {},
  18. helpFlag: true
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad(options) {
  24. const userNum = Number(options.userNum)
  25. this.setData({
  26. params: options,
  27. needHelpUserNumber: userNum,
  28. })
  29. wx.hideShareMenu()
  30. },
  31. /**
  32. * 生命周期函数--监听页面初次渲染完成
  33. */
  34. onReady() {
  35. },
  36. /**
  37. * 生命周期函数--监听页面显示
  38. */
  39. onShow() {
  40. this.showPowerModel()
  41. this.getSystemButtonLocation()
  42. },
  43. /**
  44. * @desc : 页面加载时获取返回按钮距上边距
  45. * @date : 2024/7/31 13:49
  46. * @author : 刘尧
  47. */
  48. getSystemButtonLocation() {
  49. const res = wx.getMenuButtonBoundingClientRect()
  50. this.setData({
  51. menuButtonTop: res.top
  52. })
  53. },
  54. /**
  55. * @desc : 获取微信派发的临时登录凭证
  56. * @date : 2022/5/12 13:49
  57. * @author : 姜永辉
  58. */
  59. wxlogin() {
  60. return new Promise((resolve, reject) => {
  61. // 登录
  62. wx.login({
  63. success: res => {
  64. // 发送 res.code 到后台换取 openId, sessionKey, unionId
  65. console.log("wx.login", res);
  66. if (res.code) {
  67. resolve(res)
  68. } else {
  69. reject(res)
  70. }
  71. }
  72. })
  73. })
  74. },
  75. /**
  76. * @desc : 登录
  77. * @date : 2022/5/12 13:49
  78. * @author : 姜永辉
  79. */
  80. wx_login() {
  81. let _this = this
  82. _this.wxlogin().then(res => {
  83. _this.getopenid({ code: res.code });
  84. })
  85. },
  86. /**
  87. * @desc : 打开助力弹窗
  88. * @author : 刘尧
  89. * @date : 2024/7/29 09:26
  90. */
  91. showPowerModel() {
  92. this.setData({
  93. powerModelShowFlag: true
  94. })
  95. },
  96. /**
  97. * @desc : 获取微信派发的 openid
  98. * @date : 2022/5/12 13:49
  99. * @author : 姜永辉
  100. */
  101. getopenid(param) {
  102. return api.request(Constants.SYS_OPENID_API + 'oauth/wx/login_wechat', 'POST', param)
  103. },
  104. /**
  105. * @desc : 关闭小程序
  106. * @author : 刘尧
  107. * @date : 2024/7/29 09:49
  108. */
  109. closeMiniProgram() {
  110. wx.exitMiniProgram({
  111. success: function () {
  112. console.log('关闭小程序触发');
  113. }
  114. })
  115. },
  116. /**
  117. * @desc : 助力点击
  118. * @author : 刘尧
  119. * @date : 2024/7/31 11:11
  120. */
  121. helpMe() {
  122. let _this = this
  123. console.log('helpMe');
  124. _this.wxlogin().then(res => {
  125. _this.getopenid({ code: res.code }).then(res => {
  126. if (res.data.code == Constants.SUCESS_CODE) {
  127. const openid = res.data.data.openid
  128. let service = app.globalData['couponReceiveService']
  129. const params = _this.data.params
  130. params.userWxid = openid
  131. _this.excute(service, 'insert_coupon_send', params).then(res => {
  132. if (res.data.code == Constants.SUCESS_CODE) {
  133. util.showToast('助力成功!')
  134. this.setData({
  135. helpUserNumber: this.data.helpUserNumber + 1
  136. })
  137. }
  138. this.setData({
  139. helpFlag: false,
  140. powerModelShowFlag: false
  141. })
  142. })
  143. }
  144. })
  145. })
  146. },
  147. /**
  148. * @desc : 打开助力弹窗
  149. * @author : 刘尧
  150. * @date : 2024/7/29 09:26
  151. */
  152. closePowerModel() {
  153. this.setData({
  154. powerModelShowFlag: false
  155. })
  156. },
  157. /**
  158. * 生命周期函数--监听页面隐藏
  159. */
  160. onHide() {
  161. },
  162. /**
  163. * 生命周期函数--监听页面卸载
  164. */
  165. onUnload() {
  166. },
  167. /**
  168. * 页面相关事件处理函数--监听用户下拉动作
  169. */
  170. onPullDownRefresh() {
  171. },
  172. /**
  173. * 页面上拉触底事件的处理函数
  174. */
  175. onReachBottom() {
  176. },
  177. /**
  178. * 用户点击右上角分享
  179. */
  180. onShareAppMessage() {
  181. }
  182. })