lessonstudent.js 3.2 KB

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