classes.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // teacher/pages/classes/classes.js
  2. import {
  3. request,
  4. throttle,
  5. debounce
  6. } from "../../utils/api"
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. searchValue: "",
  13. // 分页数据
  14. pageNo: 1,
  15. pageSize: 10,
  16. total: 11,
  17. // 筛选项
  18. classesName: '',
  19. classList: []
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad(options) {
  25. wx.hideHomeButton()
  26. },
  27. // 确认搜索
  28. onSearch(e) {
  29. if (!e.detail.x) {
  30. this.setData({
  31. searchValue: e.detail,
  32. pageNo: 1,
  33. total: 11,
  34. })
  35. }
  36. this.getClassesList()
  37. },
  38. onCancel(e) {
  39. // onCancel
  40. console.log(e)
  41. },
  42. onStudentList(e) {
  43. // let
  44. console.log(e)
  45. // 跳转学生列表
  46. wx.navigateTo({
  47. url: '/teacher/pages/studentList/studentList',
  48. })
  49. },
  50. getClassesList: throttle(async function () {
  51. let {
  52. pageNo,
  53. pageSize,
  54. total,
  55. searchValue
  56. } = this.data
  57. const res = await request("/app-api/tutor/h5/getClassPage", "GET", {
  58. pageNo,
  59. pageSize,
  60. className: searchValue
  61. })
  62. wx.stopPullDownRefresh()
  63. if (this.data.pageNo === 1) {
  64. this.setData({
  65. total: res.data.total,
  66. classList: res.data.list
  67. })
  68. return;
  69. }
  70. // 如果还有数据
  71. if (pageNo * pageSize < total) {
  72. this.setData({
  73. total: res.data.total,
  74. classList: [...this.data.classList, ...res.data.list]
  75. })
  76. }
  77. }),
  78. /**
  79. * 生命周期函数--监听页面初次渲染完成
  80. */
  81. onReady() {
  82. },
  83. /**
  84. * 生命周期函数--监听页面显示
  85. */
  86. onShow() {
  87. this.getClassesList()
  88. },
  89. /**
  90. * 生命周期函数--监听页面隐藏
  91. */
  92. onHide() {
  93. },
  94. /**
  95. * 生命周期函数--监听页面卸载
  96. */
  97. onUnload() {
  98. },
  99. /**
  100. * 页面相关事件处理函数--监听用户下拉动作
  101. */
  102. onPullDownRefresh() {
  103. // console.log("2")
  104. this.setData({
  105. pageNo: 1
  106. })
  107. this.getClassesList()
  108. },
  109. /**
  110. * 页面上拉触底事件的处理函数
  111. */
  112. onReachBottom() {
  113. let {
  114. pageNo,
  115. pageSize,
  116. total,
  117. searchValue
  118. } = this.data
  119. this.setData({
  120. pageNo: pageNo += 1
  121. })
  122. this.getClassesList()
  123. // console.log("1")
  124. },
  125. /**
  126. * 用户点击右上角分享
  127. */
  128. onShareAppMessage() {
  129. }
  130. })