const app = getApp() const moment = require("../../utils/moment.min") Page({ /** * 页面的初始数据 */ data: { frameStyle: { useTop: true, name: '查询团队', leftArrow: false, useBar: true }, // 主体高度 infoHeight: '', // 用户 user: {}, list: [], }, back: function () { wx.navigateBack({ url: '/pages/home/index' }) }, tabPath: function (e) { let { route } = e.detail.detail; if (route) wx.redirectTo({ url: `/${route}` }) }, // 系统团队查看详情 toView: function (e) { let { id } = e.currentTarget.dataset; wx.navigateTo({ url: `/pages/teamInfo/info?id=${id}` }) }, // 申请加入队伍 toJoin: function (e) { const that = this; const user = that.data.user; let { item } = e.currentTarget.dataset; wx.showModal({ title: '是否确认申请加入该支团队?', async success(res) { if (res.confirm) { let obj = { team_id: item._id, team_name: item.name, apply_time: moment().format('YYYY-MM-DD HH:mm:ss'), apply_user: user.nickname, apply_id: user._id } const arr = await app.$post(`/courtAdmin/api/joinapply`, obj) if (arr.errcode == '0') { wx.showToast({ title: `成功,等待审核`, icon: 'success', duration: 2000 }); that.watchLogin() } else wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) } else if (res.cancel) { } } }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { // 计算高度 this.searchHeight(); // 监听用户是否登录 this.watchLogin(); }, // 监听用户是否登录 watchLogin: async function () { const that = this; wx.getStorage({ key: 'token', success: async res => { that.setData({ user: res.data }) const arr = await app.$get(`/courtAdmin/api/team`, { status: '1' }); if (arr.errcode == '0') { let list = arr.data; // 个人用户判断当前用户是否为团队成员 if (res.data.type == '2') { for (const val of list) { let is_membes = val.members.find((i) => i.user_id == res.data._id); if (is_membes) val.is_membes = false else val.is_membes = true; } } that.setData({ list: list }) } else { wx.showToast({ title: arr.errmsg, icon: 'error', duration: 2000 }) } }, 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 () { } })