"use client"; import { ListChecks } from "lucide-react"; import { useCallback, useEffect, useState } from "react"; import { adminApi, errMessage, type TodoItem } from "@/lib/admin-api"; import { Badge, Button, Card, EmptyState, ErrorState, LoadingBlock, Pagination, SearchInput, Select, TableWrap, Td, Th, formatTime, isOverdue, statusTone, useToast, } from "@/components/admin/ui"; const STATUS_OPTIONS = [ { value: "", label: "全部状态" }, { value: "待处理", label: "待处理" }, { value: "处理中", label: "处理中" }, { value: "已完成", label: "已完成" }, ]; const PRIORITY_TONE = { 高: "danger", 中: "warning", 低: "neutral" } as const; export function TodosSection({ onOpenCustomer }: { onOpenCustomer?: (customerId: number) => void }) { const toast = useToast(); const [items, setItems] = useState([]); const [total, setTotal] = useState(0); const [totalPages, setTotalPages] = useState(0); const [page, setPage] = useState(1); const [status, setStatus] = useState("待处理"); const [type, setType] = useState(""); const [loading, setLoading] = useState(true); const [error, setError] = useState(""); const [busyId, setBusyId] = useState(null); const load = useCallback(async () => { setLoading(true); setError(""); try { const result = await adminApi.todos({ status: status || undefined, todo_type: type || undefined, page, page_size: 10 }); setItems(result.items ?? []); setTotal(result.total ?? 0); setTotalPages(result.total_pages ?? 0); } catch (e) { setError(errMessage(e, "待办加载失败")); } finally { setLoading(false); } }, [status, type, page]); useEffect(() => { void load(); }, [load]); async function handle(todo: TodoItem, action: "process" | "done") { setBusyId(todo.id); try { await adminApi.handleTodo(todo.id, action); toast(action === "done" ? "待办已标记完成" : "待办已开始处理"); await load(); } catch (e) { toast(errMessage(e, "操作失败"), "error"); } finally { setBusyId(null); } } return (
{ setType(event.target.value); setPage(1); }} />
{loading ? ( ) : error ? ( void load()} /> ) : items.length === 0 ? ( ) : ( <> 待办类型 关联客户 优先级 状态 截止时间 操作 {items.map((todo) => ( {todo.todo_type} {todo.customer_id ? ( ) : ( -- )} {todo.priority ?? "普通"} {todo.status} {formatTime(todo.due_at)} {isOverdue(todo.due_at) && todo.status !== "已完成" && " · 已逾期"}
{todo.status === "待处理" && ( )} {todo.status !== "已完成" && ( )} {todo.status === "已完成" && }
))}
)}
); }