123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- const app = getApp()
- Page({
- data: {
- frameStyle: { useTop: true, name: '比赛管理', leftArrow: false, useBar: true },
- user: {},
- searchInfo: {},
- statusList: [],
- typeList: [],
- list: [],
- total: 0,
- page: 0,
- skip: 0,
- limit: 5,
- },
- // 跳转菜单
- tabPath(e) {
- let { route } = e.detail.detail;
- if (route) wx.redirectTo({ url: `/${route}` })
- },
- // 进入系统
- toJoin: function () {
- const that = this;
- wx.getStorage({
- key: 'user',
- success: async res => {
- if (res.data.type == '10') {
- wx.showModal({ title: '提示', content: '游客不能进入比赛系统,请注册成为正式用户' })
- } else {
- const arr = await app.$post(`/user/login`, { openid: res.data.openid }, 'race');
- if (arr.errcode == '0') {
- wx.setStorageSync('raceuser', arr.data);
- that.setData({ skip: 0, page: 0, list: [] })
- wx.navigateTo({ url: `/pagesMatch/system/index` })
- } else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }); }
- }
- },
- fail: async res => {
- wx.redirectTo({ url: '/pages/index/index' })
- }
- })
- },
- // 详情
- toView: function (e) {
- const { item } = e.currentTarget.dataset;
- wx.navigateTo({ url: `/pagesMatch/match/info?id=${item._id}` })
- },
- // 选择类型
- typeChange: function (e) {
- const that = this;
- let data = that.data.typeList[e.detail.value];
- if (data) that.setData({ 'searchInfo.type': data.value, 'searchInfo.zhType': data.label })
- that.setData({ skip: 0, page: 0, list: [] })
- that.watchLogin();
- },
- // 状态选择
- statusChange: function (e) {
- const that = this;
- let data = that.data.statusList[e.detail.value];
- that.setData({ 'searchInfo.status': data.value, 'searchInfo.zhStatus': data.label });
- that.setData({ skip: 0, page: 0, list: [] })
- that.watchLogin();
- },
- // 分页
- toPage: function () {
- const that = this;
- let list = that.data.list;
- let limit = that.data.limit;
- if (that.data.total > list.length) {
- wx.showLoading({ title: '加载中', mask: true })
- let page = that.data.page + 1;
- that.setData({ page: page })
- let skip = page * limit;
- that.setData({ skip: skip })
- that.watchLogin();
- wx.hideLoading()
- } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) { },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () { },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: async function () {
- const that = this;
- // 查询其他信息
- await that.searchOther();
- // 监听用户是否登录
- await that.watchLogin();
- },
- searchOther: async function () {
- const that = this;
- let arr;
- // 状态
- arr = await app.$get(`/dict`, { code: "match_status" });
- if (arr.errcode == '0' && arr.total > 0) {
- let list = arr.data[0].list;
- list.unshift({ label: '全部', value: '100' });
- that.setData({ statusList: list });
- }
- // 赛事类别
- arr = await app.$get(`/dict`, { code: "match_type" });
- if (arr.errcode == '0' && arr.total > 0) {
- let list = arr.data[0].list;
- list.unshift({ label: '全部', value: '100' });
- that.setData({ typeList: list });
- }
- },
- // 监听用户是否登录
- watchLogin: async function () {
- const that = this;
- const searchInfo = that.data.searchInfo;
- const statusList = that.data.statusList;
- const typeList = that.data.typeList;
- wx.getStorage({
- key: 'user',
- success: async res => {
- that.setData({ user: res.data })
- let info = { skip: that.data.skip, limit: that.data.limit };
- if (searchInfo.status && searchInfo.status != '100') info.status = searchInfo.status;
- if (searchInfo.type && searchInfo.type != '100') info.type = searchInfo.type;
- const arr = await app.$get(`/match`, { ...info }, 'race');
- if (arr.errcode == '0') {
- for (const val of arr.data) {
- let status = statusList.find(i => i.value == val.status)
- if (status) val.zhStatus = status.label;
- let type = typeList.find(i => i.value == val.type)
- if (type) val.zhType = type.label;
- }
- that.setData({ list: [...that.data.list, ...arr.data] });
- that.setData({ total: arr.total });
- }
- },
- fail: async res => {
- wx.redirectTo({ url: '/pages/index/index' })
- }
- })
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- const that = this;
- that.setData({ skip: 0, page: 0, list: [] })
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|