import { useHorizontalOverflow } from "../lib/use-horizontal-overflow"; import { PageIntro } from "../components/PageIntro"; import { OpsNotice, OpsTableColumns } from "../components/OperationsKit"; import { FilterSelect } from "../components/ui/filter-select"; import { DateRangeFilter } from "../components/ui/date-range-filter"; import { TicketState } from "../components/ticketState"; import { TicketStatusTag, TicketTypeTag } from "../components/work-order/TicketBadges"; import { useEffect, useRef, useState, type FormEvent, type ReactNode } from "react"; import { Check, Clock3, Info, Plus, Search, X, } from "lucide-react"; import { Button } from "../components/ui/button"; import { Input } from "../components/ui/input"; import { SearchInput } from "../components/ui/search-input"; import { FieldHint } from "../components/ui/field-hint"; import { Link, useLocation, useNavigate, useSearchParams } from "react-router"; import { customerGetList, orderGetList, rowsOf } from "../lib/api/bos"; import { ticketCreate, TICKET_STATUSES, TICKET_TYPES, typeLabel, statusFilterLabel, } from "../lib/api/ticket"; import { classifyTicketError, fmtTime, TICKET_PAGE_SIZE, useTicketList, useTodoCounts } from "../lib/ticket"; import { useTicketStatusCounts } from "../lib/work-order-counts"; import { nextStepOf } from "../lib/work-order-next-step"; import { todoRowDueOn } from "../lib/work-order-todo-row"; import { useSubmit } from "../lib/useLoad"; import { fetchAllPages } from "../lib/fetch-all-pages"; import { LIST_PAGE_SIZE } from "../lib/list-paging"; import { useDemoIdentity } from "../lib/demo-session"; import { ServerListPager } from "../components/ListPager"; import "../styles/operations.css"; import "../styles/work-orders.css"; /** 状态 Tab 的次序(与参考界面「阶段即导航」一致):终态放最后且不显示计数。 */ const TAB_ORDER = ["unassigned", "pending", "processing", "completed", "rejected", "settled", "terminated"] as const; /** 只对「在办 + 待回执」取计数:已办结/已作废数量无运营意义,且会多打两次接口。 */ const COUNTED_STATUSES = ["unassigned", "pending", "processing", "completed", "rejected"] as const; /** * `completed` 在跨类型视图(状态 Tab/筛选器/当前视图 chip)里只写短名「待确认」 * (业主 2026-11-18 二次定案:两半全名拼起来撑破 Tab 行):两类行内叫法 * 「已完成待确认」(主线,等运营商回执)/「已处理待确认」(故障、售后,等提交方确认) * 留在徽标与这行悬停说明里,⛔ 在筛选维度上只写其中一半。 */ const COMPLETED_SCOPE_HINT = "同一状态码 completed,两类都不是终态:主线=已完成待确认(等运营商回执);故障/售后=已处理待确认(等提交方确认)"; function Drawer({ title, subtitle, onClose, children }: { title: string; subtitle: string; onClose: () => void; children: ReactNode }) { const ref = useRef(null); useEffect(() => { const dialog = ref.current; if (!dialog) return; const previous = document.activeElement as HTMLElement | null; const overflow = document.body.style.overflow; document.body.style.overflow = "hidden"; dialog.showModal(); return () => { dialog.close(); document.body.style.overflow = overflow; previous?.focus(); }; }, []); return { if (event.target === event.currentTarget) onClose(); }}>

{subtitle}

{title}

{children}
; } /** * 代客建单(`/ticket/create@v1`)。 * * 客户与订阅都从真接口选(⛔ 手输 ID:建单口的 `customer_id` 要过可见性判定, * 手输别人的客户只会拿到 `11104`)。建单口只收故障/售后两类(create.rs `CREATE_TYPES`), * 开户/到期停机/服务开通由对应业务动作生成,在此提交会被服务端拒。 */ const CREATABLE: ["fault" | "after_sale", string][] = [["fault", "故障报修"], ["after_sale", "售后服务"]]; function Editor({ onClose, onCreated }: { onClose: () => void; onCreated: (message: string) => void }) { const submit = useSubmit(); const [ticketType, setTicketType] = useState<"fault" | "after_sale">("fault"); const [keyword, setKeyword] = useState(""); const [customerId, setCustomerId] = useState(""); const [orderId, setOrderId] = useState(""); const [title, setTitle] = useState(""); const [detail, setDetail] = useState(""); const [customers, setCustomers] = useState<{ customer_id: string; customer_name: string | null }[]>([]); const [orders, setSubs] = useState<{ subscription_id: string; plan_name: string | null; contract_no: string | null }[]>([]); const [tip, setTip] = useState(""); function pickCustomer(id: string) { setCustomerId(id); setOrderId(""); } useEffect(() => { let alive = true; const timer = window.setTimeout(async () => { try { const r = await customerGetList({ page: 0, page_size: 20, keyword: keyword.trim() || undefined }); if (alive) setCustomers(rowsOf(r).map((c) => ({ customer_id: c.customer_id, customer_name: c.customer_name }))); } catch { if (alive) setCustomers([]); } }, 300); return () => { alive = false; window.clearTimeout(timer); }; }, [keyword]); useEffect(() => { if (!customerId) { setSubs([]); return; } let alive = true; fetchAllPages((page, page_size) => orderGetList({ customer_id: customerId, page, page_size }), { pageSize: LIST_PAGE_SIZE }) .then((r) => { if (alive) setSubs(rowsOf(r.items).map((s) => ({ subscription_id: s.subscription_id, plan_name: s.plan_name, contract_no: s.contract_no ?? null }))); }) .catch(() => { if (alive) setSubs([]); }); return () => { alive = false; }; }, [customerId]); async function submitForm(event: FormEvent) { event.preventDefault(); setTip(""); if (!customerId) { setTip("请选择归属客户。"); return; } if (title.trim().length < 2) { setTip("请填写事项标题(≥2 字)。"); return; } const ok = await submit.run(() => ticketCreate({ ticket_type: ticketType, customer_id: customerId, title: title.trim(), detail: detail.trim() || undefined, subscription_id: orderId || undefined, }).then((r) => onCreated(`工单 ${r.ticket_no} 已创建。`))); if (ok) return; } const failure = submit.error ? classifyTicketError(submit.error) : null; return

此处受理故障报修/售后服务。开户、到期停机、服务开通由对应业务动作生成工单,不得在此独立新建。

01事项类型

02归属客户与订阅

03事项内容