index.js 3.8 KB

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