share-power.js 4.8 KB

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