list.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. statusList: []
  12. },
  13. // 返回
  14. back(e) {
  15. wx.navigateBack({ delta: 1 })
  16. },
  17. // 查看
  18. toView: async function (e) {
  19. const that = this;
  20. that.setData({ skip: 0, page: 0, list: [] })
  21. const { item } = e.currentTarget.dataset;
  22. wx.navigateTo({ url: `/pages/stuAdmin/open/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. * 生命周期函数--监听页面加载
  41. */
  42. onLoad: function (options) {
  43. },
  44. /**
  45. * 生命周期函数--监听页面初次渲染完成
  46. */
  47. onReady: function () { },
  48. /**
  49. * 生命周期函数--监听页面显示
  50. */
  51. onShow: async function () {
  52. const that = this;
  53. // 查询其他信息
  54. await that.searchOther();
  55. // 监听用户是否登录
  56. await that.watchLogin();
  57. },
  58. searchOther: async function () {
  59. const that = this;
  60. let arr;
  61. // 状态
  62. arr = await app.$get(`/dict`, { code: 'lesson_status' });
  63. if (arr.errcode == '0' && arr.total > 0) that.setData({ statusList: arr.data[0].list });
  64. },
  65. // 监听用户是否登录
  66. watchLogin: async function () {
  67. const that = this;
  68. var list = [];
  69. let statusList = that.data.statusList;
  70. wx.getStorage({
  71. key: 'user',
  72. success: async res => {
  73. let info = { skip: that.data.skip, limit: that.data.limit };
  74. let arr = await app.$get(`/lessonPublic`, { ...info });
  75. if (arr.errcode == '0') {
  76. for (const val of arr.data) {
  77. if (val.student) {
  78. let student = val.student.find(i => i._id == res.data.info.id);
  79. if (student) {
  80. let status = statusList.find(i => i.value == val.status); if (status) val.zhStatus = status.label;
  81. list.push(val);
  82. }
  83. }
  84. }
  85. if (list) {
  86. that.setData({ list: [...that.data.list, ...list] })
  87. that.setData({ total: list.length })
  88. }
  89. } else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
  90. },
  91. fail: async res => {
  92. wx.redirectTo({ url: '/pages/index/index' })
  93. }
  94. })
  95. },
  96. /**
  97. * 页面上拉触底事件的处理函数
  98. */
  99. /**
  100. * 生命周期函数--监听页面隐藏
  101. */
  102. onHide: function () {
  103. },
  104. /**
  105. * 生命周期函数--监听页面卸载
  106. */
  107. onUnload: function () {
  108. },
  109. /**
  110. * 页面相关事件处理函数--监听用户下拉动作
  111. */
  112. onPullDownRefresh: function () {
  113. },
  114. /**
  115. * 用户点击右上角分享
  116. */
  117. onShareAppMessage: function () {
  118. }
  119. })