index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. currentTab: 0,
  17. list: []
  18. },
  19. back: function () {
  20. wx.navigateBack({ url: '/pages/home/index' })
  21. },
  22. tabPath: function (e) {
  23. let { route } = e.detail.detail;
  24. if (route) wx.redirectTo({ url: `/${route}` })
  25. },
  26. // 公共路由跳转方法
  27. toCommon: function (e) {
  28. const { route } = e.currentTarget.dataset;
  29. wx.navigateTo({ url: `/pages/${route}/index` })
  30. },
  31. //点击切换
  32. clickTab: function (e) {
  33. const that = this;
  34. if (that.data.currentTab === e.target.dataset.current) return false;
  35. else that.setData({ currentTab: e.target.dataset.current });
  36. that.watchLogin();
  37. },
  38. // 开启左右滑动
  39. bindchange: function (e) {
  40. var that = this
  41. const { current, source } = e.detail;
  42. if (source) that.setData({ currentTab: current });
  43. else return false;
  44. that.watchLogin();
  45. },
  46. // 查看详情
  47. toView: function (e) {
  48. console.log(e);
  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 type = that.data.currentTab;
  63. let status = type == '0' ? 3 : type == '1' ? 2 : 4;
  64. wx.getStorage({
  65. key: 'token',
  66. success: res => {
  67. wx.request({
  68. url: `${app.globalData.publicUrl}/courtAdmin/api/match`, //接口地址
  69. method: 'get',
  70. // data: { status: status },
  71. data: {},
  72. success(res) {
  73. if (res.data.errcode == 0) {
  74. that.setData({ list: res.data.data })
  75. } else {
  76. wx.showToast({ title: res.data.errmsg, icon: 'error', duration: 2000 })
  77. }
  78. }
  79. })
  80. },
  81. fail: res => {
  82. wx.redirectTo({ url: '/pages/index/index', })
  83. }
  84. })
  85. },
  86. // 计算高度
  87. searchHeight: function () {
  88. let frameStyle = this.data.frameStyle;
  89. let client = app.globalData.client;
  90. let infoHeight = client.windowHeight;
  91. // 是否去掉状态栏
  92. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  93. // 是否减去底部菜单
  94. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  95. if (infoHeight) this.setData({ infoHeight: infoHeight })
  96. },
  97. /**
  98. * 生命周期函数--监听页面初次渲染完成
  99. */
  100. onReady: function () {
  101. },
  102. /**
  103. * 生命周期函数--监听页面显示
  104. */
  105. onShow: function () {
  106. },
  107. /**
  108. * 生命周期函数--监听页面隐藏
  109. */
  110. onHide: function () {
  111. },
  112. /**
  113. * 生命周期函数--监听页面卸载
  114. */
  115. onUnload: function () {
  116. },
  117. /**
  118. * 页面相关事件处理函数--监听用户下拉动作
  119. */
  120. onPullDownRefresh: function () {
  121. },
  122. /**
  123. * 页面上拉触底事件的处理函数
  124. */
  125. onReachBottom: function () {
  126. },
  127. /**
  128. * 用户点击右上角分享
  129. */
  130. onShareAppMessage: function () {
  131. }
  132. })