tpStudent.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. const app = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. frameStyle: { useTop: true, name: '临时上课学员', leftArrow: true, useBar: false },
  8. iconUrl: app.globalData.icon,
  9. lesson_id: '',
  10. // 查询
  11. search: {},
  12. list: [],
  13. total: 0,
  14. skip: 0,
  15. limit: 10,
  16. page: 0,
  17. },
  18. // 跳转菜单
  19. back(e) {
  20. wx.navigateBack({ delta: 1 })
  21. },
  22. // 查询
  23. toInput(e) {
  24. const that = this;
  25. let value = e.detail.value;
  26. if (value) that.setData({ 'search.name': value })
  27. else that.setData({ search: {} })
  28. that.clearPage();
  29. that.search();
  30. },
  31. // 清空列表
  32. clearPage() {
  33. const that = this;
  34. that.setData({ list: [], skip: 0, limit: 10, page: 0 })
  35. },
  36. // 添加
  37. toAdd() {
  38. const that = this;
  39. let lesson_id = that.data.lesson_id;
  40. that.clearPage();
  41. wx.navigateTo({
  42. url: `/pagesSchool/coaAdmin/course/tpStudentadd?lesson_id=${lesson_id}`,
  43. })
  44. },
  45. /**
  46. * 生命周期函数--监听页面加载
  47. */
  48. onLoad: function (options) {
  49. const that = this;
  50. that.setData({ lesson_id: options.lesson_id || '' });
  51. },
  52. /**
  53. * 生命周期函数--监听页面初次渲染完成
  54. */
  55. onReady: function () {
  56. },
  57. /**
  58. * 生命周期函数--监听页面显示
  59. */
  60. onShow: async function () {
  61. const that = this;
  62. // 监听用户是否登录
  63. await that.watchLogin();
  64. },
  65. watchLogin: async function () {
  66. const that = this;
  67. wx.getStorage({
  68. key: 'user',
  69. success: async res => {
  70. await that.search();
  71. },
  72. fail: async res => {
  73. wx.redirectTo({ url: '/pages/index/index' })
  74. }
  75. })
  76. },
  77. async search() {
  78. const that = this;
  79. let lesson_id = that.data.lesson_id;
  80. let info = { skip: that.data.skip, limit: that.data.limit, lesson_id: lesson_id };
  81. let res = await app.$get(`/tempLessonApply`, { ...info, ...that.data.search });
  82. if (res.errcode == '0') {
  83. let list = [...that.data.list, ...res.data];
  84. that.setData({ list });
  85. that.setData({ total: res.total });
  86. }
  87. else { wx.showToast({ title: res.errmsg, icon: 'none' }) }
  88. },
  89. // 分页
  90. toPage: function () {
  91. const that = this;
  92. let list = that.data.list;
  93. let limit = that.data.limit;
  94. if (that.data.total > list.length) {
  95. wx.showLoading({ title: '加载中', mask: true })
  96. let page = that.data.page + 1;
  97. that.setData({ page: page })
  98. let skip = page * limit;
  99. that.setData({ skip: skip })
  100. that.watchLogin();
  101. wx.hideLoading()
  102. } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
  103. },
  104. /**
  105. * 生命周期函数--监听页面隐藏
  106. */
  107. onHide: function () {
  108. const that = this;
  109. that.clearPage();
  110. },
  111. /**
  112. * 生命周期函数--监听页面卸载
  113. */
  114. onUnload: function () {
  115. },
  116. /**
  117. * 页面相关事件处理函数--监听用户下拉动作
  118. */
  119. onPullDownRefresh: function () {
  120. },
  121. /**
  122. * 页面上拉触底事件的处理函数
  123. */
  124. onReachBottom: function () {
  125. },
  126. /**
  127. * 用户点击右上角分享
  128. */
  129. onShareAppMessage: function () {
  130. }
  131. })