task.js 3.6 KB

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