const app = getApp() const moment = require("../../utils/moment.min"); Page({ data: { id: "", log: '', info: {}, user: {}, adminList: [], is_apply: true }, // 申请加入团队 async toAdd() { const that = this; let user = {} let arr = await app.$api(`user/${that.data.user._id}`, 'GET', {}) if (arr.errcode == '0') { if (arr.data.name && arr.data.icon.length > 0) user = arr.data else { wx.showToast({ title: `请维护基础信息`, icon: 'none' }); return } } else { wx.showToast({ title: `请维护基础信息`, icon: 'none' }); return } const info = that.data.info const data = { team_id: info._id, team_name: info.name, apply_id: user._id, apply_name: user.name, apply_time: moment().format('YYYY-MM-DD HH:mm:ss') } let res = await app.$api(`teamApply`, 'POST', data); if (res.errcode == '0') { wx.showToast({ title: `申请加入团队成功`, icon: 'none' }); that.search() } else { wx.showToast({ title: `${res.errmsg}`, icon: 'none' }); } }, // 退出团队 async toOut() { const that = this; const memberList = that.data.info.member.filter(i => i._id !== that.data.user._id) const number = memberList.length.toString() const data = { member: memberList, number: number } let res = await app.$api(`team/${that.data.info._id}`, 'POST', data); if (res.errcode == '0') { that.setData({ is_apply: true }) // 退出把申请都删掉 await app.$api(`teamApply/out`, 'GET', { apply_id: that.data.user._id }); wx.showToast({ title: `退出团队成功`, icon: 'success' }); that.search() } else { wx.showToast({ title: `${res.errmsg}`, icon: 'none' }); } }, // 字典 getDict(value, model) { const that = this; if (model == 'admin') { if (value) { let data = that.data.adminList.find(i => i._id == value) if (data) return data.name else return '暂无' } } }, /** * 生命周期函数--监听页面加载 */ async onLoad(options) { const that = this; that.setData({ id: options.id }); wx.showLoading({ title: '加载中', mask: true }) await that.searchConfig() await that.searchOther() await that.search() wx.hideLoading() }, async searchConfig() { const that = this; wx.getStorage({ key: 'config', async success(res) { // logo if (res.data && res.data.logo_url && res.data.logo_url.length > 0) { let logo = res.data.logo_url[0].url that.setData({ logo }) } }, fail(err) { console.log(err); } }) wx.getStorage({ key: 'token', async success(res) { that.setData({ user: res.data }) }, fail(err) { console.log(err); } }) }, // 查询其他信息 async searchOther() { const that = this; let res; res = await app.$api('user', 'GET', { status: '1', type: '1' }) if (res.errcode == '0') that.setData({ adminList: res.data }) }, // 查询通知 async search() { const that = this; let res = await app.$api(`team/${that.data.id}`, 'GET', {}) if (res.errcode == '0') { let data = res.data.member.find(i => i._id === that.data.user._id) if (data) that.setData({ is_apply: false }) res.data.admin_name = that.getDict(res.data.administrator, 'admin') that.setData({ info: res.data }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })