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.
213 lines
4.5 KiB
213 lines
4.5 KiB
// pages/topics/index.js
|
|
import dayjs from '../../utils/dayjs/index.js'
|
|
import relativeTime from '../../utils/dayjs/relativeTime.js'
|
|
dayjs.extend(relativeTime);
|
|
import { TopicModel } from '../../models/topic.js'
|
|
let topicModel = new TopicModel()
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
headerTitles: ['互动区', '金点子', '留言箱'],
|
|
segmentIndex: 0,
|
|
currPage: 1,
|
|
topicList: [],
|
|
goodIdeaList:[]
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function () {
|
|
this.fetchTopicList();
|
|
},
|
|
fetchTopicList(){
|
|
let page = this.data.currPage
|
|
topicModel.getTopicList(page,res=>{
|
|
console.log('议题列表')
|
|
console.log(res)
|
|
|
|
const datas = res.result.list
|
|
let tempDatas = []
|
|
datas.forEach(item => {
|
|
tempDatas.push({
|
|
topicId: item.id,
|
|
title: item.title,
|
|
userName: item.author,
|
|
commentNum: item.commentNum,
|
|
topicImg:item.image,
|
|
time: item.createTime,
|
|
})
|
|
})
|
|
if (page == 1) {
|
|
this.setData({
|
|
topicList: tempDatas
|
|
})
|
|
} else {
|
|
if (tempDatas.length > 0) {
|
|
const list = [...this.data.topicList, ...tempDatas]
|
|
this.setData({
|
|
topicList: list
|
|
})
|
|
} else {
|
|
const page = this.data.currPage - 1
|
|
this.setData({
|
|
currPage: page
|
|
})
|
|
wx.showToast({
|
|
title: '已加载全部',
|
|
icon: 'none'
|
|
})
|
|
}
|
|
}
|
|
console.log(this.data.topicList)
|
|
wx.stopPullDownRefresh()
|
|
})
|
|
},
|
|
onRefreshList(){
|
|
this.fetchGoodIdeaList()
|
|
},
|
|
fetchGoodIdeaList(){
|
|
let page = this.data.currPage
|
|
topicModel.goldenList(page, res => {
|
|
console.log('金点子列表')
|
|
console.log(res)
|
|
|
|
const datas = res.result.list
|
|
let tempDatas = []
|
|
datas.forEach(item => {
|
|
tempDatas.push({
|
|
id: item.id,
|
|
userIcon:item.image,
|
|
groupId: item.groupId,
|
|
userName: item.username,
|
|
time: item.createTime,
|
|
comment: item.comment,
|
|
praiseNum: item.supportNum,
|
|
isPraise: false,
|
|
detail:{
|
|
userIcon: item.groupAvator,
|
|
userName: item.author,
|
|
commentNum: item.commentNum,
|
|
title: item.title,
|
|
text:item.content,
|
|
|
|
}
|
|
})
|
|
})
|
|
if (page == 1) {
|
|
this.setData({
|
|
goodIdeaList: tempDatas
|
|
})
|
|
} else {
|
|
if (tempDatas.length > 0) {
|
|
const list = [...this.data.goodIdeaList, ...tempDatas]
|
|
this.setData({
|
|
goodIdeaList: list
|
|
})
|
|
} else {
|
|
const page = this.data.currPage - 1
|
|
this.setData({
|
|
currPage: page
|
|
})
|
|
wx.showToast({
|
|
title: '已加载全部',
|
|
icon: 'none'
|
|
})
|
|
}
|
|
}
|
|
console.log(this.data.goodIdeaList)
|
|
wx.stopPullDownRefresh()
|
|
})
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh: function () {
|
|
this.setData({
|
|
currPage: 1,
|
|
})
|
|
switch (this.data.segmentIndex) {
|
|
case 0:
|
|
return this.fetchTopicList()
|
|
case 1:
|
|
return this.fetchGoodIdeaList()
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom: function () {
|
|
const page = this.data.currPage + 1
|
|
this.setData({
|
|
currPage: page
|
|
})
|
|
switch (this.data.segmentIndex) {
|
|
case 0:
|
|
return this.fetchTopicList()
|
|
case 1:
|
|
return this.fetchGoodIdeaList()
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage: function () {
|
|
|
|
},
|
|
|
|
// 定义点击标题的事件处理函数,将选中标题的id赋值给selectedTitle
|
|
tapSegment: function (e) {
|
|
console.log(e)
|
|
this.setData({
|
|
currPage:1
|
|
})
|
|
const item = e.detail;
|
|
this.setData({
|
|
segmentIndex: item.index
|
|
});
|
|
switch(item.index){
|
|
case 0:
|
|
return this.fetchTopicList()
|
|
case 1:
|
|
return this.fetchGoodIdeaList()
|
|
}
|
|
},
|
|
|
|
// tapGoodIdeaPraise(e){
|
|
// console.log('华加快速度')
|
|
// console.log(e)
|
|
// }
|
|
})
|