onSiteActivity.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. const app = require('../../utils/util.js');
  2. const tool = require('../../utils/tool.js');
  3. Page({
  4. data: {
  5. checkArr: [],
  6. member: [],
  7. planHeart: 0,
  8. heartTime: 0,
  9. myNum: 0
  10. },
  11. goTousu() {
  12. wx.switchTab({
  13. url: '/pages/service/service',
  14. })
  15. },
  16. love(e) {
  17. wx.showLoading({
  18. title: '加载中',
  19. })
  20. console.log(e)
  21. let status = this.data.member[e.currentTarget.dataset.index].hearted
  22. let status1 = 'member[' + e.currentTarget.dataset.index + '].hearted'
  23. console.log(status)
  24. if (status == 1) {
  25. wx.request({
  26. url: app.globalData.publicUrl + '/wx/actives/' + this.data.openid + '/' + this.data.activeId + '/unfollow',
  27. method: "get",
  28. data: {
  29. targetId: e.currentTarget.dataset.openid
  30. },
  31. success: (res) => {
  32. if (res.data.code == 0) {
  33. console.log(res, '我取消心动了')
  34. this.setData({
  35. [status1]: 0,
  36. member: this.data.member
  37. })
  38. console.log(this.data.member)
  39. this.getMyheartNowTimes();
  40. wx.hideLoading();
  41. }
  42. },
  43. fail:(err)=>{
  44. wx.hideLoading();
  45. }
  46. })
  47. } else {
  48. if (this.data.heartTime < this.data.planHeart) {
  49. wx.request({
  50. url: app.globalData.publicUrl + '/wx/actives/' + this.data.openid + '/' + this.data.activeId + '/heartbeat',
  51. method: "get",
  52. data: {
  53. targetId: e.currentTarget.dataset.openid
  54. },
  55. success: (res) => {
  56. if (res.data.code == 0) {
  57. console.log(res, '我心动了')
  58. this.setData({
  59. [status1]: 1,
  60. member: this.data.member
  61. })
  62. console.log(this.data.member)
  63. this.getMyheartNowTimes();
  64. wx.hideLoading();
  65. }
  66. },
  67. fail:(err)=>{
  68. wx.hideLoading();
  69. }
  70. })
  71. } else {
  72. wx.hideLoading();
  73. wx.showToast({
  74. title: '您已经达到心动上限了呦',
  75. icon: 'none',
  76. duration: 3000,
  77. })
  78. }
  79. }
  80. },
  81. // 获取我的心动次数
  82. getMyheartNowTimes() {
  83. wx.request({
  84. url: app.globalData.publicUrl + '/wx/actives/' + this.data.openid + '/' + this.data.activeId + '/myHearts',
  85. method: "get",
  86. success: (res) => {
  87. console.log(res, '查询目前心动次数')
  88. if (res.data.code == 0) {
  89. this.setData({
  90. heartTime: res.data.heartCount
  91. })
  92. }
  93. }
  94. })
  95. },
  96. getActivies() {
  97. wx.request({
  98. url: app.globalData.publicUrl + '/wx/actives/' + this.data.openid + '/' + this.data.activeId + '/detail',
  99. method: "get",
  100. success: (res) => {
  101. console.log(res, '查询活动详情获取心动上限次数')
  102. if (res.data.code == 0) {
  103. this.setData({
  104. planHeart: Number(res.data.activeRoll.planHeart)
  105. })
  106. }
  107. }
  108. })
  109. wx.request({
  110. url: app.globalData.publicUrl + '/wx/actives/' + this.data.openid + '/' + this.data.activeId + '/members',
  111. method: "get",
  112. success: (res) => {
  113. if (res.data.code == 0) {
  114. console.log(res.data.members, '我获取人员名单')
  115. this.setData({
  116. member: res.data.members
  117. })
  118. }
  119. }
  120. })
  121. wx.request({
  122. url: app.globalData.publicUrl + '/wx/actives/' + this.data.openid + '/' + this.data.activeId + '/sign',
  123. method: "get",
  124. success: (res) => {
  125. console.log(res,'我签到的结果')
  126. if (res.data.code == 0) {
  127. this.setData({
  128. myNum: res.data.activeNumber
  129. })
  130. }
  131. }
  132. })
  133. },
  134. async onLoad(options) {
  135. console.log(options)
  136. tool.openidStatus().then(result => {
  137. this.setData({
  138. openid: result[0],
  139. sessionkey: result[1],
  140. activeId: options.id
  141. })
  142. this.getActivies();
  143. this.getMyheartNowTimes();
  144. })
  145. },
  146. /**
  147. * 生命周期函数--监听页面初次渲染完成
  148. */
  149. onReady: function () {
  150. },
  151. /**
  152. * 生命周期函数--监听页面显示
  153. */
  154. onShow: function () {
  155. this.data.realTime = setInterval(()=>
  156. {
  157. this.getActivies();
  158. this.getMyheartNowTimes();
  159. }, 10000)//间隔时间
  160. // 更新数据
  161. this.setData({
  162. realTime:this.data.realTime,//实时数据对象(用于关闭实时刷新方法)
  163. })
  164. },
  165. /**
  166. * 生命周期函数--监听页面隐藏
  167. */
  168. onHide: function () {
  169. clearInterval(this.data.realTime)
  170. },
  171. /**
  172. * 生命周期函数--监听页面卸载
  173. */
  174. onUnload: function () {
  175. },
  176. /**
  177. * 页面相关事件处理函数--监听用户下拉动作
  178. */
  179. onPullDownRefresh: function () {
  180. },
  181. /**
  182. * 页面上拉触底事件的处理函数
  183. */
  184. onReachBottom: function () {
  185. },
  186. /**
  187. * 用户点击右上角分享
  188. */
  189. onShareAppMessage: function () {
  190. }
  191. })