task.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. },
  17. changeIndex: function (e) {
  18. if (e.detail == 0) {
  19. this.setData({ 'status': 0 })
  20. this.setData({
  21. doName: '做作业'
  22. })
  23. } else {
  24. this.setData({ 'status': 1 })
  25. this.setData({
  26. doName: '查看详情'
  27. })
  28. }
  29. this.queryList()
  30. },
  31. doTask: function (e) {
  32. wx.navigateTo({
  33. url: '/pages/taskDetail/taskDetail?id=' + e.currentTarget.dataset.id,
  34. })
  35. },
  36. /**
  37. * 生命周期函数--监听页面加载
  38. */
  39. onLoad: function (options) {
  40. // let bd = options.beginDate
  41. // let ed = options.endDate
  42. let bd = '2020-01-01'
  43. let ed = '2021-01-01'
  44. if (bd && ed) {
  45. this.setData({ 'beginDate': bd, 'endDate': ed })
  46. } else {
  47. let today = util.curTime().substring(0, 10).replace(/\//g, '-')
  48. this.setData({ 'beginDate': today.substring(0, 8) + '01', 'endDate': today })
  49. }
  50. },
  51. /**
  52. * 生命周期函数--监听页面初次渲染完成
  53. */
  54. onReady: function () {
  55. this.queryList()
  56. },
  57. /**
  58. * 生命周期函数--监听页面显示
  59. */
  60. onShow: function () {
  61. },
  62. /**
  63. * 生命周期函数--监听页面隐藏
  64. */
  65. onHide: function () {
  66. },
  67. /**
  68. * 生命周期函数--监听页面卸载
  69. */
  70. onUnload: function () {
  71. },
  72. /**
  73. * 页面相关事件处理函数--监听用户下拉动作
  74. */
  75. onPullDownRefresh: function () {
  76. },
  77. /**
  78. * 页面上拉触底事件的处理函数
  79. */
  80. onReachBottom: function () {
  81. },
  82. /**
  83. * 用户点击右上角分享
  84. */
  85. onShareAppMessage: function () {
  86. },
  87. queryList: function () {
  88. const urls = urlDef.urls;
  89. let stu = wx.getStorageSync('student');
  90. if (stu) {
  91. this.setData('curStu', stu);
  92. util.apiPost(urls.my_homework, { 'q.beginDate': this.data.beginDate, 'q.endDate': this.data.endDate, 'q.studentId': stu.studentId, 'q.status': this.data.status }).then(rs => {
  93. rs.map(o => {
  94. if (o.beginTime) {
  95. o.beginTime = o.beginTime.substring(11, 16)
  96. }
  97. if (o.endTime) {
  98. o.endTime = o.endTime.substring(11, 16)
  99. }
  100. if (o.completedTime) {
  101. o.completedTime = o.completedTime.substring(0, 10)
  102. }
  103. if (o.homeworkContent) {
  104. o.homeworkContent = this.parseContent(o.homeworkContent)
  105. }
  106. })
  107. this.setData({ 'list': rs })
  108. })
  109. }
  110. },
  111. parseContent(content) {
  112. let contents = null
  113. try {
  114. contents = JSON.parse(content)
  115. content = contents.content
  116. } catch (e) {
  117. contents = {}
  118. console.log(JSON.stringify(e))
  119. }
  120. return content
  121. }
  122. })