share-power.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 : 跳转Welcome
  110. * @author : 刘尧
  111. * @date : 2024/8/5 09:26
  112. */
  113. wantToApp(){
  114. let toUrl = '/pages/welcome/welcome'
  115. wx.navigateTo({
  116. url: toUrl,
  117. })
  118. },
  119. /**
  120. * @desc : 获取微信派发的 openid
  121. * @date : 2022/5/12 13:49
  122. * @author : 姜永辉
  123. */
  124. getopenid(param) {
  125. return api.request(Constants.SYS_OPENID_API + 'oauth/wx/login_wechat', 'POST', param)
  126. },
  127. /**
  128. * @desc : 关闭小程序
  129. * @author : 刘尧
  130. * @date : 2024/7/29 09:49
  131. */
  132. closeMiniProgram() {
  133. wx.exitMiniProgram({
  134. success: function () {
  135. console.log('关闭小程序触发');
  136. }
  137. })
  138. },
  139. /**
  140. * @desc : 助力点击
  141. * @author : 刘尧
  142. * @date : 2024/7/31 11:11
  143. */
  144. helpMe() {
  145. let _this = this
  146. console.log('helpMe');
  147. _this.wxlogin().then(res => {
  148. _this.getopenid({ code: res.code }).then(res => {
  149. if (res.data.code == Constants.SUCESS_CODE) {
  150. const openid = res.data.data.openid
  151. let service = app.globalData['couponReceiveService']
  152. const params = _this.data.params
  153. params.userWxid = openid
  154. _this.excute(service, 'insert_coupon_send', params).then(res => {
  155. if (res.data.code == Constants.SUCESS_CODE) {
  156. util.showToast('助力成功!')
  157. this.setData({
  158. helpUserNumber: this.data.helpUserNumber + 1
  159. })
  160. }
  161. this.setData({
  162. helpFlag: false,
  163. powerModelShowFlag: false
  164. })
  165. })
  166. }
  167. })
  168. })
  169. },
  170. /**
  171. * @desc : 打开助力弹窗
  172. * @author : 刘尧
  173. * @date : 2024/7/29 09:26
  174. */
  175. closePowerModel() {
  176. this.setData({
  177. powerModelShowFlag: false
  178. })
  179. },
  180. /**
  181. * 生命周期函数--监听页面隐藏
  182. */
  183. onHide() {
  184. },
  185. /**
  186. * 生命周期函数--监听页面卸载
  187. */
  188. onUnload() {
  189. },
  190. /**
  191. * 页面相关事件处理函数--监听用户下拉动作
  192. */
  193. onPullDownRefresh() {
  194. },
  195. /**
  196. * 页面上拉触底事件的处理函数
  197. */
  198. onReachBottom() {
  199. },
  200. /**
  201. * 用户点击右上角分享
  202. */
  203. onShareAppMessage() {
  204. }
  205. })