onSiteActivity.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. // this.data.activeId
  123. url: app.globalData.publicUrl + '/wx/actives/' + this.data.openid + '/' + this.data.activeId + '/sign',
  124. method: "get",
  125. success: (res) => {
  126. console.log(res,'我签到的结果')
  127. if (res.data.code == 0) {
  128. this.setData({
  129. myNum: res.data.activeNumber
  130. })
  131. }
  132. }
  133. })
  134. },
  135. async onLoad(options) {
  136. console.log(options)
  137. tool.openidStatus().then(result => {
  138. this.setData({
  139. openid: result[0],
  140. sessionkey: result[1],
  141. activeId: options.id
  142. })
  143. this.getActivies();
  144. this.getMyheartNowTimes();
  145. })
  146. },
  147. /**
  148. * 生命周期函数--监听页面初次渲染完成
  149. */
  150. onReady: function () {
  151. },
  152. /**
  153. * 生命周期函数--监听页面显示
  154. */
  155. onShow: function () {
  156. this.data.realTime = setInterval(()=>
  157. {
  158. this.getActivies();
  159. this.getMyheartNowTimes();
  160. }, 10000)//间隔时间
  161. // 更新数据
  162. this.setData({
  163. realTime:this.data.realTime,//实时数据对象(用于关闭实时刷新方法)
  164. })
  165. },
  166. /**
  167. * 生命周期函数--监听页面隐藏
  168. */
  169. onHide: function () {
  170. clearInterval(this.data.realTime)
  171. },
  172. /**
  173. * 生命周期函数--监听页面卸载
  174. */
  175. onUnload: function () {
  176. },
  177. /**
  178. * 页面相关事件处理函数--监听用户下拉动作
  179. */
  180. onPullDownRefresh: function () {
  181. },
  182. /**
  183. * 页面上拉触底事件的处理函数
  184. */
  185. onReachBottom: function () {
  186. },
  187. /**
  188. * 用户点击右上角分享
  189. */
  190. onShareAppMessage: function () {
  191. }
  192. })