syshxcx/pages/community/selectCommunity.js
dong_bo0602 a1f9e23f6d 0607
2022-06-07 15:43:05 +08:00

191 lines
4.0 KiB
JavaScript

// pages/community/selectCommunity.js
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
token: app.globalData.token,
sourceUrl: app.baseUrls.sourceUrl,
areaList: [],
areaAll: [],
index: 0,
areaSelected: '',
page: {
rows: 10,
page: 1,
areaCode: ''
},
keywords: '',
communityList: [],
haveMore: true
},
enterCommunity: function (e) {
var info = {
communityId: e.currentTarget.dataset.communityId,
communityName: e.currentTarget.dataset.communityName
}
app.globalData.currentCommunity = info
wx.setStorage({
data: e.currentTarget.dataset.communityName,
key: 'curCommunityName'
})
wx.setStorage({
data: e.currentTarget.dataset.communityId,
key: 'curCommunityId'
})
wx.setStorage({
data: e.currentTarget.dataset.location,
key: 'locationCode'
})
wx.reLaunch({
url: '../index/index',
})
},
getArea: function () {
var self = this
app.restAjax.get(app.restAjax.path(app.apis.getArea, [app.baseUrls.serviceUrl, '110889']), {}, {
headers: {
token: self.data.token
}
}, function (code, data) {
var arr = []
for (let i = 0; i < data.length; i++) {
arr.push(data[i].areaName)
}
self.setData({
areaList: arr,
areaAll: data,
areaSelected: data[0].areaCode,
['page.areaCode']: data[0].areaCode
})
self.getCommunity()
}, function (code, data) {
console.log(data)
})
},
bindPickerChange: function (e) {
var self = this
this.setData({
index: e.detail.value,
areaSelected: self.data.areaAll[e.detail.value].areaCode,
['page.areaCode']: self.data.areaAll[e.detail.value].areaCode,
['page.page']: 1,
haveMore: true
})
this.getCommunity()
},
getCommunity: function () {
var self = this
var info = self.data.page
if (self.data.keywords) {
info['keywords'] = self.data.keywords
}
app.restAjax.get(app.restAjax.path(app.apis.getCommunityListPage, [app.baseUrls.communityUrl]), info, {
headers: {
token: self.data.token
}
}, function (code, data) {
if (self.data.page.page == 1) {
self.setData({
communityList: data.rows
})
} else {
if (data.rows.length > 0) {
var arr = self.data.communityList
for (let i = 0; i < data.rows.length; i++) {
arr.push(data.rows[i])
}
self.setData({
communityList: arr
})
} else {
self.setData({
['page.page']: self.data.page.page - 1
})
}
}
if (data.rows.length < 10) {
self.setData({
haveMore: false
})
}
}, function (code, data) {
console.log(data)
})
},
loadMore: function () {
var self = this
this.setData({
['page.page']: self.data.page.page + 1
})
this.getCommunity()
},
selectCommunity: function (e) {
var info = {
communityId: e.currentTarget.dataset.item.communityId,
communityName: e.currentTarget.dataset.item.communityName
}
app.globalData.currentCommunity = info
wx.reLaunch({
url: '../index/index',
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.getArea()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})