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

446 lines
11 KiB

6 years ago
// pages/topics/index.js
import dayjs from '../../utils/dayjs/index.js'
import relativeTime from '../../utils/dayjs/relativeTime.js'
import { TopicModel } from '../../models/topic.js'
import { store } from '../../utils/store.js'
import { UserModel } from '../../models/user.js'
let userModel = new UserModel()
dayjs.extend(relativeTime)
let topicModel = new TopicModel()
const app = getApp()
6 years ago
Page({
6 years ago
6 years ago
/**
* 页面的初始数据
*/
data: {
headerTitles: ['找资源','报需求','交朋友' ],
segmentIndex: 0,
currPage: 1,
//留言互动的列表
topicList: [],
goodIdeaList: [],
//赋能中心的列表
centerList: [],
typeList:[]
6 years ago
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function () {
},
//进入页面判断是否绑定微信号,如果绑定手机号根据segmentIndex的数值fetch留言互动和赋能中心的资源,否则退回注册页面或者首页
onShow: function () {
if (store.hasBindUserInfo()) {
6 years ago
console.log('已经绑定微信')
if (store.hasPhone()) {
console.log('已经绑定手机号码')
// 页面出现在前台时执行
// 更新TopicList 和centerList
this.fetchTopicList()
this.fetchCenterList()
let segmentIndex = this.data.segmentIndex
if (segmentIndex === 0 || segmentIndex === 1) {
wx.pageScrollTo({
scrollTop: 0,
})
this.setData({
currPage: 1,
})
switch (this.data.segmentIndex) {
case 0:
return this.fetchTopicList()
case 1:
// return this.fetchGoodIdeaList()
//GoodIdea修改为center
return this.fetchCenterList()
}
}
6 years ago
} else {
console.log('未绑定手机号码')
wx.showModal({
title: '温馨提示',
content: '是否前往验证手机号码?',
success(res) {
// if (res.confirm) {
// wx.redirectTo({
// url: '/pages/register/index',
// })
// } else if (res.cancel) {
// wx.switchTab({
// url: '/pages/home/index',
// })
// }
if(app.globalData.navigate.mobile){
var params = {
phone:app.globalData.navigate.mobile,
nickName:app.globalData.navigate.nickname,
avatarUrl:app.globalData.navigate.faceImg
}
userModel.navigateUser(params,res=>{
store.saveUserInfo({
nickName: params.nickName,
avatarUrl: params.avatarUrl,
phone: params.phone
})
wx.reLaunch({
url: '/pages/home/index',
})
})
}else{
if (res.confirm) {
wx.redirectTo({
url: '/pages/weChatAuth/index?type=2',
})
} else if (res.cancel) {
wx.switchTab({
url: '/pages/home/index',
})
}
}
}
})
}
} else {
console.log('未绑定微信')
if(app.globalData.navigate.mobile){
var params = {
phone:app.globalData.navigate.mobile,
nickName:app.globalData.navigate.nickname,
avatarUrl:app.globalData.navigate.faceImg
}
userModel.navigateUser(params,res=>{
store.saveUserInfo({
nickName: params.nickName,
avatarUrl: params.avatarUrl,
phone: params.phone
})
wx.reLaunch({
url: '/pages/home/index',
})
})
}else{
wx.showModal({
title: '温馨提示',
content: '是否前往绑定微信?',
success(res) {
5 years ago
if (res.confirm) {
wx.redirectTo({
url: '/pages/weChatAuth/index',
5 years ago
})
} else if (res.cancel) {
wx.switchTab({
url: '/pages/home/index',
})
}
}
6 years ago
})
}
}
6 years ago
},
//留言互动
//fetch留言互动的资源
fetchTopicList () {
let page = this.data.currPage
topicModel.getTopicList(page, res => {
console.log('议题列表')
console.log(res)
if (res.result.list.length == 0) {
wx.showToast({
title: '暂无数据',
icon: 'none'
})
}
const datas = res.result.list
let tempDatas = []
datas.forEach((item,index) => {
tempDatas.push({
topicId: item.id,
6 years ago
userIcon: item.groupAvator || '',
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,
})
})
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()
})
6 years ago
},
//赋能中心
fetchCenterList(){
let page = this.data.currPage;
topicModel.getResourceTypeList(res=>{
this.setData({
typeList:res.result
})
})
topicModel.getCenterList(page,res => {
if (res.list.length == 0) {
wx.showToast({
title: '暂无数据',
icon: 'none'
})
return
}
if(page == 1){
this.setData({
centerList: res.list
})
}else{
if (res.list.length > 0) {
const list = [...this.data.centerList, ...res.list]
this.setData({
centerList: list
})
} else {
const page = this.data.currPage - 1
this.setData({
currPage: page
})
wx.showToast({
title: '已加载全部',
icon: 'none'
})
}
}
})
},
//金点子
//金点子资源刷新
onRefreshList () {
this.fetchGoodIdeaList()
},
//fetch金点子的资源
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({
// 评论数据
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({
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()
})
},
6 years ago
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
// let segmentIndex = this.data.segmentIndex
// if (segmentIndex === 2){
// wx.stopPullDownRefresh()
// }
// if (segmentIndex === 0 || segmentIndex === 1) {
// wx.pageScrollTo({
// scrollTop: 0,
// })
6 years ago
// this.setData({
// currPage: 1,
// })
// switch (this.data.segmentIndex) {
// case 0:
// return this.fetchTopicList()
// case 1:
// // return this.fetchGoodIdeaList()
// return this.fetchCenterList()
// }
// }
6 years ago
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
6 years ago
let segmentIndex = this.data.segmentIndex
if(segmentIndex === 2){
return
}
6 years ago
if (segmentIndex === 0 || segmentIndex === 1) {
const page = this.data.currPage + 1
this.setData({
currPage: page
})
switch (this.data.segmentIndex) {
case 0:
return this.fetchTopicList()
case 1:
// return this.fetchGoodIdeaList()
return this.fetchCenterList()
6 years ago
}
}
6 years ago
},
6 years ago
// 定义点击标题的事件处理函数,将选中标题的id赋值给selectedTitle
6 years ago
tapSegment: function (e) {
console.log(e)
this.setData({
currPage: 1
})
6 years ago
const item = e.detail;
6 years ago
this.setData({
segmentIndex: item.index
6 years ago
});
switch (item.index) {
case 0:
return this.fetchTopicList()
case 1:
// return this.fetchGoodIdeaList()
console.log("点击页面fetchCenterList");
return this.fetchCenterList()
}
},
deleteTopic(e) {
// console.log(e.detail.id)
let that = this
topicModel.deleteGroup(e.detail.id, res => {
console.log(res)
if (res.code === 200) {
wx.showToast({
title: '删除成功',
icon: 'none',
success() {
that.setData({
currPage: 1,
})
switch (that.data.segmentIndex) {
case 0:
return that.fetchTopicList()
case 1:
// return that.fetchGoodIdeaList()
//GoodIdea修改为center
return that.fetchCenterList()
}
}
})
}
})
},
deleteTopicComment(e){
let that = this
topicModel.deleteComment(e.detail.id,res=>{
if(res.code === 200){
wx.showToast({
title: '删除成功',
icon: 'none',
success() {
that.setData({
currPage: 1,
})
switch (that.data.segmentIndex) {
case 0:
return that.fetchTopicList()
case 1:
return that.fetchCenterList()
}
}
})
}
})
},
tapGoodIdeaPraise(e){
this.fetchGoodIdeaPraise(e.detail.commentId)
},
fetchGoodIdeaPraise(id) {
wx.showLoading()
topicModel.topicCommentPraise(id, res => {
if (res.code === 200) {
wx.hideLoading()
this.onPullDownRefresh()
}
})
},
6 years ago
})