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

151 lines
3.4 KiB

// pages/user/common/myIdea/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: {
list: [],
currentPage: 1
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
onShow: function () {
this.setData({
currentPage: 1
})
wx.pageScrollTo({
scrollTop: 0,
})
this.fetchMyIdeaList()
},
fetchMyIdeaList(){
let page = this.data.currentPage
userModel.goldenList(page,res=>{
const datas = res.result.list
let tempDatas = []
datas.forEach(item => {
tempDatas.push({
// 评论数据
commentId: item.id,
commentIcon: item.commentAvator,
commentName: item.username,
commentTime: item.createTime,
comment: item.comment,
praiseNum: item.supportNum,
isSupport: item.isSupport,
// 议题数据
topicTtitle: item.title,
topicGroupAvator: item.groupAvator,
topicAuthor: item.author,
topicGroupCreateTime: item.groupCreateTime,
topicCommentNum: item.commentNum,
topicGroupId: item.groupId,
topicDetail: item.content
})
})
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.fetchMyIdeaList()
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
let page = this.data.currentPage+1
this.setData({
currentPage:page
})
this.fetchMyIdeaList()
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
onClickPraise(e) {
const itemData = e.detail.itemData;
this.fetchGoodIdeaPraise(itemData.commentId)
},
fetchGoodIdeaPraise(id) {
wx.showLoading()
topicModel.topicCommentPraise(id, res => {
console.log(res)
if (res.code === 200) {
wx.hideLoading()
this.onPullDownRefresh()
}
})
},
deleteTopicComment(e) {
let that = this
topicModel.deleteComment(e.detail.id, res => {
if (res.code === 200) {
wx.showToast({
title: '删除成功',
icon: 'none',
success() {
that.setData({
currentPage: 1,
})
switch (that.data.segmentIndex) {
case 0:
return that.fetchTopicList()
case 1:
return that.fetchGoodIdeaList()
}
}
})
}
})
}
})