const app = getApp() Page({ data: { tab: 0, offsetTop: 0, videoList: [] as Array, videoPagination: { page: 1, pages: 1, count: 0, }, articleList: [] as Array, articlePagination: { page: 1, pages: 1, count: 0, }, }, onShow() { app.waitLogin({ type: 0 }).then(() => { this.getVideoList() this.getArticleList() }) }, onReady() { const { statusBarHeight } = wx.getSystemInfoSync() const navBarHeight = 44 this.setData({ offsetTop: statusBarHeight + navBarHeight }) }, getVideoList(page = 1, append = false) { wx.ajax({ method: 'GET', url: '?r=psvt/video/collection-list', data: { page, count: 10 }, }).then((res: any) => { const list = res.list || [] this.setData({ videoList: append ? this.data.videoList.concat(list) : list, videoPagination: { page: res.page || 1, pages: res.pages || 1, count: Number(res.count) || 0, }, }) }) }, getArticleList(page = 1, append = false) { wx.ajax({ method: 'GET', url: '?r=psvt/pic-text/collection-list', data: { page, count: 10 }, }).then((res: any) => { const list = res.list || [] this.setData({ articleList: append ? this.data.articleList.concat(list) : list, articlePagination: { page: res.page || 1, pages: res.pages || 1, count: Number(res.count) || 0, }, }) }) }, onChange(e: any) { const { index } = e.detail this.setData({ tab: index }) }, handleVideoDetail(e: any) { const { id, index } = e.currentTarget.dataset wx.navigateTo({ url: `/pages/videoDetail/index?id=${id}&index=${index}&source=collection`, }) }, handleArticleDetail(e: any) { const { id, type } = e.currentTarget.dataset if (type === '2' || type === 2) { wx.navigateTo({ url: `/pages/articleVideoDetail/index?id=${id}`, }) } else { wx.navigateTo({ url: `/pages/articleDetail/index?id=${id}`, }) } }, handleCancelVideoCollect(e: any) { const { index } = e.currentTarget.dataset const video = this.data.videoList[index] wx.ajax({ method: 'POST', url: '?r=psvt/video/cancel-collection', data: { ContentId: Number(video.Id) }, }).then(() => { const videoList = [...this.data.videoList] videoList.splice(index, 1) this.setData({ videoList, 'videoPagination.count': this.data.videoPagination.count - 1, }) }) }, handleCancelArticleCollect(e: any) { const { index } = e.currentTarget.dataset const article = this.data.articleList[index] wx.ajax({ method: 'POST', url: '?r=psvt/pic-text/cancel-collection', data: { ContentId: Number(article.Id) }, }).then(() => { const articleList = [...this.data.articleList] articleList.splice(index, 1) this.setData({ articleList, 'articlePagination.count': this.data.articlePagination.count - 1, }) }) }, onReachBottom() { const { tab } = this.data if (tab === 0) { const { videoPagination } = this.data if (videoPagination.page < videoPagination.pages) { this.getVideoList(videoPagination.page + 1, true) } } else { const { articlePagination } = this.data if (articlePagination.page < articlePagination.pages) { this.getArticleList(articlePagination.page + 1, true) } } }, handleBack() { wx.navigateBack() }, }) export {}