// pages/task-list/task-list.js const app = getApp(); const api = require('../../utils/api.js'); Page({ data: { childId: 0, childName: '', dateType: 'today', // today, week, month statusFilter: 'all', // all, pending, completed, overdue tasks: [], filteredTasks: [], loading: false, page: 1, hasMore: true }, onLoad(options) { const childId = options.childId || 0; const childName = options.childName || ''; this.setData({ childId, childName }); wx.setNavigationBarTitle({ title: childName ? `${childName}的任务` : '任务列表' }); }, onShow() { this.loadTasks(); }, // 加载任务列表 loadTasks(refresh = false) { if (refresh) { this.setData({ page: 1, hasMore: true }); } this.setData({ loading: true }); // 模拟数据 const mockTasks = [ { id: 1, title: '写作业', description: '完成数学和语文作业', points: 2, deadline: '2026-03-31 20:00', status: 'pending', category: '学习', needReview: true }, { id: 2, title: '练琴', description: '练习钢琴30分钟', points: 3, deadline: '2026-03-31 19:00', status: 'completed', category: '艺术', needReview: false }, { id: 3, title: '阅读20分钟', description: '阅读课外书籍', points: 2, deadline: '2026-03-31 21:00', status: 'overdue', category: '学习', needReview: true } ]; setTimeout(() => { this.setData({ tasks: mockTasks, filteredTasks: mockTasks, loading: false }); this.applyFilters(); }, 500); }, // 应用筛选 applyFilters() { let filtered = this.data.tasks; // 按状态筛选 if (this.data.statusFilter !== 'all') { filtered = filtered.filter(task => task.status === this.data.statusFilter); } // 按日期筛选 const now = new Date(); if (this.data.dateType === 'today') { filtered = filtered.filter(task => { const deadline = new Date(task.deadline); return deadline.toDateString() === now.toDateString(); }); } else if (this.data.dateType === 'week') { const weekAgo = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000); filtered = filtered.filter(task => { const deadline = new Date(task.deadline); return deadline >= weekAgo; }); } this.setData({ filteredTasks: filtered }); }, // 切换日期类型 onDateTypeChange(e) { this.setData({ dateType: e.currentTarget.dataset.type }); this.applyFilters(); }, // 切换状态筛选 onStatusFilterChange(e) { this.setData({ statusFilter: e.currentTarget.dataset.status }); this.applyFilters(); }, // 任务点击 onTaskTap(e) { const taskId = e.currentTarget.dataset.id; wx.navigateTo({ url: `/pages/task-detail/task-detail?id=${taskId}` }); }, // 创建任务 onCreateTask() { wx.navigateTo({ url: `/pages/task-create/task-create?childId=${this.data.childId}` }); }, // 下拉刷新 onPullDownRefresh() { this.loadTasks(true); wx.stopPullDownRefresh(); }, // 加载更多 onReachBottom() { if (this.data.hasMore && !this.data.loading) { this.loadMoreTasks(); } }, loadMoreTasks() { // 实现加载更多逻辑 } });