lessonstudent.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. wx.showModal({
  39. title: '提示',
  40. content: '是否确认签到?',
  41. async success(res) {
  42. if (res.confirm) {
  43. let res = await app.$post(`/lessonStudent/${item._id}`, { is_sign: '1' });
  44. if (res.errcode == '0') {
  45. wx.showToast({ title: '签到成功', icon: 'none' })
  46. that.clearPage();
  47. that.watchLogin();
  48. } else wx.showToast({ title: res.errmsg, icon: 'none' })
  49. }
  50. }
  51. })
  52. },
  53. /**
  54. * 生命周期函数--监听页面加载
  55. */
  56. onLoad: async function (options) {
  57. const that = this;
  58. await that.setData({ id: options.id || '' })
  59. // 监听用户是否登录
  60. await that.watchLogin();
  61. },
  62. watchLogin: async function () {
  63. const that = this;
  64. wx.getStorage({
  65. key: 'user',
  66. success: async res => {
  67. let info = { skip: that.data.skip, limit: that.data.limit, lesson_id: that.data.id };
  68. const arr = await app.$get(`/lessonStudent`, { ...info, ...that.data.search });
  69. if (arr.errcode == '0') {
  70. let list = [...that.data.list, ...arr.data];
  71. that.setData({ list });
  72. that.setData({ total: arr.total })
  73. }
  74. else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }); }
  75. },
  76. fail: async res => {
  77. wx.redirectTo({ url: '/pages/index/index' })
  78. }
  79. })
  80. },
  81. // 分页
  82. toPage: function () {
  83. const that = this;
  84. let list = that.data.list;
  85. let limit = that.data.limit;
  86. if (that.data.total > list.length) {
  87. wx.showLoading({ title: '加载中', mask: true })
  88. let page = that.data.page + 1;
  89. that.setData({ page: page })
  90. let skip = page * limit;
  91. that.setData({ skip: skip })
  92. that.watchLogin();
  93. wx.hideLoading()
  94. } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
  95. },
  96. /**
  97. * 生命周期函数--监听页面初次渲染完成
  98. */
  99. onReady: function () {
  100. },
  101. /**
  102. * 生命周期函数--监听页面显示
  103. */
  104. onShow: async function () { },
  105. /**
  106. * 生命周期函数--监听页面隐藏
  107. */
  108. onHide: function () {
  109. },
  110. /**
  111. * 生命周期函数--监听页面卸载
  112. */
  113. onUnload: function () {
  114. },
  115. /**
  116. * 页面相关事件处理函数--监听用户下拉动作
  117. */
  118. onPullDownRefresh: function () {
  119. },
  120. /**
  121. * 页面上拉触底事件的处理函数
  122. */
  123. onReachBottom: function () {
  124. },
  125. /**
  126. * 用户点击右上角分享
  127. */
  128. onShareAppMessage: function () {
  129. }
  130. })