// pages/volunteer/volunteer.js var app = getApp(); Page({ /** * 页面的初始数据 */ data: { token: '', otherTeamMap: [], type: '1', teamId: '', page: { page: 1, rows: 10 }, totalSize: 0, }, getToken: function () { var self = this; return new Promise(resolve => { wx.getStorage({ key: 'token', success(res) { self.setData({ token: res.data }) return resolve(); } }) }) }, newTeam: function () { wx.navigateTo({ url: '../newTeam/newTeam', }) }, changeTab: function (e) { var self = this; self.data.page.page = 1; self.setData({ page: self.data.page, otherTeamMap: [], totalSize: 0, type: e.currentTarget.dataset.type }) if (self.data.type === '1') { self.otherTeam(app.volunteerUrl + '/app/team/otherteamm?otherTeam=true'); } else { self.otherTeam(app.volunteerUrl + '/app/team/myjointeam?myTeam=true'); } }, otherTeam: function (url) { var self = this; app.restAjax.get(app.restAjax.path(url, []), self.data.page, { headers: { token: self.data.token } }, function (code, data) { if ('200' == code) { self.setData({ totalSize: data.total }) if (data.rows && data.rows.length > 0) { self.setData({ otherTeamMap: self.data.otherTeamMap.concat(data.rows) }) } else { app.dialog.msg('暂无更多数据了') } } }, function (code, data) { app.dialog.msg(data.msg); }, function () { wx.stopPullDownRefresh() }) }, /** * 申请/退出加入团队 */ joinOrOutTeam: function (e) { var self = this; self.setData({ teamId: e.currentTarget.dataset.teamid }) var teamMemberVO; var url; var methodType; var title; if ('1' == self.data.type) { url = app.volunteerUrl + '/app/teammember/saveteammember' teamMemberVO = { teamId: e.currentTarget.dataset.teamid } methodType = app.restAjax.post title = '申请成功!' } else { url = app.volunteerUrl + '/app/teammember/quitTeam/' + self.data.teamId methodType = app.restAjax.get title = '退出成功!' } methodType(app.restAjax.path(url, []), teamMemberVO, { headers: { token: self.data.token } }, function (code, data) { if ('200' == code) { app.dialog.msg(title); wx.navigateTo({ url: '../volunteer/volunteer', }) } }, function (code, data) { app.dialog.msg(data.msg); }, function () { }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.getToken().then(result => { this.otherTeam(app.volunteerUrl + '/app/team/otherteamm?otherTeam=true'); }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { var self = this; self.data.page.page = 1; self.setData({ page: self.data.page, otherTeamMap: [], totalSize: 0, }) if (self.data.type === '1') { self.otherTeam(app.volunteerUrl + '/app/team/otherteamm?otherTeam=true'); } else { self.otherTeam(app.volunteerUrl + '/app/team/myjointeam?myTeam=true'); } }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { var self = this; if (self.data.otherTeamMap.length < self.data.totalSize) { self.data.page.page = self.data.page.page + 1 self.setData({ page: self.data.page }) if (self.data.type === '1') { self.otherTeam(app.volunteerUrl + '/app/team/otherteamm?otherTeam=true'); } else { self.otherTeam(app.volunteerUrl + '/app/team/myjointeam?myTeam=true'); } } else { app.dialog.msg('暂无更多数据了') } }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })