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. },
  38. /**
  39. * 生命周期函数--监听页面显示
  40. */
  41. async onShow() {
  42. const that = this;
  43. wx.showLoading({ title: '加载中', mask: true })
  44. await that.searchUser()
  45. await that.searchOther()
  46. await that.search()
  47. wx.hideLoading()
  48. },
  49. async searchUser() {
  50. const that = this;
  51. wx.getStorage({
  52. key: 'user',
  53. async success(res) {
  54. that.setData({ user: res.data })
  55. }, fail(err) {
  56. // console.log(err);
  57. }
  58. })
  59. },
  60. // 查询其他信息
  61. async searchOther() {
  62. const that = this;
  63. let res;
  64. res = await app.$api('dictData', 'GET', { type: 'match_status', is_use: '0' })
  65. if (res.errcode == '0') that.setData({ statusList: res.data })
  66. },
  67. // 查询通知
  68. async search() {
  69. const that = this;
  70. let res = await app.$api(`match/${that.data.id}`, 'GET', {})
  71. if (res.errcode == '0') {
  72. res.data.status_name = that.getDict(res.data.status, 'status')
  73. if (res.data.information) res.data.information = res.data.information.replace(/\<img/gi,
  74. '<img class="rich-img"');
  75. that.setData({ info: res.data })
  76. const arr = await app.$api(`course`, 'GET', { match_id: res.data._id })
  77. if (arr.errcode == '0') { that.setData({ list: arr.data }) }
  78. }
  79. },
  80. /**
  81. * 生命周期函数--监听页面初次渲染完成
  82. */
  83. onReady() {
  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. })