index.js 3.3 KB

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