task-list.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // pages/task-list/task-list.js
  2. const app = getApp();
  3. const api = require('../../utils/api.js');
  4. Page({
  5. data: {
  6. childId: 0,
  7. childName: '',
  8. dateType: 'today', // today, week, month
  9. statusFilter: 'all', // all, pending, completed, overdue
  10. tasks: [],
  11. filteredTasks: [],
  12. loading: false,
  13. page: 1,
  14. hasMore: true
  15. },
  16. onLoad(options) {
  17. const childId = options.childId || 0;
  18. const childName = options.childName || '';
  19. this.setData({ childId, childName });
  20. wx.setNavigationBarTitle({ title: childName ? `${childName}的任务` : '任务列表' });
  21. },
  22. onShow() {
  23. this.loadTasks();
  24. },
  25. // 加载任务列表
  26. loadTasks(refresh = false) {
  27. if (refresh) {
  28. this.setData({ page: 1, hasMore: true });
  29. }
  30. this.setData({ loading: true });
  31. // 模拟数据
  32. const mockTasks = [
  33. {
  34. id: 1,
  35. title: '写作业',
  36. description: '完成数学和语文作业',
  37. points: 2,
  38. deadline: '2026-03-31 20:00',
  39. status: 'pending',
  40. category: '学习',
  41. needReview: true
  42. },
  43. {
  44. id: 2,
  45. title: '练琴',
  46. description: '练习钢琴30分钟',
  47. points: 3,
  48. deadline: '2026-03-31 19:00',
  49. status: 'completed',
  50. category: '艺术',
  51. needReview: false
  52. },
  53. {
  54. id: 3,
  55. title: '阅读20分钟',
  56. description: '阅读课外书籍',
  57. points: 2,
  58. deadline: '2026-03-31 21:00',
  59. status: 'overdue',
  60. category: '学习',
  61. needReview: true
  62. }
  63. ];
  64. setTimeout(() => {
  65. this.setData({
  66. tasks: mockTasks,
  67. filteredTasks: mockTasks,
  68. loading: false
  69. });
  70. this.applyFilters();
  71. }, 500);
  72. },
  73. // 应用筛选
  74. applyFilters() {
  75. let filtered = this.data.tasks;
  76. // 按状态筛选
  77. if (this.data.statusFilter !== 'all') {
  78. filtered = filtered.filter(task => task.status === this.data.statusFilter);
  79. }
  80. // 按日期筛选
  81. const now = new Date();
  82. if (this.data.dateType === 'today') {
  83. filtered = filtered.filter(task => {
  84. const deadline = new Date(task.deadline);
  85. return deadline.toDateString() === now.toDateString();
  86. });
  87. } else if (this.data.dateType === 'week') {
  88. const weekAgo = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000);
  89. filtered = filtered.filter(task => {
  90. const deadline = new Date(task.deadline);
  91. return deadline >= weekAgo;
  92. });
  93. }
  94. this.setData({ filteredTasks: filtered });
  95. },
  96. // 切换日期类型
  97. onDateTypeChange(e) {
  98. this.setData({ dateType: e.currentTarget.dataset.type });
  99. this.applyFilters();
  100. },
  101. // 切换状态筛选
  102. onStatusFilterChange(e) {
  103. this.setData({ statusFilter: e.currentTarget.dataset.status });
  104. this.applyFilters();
  105. },
  106. // 任务点击
  107. onTaskTap(e) {
  108. const taskId = e.currentTarget.dataset.id;
  109. wx.navigateTo({
  110. url: `/pages/task-detail/task-detail?id=${taskId}`
  111. });
  112. },
  113. // 创建任务
  114. onCreateTask() {
  115. wx.navigateTo({
  116. url: `/pages/task-create/task-create?childId=${this.data.childId}`
  117. });
  118. },
  119. // 下拉刷新
  120. onPullDownRefresh() {
  121. this.loadTasks(true);
  122. wx.stopPullDownRefresh();
  123. },
  124. // 加载更多
  125. onReachBottom() {
  126. if (this.data.hasMore && !this.data.loading) {
  127. this.loadMoreTasks();
  128. }
  129. },
  130. loadMoreTasks() {
  131. // 实现加载更多逻辑
  132. }
  133. });