index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. homeBg: '/image/home_1.png',
  12. // 比赛列表
  13. list: []
  14. },
  15. back: function () {
  16. wx.navigateBack({ url: '/pages/home/index' })
  17. },
  18. tabPath: function (e) {
  19. let { route } = e.detail.detail;
  20. if (route) wx.redirectTo({ url: `/${route}` })
  21. },
  22. // 查看比赛信息
  23. toView: function (e) {
  24. const { id } = e.currentTarget.dataset;
  25. wx.navigateTo({ url: `/pages/match/info?id=${id}` })
  26. },
  27. // 查看比赛信息
  28. scheduleView: function (e) {
  29. const { id } = e.currentTarget.dataset;
  30. wx.navigateTo({ url: `/pages/match/schedule?id=${id}` })
  31. },
  32. /**
  33. * 生命周期函数--监听页面加载
  34. */
  35. onLoad: function (options) {
  36. // 计算高度
  37. this.searchHeight();
  38. // 监听用户是否登录
  39. this.watchLogin();
  40. },
  41. // 监听用户是否登录
  42. watchLogin: function () {
  43. const that = this;
  44. wx.getStorage({
  45. key: 'token',
  46. success: async res => {
  47. const arr = await app.$get(`/courtAdmin/api/match`);
  48. if (arr.errcode == '0') {
  49. for (const val of arr.data) {
  50. if (val.status == '3') {
  51. const aee = await app.$get('/courtAdmin/api/schedule', { match_id: val._id });
  52. if (aee.errcode == '0') val.schedulelist = aee.data;
  53. }
  54. }
  55. that.setData({ list: arr.data })
  56. }
  57. },
  58. fail: res => {
  59. wx.redirectTo({ url: '/pages/index/index', })
  60. }
  61. })
  62. },
  63. // 计算高度
  64. searchHeight: function () {
  65. let frameStyle = this.data.frameStyle;
  66. let client = app.globalData.client;
  67. let infoHeight = client.windowHeight;
  68. // 是否去掉状态栏
  69. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  70. // 是否减去底部菜单
  71. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  72. if (infoHeight) this.setData({ infoHeight: infoHeight })
  73. },
  74. /**
  75. * 生命周期函数--监听页面初次渲染完成
  76. */
  77. onReady: function () {
  78. },
  79. /**
  80. * 生命周期函数--监听页面显示
  81. */
  82. onShow: function () {
  83. },
  84. /**
  85. * 生命周期函数--监听页面隐藏
  86. */
  87. onHide: function () {
  88. },
  89. /**
  90. * 生命周期函数--监听页面卸载
  91. */
  92. onUnload: function () {
  93. },
  94. /**
  95. * 页面相关事件处理函数--监听用户下拉动作
  96. */
  97. onPullDownRefresh: function () {
  98. },
  99. /**
  100. * 页面上拉触底事件的处理函数
  101. */
  102. onReachBottom: function () {
  103. },
  104. /**
  105. * 用户点击右上角分享
  106. */
  107. onShareAppMessage: function () {
  108. }
  109. })