index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. }, fail(err) {
  50. console.log(err);
  51. }
  52. })
  53. },
  54. // 查询其他信息
  55. async searchOther() {
  56. const that = this;
  57. let res;
  58. res = await app.$api('dictData', 'GET', { type: 'match_status', is_use: '0' })
  59. if (res.errcode == '0') that.setData({ statusList: res.data })
  60. },
  61. // 查询通知
  62. async search() {
  63. const that = this;
  64. let res = await app.$api(`match/${that.data.id}`, 'GET', {})
  65. if (res.errcode == '0') {
  66. res.data.status_name = that.getDict(res.data.status, 'status')
  67. if (res.data.information) res.data.information = res.data.information.replace(/\<img/gi,
  68. '<img class="rich-img"');
  69. that.setData({ info: res.data })
  70. const arr = await app.$api(`course`, 'GET', { match_id: res.data._id })
  71. if (arr.errcode == '0') { that.setData({ list: arr.data }) }
  72. }
  73. },
  74. /**
  75. * 生命周期函数--监听页面初次渲染完成
  76. */
  77. onReady() {
  78. },
  79. /**
  80. * 生命周期函数--监听页面显示
  81. */
  82. onShow() {
  83. },
  84. /**
  85. * 生命周期函数--监听页面隐藏
  86. */
  87. onHide() {
  88. },
  89. /**
  90. * 生命周期函数--监听页面卸载
  91. */
  92. onUnload() {
  93. },
  94. /**
  95. * 页面相关事件处理函数--监听用户下拉动作
  96. */
  97. onPullDownRefresh() {
  98. },
  99. /**
  100. * 页面上拉触底事件的处理函数
  101. */
  102. onReachBottom() {
  103. },
  104. /**
  105. * 用户点击右上角分享
  106. */
  107. onShareAppMessage() {
  108. }
  109. })