task.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. if (bd && ed) {
  49. this.setData({ 'beginDate': bd, 'endDate': ed })
  50. } else {
  51. let today = util.curTime().substring(0, 10).replace(/\//g, '-')
  52. this.setData({ 'beginDate': today.substring(0, 8) + '01', 'endDate': today })
  53. }
  54. },
  55. /**
  56. * 生命周期函数--监听页面初次渲染完成
  57. */
  58. onReady: function () {
  59. },
  60. /**
  61. * 生命周期函数--监听页面显示
  62. */
  63. onShow: function () {
  64. this.setData({ list: [] })
  65. this.queryList()
  66. },
  67. /**
  68. * 生命周期函数--监听页面隐藏
  69. */
  70. onHide: function () {
  71. },
  72. /**
  73. * 生命周期函数--监听页面卸载
  74. */
  75. onUnload: function () {
  76. },
  77. /**
  78. * 页面相关事件处理函数--监听用户下拉动作
  79. */
  80. onPullDownRefresh: function () {
  81. },
  82. /**
  83. * 页面上拉触底事件的处理函数
  84. */
  85. onReachBottom: function () {
  86. if (this.data.hasNextPage) {
  87. let pn = this.data.pageNum
  88. this.setData({ loading: '加载中', 'pageNum': ++pn })
  89. this.queryList()
  90. }
  91. },
  92. /**
  93. * 用户点击右上角分享
  94. */
  95. onShareAppMessage: function () {
  96. },
  97. queryList: function () {
  98. const urls = urlDef.urls;
  99. let stu = wx.getStorageSync('student');
  100. if (stu) {
  101. this.setData({ 'curStu': stu });
  102. let params = { 'q.beginDate': this.data.beginDate, 'q.endDate': this.data.endDate, 'q.studentId': stu.studentId, 'q.status': this.data.status }
  103. params.pageNum = this.data.pageNum
  104. util.apiPost(urls.my_homework, params).then(rs => {
  105. let list = rs.list;
  106. list.map(o => {
  107. if (o.beginTime) {
  108. o.beginTime = o.beginTime.substring(11, 16)
  109. }
  110. if (o.endTime) {
  111. o.endTime = o.endTime.substring(11, 16)
  112. }
  113. if (o.completedTime) {
  114. o.completedTime = o.completedTime.substring(0, 10)
  115. }
  116. if (o.homeworkContent) {
  117. o.homeworkContent = this.parseContent(o.homeworkContent)
  118. }
  119. })
  120. this.setData({
  121. 'hasNextPage': rs.hasNextPage,
  122. 'loading': rs.hasNextPage ? '下拉刷新' : '没有更多数据',
  123. 'list': this.data.list.concat(list)
  124. })
  125. })
  126. }
  127. },
  128. parseContent(content) {
  129. let contents = null
  130. try {
  131. contents = JSON.parse(content)
  132. content = contents.content
  133. } catch (e) {
  134. contents = {}
  135. console.log(JSON.stringify(e))
  136. }
  137. return content
  138. }
  139. })