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

265 lines
5.9 KiB
JavaScript

// pages/community/changeCommunity.js
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
token: app.globalData.token,
sourceUrl: app.baseUrls.sourceUrl,
areaList: [],
areaIndex: 0,
areaAll: [],
areaSelected: '',
areaName: '',
communityList: [],
myCommunityList: [],
page: {
rows: 10,
page: 1,
areaCode: ''
},
},
// 获取地区列表
getAreaList: 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 = self.data.areaList
for (let i = 0; i < data.length; i++) {
arr.push(data[i].areaName)
}
self.setData({
areaList: arr,
areaAll: data,
areaSelected: data[0].areaCode,
areaName: data[0].areaName,
['page.areaCode']: data[0].areaCode
})
self.getCommunity()
}, function (code, data) {
console.log(data)
})
},
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)
})
},
// 选择区域
bindAreaPickerChange: function (e) {
var self = this
this.setData({
areaIndex: 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()
},
// 获取我所在的社区列表
getMyCommunity: function () {
var self = this
app.restAjax.get(app.restAjax.path(app.apis.mycommunity, [app.baseUrls.requestUrl]), {}, {
headers: {
token: self.data.token
}
}, function (code, data) {
self.setData({
myCommunityList: data
})
}, function (code, data) {
console.log(data)
})
},
otherCommunity: function () {
wx.navigateTo({
url: './selectCommunity',
})
},
selectCommunity: function (e) {
var info = {
communityId: e.currentTarget.dataset.item.communityId,
communityName: e.currentTarget.dataset.item.communityName
}
app.globalData.currentCommunity = info
wx.setStorage({
data: e.currentTarget.dataset.item.communityName,
key: 'curCommunityName'
})
wx.setStorage({
data: e.currentTarget.dataset.item.communityId,
key: 'curCommunityId'
})
wx.setStorage({
data: e.currentTarget.dataset.item.locationCode,
key: 'areaCode'
})
wx.setStorage({
data: parseInt(e.currentTarget.dataset.item.areaLevel),
key: 'areaLevel'
})
// wx.setStorage({
// data: e.currentTarget.dataset.item.areaId,
// key: 'areaId'
// })
wx.reLaunch({
url: '../index/index',
})
},
selectMyCommunity: function (e) {
var info = {
communityId: e.currentTarget.dataset.item.communityId,
communityName: e.currentTarget.dataset.item.communityName
}
app.globalData.currentCommunity = info
wx.setStorage({
data: e.currentTarget.dataset.item.communityName,
key: 'curCommunityName'
})
wx.setStorage({
data: e.currentTarget.dataset.item.communityId,
key: 'curCommunityId'
})
wx.setStorage({
data: e.currentTarget.dataset.item.areaCode,
key: 'areaCode'
})
wx.setStorage({
data: '4',
key: 'areaLevel'
})
// wx.setStorage({
// data: e.currentTarget.dataset.item.areaId,
// key: 'areaId'
// })
wx.reLaunch({
url: '../index/index',
})
},
loadMore: function () {
var self = this
this.setData({
['page.page']: self.data.page.page + 1
})
this.getCommunity()
},
enterCurrentArea: function () {
var self = this
wx.setStorage({
data: self.data.areaAll[self.data.areaIndex].areaName,
key: 'curCommunityName'
})
wx.setStorage({
data: self.data.areaAll[self.data.areaIndex].areaId,
key: 'curCommunityId'
})
wx.setStorage({
data: self.data.page.areaCode,
key: 'areaCode'
})
wx.setStorage({
data: parseInt(self.data.areaAll[self.data.areaIndex].areaLevel),
key: 'areaLevel'
})
wx.reLaunch({
url: '../index/index',
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.getAreaList()
this.getMyCommunity()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})