市北人才赋能平台 --小程序端
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.
 

134 lines
3.0 KiB

// pages/user/common/myTopics/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()
import { TopicModel } from '../../../models/topic.js'
let topicModel = new TopicModel()
Page({
/**
* 页面的初始数据
*/
data: {
headerTitles: ['我参与的', '我发布的'],
selectedTitle: 0,
currentPage:1,
list:{
type:Array,
value:[]
},
currentPage:1,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
onShow: function () {
this.setData({
currentPage: 1
})
wx.pageScrollTo({
scrollTop: 0,
})
this.fetchMyTopicList()
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
this.setData({
currentPage: 1
})
this.fetchMyTopicList()
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
let page = this.data.currentPage + 1
this.setData({
currentPage: page
})
this.fetchMyTopicList()
},
fetchMyTopicList(){
let page = this.data.currentPage
userModel.getMyTopics(page,this.data.selectedTitle+1,res=>{
const datas = res.result.list
let tempDatas = []
datas.forEach((item,index) => {
tempDatas.push({
topicId: item.id,
title: item.title,
userIcon: item.groupAvator,
userName: item.author,
commentNum: item.commentNum,
topicImg: item.image,
time: item.createTime,
dataIndex: index + ((page - 1) * 10),
isTouchMove: false,
selectedTitle: this.data.selectedTitle,
})
})
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()
})
},
// 定义点击标题的事件处理函数,将选中标题的id赋值给selectedTitle
tapSegment: function (e) {
const item = e.detail;
this.setData({
selectedTitle: item.index,
list:[]
});
this.fetchMyTopicList()
},
deleteTopic(e){
let that = this
topicModel.deleteGroup(e.detail.id,res=>{
console.log(res)
if(res.code === 200){
wx.showToast({
title: '删除成功',
icon: 'none',
success(){
that.setData({
currentPage: 1
})
that.fetchMyTopicList()
}
})
}
})
}
})