import { getSelfRead, getFavoritesList } from '~/api/user' import { getFollowWorks } from '~/api/works' import { getreadInfo } from '~/api/video' import share from '~/mixins/share' import event from '~/mixins/event' import reachBottom from '~/mixins/reachBottom' Page({ behaviors: [reachBottom, share, event], data: { firstWork: '', type: 'my', emptyText: '您还没有作品哦,赶快去发表吧!' }, onLoad(options) { if (options.type && options.type != 'my') { this.setData({ type: options.type, emptyText: options.type == 'follow' ? '您还没有关注用户哦' : '快去收藏喜欢的作品吧!' }) wx.setNavigationBarTitle({ title: options.type == 'follow' ? '关注作品' : '收藏作品' }) } if (options.id) { this.getreadInfo(options.id) wx.nextTick(() => { this.selectComponent('#worksList').openTypeComment({ target: { dataset: { type: options.type, onceId: options.onceId, id: options.id } } }) }) } else { this.loadMore() } }, loadMore() { if (this.data.type == 'follow') { this.getData(getFollowWorks, {}) } else if (this.data.type == 'my') { this.getData(getSelfRead, {}) } else if (this.data.type == 'collect') { this.getData(getFavoritesList, {}) } }, getSelfRead(data) { return new Promise(async (reslove) => { let res = await getSelfRead(data) if (this.data.firstWork) { res.list = res.list.filter(item => { return item.userRead.id != this.data.firstWork.userRead.id }) res.list.unshift(this.data.firstWork) } reslove(res) }) }, async getreadInfo(videoId) { let firstWork = await getreadInfo(videoId) this.setData({ firstWork }) this.loadMore() }, onReachBottom() { this.loadMore() }, })