itemmyLikePublisher.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. Component({
  2. options: {
  3. styleIsolation: "apply-shared"
  4. },
  5. properties: {
  6. item: Object
  7. },
  8. data: {
  9. like: 1
  10. },
  11. methods: {
  12. getPublisherInfo: function () {
  13. wx.navigateTo({
  14. url: '/pages/publisher/publisher',
  15. }).then(res => {
  16. res.eventChannel.emit('loadCommonData', {
  17. data: this.data.item
  18. })
  19. })
  20. },
  21. toggleLike: function () {
  22. if (this.data.likeDisabled) {
  23. return
  24. }
  25. wx.showLoading({
  26. title: this.data.like ? '取消关注' : '关注中'
  27. })
  28. wx.cloud.callFunction({
  29. name: this.data.like ? 'deleteFollow' : 'createFollow',
  30. data: {
  31. pub_id: this.data.item._id
  32. }
  33. }).then(res => {
  34. wx.hideLoading()
  35. if (res.result.status !== 'OK') {
  36. wx.showToast({
  37. title: res.result.errMsg,
  38. icon: 'none'
  39. })
  40. return
  41. }
  42. wx.showToast({
  43. title: this.data.like ? '取消关注成功' : '关注成功',
  44. icon: 'none'
  45. })
  46. this.setData({
  47. like: !this.data.like
  48. })
  49. })
  50. }
  51. }
  52. })