index.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. this.setData({
  24. type: options.type,
  25. emptyText: options.type == 'follow' ? '您还没有关注用户哦' : '快去收藏喜欢的作品吧!'
  26. })
  27. wx.setNavigationBarTitle({
  28. title: options.type == 'follow' ? '关注作品' : '收藏作品'
  29. })
  30. }
  31. if (options.id) {
  32. this.getreadInfo(options.id)
  33. wx.nextTick(() => {
  34. this.selectComponent('#worksList').openTypeComment({
  35. target: {
  36. dataset: {
  37. type: options.type,
  38. onceId: options.onceId,
  39. id: options.id
  40. }
  41. }
  42. })
  43. })
  44. } else {
  45. this.loadMore()
  46. }
  47. },
  48. loadMore() {
  49. if (this.data.type == 'follow') {
  50. this.getData(getFollowWorks, {})
  51. } else if (this.data.type == 'my') {
  52. this.getData(getSelfRead, {})
  53. } else if (this.data.type == 'collect') {
  54. this.getData(getFavoritesList, {})
  55. }
  56. },
  57. getSelfRead(data) {
  58. return new Promise(async (reslove) => {
  59. let res = await getSelfRead(data)
  60. if (this.data.firstWork) {
  61. res.list = res.list.filter(item => {
  62. return item.userRead.id != this.data.firstWork.userRead.id
  63. })
  64. res.list.unshift(this.data.firstWork)
  65. }
  66. reslove(res)
  67. })
  68. },
  69. async getreadInfo(videoId) {
  70. let firstWork = await getreadInfo(videoId)
  71. this.setData({
  72. firstWork
  73. })
  74. this.loadMore()
  75. },
  76. onReachBottom() {
  77. this.loadMore()
  78. },
  79. })