index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. getDict(value, model) {
  22. const that = this;
  23. if (model == 'status') {
  24. if (value) {
  25. let data = that.data.statusList.find(i => i.value == value)
  26. if (data) return data.label
  27. else return '暂无'
  28. }
  29. }
  30. },
  31. /**
  32. * 生命周期函数--监听页面加载
  33. */
  34. async onLoad(options) {
  35. const that = this;
  36. that.setData({ id: options.id });
  37. wx.showLoading({ title: '加载中', mask: true })
  38. await that.searchUser()
  39. await that.searchOther()
  40. await that.search()
  41. wx.hideLoading()
  42. },
  43. async searchUser() {
  44. const that = this;
  45. wx.getStorage({
  46. key: 'token',
  47. async success(res) {
  48. that.setData({ user: res.data })
  49. },
  50. fail(err) {
  51. console.log(err);
  52. }
  53. })
  54. },
  55. // 查询其他信息
  56. async searchOther() {
  57. const that = this;
  58. let res;
  59. res = await app.$api('dictData', 'GET', { type: 'match_status', is_use: '0' })
  60. if (res.errcode == '0') that.setData({ statusList: res.data })
  61. },
  62. // 查询通知
  63. async search() {
  64. const that = this;
  65. let res = await app.$api(`match/${that.data.id}`, 'GET', {})
  66. if (res.errcode == '0') {
  67. res.data.status_name = that.getDict(res.data.status, 'status')
  68. if (res.data.information) res.data.information = res.data.information.replace(/\<img/gi,
  69. '<img class="rich-img"');
  70. that.setData({ info: res.data })
  71. const arr = await app.$api(`course`, 'GET', { match_id: res.data._id })
  72. if (arr.errcode == '0') { that.setData({ list: arr.data }) }
  73. }
  74. },
  75. /**
  76. * 生命周期函数--监听页面初次渲染完成
  77. */
  78. onReady() {
  79. },
  80. /**
  81. * 生命周期函数--监听页面显示
  82. */
  83. onShow() {
  84. },
  85. /**
  86. * 生命周期函数--监听页面隐藏
  87. */
  88. onHide() {
  89. },
  90. /**
  91. * 生命周期函数--监听页面卸载
  92. */
  93. onUnload() {
  94. },
  95. /**
  96. * 页面相关事件处理函数--监听用户下拉动作
  97. */
  98. onPullDownRefresh() {
  99. },
  100. /**
  101. * 页面上拉触底事件的处理函数
  102. */
  103. onReachBottom() {
  104. },
  105. /**
  106. * 用户点击右上角分享
  107. */
  108. onShareAppMessage() {
  109. }
  110. })