index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. // 选项卡
  31. tabsChange: function (e) {
  32. const that = this;
  33. that.setData({ 'tabs.active': e.detail.name })
  34. },
  35. tabPath: function (e) {
  36. let { route } = e.detail.detail;
  37. if (route) wx.redirectTo({ url: `/${route}` })
  38. },
  39. // 公共路由跳转方法
  40. toCommon: function (e) {
  41. const { route } = e.currentTarget.dataset;
  42. wx.navigateTo({ url: `/pages/${route}/index` })
  43. },
  44. // 查看详情
  45. toView: function (e) {
  46. console.log(e);
  47. },
  48. /**
  49. * 生命周期函数--监听页面加载
  50. */
  51. onLoad: function (options) {
  52. // 计算高度
  53. this.searchHeight();
  54. // 监听用户是否登录
  55. this.watchLogin();
  56. },
  57. // 监听用户是否登录
  58. watchLogin: function () {
  59. const that = this;
  60. let status = that.data.tabs.active;
  61. wx.getStorage({
  62. key: 'token',
  63. success: res => {
  64. wx.request({
  65. url: `${app.globalData.publicUrl}/courtAdmin/api/match`, //接口地址
  66. method: 'get',
  67. // data: { status: status },
  68. data: {},
  69. success(res) {
  70. if (res.data.errcode == 0) {
  71. that.setData({ list: res.data.data })
  72. } else {
  73. wx.showToast({ title: res.data.errmsg, icon: 'error', duration: 2000 })
  74. }
  75. }
  76. })
  77. },
  78. fail: res => {
  79. wx.redirectTo({ url: '/pages/index/index', })
  80. }
  81. })
  82. },
  83. // 计算高度
  84. searchHeight: function () {
  85. let frameStyle = this.data.frameStyle;
  86. let client = app.globalData.client;
  87. let infoHeight = client.windowHeight;
  88. // 是否去掉状态栏
  89. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  90. // 是否减去底部菜单
  91. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  92. if (infoHeight) this.setData({ infoHeight: infoHeight })
  93. },
  94. /**
  95. * 生命周期函数--监听页面初次渲染完成
  96. */
  97. onReady: function () {
  98. },
  99. /**
  100. * 生命周期函数--监听页面显示
  101. */
  102. onShow: function () {
  103. },
  104. /**
  105. * 生命周期函数--监听页面隐藏
  106. */
  107. onHide: function () {
  108. },
  109. /**
  110. * 生命周期函数--监听页面卸载
  111. */
  112. onUnload: function () {
  113. },
  114. /**
  115. * 页面相关事件处理函数--监听用户下拉动作
  116. */
  117. onPullDownRefresh: function () {
  118. },
  119. /**
  120. * 页面上拉触底事件的处理函数
  121. */
  122. onReachBottom: function () {
  123. },
  124. /**
  125. * 用户点击右上角分享
  126. */
  127. onShareAppMessage: function () {
  128. }
  129. })