index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. const app = getApp()
  2. Page({
  3. data: {
  4. id: "",
  5. info: {},
  6. user: {},
  7. statusList: [],
  8. list: []
  9. },
  10. // 报名
  11. async toAdd() {
  12. const that = this;
  13. if (that.data.user._id) wx.navigateTo({ url: '/pagesMatch/enroll/index?match=' + that.data.info._id }); else wx.navigateTo({ url: '/pagesCommon/login/index' })
  14. },
  15. // 排名
  16. toRank() {
  17. const that = this;
  18. wx.navigateTo({ url: '/pagesMy/ranking/index?id=' + that.data.info._id })
  19. },
  20. // 赛程信息
  21. toCourse(e) {
  22. const that = this;
  23. wx.navigateTo({ url: '/pagesMy/course/index?id=' + that.data.info._id })
  24. },
  25. // 参赛团队
  26. toTeam(e) {
  27. const that = this;
  28. wx.navigateTo({ url: '/pagesMatch/team/index?id=' + that.data.info._id })
  29. },
  30. // 字典
  31. getDict(value, model) {
  32. const that = this;
  33. if (model == 'status') {
  34. if (value) {
  35. let data = that.data.statusList.find(i => i.value == value)
  36. if (data) return data.label
  37. else return '暂无'
  38. }
  39. }
  40. },
  41. /**
  42. * 生命周期函数--监听页面加载
  43. */
  44. async onLoad(options) {
  45. const that = this;
  46. that.setData({ id: options.id });
  47. },
  48. /**
  49. * 生命周期函数--监听页面显示
  50. */
  51. async onShow() {
  52. const that = this;
  53. wx.showLoading({ title: '加载中', mask: true })
  54. await that.searchUser()
  55. await that.searchOther()
  56. await that.search()
  57. wx.hideLoading()
  58. },
  59. async searchUser() {
  60. const that = this;
  61. wx.getStorage({
  62. key: 'user',
  63. async success(res) {
  64. that.setData({ user: res.data })
  65. }, fail(err) {
  66. // console.log(err);
  67. }
  68. })
  69. },
  70. // 查询其他信息
  71. async searchOther() {
  72. const that = this;
  73. let res;
  74. res = await app.$api('dictData', 'GET', { type: 'match_status', is_use: '0' })
  75. if (res.errcode == '0') that.setData({ statusList: res.data })
  76. },
  77. // 查询通知
  78. async search() {
  79. const that = this;
  80. let res = await app.$api(`match/${that.data.id}`, 'GET', {})
  81. if (res.errcode == '0') {
  82. res.data.status_name = that.getDict(res.data.status, 'status')
  83. if (res.data.information) res.data.information = res.data.information.replace(/\<img/gi,
  84. '<img class="rich-img"');
  85. that.setData({ info: res.data })
  86. }
  87. },
  88. /**
  89. * 生命周期函数--监听页面初次渲染完成
  90. */
  91. onReady() {
  92. },
  93. /**
  94. * 生命周期函数--监听页面隐藏
  95. */
  96. onHide() {
  97. },
  98. /**
  99. * 生命周期函数--监听页面卸载
  100. */
  101. onUnload() {
  102. },
  103. /**
  104. * 页面相关事件处理函数--监听用户下拉动作
  105. */
  106. onPullDownRefresh() {
  107. },
  108. /**
  109. * 页面上拉触底事件的处理函数
  110. */
  111. onReachBottom() {
  112. },
  113. /**
  114. * 用户点击右上角分享
  115. */
  116. onShareAppMessage() {
  117. }
  118. })