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

99 lines
2.0 KiB

// pages/user/common/myActivity/index.js
import { UserModel } from '../../../models/user.js'
let userModel = new UserModel()
Page({
/**
* 页面的初始数据
*/
data: {
list: [],
currentPage:1
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.fetchDataList()
},
fetchDataList(){
let page = this.data.currentPage
userModel.getMyActivityList(page,res=>{
console.log(res)
if (res.result.list.length == 0) {
wx.showToast({
title: '暂无数据',
icon: 'none'
})
}
const datas = res.result.list
let tempDatas = []
datas.forEach(item => {
tempDatas.push({
articleId: item.contentId,
title: item.title,
articleImg: item.image,
userName: item.author,
time: item.createTime
})
})
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.currPage - 1
this.setData({
currPage: page
})
wx.showToast({
title: '已加载全部',
icon: 'none'
})
}
}
console.log(this.data.list)
wx.stopPullDownRefresh()
})
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
this.setData({
currentPage:1
})
this.fetchDataList()
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
let page = this.data.currentPage+1
this.setData({
currentPage: page
})
this.fetchDataList()
},
clickListItem(e) {
const item = e.detail.item;
console.log(item);
let id = item.articleId
wx.navigateTo({
url: `/pages/article/index?id=${id}`,
})
}
})