list.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. const app = getApp()
  2. const moment = require("../../../utils/moment.min")
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. frameStyle: { useTop: true, name: '详细信息', leftArrow: true, useBar: false },
  9. list: [],
  10. total: 0,
  11. page: 0,
  12. skip: 0,
  13. limit: 5,
  14. // 课程类型
  15. typeList: [],
  16. // 状态
  17. statusList: []
  18. },
  19. // 返回
  20. back: function () {
  21. wx.navigateBack({ delta: 1 })
  22. },
  23. //添加信息,信息维护
  24. toCommon: function (e) {
  25. const that = this;
  26. const { item, route } = e.currentTarget.dataset;
  27. that.setData({ skip: 0, page: 0, list: [] });
  28. wx.navigateTo({ url: `/pages/${route}?id=${item && item._id ? item._id : ''}` })
  29. },
  30. // 分页
  31. toPage: function () {
  32. const that = this;
  33. let list = that.data.list;
  34. let limit = that.data.limit;
  35. if (that.data.total > list.length) {
  36. wx.showLoading({ title: '加载中', mask: true })
  37. let page = that.data.page + 1;
  38. that.setData({ page: page })
  39. let skip = page * limit;
  40. that.setData({ skip: skip })
  41. that.watchLogin();
  42. wx.hideLoading()
  43. } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
  44. },
  45. /**
  46. * 生命周期函数--监听页面加载
  47. */
  48. onLoad: function (options) {
  49. },
  50. /**
  51. * 生命周期函数--监听页面初次渲染完成
  52. */
  53. onReady: function () {
  54. },
  55. /**
  56. * 生命周期函数--监听页面显示
  57. */
  58. onShow: async function () {
  59. const that = this;
  60. // 查询其他信息
  61. await that.searchOther();
  62. // 监听用户是否登录
  63. await that.watchLogin();
  64. },
  65. // 查询其他信息
  66. searchOther: async function () {
  67. const that = this;
  68. let arr;
  69. // 课程类型
  70. arr = await app.$get(`/dict`, { code: 'lesson_type' });
  71. if (arr.errcode == '0' && arr.total > 0) that.setData({ typeList: arr.data[0].list });
  72. // 审核状态
  73. arr = await app.$get(`/dict`, { code: 'lesson_status' })
  74. if (arr.errcode == '0' && arr.total > 0) that.setData({ statusList: arr.data[0].list });
  75. },
  76. // 监听用户是否登录
  77. watchLogin: async function () {
  78. const that = this;
  79. let typeList = that.data.typeList;
  80. let statusList = that.data.statusList;
  81. wx.getStorage({
  82. key: 'user',
  83. success: async res => {
  84. let info = { skip: that.data.skip, limit: that.data.limit };
  85. let arr = await app.$get(`/lesson`, { ...info });
  86. if (arr.errcode == '0') {
  87. let list = [...that.data.list, ...arr.data];
  88. for (const val of list) {
  89. // 课程类型
  90. let type = typeList.find(i => i.value == val.type);
  91. if (type) val.zhType = type.label;
  92. // 课程状态
  93. let status = statusList.find(i => i.value == val.type);
  94. if (status) val.zhStatus = status.label;
  95. }
  96. that.setData({ list: list })
  97. that.setData({ total: arr.total })
  98. } else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
  99. },
  100. fail: async res => {
  101. wx.redirectTo({ url: '/pages/index/index' })
  102. }
  103. })
  104. },
  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. })