index.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import {
  2. getSelfRead,
  3. getFavoritesList
  4. } from '~/api/user'
  5. import {
  6. getFollowWorks
  7. } from '~/api/works'
  8. import {
  9. getreadInfo
  10. } from '~/api/video'
  11. import share from '~/mixins/share'
  12. import event from '~/mixins/event'
  13. import reachBottom from '~/mixins/reachBottom'
  14. Page({
  15. behaviors: [reachBottom, share, event],
  16. data: {
  17. firstWork: '',
  18. type: 'my',
  19. emptyText: '您还没有作品哦,赶快去发表吧!'
  20. },
  21. onLoad(options) {
  22. if (options.type && options.type != 'my') {
  23. let type = options.type
  24. let emptyText = ''
  25. let title = ''
  26. if (type == 'follow') {
  27. emptyText = '您还没有关注用户哦~'
  28. title = '关注作品'
  29. } else if (type == 'like') {
  30. emptyText = '还没有点赞记录哦~'
  31. title = '点赞'
  32. } else if (type == 'collect') {
  33. emptyText = '快去收藏喜欢的作品吧!'
  34. title = '收藏作品'
  35. } else if (type == 'comment') {
  36. emptyText = '还没有收到评论哦~'
  37. title = '作品评论'
  38. }
  39. this.setData({
  40. type,
  41. emptyText
  42. })
  43. wx.setNavigationBarTitle({
  44. title
  45. })
  46. }
  47. if (options.id) {
  48. this.getreadInfo(options.id)
  49. wx.nextTick(() => {
  50. this.selectComponent('#worksList').openTypeComment({
  51. target: {
  52. dataset: {
  53. type: options.type,
  54. onceId: options.onceId,
  55. id: options.id
  56. }
  57. }
  58. })
  59. })
  60. } else {
  61. this.loadMore()
  62. }
  63. },
  64. loadMore() {
  65. if (this.data.type == 'follow') {
  66. this.getData(getFollowWorks, {})
  67. } else if (this.data.type == 'collect') {
  68. this.getData(getFavoritesList, {})
  69. } else {
  70. console.log('zzz');
  71. this.getData(this.getSelfRead, {})
  72. }
  73. },
  74. getSelfRead(data) {
  75. return new Promise(async (reslove) => {
  76. let res = await getSelfRead(data)
  77. if (this.data.firstWork) {
  78. res.list = res.list.filter(item => {
  79. return item.userRead.id != this.data.firstWork.userRead.id
  80. })
  81. res.list.unshift(this.data.firstWork)
  82. }
  83. reslove(res)
  84. })
  85. },
  86. async getreadInfo(videoId) {
  87. let firstWork = await getreadInfo(videoId)
  88. this.setData({
  89. firstWork
  90. })
  91. this.loadMore()
  92. },
  93. onReachBottom() {
  94. this.loadMore()
  95. },
  96. })