锦水居民端小程序
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.
 

124 lines
2.9 KiB

import {
getPartyUserList,
postUserBanned,
postModifyIdentity,
getCurrentUserInfo
} from '../../utils/api'
Page({
/**
* 页面的初始数据
*/
data: {
currentUser: {},
gMembersList: [],
loadMoreVisible: false,
loadMoreType: 'none',
preloadVisible: true,
pageNo: 1,
pageSize: 10,
partyGroupId: ''
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.data.partyGroupId = options.partyGroupId
this.getCurrentUserInfo().then(res => {
if (res) {
this.getPartyUserList();
}
})
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
this.setData({
loadMoreVisible: true
})
if (this.data.loadMoreType === 'loading') {
this.setData({
pageNo: this.data.pageNo + 1
})
this.getPartyUserList()
}
},
//获取当前用户信息
getCurrentUserInfo () {
return new Promise ((resolve,reject) => {
getCurrentUserInfo (this.data.partyGroupId).then(res => {
console.log('获取当前用户信息', res)
this.setData({
currentUser: {...res.data}
})
resolve(true)
}).catch(err =>{
console.log(err)
this.data.currentUser = {}
reject(false)
})
})
},
// 获取群成员列表
getPartyUserList () {
const para = {
pageIndex: this.data.pageNo,
pageSize: this.data.pageSize,
partyGroupId: this.data.partyGroupId
}
getPartyUserList(para).then(res => {
console.log('获取群成员列表', res)
this.setData({
// currentUser: {...res.data.currentUser},
gMembersList: [...this.data.gMembersList, ...res.data],
loadMoreType: res.data.length === this.data.pageSize ? 'loading': 'none',
preloadVisible: false
})
}).catch(err => {
console.log(err)
this.setData({
gMembersList: [],
loadMoreType: 'none',
preloadVisible: false
})
})
},
bannedChangeCallBack (e) {
console.log(e.detail)
const para = {...e.detail}
postUserBanned(para).then(res => {
console.log('用户禁言', res)
this.data.gMembersList = this.data.gMembersList.map( item => {
if (item.userId === e.detail.userId) {
item.bannedFlag = e.detail.bannedFlag
}
return item
})
this.setData({
gMembersList: this.data.gMembersList
})
}).catch(err => {
console.log(err)
})
},
modifyIdentityCallBack (e) {
console.log(e.detail)
const para = {...e.detail}
postModifyIdentity(para).then(res => {
console.log('修改用户身份', res)
this.getPartyUserList();
}).catch(err => {
console.log(err)
})
}
})