activity.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. const app = getApp()
  2. const util = require('../../utils/util.js')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. activityInfo: {},
  9. activityComment: [],
  10. like: -1,
  11. likeEnable: true,
  12. commentText: ""
  13. },
  14. // getPublisherInfo: function () {
  15. // wx.navigateTo({
  16. // url: "/pages/publisher/publisher?id=" + this.data.activityInfo.publisherId
  17. // })
  18. // },
  19. // components/itemCard.js
  20. getPublisherInfo: function () {
  21. wx.navigateTo({
  22. url: "/pages/publisher/publisher?id=" + this.data.activityInfo.pub_id
  23. })
  24. },
  25. toggleLike: function () {
  26. if (!this.data.likeEnable) return
  27. this.setData({
  28. likeEnable: false
  29. })
  30. const db = wx.cloud.database()
  31. if (this.data.like == 0) {
  32. db.collection("likeData").add({
  33. data: {
  34. type: "message",
  35. id: this.data.activityInfo._id
  36. },
  37. success: function () {
  38. this.setData({
  39. like: 1,
  40. likeEnable: true
  41. })
  42. wx.showToast({
  43. title: "已收藏",
  44. })
  45. }.bind(this),
  46. fail: function () {
  47. wx.showToast({
  48. title: "网络错误",
  49. icon: "none"
  50. })
  51. }
  52. })
  53. } else {
  54. db.collection("likeData").where({
  55. type: "message",
  56. id: this.data.activityInfo._id
  57. }).remove({
  58. success: function () {
  59. this.setData({
  60. like: 0,
  61. likeEnable: true
  62. })
  63. wx.showToast({
  64. title: "已取消收藏",
  65. })
  66. }.bind(this),
  67. fail: function () {
  68. wx.showToast({
  69. title: "网络错误",
  70. icon: "none"
  71. })
  72. }
  73. })
  74. }
  75. },
  76. comment: function () {
  77. if (this.data.commentText.length < 5) {
  78. wx.showToast({
  79. title: "提问字数至少为5",
  80. icon: "none"
  81. })
  82. } else {
  83. wx.showLoading({
  84. title: '发送中',
  85. })
  86. wx.cloud.callFunction({
  87. name: 'createQuestion',
  88. data: {
  89. msg_id: this.data.activityInfo._id,
  90. question: this.data.commentText
  91. }
  92. }).then(res => {
  93. wx.hideLoading()
  94. wx.showToast({
  95. title: '发送成功,请等待发布者回复',
  96. icon: 'none'
  97. })
  98. this.setData({
  99. commentText: ''
  100. })
  101. })
  102. // const db = wx.cloud.database()
  103. // db.collection("qaData").where({
  104. // _openid: app.globalData.openId,
  105. // activityId: this.data.activityInfo._id
  106. // }).get({
  107. // success: function (res) {
  108. // console.log(res)
  109. // if (res.data.length >= 10) {
  110. // wx.showToast({
  111. // title: "为防止刷屏,每人每消息至多提问10条",
  112. // icon: "none"
  113. // })
  114. // } else {
  115. // db.collection("qaData").add({
  116. // data: {
  117. // activityId: this.data.activityInfo._id,
  118. // publisherId: this.data.activityInfo.publisherId,
  119. // answer: "",
  120. // answerTime: "",
  121. // question: this.data.commentText,
  122. // questionTime: new Date(),
  123. // rank: ""
  124. // },
  125. // success: function () {
  126. // this.setData({
  127. // commentText: ""
  128. // })
  129. // wx.showToast({
  130. // title: "提问成功"
  131. // })
  132. // }.bind(this)
  133. // })
  134. // }
  135. // }.bind(this)
  136. // })
  137. }
  138. },
  139. /**
  140. * 生命周期函数--监听页面加载
  141. */
  142. onLoad: function (options) {
  143. wx.showLoading({
  144. title: "加载中",
  145. })
  146. wx.cloud.callFunction({
  147. name: 'getMessage',
  148. data: {
  149. msg_id: options.id
  150. }
  151. }).then(res => {
  152. wx.hideLoading()
  153. res.result.list[0].photo = res.result.list[0].photo.split(',')
  154. res.result.list[0].tag = res.result.list[0].tag.split(',')
  155. res.result.list[0].publish_time = util.handleDate(res.result.list[0].publish_time)
  156. this.setData({
  157. activityInfo: res.result.list[0]
  158. })
  159. })
  160. // const db = wx.cloud.database()
  161. // const _ = db.command
  162. // db.collection("mainData").doc(options.id).get({
  163. // success: function (res) {
  164. // res.data.time = util.handleDate(res.data.time)
  165. // this.setData({
  166. // activityInfo: res.data
  167. // })
  168. // wx.hideLoading()
  169. // }.bind(this)
  170. // })
  171. // db.collection("qaData").where({
  172. // activityId: options.id,
  173. // answer: _.neq("")
  174. // }).get({
  175. // success: function (res) {
  176. // for (let i = 0; i < res.data.length; i++) {
  177. // if (res.data[i].answerTime !== "") {
  178. // res.data[i].time = util.handleDate(res.data[i].answerTime)
  179. // } else {
  180. // res.data[i].time = ""
  181. // }
  182. // }
  183. // this.setData({
  184. // activityComment: res.data
  185. // })
  186. // }.bind(this)
  187. // })
  188. // db.collection("likeData").where({
  189. // type: "message",
  190. // id: options.id
  191. // }).get({
  192. // success: function (res) {
  193. // this.setData({
  194. // like: res.data.length
  195. // })
  196. // }.bind(this)
  197. // })
  198. },
  199. /**
  200. * 生命周期函数--监听页面初次渲染完成
  201. */
  202. onReady: function () {
  203. },
  204. /**
  205. * 生命周期函数--监听页面显示
  206. */
  207. onShow: function () {
  208. },
  209. /**
  210. * 生命周期函数--监听页面隐藏
  211. */
  212. onHide: function () {
  213. },
  214. /**
  215. * 生命周期函数--监听页面卸载
  216. */
  217. onUnload: function () {
  218. },
  219. /**
  220. * 页面相关事件处理函数--监听用户下拉动作
  221. */
  222. onPullDownRefresh: function () {
  223. },
  224. /**
  225. * 页面上拉触底事件的处理函数
  226. */
  227. onReachBottom: function () {
  228. },
  229. /**
  230. * 用户点击右上角分享
  231. */
  232. onShareAppMessage: function () {
  233. }
  234. })