| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- // pages/task-detail/task-detail.js
- const app = getApp();
- const api = require('../../utils/api.js');
- Page({
- data: {
- taskId: 0,
- task: null,
- loading: true,
- canComplete: false,
- canReview: false,
- remainingTime: '',
- photoUrl: '',
- voiceUrl: ''
- },
- onLoad(options) {
- const taskId = options.id || 0;
- this.setData({ taskId });
- this.loadTaskDetail();
- },
- onShow() {
- this.loadTaskDetail();
- },
- // 加载任务详情
- loadTaskDetail() {
- this.setData({ loading: true });
-
- // 模拟数据
- const mockTask = {
- id: this.data.taskId,
- title: '写作业',
- description: '完成数学和语文作业,认真书写,仔细检查',
- points: 2,
- deadline: '2026-03-31 20:00',
- status: 'pending',
- category: '学习',
- needReview: true,
- reviewByCategory: false,
- createdAt: '2026-03-31 08:00',
- creatorName: '妈妈',
- childName: '小明',
- completedAt: null,
- reviewedAt: null
- };
- setTimeout(() => {
- this.setData({
- task: mockTask,
- loading: false,
- canComplete: mockTask.status === 'pending',
- canReview: mockTask.status === 'completed' && mockTask.needReview
- });
- this.updateRemainingTime();
- wx.setNavigationBarTitle({ title: mockTask.title });
- }, 500);
- },
- // 更新剩余时间
- updateRemainingTime() {
- if (!this.data.task) return;
-
- const now = new Date();
- const deadline = new Date(this.data.task.deadline);
- const diff = deadline - now;
-
- if (diff <= 0) {
- this.setData({ remainingTime: '已逾期' });
- return;
- }
-
- const hours = Math.floor(diff / (1000 * 60 * 60));
- const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
-
- this.setData({
- remainingTime: `${hours}小时${minutes}分钟`
- });
- },
- // 选择照片
- onChoosePhoto() {
- wx.chooseImage({
- count: 1,
- sizeType: ['compressed'],
- sourceType: ['album', 'camera'],
- success: (res) => {
- const tempFilePath = res.tempFilePaths[0];
- this.setData({ photoUrl: tempFilePath });
- // 这里应该上传到服务器
- }
- });
- },
- // 选择语音
- onChooseVoice() {
- wx.chooseMessageFile({
- count: 1,
- type: 'file',
- extension: ['mp3', 'wav', 'm4a'],
- success: (res) => {
- const tempFilePath = res.tempFilePaths[0];
- this.setData({ voiceUrl: tempFilePath });
- // 这里应该上传到服务器
- }
- });
- },
- // 完成任务
- onCompleteTask() {
- wx.showModal({
- title: '确认完成',
- content: '确定要完成这个任务吗?',
- success: (res) => {
- if (res.confirm) {
- this.doCompleteTask();
- }
- }
- });
- },
- doCompleteTask() {
- wx.showLoading({ title: '提交中...' });
-
- // 模拟API调用
- setTimeout(() => {
- wx.hideLoading();
-
- // 更新任务状态
- const task = this.data.task;
- task.status = 'completed';
- task.completedAt = new Date().toLocaleString();
-
- this.setData({
- task,
- canComplete: false,
- canReview: task.needReview
- });
-
- // 显示积分动画
- this.showPointsAnimation();
-
- wx.showToast({
- title: '任务完成',
- icon: 'success'
- });
- }, 1000);
- },
- // 显示积分动画
- showPointsAnimation() {
- wx.showModal({
- title: '🎉 恭喜完成任务',
- content: `获得 ${this.data.task.points} 积分`,
- showCancel: false,
- confirmText: '太棒了'
- });
- },
- // 审核通过
- onReviewPass() {
- wx.showModal({
- title: '审核确认',
- content: '确定通过这个任务吗?',
- success: (res) => {
- if (res.confirm) {
- this.doReviewTask('pass');
- }
- }
- });
- },
- // 审核拒绝
- onReviewReject() {
- wx.showModal({
- title: '审核确认',
- content: '确定拒绝这个任务吗?',
- success: (res) => {
- if (res.confirm) {
- this.doReviewTask('reject');
- }
- }
- });
- },
- doReviewTask(result) {
- wx.showLoading({ title: '提交中...' });
-
- // 模拟API调用
- setTimeout(() => {
- wx.hideLoading();
-
- // 更新任务状态
- const task = this.data.task;
- task.status = result === 'pass' ? 'completed' : 'pending';
- task.reviewedAt = new Date().toLocaleString();
-
- this.setData({
- task,
- canReview: false
- });
-
- wx.showToast({
- title: result === 'pass' ? '审核通过' : '已拒绝',
- icon: 'success'
- });
- }, 1000);
- },
- // 分享
- onShareAppMessage() {
- return {
- title: `${this.data.task?.childName}完成了任务「${this.data.task?.title}」`,
- path: `/pages/task-detail/task-detail?id=${this.data.taskId}`
- };
- }
- });
|