// pages/login/login.js import WxValidate from '../../utils/wxValidate' const app = getApp() Page({ /** * 页面的初始数据 */ data: { frameStyle: { useTop: true, name: '团队详细信息', leftArrow: true, useBar: false }, // 主体高度 infoHeight: '', // 用户信息 user: {}, // 当前用户是否在团队成员列表里面 is_membes: false, // 背景图片 bg_img: '/image/team_1.jpg', id: '62985b80006dd062af49fdf9', form: {}, }, back: function () { wx.navigateBack({ delta: 1 }) }, // 删除成员 toDel: async function (e) { const that = this; const data = that.data.form; const { id } = e.currentTarget.dataset; wx.showModal({ title: '是否删除该名队员', async success(res) { if (res.confirm) { let members = data.members.filter((i) => i.user_id != id); const arr = await app.$post(`/courtAdmin/api/team/${data.id}`, { members: members }); if (arr.errcode == '0') { wx.showToast({ title: `删除成员成功`, icon: 'error', duration: 2000 }); that.watchLogin(); } else wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) } else if (res.cancel) { } } }) }, // 退出团队 delTeam: function () { const that = this; const data = that.data.form; const user = that.data.user; wx.showModal({ title: '是否确认退出团队?', async success(res) { if (res.confirm) { const arr = await app.$get(`/courtAdmin/api/team/leaves`, { user_id: user._id, team_id: data.id }); if (arr.errcode == '0') { wx.showToast({ title: `退出团队成功`, icon: 'error', duration: 2000 }); that.watchLogin(); } else wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) } else if (res.cancel) { } } }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { const that = this; if (options && options.id) that.setData({ id: options.id }) // 计算高度 this.searchHeight(); // 监听用户是否登录 this.watchLogin(); }, // 监听用户是否登录 watchLogin: function () { const that = this; wx.getStorage({ key: 'token', success: async res => { that.setData({ user: res.data }) let arr; // 系统团队 arr = await app.$get(`/courtAdmin/api/team/${that.data.id}`); if (arr.errcode == '0') { that.setData({ form: arr.data }); // 个人用户判断当前用户是否为团队成员 if (res.data.type == '2') { let is_membes = arr.data.members.find((i) => i.user_id == res.data._id); if (is_membes) that.setData({ is_membes: true }) } } }, fail: res => { wx.redirectTo({ url: '/pages/index/index', }) } }) }, // 计算高度 searchHeight: function () { let frameStyle = this.data.frameStyle; let client = app.globalData.client; let infoHeight = client.windowHeight; // 是否去掉状态栏 if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2); // 是否减去底部菜单 if (frameStyle.useBar) infoHeight = infoHeight - 50; if (infoHeight) this.setData({ infoHeight: infoHeight }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })