index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. const app = getApp()
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. frameStyle: { useTop: true, name: '查询比赛', leftArrow: false, useBar: true },
  8. // 主体高度
  9. infoHeight: '',
  10. currentTab: 0,
  11. list: []
  12. },
  13. back: function () {
  14. wx.navigateBack({ url: '/pages/home/index' })
  15. },
  16. tabPath: function (e) {
  17. let { route } = e.detail.detail;
  18. if (route) wx.redirectTo({ url: `/${route}` })
  19. },
  20. //点击切换
  21. clickTab: function (e) {
  22. const that = this;
  23. if (that.data.currentTab === e.target.dataset.current) return false;
  24. else that.setData({ currentTab: e.target.dataset.current });
  25. that.watchLogin();
  26. },
  27. // 开启左右滑动
  28. bindchange: function (e) {
  29. var that = this
  30. const { current, source } = e.detail;
  31. if (source) that.setData({ currentTab: current });
  32. else return false;
  33. that.watchLogin();
  34. },
  35. // 查看详情
  36. toView: function (e) {
  37. console.log(e);
  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. let type = that.data.currentTab;
  52. let status = type == '0' ? 2 : 4;
  53. wx.getStorage({
  54. key: 'token',
  55. success: res => {
  56. wx.request({
  57. url: `${app.globalData.publicUrl}/courtAdmin/api/match`, //接口地址
  58. method: 'get',
  59. // data: { status: status },
  60. data: {},
  61. success(res) {
  62. if (res.data.errcode == 0) {
  63. that.setData({ list: res.data.data })
  64. } else {
  65. wx.showToast({ title: res.data.errmsg, icon: 'error', duration: 2000 })
  66. }
  67. }
  68. })
  69. },
  70. fail: res => {
  71. wx.redirectTo({ url: '/pages/index/index', })
  72. }
  73. })
  74. },
  75. // 计算高度
  76. searchHeight: function () {
  77. let frameStyle = this.data.frameStyle;
  78. let client = app.globalData.client;
  79. let infoHeight = client.windowHeight;
  80. // 是否去掉状态栏
  81. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  82. // 是否减去底部菜单
  83. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  84. if (infoHeight) this.setData({ infoHeight: infoHeight })
  85. },
  86. /**
  87. * 生命周期函数--监听页面初次渲染完成
  88. */
  89. onReady: function () {
  90. },
  91. /**
  92. * 生命周期函数--监听页面显示
  93. */
  94. onShow: function () {
  95. },
  96. /**
  97. * 生命周期函数--监听页面隐藏
  98. */
  99. onHide: function () {
  100. },
  101. /**
  102. * 生命周期函数--监听页面卸载
  103. */
  104. onUnload: function () {
  105. },
  106. /**
  107. * 页面相关事件处理函数--监听用户下拉动作
  108. */
  109. onPullDownRefresh: function () {
  110. },
  111. /**
  112. * 页面上拉触底事件的处理函数
  113. */
  114. onReachBottom: function () {
  115. },
  116. /**
  117. * 用户点击右上角分享
  118. */
  119. onShareAppMessage: function () {
  120. }
  121. })