index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. const app = getApp()
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. frameStyle: { useTop: false, name: '比赛管理', leftArrow: false, useBar: true },
  8. // 主体高度
  9. infoHeight: '',
  10. // 背景
  11. bg_1: '/image/match_1.png',
  12. bg_2: '/image/match_2.png',
  13. bg_3: '/image/match_3.png',
  14. pm_1: '/image/paiming.png',
  15. sp_1: '/image/shenpi.png',
  16. list: [],
  17. // 选项卡
  18. tabs: {
  19. active: '3',
  20. list: [
  21. { title: '进行中', name: '3' },
  22. { title: '未开始', name: '0' },
  23. { title: '已结束', name: '4' },
  24. ],
  25. },
  26. },
  27. back: function () {
  28. wx.navigateBack({ url: '/pages/home/index' })
  29. },
  30. tabPath: function (e) {
  31. let { route } = e.detail.detail;
  32. if (route) wx.redirectTo({ url: `/${route}` })
  33. },
  34. // 选项卡
  35. tabsChange: function (e) {
  36. const that = this;
  37. that.setData({ 'tabs.active': e.detail.name })
  38. that.watchLogin();
  39. },
  40. // 公共路由跳转方法
  41. toCommon: function (e) {
  42. const { route } = e.currentTarget.dataset;
  43. wx.navigateTo({ url: `/pages/${route}/index` })
  44. },
  45. // 查看比赛信息
  46. toView: function (e) {
  47. const { id } = e.currentTarget.dataset;
  48. wx.navigateTo({ url: `/pages/match/info?id=${id}` })
  49. },
  50. /**
  51. * 生命周期函数--监听页面加载
  52. */
  53. onLoad: function (options) {
  54. // 计算高度
  55. this.searchHeight();
  56. // 监听用户是否登录
  57. this.watchLogin();
  58. },
  59. // 监听用户是否登录
  60. watchLogin: function () {
  61. const that = this;
  62. let status = that.data.tabs.active;
  63. wx.getStorage({
  64. key: 'token',
  65. success: async res => {
  66. const arr = await app.$get(`/courtAdmin/api/match`, { status: status })
  67. if (arr.errcode == '0') that.setData({ list: arr.data })
  68. },
  69. fail: res => {
  70. wx.redirectTo({ url: '/pages/index/index', })
  71. }
  72. })
  73. },
  74. // 计算高度
  75. searchHeight: function () {
  76. let frameStyle = this.data.frameStyle;
  77. let client = app.globalData.client;
  78. let infoHeight = client.windowHeight;
  79. // 是否去掉状态栏
  80. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  81. // 是否减去底部菜单
  82. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  83. if (infoHeight) this.setData({ infoHeight: infoHeight })
  84. },
  85. /**
  86. * 生命周期函数--监听页面初次渲染完成
  87. */
  88. onReady: function () {
  89. },
  90. /**
  91. * 生命周期函数--监听页面显示
  92. */
  93. onShow: function () {
  94. },
  95. /**
  96. * 生命周期函数--监听页面隐藏
  97. */
  98. onHide: function () {
  99. },
  100. /**
  101. * 生命周期函数--监听页面卸载
  102. */
  103. onUnload: function () {
  104. },
  105. /**
  106. * 页面相关事件处理函数--监听用户下拉动作
  107. */
  108. onPullDownRefresh: function () {
  109. },
  110. /**
  111. * 页面上拉触底事件的处理函数
  112. */
  113. onReachBottom: function () {
  114. },
  115. /**
  116. * 用户点击右上角分享
  117. */
  118. onShareAppMessage: function () {
  119. }
  120. })