123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- const app = getApp();
- import { btn } from '../../utils/dict';
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- frameStyle: { useTop: true, name: '我的', leftArrow: false, useBar: true },
- // 主体高度
- infoHeight: '',
- bg: '/image/me_1.jpg',
- // 用户信息
- userInfo: {},
- // 正在比赛
- ismatchList: [
- {
- id: '1',
- _id: '1',
- status: '0',
- match_time: '2020-11-11 10:11',
- red_logo: [{
- name: "20220331104915.jpg",
- uri: "/files/court/elimg/20220331104915.jpg",
- url: "http://broadcast.waityou24.cn/files/court/elimg/20220331104915.jpg",
- }],
- red_name: '红方名称',
- red_branch: '11',
- blue_branch: '11',
- blue_name: '蓝方名称',
- blue_logo: [{
- name: "20220331104915.jpg",
- uri: "/files/court/elimg/20220331104915.jpg",
- url: "http://broadcast.waityou24.cn/files/court/elimg/20220331104915.jpg",
- }],
- },
- ],
- ismatch_url: '/image/me_2.png',
- // 我的团队
- teamList: [],
- // 我的服务
- btnList: [],
- // 弹框
- dialog: { title: '上传比分', show: false, type: '1' }
- },
- tabPath: function (e) {
- let { route } = e.detail.detail;
- if (route) wx.redirectTo({ url: `/${route}` })
- },
- // 上传比分
- toScore: function () {
- const that = this;
- that.setData({ dialog: { title: '上传比分', show: true, type: '1' } })
- },
- // 比赛信息
- matchView: function (e) {
- const { id } = e.currentTarget.dataset;
- wx.navigateTo({ url: `/pages/match/info?id=${id}` })
- },
- // 团队信息
- teamView: function (e) {
- const { id } = e.currentTarget.dataset;
- wx.navigateTo({ url: `/pages/teamInfo/info?id=${id}` })
- },
- // 公共跳转路由方法
- toCommon: function (e) {
- let { route, method } = e.currentTarget.dataset;
- if (method) {
- wx.showModal({
- title: '提示',
- content: '是否确认退出登录',
- success(res) {
- if (res.confirm) {
- wx.removeStorage({
- key: 'token',
- success(res) {
- return wx.redirectTo({ url: '/pages/index/index', })
- }
- })
- }
- }
- })
- } else {
- wx.navigateTo({ url: `/pages/${route}/index` })
- }
- },
- // 关闭弹框
- toClose: function () {
- const that = this;
- that.setData({ dialog: { title: '上传比分', show: false, type: '1' } })
- that.watchLogin()
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- // 计算高度
- this.searchHeight();
- // 监听用户是否登录
- this.watchLogin();
- },
- // 监听用户是否登录
- watchLogin: function () {
- const that = this;
- wx.getStorage({
- key: 'token',
- success: async res => {
- wx.request({
- url: `${app.globalData.publicUrl}/courtAdmin/api/user/${res.data.id}`, //接口地址
- method: 'get',
- data: {},
- async success(res) {
- if (res.data.errcode == 0) {
- let user = res.data.data;
- // 头像
- user.icons = user.icon[0] ? user.icon[0].url : '';
- // 我的服务,判断不同用户显示不同功能按钮
- let menu = btn.filter((i) => i.type.includes(user.type));
- if (menu) that.setData({ btnList: menu });
- // 团队信息,所在团队信息
- if (user.type == '0') {
- that.setData({ userInfo: user })
- } else if (user.type == '1') {
- let arr = await app.$get(`/courtAdmin/api/team`, { create_id: user._id, status: '1' });
- if (arr.errcode == '0') {
- let team = arr.data;
- that.setData({ teamList: team });
- if (arr.total > 0) {
- let teamInfo = team[0] ? team[0] : { name: '' };
- user.team_name = teamInfo.name;
- }
- that.setData({ userInfo: user })
- } else wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
- } else if (user.type == '2') {
- const arr = await app.$get(`/courtAdmin/api/team/userteams`, { user_id: user._id });
- if (arr.errcode == '0') {
- let team = arr.data;
- that.setData({ teamList: team });
- let teamInfo = team[0] ? team[0] : { name: '' };
- user.team_name = teamInfo.name;
- that.setData({ userInfo: user })
- } else {
- wx.showToast({ title: arr.data.errmsg, icon: 'error', duration: 2000 })
- }
- }
- } else {
- wx.showToast({ title: res.data.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 () {
- this.watchLogin();
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|