index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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: false, name: '首页', leftArrow: false, useBar: true, tabSelectid: '0' },
  11. // 主体高度
  12. infoHeight: '',
  13. list: [],
  14. },
  15. // 查询数据
  16. search: function () {
  17. var that = this;
  18. wx.request({
  19. url: `${app.globalData.publicUrl}/courtAdmin/api/match`, //接口地址
  20. method: 'get',
  21. data: {},
  22. success(res) {
  23. console.log('res', res.data);
  24. if (res.data.errcode == 0) {
  25. let datas = res.data.data
  26. for (let i = 0; i < datas.length; i++) {
  27. if (datas[i].status == 0) {
  28. datas[i].status = '待比赛'
  29. } else if (datas[i].status == 1) {
  30. datas[i].status = '进行中'
  31. } else if (datas[i].status == 2) {
  32. datas[i].status = '报名中'
  33. } else if (datas[i].status == 3) {
  34. datas[i].status = '已结束'
  35. }
  36. }
  37. that.setData({
  38. //getSales:temp,
  39. list: datas,
  40. });
  41. } else {
  42. wx.showToast({
  43. title: res.data.errmsg,
  44. icon: 'none',
  45. duration: 2000
  46. })
  47. }
  48. }
  49. })
  50. },
  51. tiao: function (e) {
  52. let id= e.currentTarget.dataset.name;
  53. console.log(id);
  54. wx.navigateTo({
  55. url: '/pages/list/index?id='+id,
  56. })
  57. },
  58. xun: function () {
  59. wx.navigateTo({
  60. url: '/pages/match/detail',
  61. })
  62. },
  63. tabPath(e) {
  64. let query = e.detail.detail;
  65. if (query) wx.redirectTo({ url: `/pages/${query}/index` })
  66. },
  67. /**
  68. * 生命周期函数--监听页面加载
  69. */
  70. onLoad: function (options) {
  71. // 监听用户是否登录
  72. this.watchLogin();
  73. // 计算高度
  74. this.searchHeight();
  75. // 查询数据
  76. this.search();
  77. },
  78. // 监听用户是否登录
  79. watchLogin: function () {
  80. wx.getStorage({
  81. key: 'token',
  82. success: res => {
  83. console.log(res);
  84. },
  85. fail: res => {
  86. return wx.redirectTo({ url: '/pages/login/index', })
  87. }
  88. })
  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. })