list.js 3.3 KB

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