榆山
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.

168 lines
4.8 KiB

import { getGridEvaList } from '../../../../api/clerkOnline'
import regeneratorRuntime from '../../../../utils/runtime.js'
Page({
data: {
pageIndex: 1,
pageSize: 10,
loadVisible: true,
loadType: 'more',
grounpList: [],
grounpListLength: 0,
isBackOpen: false,//true 是返回的 false是跳转的
isLoadingBottom: true,//true 正常调用,false不调用
},
onLoad: function () {
console.log('onload')
},
async getGridEvaList() {
this.setData({
loadVisible: true,
loadType: 'more'
})
if (this.data.isBackOpen) {
var obj = {
pageIndex: 1,
pageSize: this.data.pageSize,
id: wx.getStorageSync('id')
}
} else if (!this.data.isBackOpen) {
// @ts-ignore
var obj = {
pageIndex: this.data.pageIndex,
pageSize: this.data.pageSize,
id: ''
}
}
try {
let res = await getGridEvaList(obj)
if (!this.data.isBackOpen && this.data.pageIndex == 1) {
console.log('这是请求加载群列表pageIndex=1')
this.setData({
grounpList: res.data,
grounpListLength: res.data.length,//判断是否还需要发送请求
loadVisible: false,
// isLoadingBottom:false
// isBackOpen:true
})
} else if (!this.data.isBackOpen && this.data.pageIndex > 1) {
console.log('这是请求加载群列表pageIndex>1')
this.setData({
grounpList: this.data.grounpList.concat(res.data),
grounpListLength: res.data.length,//判断是否还需要发送请求
loadVisible: false,
})
} else if (this.data.isBackOpen) {
// 局部刷新
this.setData({
isBackOpen: wx.getStorageSync('isBackOpen')
})
this.data.grounpList.forEach((element, index) => {
if (element.id == res.data[0].id) {
this.setData({
[`grounpList[${index}]`]: res.data[0]
})
}
})
}
if (this.data.grounpListLength < this.data.pageSize) {
this.setData({
loadVisible: true,
loadType: 'none'
})
}
} catch(err){
this.setData({
loadVisible: false,
})
}
},
/***************跳转到我有话说,和发布通知**************/
goMyTalk(e) {
wx.navigateTo({
url: `/subpages/clerkOnline/pages/myTalk/myTalk?type=${e.currentTarget.dataset.type}`
});
},
/***************跳转到群成员**************/
goGroupPeople() {
wx.setStorageSync('isBackOpen', true)
wx.navigateTo({
url: '/subpages/clerkOnline/pages/memberList/memberList'
});
},
/***************跳转到详情页**************/
goTopicDetail(e) {
// 信息类型 :1话题,2通知
wx.setStorageSync('id', e.currentTarget.dataset.id)
if (e.currentTarget.dataset.messagetype == '1') {
wx.navigateTo({
url: `/subpages/clerkOnline/pages/topicDetail/topicDetail?id=${e.currentTarget.dataset.id}`
});
wx.setStorageSync('isBackOpen', true)
wx.setStorageSync('isBackOpenTopic', true)
} else if (e.currentTarget.dataset.messagetype == '2') {
wx.navigateTo({
url: `/subpages/clerkOnline/pages/noticeDetail/noticeDetail?id=${e.currentTarget.dataset.id}`
});
wx.setStorageSync('isBackOpen', true)
}
},
onReachBottom: function () {
if (!this.data.isLoadingBottom) { return }
if (this.data.isBackOpen) { return }
this.setData({
isBackOpen: wx.getStorageSync('isBackOpen')
})
if (this.data.grounpListLength < this.data.pageSize) {
return this.setData({
loadVisible: true,
loadType: 'none'
})
//获取的长度小于10 将不再发请求
}
this.setData({
pageIndex: ++this.data.pageIndex,
loadVisible: true,
loadType: 'more'
})
this.getGridEvaList()
},
async onShow() {
this.setData({
isBackOpen: wx.getStorageSync('isBackOpen')
})
if (this.data.isBackOpen) {
this.getGridEvaList()
wx.setStorageSync('isBackOpen', false)
return
}
// wx.pageScrollTo({
// scrollTop:0
// })
this.setData({
// grounpList: [],
pageIndex: 1
})
await this.getGridEvaList()
},
onReady: function () {
console.log('onReady')
},
goIsRead(e) {
wx.setStorageSync('isBackOpen', true)
wx.navigateTo({ url: `/subpages/clerkOnline/pages/readlist/readlist?id=${e.currentTarget.dataset.id}&type=${e.currentTarget.dataset.type}` });
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
async onPullDownRefresh() {
wx.setStorageSync('isBackOpen', false)
this.setData({
pageIndex: 1,
loadVisible: false,
})
await this.getGridEvaList()
wx.stopPullDownRefresh();
},
})