index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. const app = getApp()
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. frameStyle: { useTop: true, name: '赛事信息', leftArrow: true, useBar: false },
  8. id: '',
  9. info: {},
  10. // 选项卡
  11. tabs: {
  12. active: 'a',
  13. list: [
  14. { title: '规程', name: 'a' },
  15. { title: '选手', name: 'b' },
  16. { title: '秩序册', name: 'c' },
  17. { title: '赛况', name: 'd' },
  18. { title: '成绩册', name: 'e' },
  19. ],
  20. },
  21. },
  22. // 跳转菜单
  23. back(e) {
  24. wx.navigateBack({ delta: 1 })
  25. },
  26. // 选项卡
  27. tabsChange: function (e) {
  28. const that = this;
  29. that.setData({ 'tabs.active': e.detail.name });
  30. },
  31. // 报名
  32. toSign: function (e) {
  33. const { item } = e.currentTarget.dataset;
  34. wx.navigateTo({ url: `/pages/matchInfo/sign?id=${item._id}` })
  35. },
  36. /**
  37. * 生命周期函数--监听页面加载
  38. */
  39. onLoad: function (options) {
  40. const that = this;
  41. that.setData({ id: options.id || '62e23cd3bb22e03d0b49d73b' });
  42. // 监听用户是否登录
  43. that.watchLogin();
  44. },
  45. watchLogin: function () {
  46. const that = this;
  47. wx.getStorage({
  48. key: 'user',
  49. success: async (res) => {
  50. if (that.data.id) {
  51. const arr = await app.$get(`/newCourt/api/match/${that.data.id}`);
  52. if (arr.errcode == '0') {
  53. that.setData({ info: arr.data })
  54. } else { wx.showToast({ title: `${res.errMsg}`, icon: 'fail', duration: 2000 }); }
  55. }
  56. },
  57. fail: async (res) => {
  58. wx.redirectTo({ url: '/pages/index/index' });
  59. },
  60. });
  61. },
  62. /**
  63. * 生命周期函数--监听页面初次渲染完成
  64. */
  65. onReady: function () {
  66. },
  67. /**
  68. * 生命周期函数--监听页面显示
  69. */
  70. onShow: function () {
  71. },
  72. /**
  73. * 生命周期函数--监听页面隐藏
  74. */
  75. onHide: function () {
  76. },
  77. /**
  78. * 生命周期函数--监听页面卸载
  79. */
  80. onUnload: function () {
  81. },
  82. /**
  83. * 页面相关事件处理函数--监听用户下拉动作
  84. */
  85. onPullDownRefresh: function () {
  86. },
  87. /**
  88. * 页面上拉触底事件的处理函数
  89. */
  90. onReachBottom: function () {
  91. },
  92. /**
  93. * 用户点击右上角分享
  94. */
  95. onShareAppMessage: function () {
  96. }
  97. })