You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
150 lines
3.9 KiB
150 lines
3.9 KiB
const app = getApp<IAppOption>() |
|
|
|
Page({ |
|
data: { |
|
tab: 0, |
|
offsetTop: 0, |
|
search: '', |
|
|
|
videoList: [] as Array<any>, |
|
videoPagination: { |
|
page: 1, |
|
pages: 1, |
|
count: 0, |
|
}, |
|
|
|
articleList: [] as Array<any>, |
|
articlePagination: { |
|
page: 1, |
|
pages: 1, |
|
count: 0, |
|
}, |
|
}, |
|
onShow() { |
|
app.waitLogin({ type: 1 }).then(() => { |
|
this.getVideoList() |
|
this.getArticleList() |
|
}) |
|
}, |
|
onReady() { |
|
const { statusBarHeight } = wx.getSystemInfoSync() |
|
const navBarHeight = 44 |
|
this.setData({ offsetTop: statusBarHeight + navBarHeight }) |
|
}, |
|
getVideoList(page = 1, append = false) { |
|
const { search } = this.data |
|
wx.ajax({ |
|
method: 'GET', |
|
url: '?r=psvt/video/collection-list', |
|
data: { page, count: 10, ...(search ? { Search: search } : {}) }, |
|
}).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) { |
|
const { search } = this.data |
|
wx.ajax({ |
|
method: 'GET', |
|
url: '?r=psvt/pic-text/collection-list', |
|
data: { page, count: 10, ...(search ? { Search: search } : {}) }, |
|
}).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, |
|
}, |
|
}) |
|
}) |
|
}, |
|
onSearchInput(e: any) { |
|
this.setData({ search: e.detail.value }) |
|
}, |
|
onSearch() { |
|
this.getVideoList() |
|
this.getArticleList() |
|
}, |
|
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 {}
|
|
|