123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- const app = getApp();
- Page({
- data: {
- frameStyle: { useTop: true, name: '赛事赛程', leftArrow: true, useBar: false },
- // 选项卡
- tabs: {
- active: 'a',
- menu: [
- { title: '小组赛', active: 'a' },
- { title: '淘汰赛', active: 'b' },
- ],
- },
- list: [],
- total: 0,
- page: 0,
- skip: 0,
- limit: 10,
- statusList: []
- },
- // 返回
- back: function () { wx.navigateBack({ delta: 1 }) },
- // 选项卡
- tabsChange: function (e) {
- const that = this;
- that.setData({ 'tabs.active': e.detail.active });
- that.setData({ skip: 0, page: 0, list: [] });
- that.watchLogin();
- },
- //通用添加 详细信息
- toCommon: function (e) {
- const that = this;
- const { item, route } = e.currentTarget.dataset;
- that.setData({ skip: 0, page: 0, list: [] });
- wx.navigateTo({ url: `/pagesMatch/${route}?id=${item && item._id ? item._id : ''}` })
- },
- // 分页
- 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: "schedule_status" });
- if (arr.errcode == '0' && arr.total > 0) that.setData({ statusList: arr.data[0].list });
- },
- // 监听用户是否登录
- watchLogin: async function () {
- const that = this;
- const tabs = that.data.tabs;
- wx.getStorage({
- key: 'raceuser',
- success: async res => {
- let arr;
- let info = { skip: that.data.skip, limit: that.data.limit, user_id: res.data._id };
- if (tabs.active == 'a') arr = await app.$get(`/msgs`, { ...info }, 'race');
- if (tabs.active == 'b') arr = await app.$get(`/eliminate`, { ...info }, 'race');
- if (arr.errcode == '0') {
- let list = [...that.data.list, ...arr.data]
- for (const val of list) {
- let status = that.data.statusList.find(i => i.value == val.status)
- if (status) val.zhStatus = status.label;
- }
- that.setData({ list })
- that.setData({ total: arr.total })
- } else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
- },
- fail: async res => {
- wx.redirectTo({ url: '/pages/index/index' })
- }
- })
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- const that = this;
- that.setData({ skip: 0, page: 0, groupList: [], eliminatelist: [], });
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|