list.js 5.8 KB

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