list.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. tabs: {
  14. active: '0',
  15. menu: [
  16. { title: '公开课', active: '0' },
  17. { title: '私教课', active: '1' },
  18. ]
  19. },
  20. },
  21. // 返回
  22. back(e) {
  23. wx.navigateBack({ delta: 1 })
  24. },
  25. // 选项卡选择
  26. tabsChange: function (e) {
  27. const that = this;
  28. let data = e.detail;
  29. that.setData({ 'tabs.active': data.active })
  30. that.setData({ skip: 0, page: 0, list: [] })
  31. that.watchLogin();
  32. },
  33. // 查看
  34. toView: async function (e) {
  35. const that = this;
  36. that.setData({ skip: 0, page: 0, list: [] })
  37. const { item } = e.currentTarget.dataset;
  38. wx.navigateTo({ url: `/pages/stuAdmin/course/info?id=${item._id}` })
  39. },
  40. // 分页
  41. toPage: function () {
  42. const that = this;
  43. let list = that.data.list;
  44. let limit = that.data.limit;
  45. if (that.data.total > list.length) {
  46. wx.showLoading({ title: '加载中', mask: true })
  47. let page = that.data.page + 1;
  48. that.setData({ page: page })
  49. let skip = page * limit;
  50. that.setData({ skip: skip })
  51. that.watchLogin();
  52. wx.hideLoading()
  53. } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
  54. },
  55. /**
  56. * 生命周期函数--监听页面加载
  57. */
  58. onLoad: function (options) {
  59. },
  60. /**
  61. * 生命周期函数--监听页面初次渲染完成
  62. */
  63. onReady: function () { },
  64. /**
  65. * 生命周期函数--监听页面显示
  66. */
  67. onShow: async function () {
  68. const that = this;
  69. // 查询其他信息
  70. await that.searchOther();
  71. // 监听用户是否登录
  72. await that.watchLogin();
  73. },
  74. searchOther: async function () {
  75. const that = this;
  76. let arr;
  77. // 状态
  78. arr = await app.$get(`/dict`, { code: 'lesson_status' });
  79. if (arr.errcode == '0' && arr.total > 0) that.setData({ statusList: arr.data[0].list });
  80. },
  81. // 监听用户是否登录
  82. watchLogin: async function () {
  83. const that = this;
  84. let statusList = that.data.statusList;
  85. wx.getStorage({
  86. key: 'user',
  87. success: async res => {
  88. let info = { skip: that.data.skip, limit: that.data.limit, type: that.data.tabs.active, student_id: res.data.info._id };
  89. let arr = await app.$get(`/studentView/lessonList`, { ...info });
  90. if (arr.errcode == '0') {
  91. for (const val of arr.data) { let status = statusList.find(i => i.value == val.status); if (status) val.zhStatus = status.label; }
  92. that.setData({ list: [...that.data.list, ...arr.data] })
  93. that.setData({ total: arr.total })
  94. } else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
  95. },
  96. fail: async res => {
  97. wx.redirectTo({ url: '/pages/index/index' })
  98. }
  99. })
  100. },
  101. /**
  102. * 页面上拉触底事件的处理函数
  103. */
  104. /**
  105. * 生命周期函数--监听页面隐藏
  106. */
  107. onHide: function () {
  108. },
  109. /**
  110. * 生命周期函数--监听页面卸载
  111. */
  112. onUnload: function () {
  113. },
  114. /**
  115. * 页面相关事件处理函数--监听用户下拉动作
  116. */
  117. onPullDownRefresh: function () {
  118. },
  119. /**
  120. * 用户点击右上角分享
  121. */
  122. onShareAppMessage: function () {
  123. }
  124. })