xi_sangzhuzi/pages/myVolunteerTeam/myVolunteerTeam.js

153 lines
2.8 KiB
JavaScript
Raw Normal View History

2020-06-26 14:06:35 +08:00
// pages/volunteer/volunteer.js
2020-06-26 18:51:28 +08:00
var app = getApp();
2020-06-26 14:06:35 +08:00
Page({
/**
* 页面的初始数据
*/
data: {
token: '',
otherTeamMap: {},
type: '1',
teamId: '',
},
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',
})
},
otherTeam: function(url) {
var self = this;
2020-06-26 18:51:28 +08:00
app.restAjax.get(app.restAjax.path(url, []),
{}, {
headers: {
token: self.data.token
}
}, function(code, data) {
if('200' == code) {
2020-06-26 14:06:35 +08:00
self.setData({
2020-06-26 18:51:28 +08:00
otherTeamMap: data.rows
2020-06-26 14:06:35 +08:00
})
}
2020-06-26 18:51:28 +08:00
}, function(code, data) {
app.dialog.msg(data.msg);
}, function() {
2020-06-26 14:06:35 +08:00
})
},
/**
* 申请/退出加入团队
*/
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) {
2020-06-26 18:51:28 +08:00
url = app.volunteerUrl + 'wxminiapp/teammember/saveteammember'
2020-06-26 14:06:35 +08:00
teamMemberVO = {
teamId: e.currentTarget.dataset.teamid
}
2020-06-26 18:51:28 +08:00
methodType = app.restAjax.post
2020-06-26 14:06:35 +08:00
title = '申请成功!'
}else {
2020-06-26 18:51:28 +08:00
url = app.volunteerUrl + 'wxminiapp/teammember/quitTeam/' + self.data.teamId
methodType = app.restAjax.get
2020-06-26 14:06:35 +08:00
title = '退出成功!'
}
2020-06-26 18:51:28 +08:00
methodType(app.restAjax.path(url, []),
teamMemberVO, {
headers: {
token: self.data.token
}
}, function(code, data) {
if('200' == code) {
app.dialog.msg(title);
2020-06-26 14:06:35 +08:00
wx.navigateTo({
url: '../volunteer/volunteer',
})
}
2020-06-26 18:51:28 +08:00
}, function(code, data) {
app.dialog.msg(data.msg);
}, function() {
2020-06-26 14:06:35 +08:00
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.getToken().then(result => {
2020-06-26 18:51:28 +08:00
this.otherTeam(app.volunteerUrl + 'wxminiapp/team/myteamm');
2020-06-26 14:06:35 +08:00
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})