list.js 5.0 KB

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