// pages/community/join/select.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { token: app.globalData.token, areaList: ['请选择地区'], areaIndex: 0, areaAll: [], areaSelected: '', officeList: ['请选择办事处'], officeIndex: 0, officeAll: [], officeSelected: '', committeeList: [] }, joinCommunity: function (e) { var item = e.currentTarget.dataset.item wx.navigateTo({ url: './joinDetail?communityId=' + item.communityId + '&communityName=' + item.communityName + '&locationCode=' + item.locationCode, }) }, // 获取地区列表 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 }) }, 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 - 1].areaId }) this.getOfficeList() }, // 获取办事处 getOfficeList: function (e) { var self = this app.restAjax.get(app.restAjax.path(app.apis.getArea, [app.baseUrls.serviceUrl, self.data.areaSelected]), {}, { headers: { token: self.data.token } }, function (code, data) { var arr = self.data.officeList for (let i = 0; i < data.length; i++) { arr.push(data[i].areaName) } self.setData({ officeList: arr, officeAll: data }) }, function (code, data) { console.log(data) }) }, // 选择办事处 bindOfficePickerChange: function (e) { var self = this this.setData({ officeIndex: e.detail.value, officeSelected: self.data.officeAll[e.detail.value - 1].areaId }) this.getCommunityList() }, // 获取居委会列表 getCommunityList: function () { var self = this app.restAjax.get(app.restAjax.path(app.apis.getCommunityList, [app.baseUrls.communityUrl]), { parentCode: self.data.officeSelected }, { headers: { token: self.data.token } }, function (code, data) { self.setData({ committeeList: data }) }, function (code, data) { console.log(data) }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.getAreaList() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })