list.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 typeList = that.data.typeList;
  70. let statusList = that.data.statusList;
  71. wx.getStorage({
  72. key: 'user',
  73. success: async res => {
  74. let info = { skip: that.data.skip, limit: that.data.limit };
  75. let arr = await app.$get(`/lessonPublic`, { ...info });
  76. if (arr.errcode == '0') {
  77. for (const val of arr.data) {
  78. if (val.student.length > 0) {
  79. let student = val.student.find(i => i._id == res.data.info.id);
  80. if (student) {
  81. let type = typeList.find(i => i.value == val.type); if (type) val.zhType = type.label;
  82. let status = statusList.find(i => i.value == val.status); if (status) val.zhStatus = status.label;
  83. list.push(val);
  84. }
  85. }
  86. }
  87. if (list) {
  88. that.setData({ list: [...that.data.list, ...list] })
  89. that.setData({ total: list.length })
  90. }
  91. } else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
  92. },
  93. fail: async res => {
  94. wx.redirectTo({ url: '/pages/index/index' })
  95. }
  96. })
  97. },
  98. /**
  99. * 页面上拉触底事件的处理函数
  100. */
  101. /**
  102. * 生命周期函数--监听页面隐藏
  103. */
  104. onHide: function () {
  105. },
  106. /**
  107. * 生命周期函数--监听页面卸载
  108. */
  109. onUnload: function () {
  110. },
  111. /**
  112. * 页面相关事件处理函数--监听用户下拉动作
  113. */
  114. onPullDownRefresh: function () {
  115. },
  116. /**
  117. * 用户点击右上角分享
  118. */
  119. onShareAppMessage: function () {
  120. }
  121. })