index.js 3.8 KB

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