|
|
|
// pages/user/common/myFavorite/index.js
|
|
|
|
import dayjs from '../../../utils/dayjs/index.js'
|
|
|
|
import relativeTime from '../../../utils/dayjs/relativeTime.js'
|
|
|
|
dayjs.extend(relativeTime);
|
|
|
|
import { UserModel } from '../../../models/user.js'
|
|
|
|
let userModel = new UserModel()
|
|
|
|
Page({
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面的初始数据
|
|
|
|
*/
|
|
|
|
data: {
|
|
|
|
list: [],
|
|
|
|
currentPage: 1,
|
|
|
|
type:1
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
*/
|
|
|
|
onLoad: function (options) {
|
|
|
|
|
|
|
|
},
|
|
|
|
onShow :function (){
|
|
|
|
this.setData({
|
|
|
|
currentPage: 1
|
|
|
|
})
|
|
|
|
wx.pageScrollTo({
|
|
|
|
scrollTop: 0,
|
|
|
|
})
|
|
|
|
this.fetchMyFavoriteList()
|
|
|
|
},
|
|
|
|
fetchMyFavoriteList () {
|
|
|
|
let page = this.data.currentPage;
|
|
|
|
let type = this.data.type;
|
|
|
|
userModel.getMyFavoriteList(page,type,res => {
|
|
|
|
const datas = res.result.list;
|
|
|
|
let tempDatas = [];
|
|
|
|
datas.forEach(item => {
|
|
|
|
tempDatas.push({
|
|
|
|
topicId: item.contentId,
|
|
|
|
title: item.title,
|
|
|
|
topicImg: item.image,
|
|
|
|
userIcon: item.groupAvator,
|
|
|
|
userName: item.author,
|
|
|
|
time: item.createTime,
|
|
|
|
commentNum: item.commentNum || '',
|
|
|
|
type: item.type
|
|
|
|
})
|
|
|
|
})
|
|
|
|
if (page == 1) {
|
|
|
|
this.setData({
|
|
|
|
list: tempDatas
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
if (tempDatas.length > 0) {
|
|
|
|
const list = [...this.data.list, ...tempDatas]
|
|
|
|
this.setData({
|
|
|
|
list: list
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
const page = this.data.currentPage - 1
|
|
|
|
this.setData({
|
|
|
|
currentPage: page
|
|
|
|
})
|
|
|
|
wx.showToast({
|
|
|
|
title: '已加载全部',
|
|
|
|
icon: 'none'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log(this.data.list)
|
|
|
|
wx.stopPullDownRefresh()
|
|
|
|
})
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
*/
|
|
|
|
onPullDownRefresh: function () {
|
|
|
|
this.setData({
|
|
|
|
currentPage: 1,
|
|
|
|
})
|
|
|
|
this.fetchMyFavoriteList()
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
*/
|
|
|
|
onReachBottom: function () {
|
|
|
|
let page = this.data.currentPage + 1
|
|
|
|
this.setData({
|
|
|
|
currentPage: page,
|
|
|
|
})
|
|
|
|
this.fetchMyFavoriteList()
|
|
|
|
},
|
|
|
|
clickListItem (e) {
|
|
|
|
if (e.detail.id) {
|
|
|
|
let id = e.detail.id
|
|
|
|
let type = e.detail.type;
|
|
|
|
if(type == '3'){
|
|
|
|
wx.navigateTo({
|
|
|
|
url: '/pages/resource/detail/index?id=' + id
|
|
|
|
})
|
|
|
|
return;
|
|
|
|
}else if(type == '4'){
|
|
|
|
wx.navigateTo({
|
|
|
|
url: '/pages/topics/rent/detail/index?id=' + id
|
|
|
|
})
|
|
|
|
return;
|
|
|
|
}else{
|
|
|
|
wx.navigateTo({
|
|
|
|
url: `/pages/article/index?id=${id}`,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
const item = e.detail.item;
|
|
|
|
let id = item.topicId
|
|
|
|
wx.navigateTo({
|
|
|
|
url: `/pages/topics/interactive/topicArticle/index?topicId=${id}`,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
refresh:function(e){
|
|
|
|
var type = e.currentTarget.dataset.type;
|
|
|
|
this.setData({
|
|
|
|
type:type,
|
|
|
|
currentPage: 1
|
|
|
|
});
|
|
|
|
this.fetchMyFavoriteList();
|
|
|
|
}
|
|
|
|
})
|