183 lines
3.9 KiB
JavaScript
183 lines
3.9 KiB
JavaScript
import commonApi from '../../../api/common';
|
|
const app = getApp();
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
currentCommunity:null,
|
|
defaultCommunityId:null,
|
|
communityList:[],
|
|
scrollViewHeight:0,
|
|
lng:0,
|
|
lat:0,
|
|
pager:{limit:10,loading:false,loadAll:false,pageIndex:0,refreshTrigger:false},
|
|
appConfig:{},
|
|
userInfo:{}
|
|
},
|
|
onSelectItem(event){
|
|
const pages = getCurrentPages();
|
|
const prePage = pages[pages.length-2];
|
|
const currentCommunity = event.currentTarget.dataset.item;
|
|
this.setData({currentCommunity})
|
|
prePage.changeCommunity(currentCommunity);
|
|
wx.navigateBack();
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
const windowInfo = wx.getWindowInfo();
|
|
this.setData({
|
|
scrollViewHeight:windowInfo.windowHeight,
|
|
defaultCommunityId:options.communityId
|
|
})
|
|
this.data.pager.loading = false;
|
|
this.data.pager.loadAll = false;
|
|
app.getLocation().then((res)=>{
|
|
this.setData({
|
|
lng:res.longitude,
|
|
lat:res.latitude
|
|
});
|
|
this.loadList();
|
|
}).catch(()=>{
|
|
this.loadList();
|
|
});
|
|
app.getAppConfig().then((res)=>{
|
|
this.setData({
|
|
appConfig:res
|
|
})
|
|
});
|
|
app.getUserInfo().then((data)=>{
|
|
this.setData({
|
|
userInfo:data
|
|
})
|
|
})
|
|
},
|
|
refreshList(){
|
|
this.data.pager.loadAll = false;
|
|
this.data.pager.pageIndex = 0;
|
|
this.setData({
|
|
pager:this.data.pager
|
|
});
|
|
this.loadList();
|
|
},
|
|
loadList(){
|
|
if(this.data.pager.loading||this.data.pager.loadAll){
|
|
return;
|
|
}
|
|
this.data.pager.loading = true;
|
|
this.setData({
|
|
pager:this.data.pager
|
|
});
|
|
const data = {
|
|
skip:this.data.pager.limit*this.data.pager.pageIndex,
|
|
limit:this.data.pager.limit,
|
|
status:'OPENING'
|
|
}
|
|
if(this.data.lng&&this.data.lat){
|
|
data.longitude = this.data.lng;
|
|
data.latitude = this.data.lat;
|
|
}
|
|
commonApi.community.list(data).then((data)=>{
|
|
let currentCommunity;
|
|
data.items.map((item)=>{
|
|
if(item.distance){
|
|
if(item.distance>=100){
|
|
item.distance = parseFloat(item.distance/1000).toFixed(1)+'km';
|
|
}else{
|
|
item.distance+='m';
|
|
}
|
|
}
|
|
if(item.id==this.data.defaultCommunityId){
|
|
currentCommunity = item;
|
|
}
|
|
})
|
|
|
|
if(this.data.pager.pageIndex==0){
|
|
this.data.communityList = data.items;
|
|
}else{
|
|
this.data.communityList = this.data.communityList.concat(data.items);
|
|
}
|
|
this.data.pager.loading = false;
|
|
this.data.pager.pageIndex++;
|
|
this.data.pager.refreshTrigger = false;
|
|
if(data.items.length<this.data.pager.limit){
|
|
this.data.pager.loadAll = true;
|
|
}
|
|
|
|
this.setData({
|
|
communityList:this.data.communityList,
|
|
currentCommunity,
|
|
pager:this.data.pager
|
|
});
|
|
}).catch(()=>{
|
|
this.setData({
|
|
"pager.loading":false,
|
|
"pager.refreshTrigger":false
|
|
})
|
|
});
|
|
},
|
|
applyNewCommunity(){
|
|
let url = this.data.appConfig.url_community_apply;
|
|
if(url.indexOf('?')>-1){
|
|
url = `${url}&userid=${this.data.userInfo.userid}`
|
|
}else{
|
|
url = `${url}?userid=${this.data.userInfo.userid}`
|
|
}
|
|
wx.navigateTo({
|
|
url: `/pages/browser/index?url=${encodeURIComponent(url)}`,
|
|
})
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
onHide() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
*/
|
|
onPullDownRefresh() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 页面上拉触底事件的处理函数
|
|
*/
|
|
onReachBottom() {
|
|
|
|
},
|
|
|
|
/**
|
|
* 用户点击右上角分享
|
|
*/
|
|
onShareAppMessage() {
|
|
|
|
}
|
|
}) |