lesson.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. const app = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. frameStyle: { useTop: true, name: '课程统计', leftArrow: true, useBar: false },
  8. user: {},
  9. list: [],
  10. total: 0,
  11. skip: 0,
  12. limit: 10,
  13. page: 0,
  14. // dialog弹框
  15. dialog: { title: '筛选条件', show: false, type: '1' },
  16. form: {},
  17. // 课程信息
  18. lessonList: [],
  19. // 学生
  20. studentList: []
  21. },
  22. // 跳转菜单
  23. back(e) {
  24. wx.navigateBack({ delta: 1 })
  25. },
  26. // 清空列表
  27. clearPage() {
  28. const that = this;
  29. that.setData({ list: [], skip: 0, limit: 10, page: 0 })
  30. },
  31. // 筛选条件
  32. toSearch() {
  33. const that = this;
  34. that.clearPage();
  35. that.setData({ dialog: { title: '筛选条件', show: true, type: '1' } })
  36. },
  37. // 选择课程
  38. lessonChange(e) {
  39. const that = this;
  40. let data = that.data.lessonList[e.detail.value];
  41. console.log(data);
  42. if (data) that.setData({ 'form.lesson_id': data.id, 'form.lesson_title': data.title })
  43. },
  44. // 选择学员
  45. stuChange(e) {
  46. const that = this;
  47. let data = that.data.studentList[e.detail.value];
  48. if (data) that.setData({ 'form.student_id': data.student_id, 'form.student_id_name': data.student_id_name })
  49. },
  50. // 时间确定选择
  51. datetimeChange: function (e) {
  52. const that = this;
  53. that.setData({ [`form.${e.detail.name}`]: e.detail.datetime });
  54. },
  55. // 提交查询
  56. onSubmit(e) {
  57. const that = this;
  58. // let form = that.data.form;
  59. // const params = e.detail.value;
  60. // params.time_start = form.time_start;
  61. // params.time_end = form.time_end;
  62. that.search()
  63. },
  64. // 关闭弹框
  65. toClose: function () {
  66. const that = this;
  67. that.clearPage();
  68. that.setData({ form: {} })
  69. that.setData({ dialog: { title: '筛选条件', show: false, type: '1' } })
  70. that.search()
  71. },
  72. // 重置查询
  73. onReset(e) {
  74. const that = this;
  75. that.clearPage()
  76. that.setData({ form: {} })
  77. that.search();
  78. },
  79. /**
  80. * 生命周期函数--监听页面加载
  81. */
  82. onLoad: function (options) {
  83. },
  84. /**
  85. * 生命周期函数--监听页面初次渲染完成
  86. */
  87. onReady: function () {
  88. },
  89. /**
  90. * 生命周期函数--监听页面显示
  91. */
  92. onShow: async function () {
  93. const that = this;
  94. // 监听用户登录
  95. await that.watchLogin();
  96. },
  97. watchLogin() {
  98. const that = this;
  99. wx.getStorage({
  100. key: 'user',
  101. success: async res => {
  102. that.setData({ user: res.data })
  103. await that.searchOther()
  104. await that.search()
  105. },
  106. fail: async res => {
  107. wx.redirectTo({ url: '/pages/index/index' })
  108. }
  109. })
  110. },
  111. async search() {
  112. const that = this;
  113. console.log(that.data.form);
  114. },
  115. async searchOther() {
  116. const that = this;
  117. let user = that.data.user;
  118. let res;
  119. // 查詢課程信息
  120. res = await app.$get(`/lesson`, { school_id: user.info.id });
  121. if (res.errcode == '0') { that.setData({ lessonList: res.data }) }
  122. // 查询学校学生
  123. res = await app.$get(`/rss`, { school_id: user.info.id })
  124. if (res.errcode == '0') { that.setData({ studentList: res.data }) }
  125. },
  126. /**
  127. * 生命周期函数--监听页面隐藏
  128. */
  129. onHide: function () {
  130. const that = this;
  131. that.clearPage();
  132. },
  133. /**
  134. * 生命周期函数--监听页面卸载
  135. */
  136. onUnload: function () {
  137. },
  138. /**
  139. * 页面相关事件处理函数--监听用户下拉动作
  140. */
  141. onPullDownRefresh: function () {
  142. },
  143. /**
  144. * 页面上拉触底事件的处理函数
  145. */
  146. onReachBottom: function () {
  147. },
  148. /**
  149. * 用户点击右上角分享
  150. */
  151. onShareAppMessage: function () {
  152. }
  153. })