list.js 5.3 KB

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