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.
241 lines
6.4 KiB
241 lines
6.4 KiB
import { getTopicList, getAssociationDetail, getAssociationMember } from '../../utils/api'
|
|
const app = getApp()
|
|
|
|
Page({
|
|
data: {
|
|
groupId: '',
|
|
groupName: '',
|
|
pageNo: 1,
|
|
pageSize: 10,
|
|
topicList: [],
|
|
loadMoreType: 'loading',
|
|
loadMoreVisible: false,
|
|
timestamp: '',
|
|
noDataVisible: true,
|
|
checkPenddingNum: 0,
|
|
groupState: '',
|
|
infoCompleted: 0,
|
|
completeInfoDialogVisible: false,
|
|
userInfo: {
|
|
lordFlag: '0'
|
|
},
|
|
selectedTopicId: ''
|
|
},
|
|
onLoad(options) {
|
|
this.refreshScroll = this.selectComponent('#refreshScroll')
|
|
this.setData({
|
|
groupId: options.groupId,
|
|
groupName: options.groupName,
|
|
groupState: options.state,
|
|
infoCompleted: app.globalData.infoCompleted
|
|
})
|
|
this.pullRefreshGetTopicList()
|
|
this.getAssociationDetail()
|
|
},
|
|
onShow () {
|
|
this.getCheckMemberNum()
|
|
this.backAndRefreshTopicList()
|
|
},
|
|
onReachBottom () {
|
|
if (!this.data.loadMoreVisible) {
|
|
this.setData({
|
|
loadMoreVisible: true
|
|
})
|
|
}
|
|
if (this.data.loadMoreType === 'loading') {
|
|
this.setData({
|
|
loadMoreVisible: true,
|
|
pageNo: parseInt(this.data.pageNo) + 1
|
|
})
|
|
this.loadMoreGetTopicList()
|
|
}
|
|
},
|
|
onPageScroll (e) {
|
|
this.refreshScroll.onPageScroll(e)
|
|
},
|
|
// 跳转 群详情
|
|
naavigateToSettings () {
|
|
wx.navigateTo({
|
|
url: `/subpages/association/pages/associationDetail/associationDetail?groupId=${this.data.groupId}`
|
|
})
|
|
},
|
|
// 跳转 发布话题
|
|
navigateToAddTopic () {
|
|
if (this.data.infoCompleted == 0) {
|
|
this.setData({
|
|
completeInfoDialogVisible: !this.data.completeInfoDialogVisible
|
|
})
|
|
return false
|
|
}
|
|
if (this.data.groupState === '15') {
|
|
wx.showToast({
|
|
title: '该群已禁言,暂不可发布话题',
|
|
icon: 'none',
|
|
duration: 2000
|
|
})
|
|
return false
|
|
}
|
|
wx.navigateTo({
|
|
url: `/subpages/association/pages/addTopic/addTopic?groupId=${this.data.groupId}&groupName=${this.data.groupName}`
|
|
})
|
|
},
|
|
// 获取话题列表
|
|
pullRefreshGetTopicList () {
|
|
this.setData({
|
|
timestamp: '',
|
|
pageNo: 1,
|
|
loadMoreType: 'loading',
|
|
loadMoreVisible: false,
|
|
noDataVisible: true
|
|
})
|
|
const para = {
|
|
groupId: this.data.groupId,
|
|
timestamp: this.data.timestamp,
|
|
pageSize: this.data.pageSize,
|
|
pageIndex: this.data.pageNo,
|
|
topicId: ''
|
|
}
|
|
getTopicList(para).then(res => {
|
|
this.refreshScroll.stopRefresh()
|
|
console.log('话题列表', res)
|
|
res.data.forEach(item => {
|
|
if (item.userId === app.globalData.userInfo.userId) {
|
|
item.isSelf = true
|
|
} else {
|
|
item.isSelf = false
|
|
}
|
|
})
|
|
this.setData({
|
|
topicList: res.data,
|
|
loadMoreType: res.data.length === 10 ? 'loading' : 'none',
|
|
noDataVisible: false,
|
|
timestamp: res.data.length > 0 ? res.data[0].createdTime : ''
|
|
})
|
|
}).catch(err => {
|
|
this.refreshScroll.stopRefresh()
|
|
this.setData({
|
|
noDataVisible: false,
|
|
timestamp: ''
|
|
})
|
|
console.log(err)
|
|
})
|
|
},
|
|
// 上拉加载
|
|
loadMoreGetTopicList () {
|
|
const para = {
|
|
groupId: this.data.groupId,
|
|
timestamp: this.data.timestamp,
|
|
pageSize: this.data.pageSize,
|
|
pageIndex: this.data.pageNo,
|
|
topicId: ''
|
|
}
|
|
getTopicList(para).then(res => {
|
|
console.log('话题列表', res)
|
|
res.data.forEach(item => {
|
|
if (item.userId === app.globalData.userInfo.userId) {
|
|
item.isSelf = true
|
|
} else {
|
|
item.isSelf = false
|
|
}
|
|
})
|
|
const topicList = [...this.data.topicList, ...res.data]
|
|
this.setData({
|
|
topicList,
|
|
loadMoreType: res.data.length === 10 ? 'loading' : 'none'
|
|
})
|
|
}).catch(err => {
|
|
console.log(err)
|
|
})
|
|
},
|
|
// 获取群详情
|
|
getAssociationDetail() {
|
|
getAssociationDetail(this.data.groupId).then(res => {
|
|
console.log('群详情', res)
|
|
const userInfo = {}
|
|
for (const key in res.data) {
|
|
userInfo[key] = res.data[key]
|
|
}
|
|
app.globalData.groupInfo = {
|
|
groupAvatar: res.data.groupAvatar,
|
|
groupLeader: res.data.nickname,
|
|
groupName: res.data.groupName,
|
|
groupId: res.data.id,
|
|
lordFlag: res.data.lordFlag
|
|
}
|
|
this.setData({
|
|
userInfo
|
|
})
|
|
}).catch(err => {
|
|
console.log(err)
|
|
})
|
|
},
|
|
// 获取 是否存在待审核人数
|
|
getCheckMemberNum () {
|
|
const para = {
|
|
groupId: this.data.groupId,
|
|
state: 0
|
|
}
|
|
getAssociationMember(para).then(res => {
|
|
console.log('是否存在待审核人数', res)
|
|
this.setData({
|
|
checkPenddingNum: res.data.length
|
|
})
|
|
}).catch(err => {
|
|
this.setData({
|
|
checkPenddingNum: 0
|
|
})
|
|
console.log(err)
|
|
})
|
|
},
|
|
// 跳转详情
|
|
navigateToDetail (e) {
|
|
if (e.detail.itemid) {
|
|
wx.navigateTo({
|
|
url: `/subpages/discussion/pages/discussionDetail/discussionDetail?detailId=${e.detail.itemid}&type=project`
|
|
})
|
|
} else if (e.detail.issueid) {
|
|
wx.navigateTo({
|
|
url: `/subpages/discussion/pages/discussionDetail/discussionDetail?detailId=${e.detail.issueid}&type=issue`
|
|
})
|
|
} else {
|
|
this.data.selectedTopicId = e.detail.detailid
|
|
wx.navigateTo({
|
|
url: `/subpages/association/pages/topicDetail/topicDetail?detailId=${e.detail.detailid}`
|
|
})
|
|
}
|
|
},
|
|
// 详情返回列表,更新数据
|
|
backAndRefreshTopicList () {
|
|
if (this.data.selectedTopicId) {
|
|
const para = {
|
|
groupId: this.data.groupId,
|
|
timestamp: this.data.timestamp,
|
|
pageSize: 10,
|
|
pageIndex: 1,
|
|
topicId: this.data.selectedTopicId
|
|
}
|
|
getTopicList(para).then(res => {
|
|
console.log('详情返回列表,更新数据', res)
|
|
res.data.forEach(resItem => {
|
|
if (resItem.userId === app.globalData.userInfo.userId) {
|
|
resItem.isSelf = true
|
|
} else {
|
|
resItem.isSelf = false
|
|
}
|
|
if (resItem.id === this.data.selectedTopicId) {
|
|
this.data.topicList.forEach((item, index) => {
|
|
if (item.id === this.data.selectedTopicId) {
|
|
this.data.topicList.splice(index, 1, resItem)
|
|
}
|
|
})
|
|
}
|
|
})
|
|
this.setData({
|
|
topicList: this.data.topicList
|
|
})
|
|
}).finally(() => {
|
|
this.data.selectedTopicId = ''
|
|
})
|
|
}
|
|
}
|
|
})
|