import React, { useState, useCallback } from 'react'; import { View, Text } from '@tarojs/components'; import Taro, { useDidShow } from '@tarojs/taro'; import { listTasks, FollowUpTask } from '../../../services/followup'; import EmptyState from '../../../components/EmptyState'; import Loading from '../../../components/Loading'; import './index.scss'; const TABS = [ { key: 'pending', label: '待完成' }, { key: 'completed', label: '已完成' }, { key: 'overdue', label: '已过期' }, ]; export default function MyFollowUps() { const [activeTab, setActiveTab] = useState('pending'); const [tasks, setTasks] = useState([]); const [loading, setLoading] = useState(false); const fetchTasks = useCallback(async (status: string) => { setLoading(true); try { const res = await listTasks(status); setTasks(res.data || []); } catch { Taro.showToast({ title: '加载失败', icon: 'none' }); } finally { setLoading(false); } }, []); useDidShow(() => { fetchTasks(activeTab); }); const handleTabChange = (key: string) => { setActiveTab(key); fetchTasks(key); }; const goToDetail = (id: string) => { Taro.navigateTo({ url: `/pages/followup/detail/index?id=${id}` }); }; const getStatusClass = (status: string) => { if (status === 'completed') return 'completed'; if (status === 'overdue') return 'overdue'; return 'pending'; }; const getStatusLabel = (status: string) => { if (status === 'completed') return '已完成'; if (status === 'overdue') return '已过期'; return '待完成'; }; return ( {TABS.map((tab) => ( handleTabChange(tab.key)} > {tab.label} ))} {tasks.map((t) => ( goToDetail(t.id)} > {t.task_type} {getStatusLabel(t.status)} {t.description} 截止日期:{t.due_date} ))} {tasks.length === 0 && !loading && ( { const tab = TABS.find((t) => t.key === activeTab); return tab ? tab.label : ''; })()}任务`} /> )} {loading && ( )} ); }