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

413 lines
9.5 KiB

6 years ago
// pages/topics/index.js
import dayjs from '../../utils/dayjs/index.js'
import relativeTime from '../../utils/dayjs/relativeTime.js'
4 years ago
import {
TopicModel
} from '../../models/topic.js'
import {
store
} from '../../utils/store.js'
import {
UserModel
} from '../../models/user.js'
let userModel = new UserModel()
const app = getApp()
dayjs.extend(relativeTime)
let topicModel = new TopicModel()
6 years ago
Page({
6 years ago
6 years ago
/**
* 页面的初始数据
*/
data: {
segmentIndex: 0,
//留言互动的列表
topicList: [],
goodIdeaList: [],
//赋能中心的列表
centerList: [],
4 years ago
typeList: [],
page: 1,
next: true,
tab: "",
active: "1",
loan: {},
apartment: [],
nodes: '',
rentNode: '',
height: app.globalData.windowHeight - 44,
flag: 0,
//来活动
4 years ago
activityList: []
6 years ago
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function () {
this.setData({
4 years ago
flag: app.globalData.flag
})
},
//进入页面判断是否绑定微信号,如果绑定手机号根据segmentIndex的数值fetch留言互动和赋能中心的资源,否则退回注册页面或者首页
onShow: function () {
4 years ago
//文章关联链接跳转 显示 报需求 还是来活动 tab
let curTab = app.globalData.currentTab
if (curTab) {
4 years ago
// console.log("currentTab:" + curTab)
4 years ago
this.setData({
active: curTab,
tab: curTab
})
}
if (store.hasBindUserInfo()) {
6 years ago
console.log('已经绑定微信')
if (store.hasPhone()) {
console.log('已经绑定手机号码')
this.setData({
topicList: [],
goodIdeaList: [],
centerList: [],
4 years ago
activityList: [],
4 years ago
page: 1,
next: true
})
4 years ago
if (!this.data.tab) {
this.setData({
4 years ago
tab: '1'
})
}
return this.getData(this.data.tab);
6 years ago
} else {
console.log('未绑定手机号码')
4 years ago
if (app.globalData.navigate.mobile) {
var params = {
4 years ago
phone: app.globalData.navigate.mobile,
nickName: app.globalData.navigate.nickname,
avatarUrl: app.globalData.navigate.faceImg
}
4 years ago
userModel.navigateUser(params, res => {
store.saveUserInfo({
nickName: params.nickName,
avatarUrl: params.avatarUrl,
phone: params.phone
})
wx.reLaunch({
url: '/pages/topics/index',
})
})
4 years ago
} else {
wx.showModal({
title: '温馨提示',
content: '是否前往验证手机号码?',
success(res) {
if (res.confirm) {
wx.redirectTo({
url: '/pages/weChatAuth/index?type=2',
})
} else if (res.cancel) {
wx.switchTab({
url: '/pages/home/index',
})
}
}
})
}
}
} else {
console.log('未绑定微信')
4 years ago
if (app.globalData.navigate.mobile) {
var params = {
4 years ago
phone: app.globalData.navigate.mobile,
nickName: app.globalData.navigate.nickname,
avatarUrl: app.globalData.navigate.faceImg
}
4 years ago
userModel.navigateUser(params, res => {
store.saveUserInfo({
nickName: params.nickName,
avatarUrl: params.avatarUrl,
phone: params.phone
})
wx.reLaunch({
url: '/pages/topics/index',
})
})
4 years ago
} 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
},
4 years ago
changeTabs: function (e) {
var tab = e.detail.name;
this.setData({
4 years ago
page: 1,
next: true,
tab: tab,
topicList: [],
centerList: [],
4 years ago
activityList: [],
})
this.getData(tab);
},
4 years ago
getData: function (tab) {
4 years ago
console.log(tab)
switch (tab) {
case "3":
4 years ago
return this.fetchCenterList()
case "5":
4 years ago
return this.fetchActivityList();
default:
return;
}
},
//留言互动
//fetch留言互动的资源
4 years ago
fetchTopicList() {
var th = this;
var page = th.data.page;
var list = th.data.topicList;
topicModel.getTopicList(page, res => {
console.log('议题列表')
console.log(res)
if (res.result.list.length == 0 && page == 1) {
wx.showToast({
title: '暂无数据',
icon: 'none'
})
}
const datas = res.result.list
let tempDatas = []
4 years ago
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,
4 years ago
dataIndex: index + ((page - 1) * 10),
isTouchMove: false,
})
})
4 years ago
if (tempDatas.length > 0) {
list = list.concat(tempDatas);
th.setData({
topicList: list,
})
4 years ago
} else {
th.setData({
next: false,
4 years ago
page: page - 1
})
}
})
6 years ago
},
//赋能中心
4 years ago
fetchCenterList() {
// let page = this.data.currPage;
var th = this;
var page = th.data.page;
var list = th.data.centerList;
4 years ago
if (th.data.typeList.length == 0) {
topicModel.getResourceTypeList(res => {
this.setData({
4 years ago
typeList: res.result
})
})
}
4 years ago
topicModel.getResourceList('', page, res => {
if (res.result.records.length > 0) {
list = list.concat(res.result.records);
th.setData({
centerList: list,
4 years ago
nodes: res.result.agreement
})
4 years ago
} else {
th.setData({
next: false,
4 years ago
page: page - 1
})
}
})
},
4 years ago
fetchLoan: function () {
topicModel.getResourceDetail('aba954f98c489bddf137f6f9f83d6c89', res => {
console.log('找贷款-->', res)
this.setData({
4 years ago
loan: res.result,
})
})
},
4 years ago
fetchRent: function () {
if (this.data.apartment.length == 0) {
topicModel.getApartment(res => {
this.setData({
4 years ago
apartment: res.result.list,
rentNode: res.result.agreement
})
})
}
},
6 years ago
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
4 years ago
console.log('---触底了---')
var next = this.data.next;
var tab = this.data.tab;
var page = this.data.page;
4 years ago
if (!next) {
return;
6 years ago
}
this.setData({
page: page + 1
})
switch (tab) {
case "3":
4 years ago
this.fetchCenterList()
return;
case "5":
return this.fetchActivityList();
default:
return;
}
4 years ago
},
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.fetchCenterList()
}
}
})
}
})
},
4 years ago
deleteTopicComment(e) {
let that = this
4 years ago
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()
4 years ago
case 3:
4 years ago
return that.fetchCenterList()
}
}
})
}
})
},
4 years ago
tapGoodIdeaPraise(e) {
this.fetchGoodIdeaPraise(e.detail.commentId)
},
fetchGoodIdeaPraise(id) {
wx.showLoading()
topicModel.topicCommentPraise(id, res => {
if (res.code === 200) {
wx.hideLoading()
this.onPullDownRefresh()
}
})
},
4 years ago
//活动
fetchActivityList() {
var th = this;
var page = th.data.page;
var list = th.data.activityList;
4 years ago
let source = ''
topicModel.getActivityList(source, page, res => {
console.log('活动列表---')
4 years ago
console.log(res)
if (res.result.records.length == 0 && page == 1) {
wx.showToast({
title: '暂无数据',
icon: 'none'
})
}
const datas = res.result.records
let tempDatas = []
datas.forEach((item, index) => {
tempDatas.push({
activityId: item.id,
title: item.title,
activityImg: item.titlePic,
time: item.createTime,
4 years ago
commentNum: item.commentNum,
4 years ago
dataIndex: index + ((page - 1) * 10),
isTouchMove: false,
})
})
if (tempDatas.length > 0) {
list = list.concat(tempDatas);
th.setData({
activityList: list,
})
} else {
th.setData({
next: false,
page: page - 1
})
}
4 years ago
4 years ago
})
},
6 years ago
})