index.js 4.0 KB

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