lessonstudent.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. const app = getApp();
  2. import { is_pay } from '../../utils/dict';
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. frameStyle: { useTop: true, name: '学员信息', leftArrow: true, useBar: false },
  9. id: '',
  10. // 查询
  11. search: {},
  12. list: [],
  13. total: 0,
  14. skip: 0,
  15. limit: 10,
  16. page: 0,
  17. is_payList: is_pay,
  18. },
  19. // 跳转菜单
  20. back(e) {
  21. wx.navigateBack({ delta: 1 })
  22. },
  23. // 查询
  24. toInput(e) {
  25. const that = this;
  26. let value = e.detail.value;
  27. if (value) that.setData({ 'search.student_id_name': value })
  28. else that.setData({ search: {} })
  29. that.clearPage(); that.watchLogin();
  30. },
  31. // 清空列表
  32. clearPage() {
  33. const that = this;
  34. that.setData({ list: [], skip: 0, limit: 10, page: 0 })
  35. },
  36. // 签到
  37. toSign(e) {
  38. const that = this;
  39. let { item } = e.currentTarget.dataset;
  40. wx.showModal({
  41. title: '提示',
  42. content: '是否确认签到?',
  43. async success(res) {
  44. if (res.confirm) {
  45. let res = await app.$post(`/lessonStudent/${item._id}`, { is_sign: '1' });
  46. if (res.errcode == '0') {
  47. wx.showToast({ title: '签到成功', icon: 'none' })
  48. that.clearPage();
  49. that.watchLogin();
  50. } else wx.showToast({ title: res.errmsg, icon: 'none' })
  51. }
  52. }
  53. })
  54. },
  55. /**
  56. * 生命周期函数--监听页面加载
  57. */
  58. onLoad: async function (options) {
  59. const that = this;
  60. await that.setData({ id: options.id || '' })
  61. // 监听用户是否登录
  62. await that.watchLogin();
  63. },
  64. watchLogin: async function () {
  65. const that = this;
  66. wx.getStorage({
  67. key: 'user',
  68. success: async res => {
  69. let info = { skip: that.data.skip, limit: that.data.limit, lesson_id: that.data.id };
  70. const arr = await app.$get(`/lessonStudent`, { ...info, ...that.data.search });
  71. if (arr.errcode == '0') {
  72. let list = [...that.data.list, ...arr.data];
  73. for (const val of list) {
  74. val.zhis_pay = that.searchPay(val.is_pay)
  75. }
  76. that.setData({ list });
  77. that.setData({ total: arr.total })
  78. }
  79. else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }); }
  80. },
  81. fail: async res => {
  82. wx.redirectTo({ url: '/pages/index/index' })
  83. }
  84. })
  85. },
  86. searchPay(e) {
  87. const that = this;
  88. let data = that.data.is_payList.find((i => i.value == e))
  89. if (data) return data.label
  90. },
  91. // 分页
  92. toPage: function () {
  93. const that = this;
  94. let list = that.data.list;
  95. let limit = that.data.limit;
  96. if (that.data.total > list.length) {
  97. wx.showLoading({ title: '加载中', mask: true })
  98. let page = that.data.page + 1;
  99. that.setData({ page: page })
  100. let skip = page * limit;
  101. that.setData({ skip: skip })
  102. that.watchLogin();
  103. wx.hideLoading()
  104. } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
  105. },
  106. /**
  107. * 生命周期函数--监听页面初次渲染完成
  108. */
  109. onReady: function () {
  110. },
  111. /**
  112. * 生命周期函数--监听页面显示
  113. */
  114. onShow: async function () { },
  115. /**
  116. * 生命周期函数--监听页面隐藏
  117. */
  118. onHide: function () {
  119. },
  120. /**
  121. * 生命周期函数--监听页面卸载
  122. */
  123. onUnload: function () {
  124. },
  125. /**
  126. * 页面相关事件处理函数--监听用户下拉动作
  127. */
  128. onPullDownRefresh: function () {
  129. },
  130. /**
  131. * 页面上拉触底事件的处理函数
  132. */
  133. onReachBottom: function () {
  134. },
  135. /**
  136. * 用户点击右上角分享
  137. */
  138. onShareAppMessage: function () {
  139. }
  140. })