// pages/login/login.js import WxValidate from '../../utils/wxValidate' const app = getApp() Page({ /** * 页面的初始数据 */ data: { frameStyle: { useTop: true, name: '比赛信息', leftArrow: true, useBar: false }, // 主体高度 infoHeight: '', // 用户信息 user: {}, // 数据id id: '', // 赛程信息 form: {}, // 红方团队 redTeam: {}, // 蓝方团队 blueTeam: {}, // 现场图片 match_file: [], }, back: function () { wx.navigateBack({ delta: 1 }) }, //上传图片 imgUpload: async function (e) { const that = this; const user = that.data.user; const red = that.data.redTeam; const blue = that.data.blueTeam; const data = that.data.form; let list = that.data.match_file; if (user.type == '0') { wx.showToast({ title: '不可上传', duration: 2000, icon: 'error', }) } else if (user.type == '1') { // 判断当前红方团队创建人是否为当前用户 if (red.create_id == user._id) { list.push(e.detail); that.commonUpload(list); } else { // 判断当前蓝方团队创建人是否为当前用户 if (blue.create_id == user._id) { list.push(e.detail); that.commonUpload(list); } else wx.showToast({ title: '不可上传', duration: 2000, icon: 'error', }) } } else if (user.type == '2') { let memebers = [...data.red_members, ...data.blue_members]; let memebersInfo = memebers.find((i) => i.user_id == user._id); if (memebersInfo) { list.push(e.detail); that.commonUpload(list); } else wx.showToast({ title: '不可上传', duration: 2000, icon: 'error', }) } }, // 公共修改图片方法 commonUpload: async function (data) { const that = this; const arr = await app.$post(`/courtAdmin/api/schedule/${that.data.id}`, { match_file: data }); if (arr.errcode == '0') { wx.showToast({ title: `上传图片成功`, duration: 2000, icon: 'success', }) this.watchLogin(); } else { wx.showToast({ title: `${arr.errmsg}`, duration: 2000, icon: 'error', }) } }, //删除图片 imgDel: async function (e) { const that = this; const user = that.data.user; const red = that.data.redTeam; const blue = that.data.blueTeam; const data = that.data.form; let list = that.data.match_file; if (user.type == '0') { wx.showToast({ title: '不可删除', duration: 2000, icon: 'error', }) } else if ((user.type == '1')) { // 判断当前红方团队创建人是否为当前用户 if (red.create_id == user._id) { let match_file = list.filter((i, index) => index != e.detail.index); that.commonUpload(match_file); } else { // 判断当前蓝方团队创建人是否为当前用户 if (blue.create_id == user._id) { let match_file = list.filter((i, index) => index != e.detail.index); that.commonUpload(match_file); } else wx.showToast({ title: '不可删除', duration: 2000, icon: 'error', }) } } else if (user.type == '2') { let memebers = [...data.red_members, ...data.blue_members]; let memebersInfo = memebers.find((i) => i.user_id == user._id); if (memebersInfo) { let match_file = list.filter((i, index) => index != e.detail.index); that.commonUpload(match_file); } else wx.showToast({ title: '不可删除', duration: 2000, icon: 'error', }) } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { const that = this; that.setData({ id: options.id || '62a04673b3fcf97310b3e9b9' }) // 计算高度 this.searchHeight() // 监听用户是否登录 this.watchLogin(); }, // 监听用户是否登录 watchLogin: async function () { const that = this; wx.getStorage({ key: 'token', success: async res => { let arr; // 用户信息 that.setData({ user: res.data }); // 赛程信息 arr = await app.$get(`/courtAdmin/api/schedule/${that.data.id}`); let schedule = arr.data; if (arr.errcode == '0') that.setData({ form: schedule }); that.setData({ match_file: schedule.match_file || [] }); // 红方 if (schedule && schedule.red_id) { arr = await app.$get(`/courtAdmin/api/team/${schedule.red_id}`); if (arr.errcode == '0') that.setData({ redTeam: arr.data }); } // 蓝方 if (schedule && schedule.blue_id) { arr = await app.$get(`/courtAdmin/api/team/${schedule.blue_id}`); if (arr.errcode == '0') that.setData({ blueTeam: arr.data }); } }, fail: res => { return wx.redirectTo({ url: '/pages/login/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 () { } })