index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate'
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. src: '/image/home.png',
  10. frameStyle: { useTop: true, name: '查询比赛', leftArrow: false, useBar: true },
  11. // 主体高度
  12. infoHeight: '',
  13. list: [],
  14. listend: [],
  15. },
  16. tiao: function (e) {
  17. let id = e.currentTarget.dataset.name;
  18. console.log(id);
  19. wx.navigateTo({
  20. url: '/pages/list/index?id=' + id,
  21. })
  22. },
  23. //标签页
  24. setup() {
  25. const activeName = ref('a');
  26. return { activeName };
  27. },
  28. tabPath(e) {
  29. let query = e.detail.detail;
  30. if (query) wx.redirectTo({ url: `/pages/${query}/index` })
  31. },
  32. // 监听用户是否登录
  33. watchLogin: function () {
  34. var that = this;
  35. wx.getStorage({
  36. key: 'token',
  37. success: res => {
  38. var that = this;
  39. wx.request({
  40. url: `${app.globalData.publicUrl}/courtAdmin/api/match`, //接口地址
  41. method: 'get',
  42. data: {},
  43. success(res) {
  44. console.log('res', res.data);
  45. if (res.data.errcode == 0) {
  46. let datas = res.data.data
  47. let datass = []
  48. let datasss = []
  49. for (let i = 0; i < datas.length; i++) {
  50. if (datas[i].status == 0) {
  51. datas[i].status = '待比赛'
  52. datass.push(datas[i])
  53. } else if (datas[i].status == 1) {
  54. datas[i].status = '进行中'
  55. } else if (datas[i].status == 2) {
  56. datas[i].status = '报名中'
  57. } else if (datas[i].status == 3) {
  58. datas[i].status = '已结束'
  59. datasss.push(datas[i])
  60. }
  61. }
  62. that.setData({
  63. list: datass,
  64. listend: datasss,
  65. });
  66. } else {
  67. wx.showToast({
  68. title: res.data.errmsg,
  69. icon: 'none',
  70. duration: 2000
  71. })
  72. }
  73. }
  74. })
  75. },
  76. fail: res => {
  77. return wx.redirectTo({ url: '/pages/login/index', })
  78. }
  79. })
  80. },
  81. /**
  82. * 生命周期函数--监听页面加载
  83. */
  84. onLoad: function (options) {
  85. // 计算高度
  86. this.searchHeight();
  87. // 监听用户是否登录
  88. this.watchLogin();
  89. },
  90. // 计算高度
  91. searchHeight: function () {
  92. let frameStyle = this.data.frameStyle;
  93. let client = app.globalData.client;
  94. let infoHeight = client.windowHeight;
  95. // 减去状态栏
  96. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2)
  97. // 是否减去底部菜单
  98. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  99. if (infoHeight) this.setData({ infoHeight: infoHeight })
  100. },
  101. /**
  102. * 生命周期函数--监听页面初次渲染完成
  103. */
  104. onReady: function () {
  105. },
  106. /**
  107. * 生命周期函数--监听页面显示
  108. */
  109. onShow: function () {
  110. },
  111. /**
  112. * 生命周期函数--监听页面隐藏
  113. */
  114. onHide: function () {
  115. },
  116. /**
  117. * 生命周期函数--监听页面卸载
  118. */
  119. onUnload: function () {
  120. },
  121. /**
  122. * 页面相关事件处理函数--监听用户下拉动作
  123. */
  124. onPullDownRefresh: function () {
  125. },
  126. /**
  127. * 页面上拉触底事件的处理函数
  128. */
  129. onReachBottom: function () {
  130. },
  131. /**
  132. * 用户点击右上角分享
  133. */
  134. onShareAppMessage: function () {
  135. }
  136. })