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.

141 lines
3.6 KiB

5 days ago
const app = getApp<IAppOption>()
Page({
data: {
tab: 0,
offsetTop: 0,
5 days ago
videoList: [] as Array<any>,
videoPagination: {
page: 1,
pages: 1,
count: 0,
},
5 days ago
articleList: [] as Array<any>,
articlePagination: {
page: 1,
pages: 1,
count: 0,
},
5 days ago
},
2 days ago
onShow() {
app.waitLogin({ type: 0 }).then(() => {
this.getVideoList()
this.getArticleList()
})
5 days ago
},
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 || []
5 days ago
this.setData({
videoList: append ? this.data.videoList.concat(list) : list,
videoPagination: {
page: res.page || 1,
pages: res.pages || 1,
count: Number(res.count) || 0,
5 days ago
},
})
})
5 days ago
},
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 || []
5 days ago
this.setData({
articleList: append ? this.data.articleList.concat(list) : list,
articlePagination: {
page: res.page || 1,
pages: res.pages || 1,
count: Number(res.count) || 0,
5 days ago
},
})
})
5 days ago
},
onChange(e: any) {
const { index } = e.detail
this.setData({ tab: index })
},
handleVideoDetail(e: any) {
const { id, index } = e.currentTarget.dataset
5 days ago
wx.navigateTo({
url: `/pages/videoDetail/index?id=${id}&index=${index}&source=collection`,
5 days ago
})
},
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}`,
})
}
5 days ago
},
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,
})
5 days ago
})
},
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,
})
5 days ago
})
},
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()
},
5 days ago
})
export {}