list.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 user = that.data.user;
  46. const { item } = e.currentTarget.dataset;
  47. wx.showModal({
  48. title: '提示',
  49. content: '您是否确定退课?',
  50. async success(res) {
  51. if (res.confirm) {
  52. let toRefund = await app.$post(`/lessonStudent/toRefund`, { student_id: user.info.id, lesson_id: item._id });
  53. if (toRefund.errcode == '0') {
  54. wx.showToast({ title: `退课成功`, icon: 'success', duration: 2000 });
  55. that.setData({ skip: 0, page: 0, list: [] })
  56. that.watchLogin();
  57. } else wx.showToast({ title: `${toRefund.errmsg}`, icon: 'none', duration: 2000 })
  58. } else if (res.cancel) { }
  59. }
  60. });
  61. },
  62. // 签到
  63. toSign: async function (e) {
  64. const that = this;
  65. const { item } = e.currentTarget.dataset;
  66. const user = that.data.user;
  67. wx.showModal({
  68. title: '提示',
  69. content: '您是否确定签到?',
  70. async success(res) {
  71. if (res.confirm) {
  72. let params = { school_id: item.school_id, lesson_id: item._id, student_id: user.info.id, is_pay: '1' }
  73. let lessonStudent = await app.$get(`/lessonStudent`, params);
  74. if (lessonStudent.errcode == '0' && lessonStudent.total > 0) {
  75. const arr = await app.$post(`/lessonStudent/${lessonStudent.data[0]._id}`, { is_sign: '1' });
  76. if (arr.errcode == '0') {
  77. wx.showToast({ title: `签到成功`, icon: 'success', duration: 2000 });
  78. that.setData({ skip: 0, page: 0, list: [] })
  79. that.watchLogin();
  80. }
  81. }
  82. } else if (res.cancel) { }
  83. }
  84. });
  85. },
  86. // 分页
  87. toPage: function () {
  88. const that = this;
  89. let list = that.data.list;
  90. let limit = that.data.limit;
  91. if (that.data.total > list.length) {
  92. wx.showLoading({ title: '加载中', mask: true })
  93. let page = that.data.page + 1;
  94. that.setData({ page: page })
  95. let skip = page * limit;
  96. that.setData({ skip: skip })
  97. that.watchLogin();
  98. wx.hideLoading()
  99. } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
  100. },
  101. /**
  102. * 生命周期函数--监听页面加载
  103. */
  104. onLoad: function (options) {
  105. },
  106. /**
  107. * 生命周期函数--监听页面初次渲染完成
  108. */
  109. onReady: function () { },
  110. /**
  111. * 生命周期函数--监听页面显示
  112. */
  113. onShow: async function () {
  114. const that = this;
  115. // 查询其他信息
  116. await that.searchOther();
  117. // 监听用户是否登录
  118. await that.watchLogin();
  119. },
  120. searchOther: async function () {
  121. const that = this;
  122. let arr;
  123. // 状态
  124. arr = await app.$get(`/dict`, { code: 'lesson_status' });
  125. if (arr.errcode == '0' && arr.total > 0) that.setData({ statusList: arr.data[0].list });
  126. },
  127. // 监听用户是否登录
  128. watchLogin: async function () {
  129. const that = this;
  130. let statusList = that.data.statusList;
  131. wx.getStorage({
  132. key: 'user',
  133. success: async res => {
  134. that.setData({ user: res.data })
  135. let info = { skip: that.data.skip, limit: that.data.limit, type: that.data.tabs.active, student_id: res.data.info._id, is_pay: '1' };
  136. let arr = await app.$get(`/studentView/lessonList`, { ...info });
  137. if (arr.errcode == '0') {
  138. for (const val of arr.data) {
  139. let status = statusList.find(i => i.value == val.status); if (status) val.zhStatus = status.label;
  140. let date = moment().isBefore(val.refund_hour)
  141. if (date == true) val.drop = '0'
  142. else val.drop = '1'
  143. }
  144. that.setData({ list: [...that.data.list, ...arr.data] })
  145. that.setData({ total: arr.total })
  146. } else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
  147. },
  148. fail: async res => {
  149. wx.redirectTo({ url: '/pages/index/index' })
  150. }
  151. })
  152. },
  153. /**
  154. * 页面上拉触底事件的处理函数
  155. */
  156. /**
  157. * 生命周期函数--监听页面隐藏
  158. */
  159. onHide: function () {
  160. },
  161. /**
  162. * 生命周期函数--监听页面卸载
  163. */
  164. onUnload: function () {
  165. },
  166. /**
  167. * 页面相关事件处理函数--监听用户下拉动作
  168. */
  169. onPullDownRefresh: function () {
  170. },
  171. /**
  172. * 用户点击右上角分享
  173. */
  174. onShareAppMessage: function () {
  175. }
  176. })