list.js 4.9 KB

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