index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. const app = getApp()
  2. Page({
  3. data: {
  4. id: '',
  5. // 用户信息
  6. user: {},
  7. list: [],
  8. total: 0,
  9. page: 0,
  10. skip: 0,
  11. limit: 5,
  12. statusList: []
  13. },
  14. // 上传比分
  15. async toUpload(e) {
  16. let item = e.currentTarget.dataset.item
  17. wx.navigateTo({ url: '/pagesMy/score/index?id=' + item._id })
  18. },
  19. // 分页-触底
  20. toLower() {
  21. const that = this;
  22. let list = that.data.list;
  23. let limit = that.data.limit;
  24. if (that.data.total > list.length) {
  25. wx.showLoading({ title: '加载中', mask: true })
  26. let page = that.data.page + 1;
  27. that.setData({ page })
  28. let skip = page * limit
  29. that.setData({ skip })
  30. that.search()
  31. wx.hideLoading()
  32. } else {
  33. wx.showToast({ title: `到底了没数据了`, icon: 'none' });
  34. }
  35. },
  36. // 分页-滚动
  37. toScroll() {
  38. // console.log('滚动');
  39. },
  40. // 字典
  41. getDict(value, model) {
  42. const that = this;
  43. if (model == 'status') {
  44. if (value) {
  45. let data = that.data.statusList.find(i => i.value == value)
  46. if (data) return data.label
  47. else return '暂无'
  48. }
  49. }
  50. },
  51. // 清空列表
  52. clearPage() {
  53. const that = this;
  54. that.setData({ list: [] })
  55. that.setData({ skip: 0 })
  56. that.setData({ limit: 5 })
  57. that.setData({ total: 0 })
  58. },
  59. /**
  60. * 生命周期函数--监听页面加载
  61. */
  62. async onLoad(options) {
  63. const that = this;
  64. that.setData({ id: options.id });
  65. },
  66. /**
  67. * 生命周期函数--监听页面显示
  68. */
  69. async onShow() {
  70. const that = this;
  71. wx.showLoading({ title: '加载中', mask: true })
  72. await that.searchUser()
  73. await that.searchOther()
  74. await that.clearPage()
  75. await that.search()
  76. wx.hideLoading()
  77. },
  78. async searchUser() {
  79. const that = this;
  80. wx.getStorage({
  81. key: 'user',
  82. async success(res) {
  83. that.setData({ user: res.data })
  84. },
  85. fail(err) {
  86. console.log(err);
  87. }
  88. })
  89. },
  90. // 查询其他信息
  91. async searchOther() {
  92. const that = this;
  93. let res;
  94. res = await app.$api('dictData', 'GET', { type: 'course_status', is_use: '0' })
  95. if (res.errcode == '0') that.setData({ statusList: res.data })
  96. // 查分数
  97. res = await app.$api('course/ranking', 'GET', { match_id: that.data.id })
  98. },
  99. // 查询通知
  100. async search() {
  101. const that = this;
  102. let info = { skip: that.data.skip, limit: that.data.limit };
  103. info.match_id = that.data.id
  104. let res = await app.$api('course', 'GET', { ...info })
  105. if (res.errcode == '0') {
  106. let list = [...that.data.list, ...res.data]
  107. for (const val of list) {
  108. val.status_name = that.getDict(val.status, 'status')
  109. }
  110. that.setData({ list })
  111. that.setData({ total: res.total })
  112. }
  113. },
  114. /**
  115. * 生命周期函数--监听页面初次渲染完成
  116. */
  117. onReady() {
  118. },
  119. /**
  120. * 生命周期函数--监听页面隐藏
  121. */
  122. onHide() {
  123. },
  124. /**
  125. * 生命周期函数--监听页面卸载
  126. */
  127. onUnload() {
  128. },
  129. /**
  130. * 页面相关事件处理函数--监听用户下拉动作
  131. */
  132. onPullDownRefresh() {
  133. },
  134. /**
  135. * 页面上拉触底事件的处理函数
  136. */
  137. onReachBottom() {
  138. },
  139. /**
  140. * 用户点击右上角分享
  141. */
  142. onShareAppMessage() {
  143. }
  144. })