task.js 3.7 KB

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