itemmyLikeMessage.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. Component({
  2. options: {
  3. styleIsolation: "apply-shared"
  4. },
  5. properties: {
  6. item: Object
  7. },
  8. data: {
  9. show: true,
  10. like: 1
  11. },
  12. methods: {
  13. getActivityInfo: function () {
  14. wx.navigateTo({
  15. url: '/pages/activity/activity',
  16. events: {
  17. deleteMessage: () => {
  18. this.setData({
  19. show: false
  20. })
  21. }
  22. }
  23. }).then(res => {
  24. res.eventChannel.emit('loadCommonData', {
  25. data: this.data.item
  26. })
  27. })
  28. },
  29. getPublisherInfo: function () {
  30. wx.navigateTo({
  31. url: '/pages/publisher/publisher',
  32. }).then(res => {
  33. res.eventChannel.emit('loadCommonData', {
  34. data: this.data.item.publisher
  35. })
  36. })
  37. },
  38. toggleLike: function () {
  39. if (this.data.likeDisabled) {
  40. return
  41. }
  42. wx.showLoading({
  43. title: this.data.like ? '取消收藏' : '收藏中'
  44. })
  45. wx.cloud.callFunction({
  46. name: this.data.like ? 'deleteFavorite' : 'createFavorite',
  47. data: {
  48. msg_id: this.data.item._id
  49. }
  50. }).then(res => {
  51. wx.hideLoading()
  52. if (res.result.status !== 'OK') {
  53. wx.showToast({
  54. title: res.result.errMsg,
  55. icon: 'none'
  56. })
  57. return
  58. }
  59. wx.showToast({
  60. title: this.data.like ? '取消收藏成功' : '收藏成功',
  61. icon: 'none'
  62. })
  63. this.setData({
  64. like: !this.data.like
  65. })
  66. })
  67. }
  68. }
  69. })