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.
116 lines
3.2 KiB
116 lines
3.2 KiB
const api = require('../../../../utils/api')
|
|
let leftHeight = 0
|
|
let rightHeight = 0
|
|
let query = ''
|
|
Page({
|
|
data: {
|
|
loadMoreType: 'none',
|
|
loadMoreVisible: false,
|
|
pageNo: 1,
|
|
pageSize: 10,
|
|
deptName: '',
|
|
deptIntro: '',
|
|
griderList: [],
|
|
griderLeftList: [],
|
|
griderRightList: []
|
|
},
|
|
onLoad() {
|
|
query = wx.createSelectorQuery()
|
|
this.getDeptInfo()
|
|
this.getMemberList()
|
|
},
|
|
onReachBottom() {
|
|
this.setData({
|
|
loadMoreVisible: true
|
|
})
|
|
if (this.data.loadMoreType === 'loading') {
|
|
this.data.pageNo += 1
|
|
this.loadMoreMemberList()
|
|
}
|
|
},
|
|
getBoxHeight(griderLeftList, griderRightList) { //获取左右两边高度
|
|
return new Promise((resolve, reject) => {
|
|
this.setData({ griderLeftList, griderRightList }, () => {
|
|
query.select('#left').boundingClientRect()
|
|
query.select('#right').boundingClientRect()
|
|
query.exec((res) => {
|
|
leftHeight = res[0].height //获取左边列表的高度
|
|
rightHeight = res[1].height //获取右边列表的高度
|
|
resolve()
|
|
})
|
|
})
|
|
})
|
|
},
|
|
// 社区介绍
|
|
getDeptInfo() {
|
|
api.getDeptInfo().then(res => {
|
|
console.log(res)
|
|
const { deptInfo, deptName } = res.data
|
|
this.setData({
|
|
deptName: deptName,
|
|
deptIntro: deptInfo
|
|
})
|
|
}).catch(err => {
|
|
console.error(err)
|
|
})
|
|
},
|
|
// 初始化加载网格员队伍
|
|
getMemberList() {
|
|
const params = {
|
|
pageIndex: this.data.pageNo,
|
|
pageSize: this.data.pageSize
|
|
}
|
|
wx.showLoading({
|
|
title: '加载中...'
|
|
})
|
|
api.getMemberList(params).then(async (res) => {
|
|
wx.hideLoading()
|
|
this.setData({
|
|
griderList: res.data,
|
|
loadMoreType: res.data.length === this.data.pageSize ? 'loading' : 'none'
|
|
})
|
|
const { griderList, griderLeftList, griderRightList } = this.data
|
|
for (const item of griderList) {
|
|
leftHeight <= rightHeight ? griderLeftList.push(item) : griderRightList.push(item) //判断两边高度,来觉得添加到那边
|
|
await this.getBoxHeight(griderLeftList, griderRightList)
|
|
}
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
this.setData({
|
|
griderList: [],
|
|
loadMoreType: 'none'
|
|
})
|
|
})
|
|
},
|
|
// 下拉加载 网格员列表
|
|
loadMoreMemberList() {
|
|
const params = {
|
|
pageIndex: this.data.pageNo,
|
|
pageSize: this.data.pageSize
|
|
}
|
|
wx.showLoading({
|
|
title: '加载中...'
|
|
})
|
|
api.getMemberList(params).then(async (res) => {
|
|
wx.hideLoading()
|
|
this.setData({
|
|
griderList: this.data.griderList.concat(res.data),
|
|
loadMoreType: res.data.length === this.data.pageSize ? 'loading' : 'none'
|
|
})
|
|
const { griderList, griderLeftList, griderRightList } = this.data
|
|
for (const item of griderList) {
|
|
leftHeight <= rightHeight ? griderLeftList.push(item) : griderRightList.push(item) //判断两边高度,来觉得添加到那边
|
|
await this.getBoxHeight(griderLeftList, griderRightList)
|
|
}
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
console.error(err)
|
|
})
|
|
},
|
|
callGrider(e) {
|
|
const { phone } = e.currentTarget.dataset
|
|
wx.makePhoneCall({
|
|
phoneNumber: phone
|
|
})
|
|
}
|
|
})
|