task.js 3.5 KB

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