ranking_list.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // pages/ranking_list/ranking_list.js
  2. // pages/child_list/child_list.js
  3. import { routers, viewImage, sharePage, isFn, getGlobalVal, formatDateTime, formateNumber } from '../../utils/util.js'
  4. import { GetServiceRecordsV1,HomeworkUploadRecord,CoreRanking} from '../../utils/api.js'
  5. const { navigateTo, redirectTo, navigateBack } = routers()
  6. const { globalData, saveUserInfo, getWxloginCode, checkStatus } = getApp()
  7. const { baseImgUrl, thumbnail } = globalData
  8. const app = getApp()
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. baseImgUrl,
  15. thumbnail,
  16. statusBar: app.globalData.statusBar,
  17. isLoaded: false,
  18. isChild:false,
  19. searchKey: '',
  20. checkNum:0,
  21. isCheck:false,
  22. pageNo: 1,
  23. pageSize: 20,
  24. isAll: false,
  25. list:[],
  26. nodata: [
  27. {
  28. text: '暂无数据'
  29. }
  30. ],
  31. },
  32. /**
  33. * 生命周期函数--监听页面加载
  34. */
  35. onLoad: function (options) {
  36. options.libId = wx.getStorageSync('libId')||options.libId;
  37. if (options.isType==1){
  38. wx.setNavigationBarTitle({
  39. title: '校区排行榜',
  40. })
  41. }else if(options.isType==2){
  42. wx.setNavigationBarTitle({
  43. title: '消费记录',
  44. })
  45. }else if(options.isType==3){
  46. wx.setNavigationBarTitle({
  47. title: '班级排行榜',
  48. })
  49. }else if(options.isType==4){
  50. wx.setNavigationBarTitle({
  51. title: '班级作业上传记录',
  52. })
  53. }else if(options.isType==5){
  54. wx.setNavigationBarTitle({
  55. title: `${options.childName}`,
  56. })
  57. }
  58. this.setData(options)
  59. },
  60. /**
  61. * 生命周期函数--监听页面初次渲染完成
  62. */
  63. onReady: function () {
  64. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  65. for (const i in obj) {
  66. this[i] = obj[i]
  67. }
  68. },
  69. /**
  70. * 生命周期函数--监听页面显示
  71. */
  72. onShow: function () {
  73. wx.showLoading({
  74. title: '加载中',
  75. })
  76. this.getData();
  77. },
  78. /**
  79. * 生命周期函数--监听页面隐藏
  80. */
  81. onHide: function () {
  82. },
  83. /**
  84. * 生命周期函数--监听页面卸载
  85. */
  86. onUnload: function () {
  87. },
  88. /**
  89. * 页面相关事件处理函数--监听用户下拉动作
  90. */
  91. onPullDownRefresh: function () {
  92. this.setData({ pageNo: 1 })
  93. this.getData(res => {
  94. wx.stopPullDownRefresh()
  95. })
  96. },
  97. /**
  98. * 页面上拉触底事件的处理函数
  99. */
  100. onReachBottom: function () {
  101. const { isAll} = this.data
  102. if (isAll) {
  103. return
  104. }
  105. this.getData()
  106. },
  107. /**
  108. * 用户点击右上角分享
  109. */
  110. onShareAppMessage: function () {
  111. if (app.sharePageDefaultCtl) {
  112. return app.sharePageDefaultCtl()
  113. }
  114. },
  115. /**
  116. * 获取学生数据
  117. */
  118. getData: function (cb) {
  119. const continuousFn = { fn: this.getData, param: { ...arguments } }
  120. const {pageNo, pageSize, list=[], classId,libId,vipId,isType}=this.data;
  121. var obj = [CoreRanking,GetServiceRecordsV1,CoreRanking,HomeworkUploadRecord,GetServiceRecordsV1]
  122. var dataList=[{pageNo,pageSize},{pageNo,pageSize,libId},{pageNo,pageSize,classId},{pageNo,pageSize,classId},{pageNo,pageSize,libId,vipId}]
  123. obj[isType-1]({ data:dataList[isType-1], continuousFn }).then(res => {
  124. wx.hideLoading();
  125. const temp = res.data.list;
  126. const tempList = (res => {
  127. if(isType==2||isType==5){
  128. for (let i in res) {
  129. if (res[i].consumer.length>5){
  130. res[i].consumer = res[i].consumer.slice(0, 5)+ '...'
  131. }else{
  132. res[i].consumer = res[i].consumer
  133. }
  134. }
  135. }
  136. return res
  137. })(temp || [])
  138. let arr = []
  139. if (pageNo == 1) {
  140. arr = [...tempList]
  141. } else {
  142. arr = [...list, ...tempList]
  143. }
  144. this.setData({
  145. list: arr,
  146. pageNo: tempList.length == pageSize ? Number(pageNo) + 1 : pageNo,
  147. isAll: tempList.length < pageSize,
  148. isLoaded: true
  149. })
  150. if (isFn(cb)) cb()
  151. }).catch(res => {
  152. this.setData({ isLoaded: true })
  153. if (isFn(cb)) cb()
  154. })
  155. }
  156. })