problem_list.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // pages/problem_list/problem_list.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal, formatDateTime, formateNumber, formatDate,throttle} from '../../utils/util.js'
  3. import { ProblemList} from '../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData } = getApp()
  6. const { baseImgUrl, thumbnail } = globalData
  7. const app = getApp()
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. baseImgUrl,
  14. thumbnail,
  15. pageNo: 1,
  16. pageSize: 5,
  17. maxCreateTime: formatDateTime(new Date()),
  18. isAll: false,
  19. isLoaded: false,
  20. navIndex:0,
  21. subject:'语文',
  22. nodata: [
  23. {
  24. text: '暂无语文数据'
  25. },
  26. {
  27. text: '暂无数学数据'
  28. },
  29. {
  30. text: '暂无英语数据'
  31. }
  32. ],
  33. navList: [
  34. {
  35. text: '语文'
  36. },
  37. {
  38. text: '数学'
  39. },
  40. {
  41. text: '英语'
  42. },
  43. ],
  44. },
  45. /**
  46. * 生命周期函数--监听页面加载
  47. */
  48. onLoad: function (options) {
  49. this.setData(options)
  50. },
  51. /**
  52. * 生命周期函数--监听页面初次渲染完成
  53. */
  54. onReady: function () {
  55. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  56. for (const i in obj) {
  57. this[i] = obj[i]
  58. }
  59. },
  60. /**
  61. * 生命周期函数--监听页面显示
  62. */
  63. onShow: function () {
  64. this.getData()
  65. },
  66. /**
  67. * 生命周期函数--监听页面隐藏
  68. */
  69. onHide: function () {
  70. },
  71. /**
  72. * 生命周期函数--监听页面卸载
  73. */
  74. onUnload: function () {
  75. },
  76. /**
  77. * 页面相关事件处理函数--监听用户下拉动作
  78. */
  79. onPullDownRefresh: function () {
  80. this.setData({ pageNo: 1 })
  81. this.getData(res => {
  82. wx.stopPullDownRefresh()
  83. })
  84. },
  85. /**
  86. * 页面上拉触底事件的处理函数
  87. */
  88. onReachBottom: function () {
  89. const { isAll } = this.data
  90. if (isAll) {
  91. return
  92. }
  93. this.getData()
  94. },
  95. /**
  96. * 用户点击右上角分享
  97. */
  98. onShareAppMessage: function () {
  99. if (app.sharePageDefaultCtl) {
  100. return app.sharePageDefaultCtl()
  101. }
  102. },
  103. /**
  104. * 选择切换项
  105. */
  106. selectNavIndexCtl:throttle(function (e) {
  107. const { index,subject } = e.currentTarget.dataset
  108. const {navIndex}=this.data
  109. if (navIndex == index) return
  110. this.setData({ navIndex: index, subject,list:[],pageNo:1})
  111. this.getData()
  112. },500),
  113. /**
  114. * 返回上一页
  115. */
  116. backBook: function () {
  117. wx.navigateBack({
  118. delta: 1,
  119. })
  120. },
  121. /**
  122. * 获取数据
  123. */
  124. getData: function (cb) {
  125. const continuousFn = { fn: this.getData, param: { ...arguments } }
  126. const { vipId, pageNo, pageSize, list, subject, maxCreateTime } = this.data
  127. ProblemList({ data: { vipId, pageNo, pageSize, subject, maxCreateTime }, continuousFn }).then(res => {
  128. const listTemp = res.data.list;
  129. let arr = []
  130. if (pageNo == 1) {
  131. arr = [...listTemp]
  132. } else {
  133. arr = [...list, ...listTemp]
  134. }
  135. this.setData({
  136. list: arr,
  137. pageNo: listTemp.length == pageSize ? pageNo + 1 : pageNo,
  138. isAll: listTemp.length < pageSize,
  139. isLoaded: true
  140. })
  141. if (isFn(cb)) cb()
  142. }).catch(res => {
  143. this.setData({ isLoaded: true })
  144. if (isFn(cb)) cb()
  145. })
  146. },
  147. })