list.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. const app = getApp();
  2. Page({
  3. data: {
  4. frameStyle: { useTop: true, name: '赛事赛程', leftArrow: true, useBar: false },
  5. // 选项卡
  6. tabs: {
  7. active: 'a',
  8. menu: [
  9. { title: '小组赛', active: 'a' },
  10. { title: '淘汰赛', active: 'b' },
  11. ],
  12. },
  13. list: [],
  14. total: 0,
  15. page: 0,
  16. skip: 0,
  17. limit: 5,
  18. statusList: []
  19. },
  20. // 返回
  21. back: function () { wx.navigateBack({ delta: 1 }) },
  22. // 选项卡
  23. tabsChange: function (e) {
  24. const that = this;
  25. that.setData({ 'tabs.active': e.detail.active });
  26. that.setData({ skip: 0, page: 0, list: [] });
  27. that.watchLogin();
  28. },
  29. //通用添加 详细信息
  30. toCommon: function (e) {
  31. const that = this;
  32. const { item, route } = e.currentTarget.dataset;
  33. that.setData({ skip: 0, page: 0, list: [] });
  34. wx.navigateTo({ url: `/pagesMatch/${route}?id=${item && item._id ? item._id : ''}` })
  35. },
  36. // 分页
  37. toPage: function () {
  38. const that = this;
  39. let list = that.data.list;
  40. let limit = that.data.limit;
  41. if (that.data.total > list.length) {
  42. wx.showLoading({ title: '加载中', mask: true })
  43. let page = that.data.page + 1;
  44. that.setData({ page: page })
  45. let skip = page * limit;
  46. that.setData({ skip: skip })
  47. that.watchLogin();
  48. wx.hideLoading()
  49. } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
  50. },
  51. /**
  52. * 生命周期函数--监听页面加载
  53. */
  54. onLoad: function (options) { },
  55. /**
  56. * 生命周期函数--监听页面初次渲染完成
  57. */
  58. onReady: function () { },
  59. /**
  60. * 生命周期函数--监听页面显示
  61. */
  62. onShow: async function () {
  63. const that = this;
  64. // 查询其他信息
  65. await that.searchOther();
  66. // 监听用户是否登录
  67. await that.watchLogin();
  68. },
  69. searchOther: async function () {
  70. const that = this;
  71. let arr;
  72. arr = await app.$get(`/dict`, { code: "schedule_status" });
  73. if (arr.errcode == '0' && arr.total > 0) that.setData({ statusList: arr.data[0].list });
  74. },
  75. // 监听用户是否登录
  76. watchLogin: async function () {
  77. const that = this;
  78. const tabs = that.data.tabs;
  79. wx.getStorage({
  80. key: 'raceuser',
  81. success: async res => {
  82. let arr;
  83. let info = { skip: that.data.skip, limit: that.data.limit, user_id: res.data._id };
  84. if (tabs.active == 'a') arr = await app.$get(`/msgs`, { ...info }, 'race');
  85. if (tabs.active == 'b') arr = await app.$get(`/eliminate`, { ...info }, 'race');
  86. if (arr.errcode == '0') {
  87. let list = [...that.data.list, ...arr.data]
  88. for (const val of list) {
  89. let status = that.data.statusList.find(i => i.value == val.status)
  90. if (status) val.zhStatus = status.label;
  91. }
  92. that.setData({ list })
  93. that.setData({ total: arr.total })
  94. } else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
  95. },
  96. fail: async res => {
  97. wx.redirectTo({ url: '/pages/index/index' })
  98. }
  99. })
  100. },
  101. /**
  102. * 页面上拉触底事件的处理函数
  103. */
  104. /**
  105. * 生命周期函数--监听页面隐藏
  106. */
  107. onHide: function () {
  108. const that = this;
  109. that.setData({ skip: 0, page: 0, groupList: [], eliminatelist: [], });
  110. },
  111. /**
  112. * 生命周期函数--监听页面卸载
  113. */
  114. onUnload: function () {
  115. },
  116. /**
  117. * 页面相关事件处理函数--监听用户下拉动作
  118. */
  119. onPullDownRefresh: function () {
  120. },
  121. /**
  122. * 用户点击右上角分享
  123. */
  124. onShareAppMessage: function () {
  125. }
  126. })