task.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // pages/task/task.js
  2. const app = getApp()
  3. const util = require("../../utils/util")
  4. const urlDef = require("../../utils/urls")
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. curStu: null,
  11. switchTitle: ['待提交', '已提交'],
  12. doName: "做作业",
  13. beginDate: null,
  14. endDate: null,
  15. status: 0,
  16. loading: '上拉加载',
  17. list: [],
  18. pageNum: 0,
  19. hasNextPage: true,
  20. },
  21. changeIndex: function (e) {
  22. if (e.detail == 0) {
  23. this.setData({ 'status': 0, pageNum: 0, list: [], doName: '做作业' })
  24. } else {
  25. this.setData({ 'status': 1, pageNum: 0, list: [], doName: '查看详情' })
  26. }
  27. this.queryList()
  28. },
  29. doTask: function (e) {
  30. wx.navigateTo({
  31. url: '/pages/taskDetail/taskDetail?id=' + e.currentTarget.dataset.id,
  32. })
  33. },
  34. getDates:function(e){
  35. this.setData({
  36. beginDate: e.detail[0],
  37. endDate: e.detail[1],
  38. loading: '加载中'
  39. })
  40. this.queryList()
  41. },
  42. /**
  43. * 生命周期函数--监听页面加载
  44. */
  45. onLoad: function (options) {
  46. let bd = options.beginDate
  47. let ed = options.endDate
  48. bd = '2020-01-01'
  49. ed = '2021-03-01'
  50. if (bd && ed) {
  51. this.setData({ 'beginDate': bd, 'endDate': ed })
  52. } else {
  53. let today = util.curTime().substring(0, 10).replace(/\//g, '-')
  54. this.setData({ 'beginDate': today.substring(0, 8) + '01', 'endDate': today })
  55. }
  56. },
  57. /**
  58. * 生命周期函数--监听页面初次渲染完成
  59. */
  60. onReady: function () {
  61. },
  62. /**
  63. * 生命周期函数--监听页面显示
  64. */
  65. onShow: function () {
  66. this.setData({ list: [] })
  67. this.queryList()
  68. },
  69. /**
  70. * 生命周期函数--监听页面隐藏
  71. */
  72. onHide: function () {
  73. },
  74. /**
  75. * 生命周期函数--监听页面卸载
  76. */
  77. onUnload: function () {
  78. },
  79. /**
  80. * 页面相关事件处理函数--监听用户下拉动作
  81. */
  82. onPullDownRefresh: function () {
  83. },
  84. /**
  85. * 页面上拉触底事件的处理函数
  86. */
  87. onReachBottom: function () {
  88. if (this.data.hasNextPage) {
  89. let pn = this.data.pageNum
  90. this.setData({ loading: '加载中', 'pageNum': ++pn })
  91. this.queryList()
  92. }
  93. },
  94. /**
  95. * 用户点击右上角分享
  96. */
  97. onShareAppMessage: function () {
  98. },
  99. queryList: function () {
  100. const urls = urlDef.urls;
  101. let stu = wx.getStorageSync('student');
  102. if (stu) {
  103. this.setData('curStu', stu);
  104. let params = { 'q.beginDate': this.data.beginDate, 'q.endDate': this.data.endDate, 'q.studentId': stu.studentId, 'q.status': this.data.status }
  105. params.pageNum = this.data.pageNum
  106. util.apiPost(urls.my_homework, params).then(rs => {
  107. let list = rs.list;
  108. list.map(o => {
  109. if (o.beginTime) {
  110. o.beginTime = o.beginTime.substring(11, 16)
  111. }
  112. if (o.endTime) {
  113. o.endTime = o.endTime.substring(11, 16)
  114. }
  115. if (o.completedTime) {
  116. o.completedTime = o.completedTime.substring(0, 10)
  117. }
  118. if (o.homeworkContent) {
  119. o.homeworkContent = this.parseContent(o.homeworkContent)
  120. }
  121. })
  122. this.setData({
  123. 'hasNextPage': rs.hasNextPage,
  124. 'loading': rs.hasNextPage ? '下拉刷新' : '没有更多数据',
  125. 'list': this.data.list.concat(list)
  126. })
  127. })
  128. }
  129. },
  130. parseContent(content) {
  131. let contents = null
  132. try {
  133. contents = JSON.parse(content)
  134. content = contents.content
  135. } catch (e) {
  136. contents = {}
  137. console.log(JSON.stringify(e))
  138. }
  139. return content
  140. }
  141. })