onSiteActivity.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. console.log(e)
  18. let status = this.data.member[e.currentTarget.dataset.index].hearted
  19. let status1 = 'member[' + e.currentTarget.dataset.index + '].hearted'
  20. console.log(status)
  21. if (status == 0) {
  22. wx.request({
  23. url: app.globalData.publicUrl + '/wx/actives/' + this.data.openid + '/' + this.data.activeId + '/unfollow',
  24. method: "get",
  25. data: {
  26. targetId: e.currentTarget.dataset.openid
  27. },
  28. success: (res) => {
  29. if (res.data.code == 0) {
  30. console.log(res, '我取消心动了')
  31. this.setData({
  32. [status1]: 1,
  33. member: this.data.member
  34. })
  35. console.log(this.data.member)
  36. this.getMyheartNowTimes();
  37. }
  38. }
  39. })
  40. } else {
  41. if (this.data.heartTime < this.data.planHeart) {
  42. wx.request({
  43. url: app.globalData.publicUrl + '/wx/actives/' + this.data.openid + '/' + this.data.activeId + '/heartbeat',
  44. method: "get",
  45. data: {
  46. targetId: e.currentTarget.dataset.openid
  47. },
  48. success: (res) => {
  49. if (res.data.code == 0) {
  50. console.log(res, '我心动了')
  51. this.setData({
  52. [status1]: 0,
  53. member: this.data.member
  54. })
  55. console.log(this.data.member)
  56. this.getMyheartNowTimes();
  57. }
  58. }
  59. })
  60. } else {
  61. wx.showToast({
  62. title: '您已经达到心动上限了呦',
  63. icon: 'none',
  64. duration: 3000,
  65. })
  66. }
  67. }
  68. },
  69. // 获取我的心动次数
  70. getMyheartNowTimes() {
  71. wx.request({
  72. url: app.globalData.publicUrl + '/wx/actives/' + this.data.openid + '/' + this.data.activeId + '/myHearts',
  73. method: "get",
  74. success: (res) => {
  75. console.log(res, '查询目前心动次数')
  76. if (res.data.code == 0) {
  77. this.setData({
  78. heartTime: res.data.heartCount
  79. })
  80. }
  81. }
  82. })
  83. },
  84. getActivies() {
  85. wx.request({
  86. url: app.globalData.publicUrl + '/wx/actives/' + this.data.openid + '/' + this.data.activeId + '/detail',
  87. method: "get",
  88. success: (res) => {
  89. console.log(res, '查询活动详情获取心动上限次数')
  90. if (res.data.code == 0) {
  91. this.setData({
  92. planHeart: Number(res.data.activeRoll.planHeart)
  93. })
  94. }
  95. }
  96. })
  97. wx.request({
  98. url: app.globalData.publicUrl + '/wx/actives/' + this.data.openid + '/' + this.data.activeId + '/members',
  99. method: "get",
  100. success: (res) => {
  101. if (res.data.code == 0) {
  102. console.log(res.data.members, '我获取人员名单')
  103. for (let i = 0; i < res.data.members.length; i++) {
  104. if (res.data.members[i].openId == this.data.openid) {
  105. this.setData({
  106. myNum: res.data.members[i].activeNumber
  107. })
  108. // 删除自己
  109. res.data.members.splice(i, 1);
  110. }
  111. }
  112. this.setData({
  113. member: res.data.members
  114. })
  115. }
  116. }
  117. })
  118. },
  119. async onLoad(options) {
  120. tool.openidStatus().then(result => {
  121. this.setData({
  122. openid: result[0],
  123. sessionkey: result[1],
  124. activeId: options.id
  125. })
  126. this.getActivies();
  127. this.getMyheartNowTimes();
  128. })
  129. },
  130. /**
  131. * 生命周期函数--监听页面初次渲染完成
  132. */
  133. onReady: function () {
  134. },
  135. /**
  136. * 生命周期函数--监听页面显示
  137. */
  138. onShow: function () {
  139. },
  140. /**
  141. * 生命周期函数--监听页面隐藏
  142. */
  143. onHide: function () {
  144. },
  145. /**
  146. * 生命周期函数--监听页面卸载
  147. */
  148. onUnload: function () {
  149. },
  150. /**
  151. * 页面相关事件处理函数--监听用户下拉动作
  152. */
  153. onPullDownRefresh: function () {
  154. },
  155. /**
  156. * 页面上拉触底事件的处理函数
  157. */
  158. onReachBottom: function () {
  159. },
  160. /**
  161. * 用户点击右上角分享
  162. */
  163. onShareAppMessage: function () {
  164. }
  165. })