share-power.js 4.2 KB

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