// pages/neighbor/neighbor.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { token: app.globalData.token, sourceUrl: app.baseUrls.sourceUrl, array: [], index: 0, communityList: [], communitySelected: '', areaCode: '', page: { page: 1, rows: 5, communityId: '' }, helpList: [], circleList: [], serviceUrl: app.baseUrls.serviceUrl, baseImgUrl: app.baseUrls.baseImgUrl, tab: '1' }, // 邻里互助查看更多 checkHelpMore: function () { var self = this if (this.data.tab == '1') { wx.navigateTo({ url: './help/helpList?communityId=' + self.data.communitySelected, }) } else { wx.navigateTo({ url: './circle/circleList', }) } }, // 邻里互助查看详情 checkHelpDetail: function (e) { var id = e.currentTarget.dataset.id wx.navigateTo({ url: './help/helpDetail?neighborId=' + id, }) }, // 切换社区 bindPickerChange: function(e) { var self = this this.setData({ index: e.detail.value, communitySelected: self.data.communityList[e.detail.value].communityId, ['page.communityId']: self.data.communityList[e.detail.value].communityId, areaCode: self.data.communityList[e.detail.value].areaCode, }) wx.setStorage({ data: e.detail.value, key: 'communityIndex' }) if (this.data.tab == '1') { self.getHelpList() } else { self.getCircleList() } }, // 发布新的邻里互助 newHelp: function () { var self = this wx.navigateTo({ url: './help/new?communityId=' + self.data.communitySelected + '&areaCode=' + self.data.areaCode, }) }, // 发布新的邻里圈 newCircle: function () { var self = this wx.navigateTo({ url: './circle/new?communityId=' + self.data.communitySelected + '&areaCode=' + self.data.areaCode, }) }, // 获取邻里互助列表 getHelpList: function () { var self = this app.restAjax.get(app.restAjax.path(app.apis.getHelpList, [app.baseUrls.requestUrl]), self.data.page, { headers: { token: self.data.token } }, function (code, data) { for (let i = 0; i < data.rows.length; i++) { if (data.rows[i].photo) { data.rows[i].photo = data.rows[i].photo.split(',') } } self.setData({ helpList: data.rows }) }, function (code, data) { console.log(data) }) }, // 获取邻里圈列表 getCircleList: function () { var self = this app.restAjax.get(app.restAjax.path(app.apis.getCircleList, [app.baseUrls.requestUrl]), self.data.page, { headers: { token: self.data.token } }, function (code, data) { for (let i = 0; i < data.rows.length; i++) { if (data.rows[i].photo) { data.rows[i].photo = data.rows[i].photo.split(',') } } self.setData({ helpList: data.rows }) }, function (code, data) { console.log(data) }) }, // 查看邻里圈详情 checkCircleDetail: function (e) { var id = e.currentTarget.dataset.id wx.navigateTo({ url: './circle/circleDetail?neighborCircleId=' + id, }) }, // 获取我所在的社区列表 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) { if (data.length > 0) { var arr = [] for (let i = 0; i < data.length; i++) { arr.push(data[i].communityName) } self.setData({ communityList: data, array: arr, communitySelected: wx.getStorageSync('communityIndex') ? data[wx.getStorageSync('communityIndex')].communityId : data[0].communityId, ['page.communityId']: wx.getStorageSync('communityIndex') ? data[wx.getStorageSync('communityIndex')].communityId : data[0].communityId, areaCode: wx.getStorageSync('communityIndex') ? data[wx.getStorageSync('communityIndex')].areaCode : data[0].areaCode, }) if (self.data.tab == '1') { self.getHelpList() } else { self.getCircleList() } } else { wx.showToast({ title: '请先在首页加入您的社区', icon: 'none' }) setTimeout(function () { wx.switchTab({ url: '../index/index', }) }, 1500) } }, function (code, data) { console.log(data) }) }, // 发布新内容 newContent: function () { if (this.data.tab == '1') { this.newHelp() } else { this.newCircle() } }, // 切换tab changeTab: function (e) { var tab = e.currentTarget.dataset.tab if (tab != this.data.tab) { if (tab == '1') { this.setData({ tab: tab, ['page.page']: 1 }) this.getHelpList() } else { this.setData({ tab: tab, ['page.page']: 1 }) this.getCircleList() } } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.getMyCommunity() }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })