| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473 |
- import { detailLinkState } from "../lib/detail-navigation";
- import { isImeComposing } from "../lib/ime";
- import { PageIntro } from "../components/PageIntro";
- import { OpsDialog, OpsNotice } from "../components/OperationsKit";
- import { FilterSelect } from "../components/ui/filter-select";
- import { DateRangeFilter } from "../components/ui/date-range-filter";
- import { TicketState } from "../components/ticketState";
- import { WorkOrderLedgerList } from "../components/work-order/WorkOrderLedgerList";
- import { useEffect, useId, useRef, useState, type FormEvent, type KeyboardEvent } from "react";
- import {
- ArrowRight, ClipboardCheck, ClipboardList, Clock3, Headphones, Inbox, Plus, Search, Wrench, X,
- } from "lucide-react";
- import { Button } from "../components/ui/button";
- import { Input } from "../components/ui/input";
- import { SearchInput } from "../components/ui/search-input";
- import { FieldLabel } from "../components/ui/field-label";
- 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, TICKET_PAGE_SIZE, useTicketList, useTodoCounts } from "../lib/ticket";
- import { useTicketStatusCounts } from "../lib/work-order-counts";
- 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 { ListPager } from "../components/ListPager";
- import "../styles/operations.css";
- import "../styles/orders.css";
- import "../styles/work-orders.css";
- import "../styles/work-order-ledger.css";
- /** 状态页签按处理阶段排列,终态放最后。 */
- const TAB_ORDER = ["unassigned", "pending", "processing", "completed", "rejected", "settled", "terminated"] as const;
- /**
- * `completed` 在跨类型视图(状态 Tab/筛选器/当前视图 chip)里只写短名「待确认」
- * (业主 2026-11-18 二次定案:两半全名拼起来撑破 Tab 行):两类行内叫法
- * 「已完成待确认」(主线,等运营商回执)/「已处理待确认」(故障、售后,等提交方确认)
- * 留在徽标与这行悬停说明里,⛔ 在筛选维度上只写其中一半。
- */
- const COMPLETED_SCOPE_HINT = "同一状态码 completed,两类都不是终态:主线=已完成待确认(等运营商回执);故障/售后=已处理待确认(等提交方确认)";
- /**
- * 代客建单(`/ticket/create@v1`)。
- *
- * 客户与订阅都从真接口选(⛔ 手输 ID:建单口的 `customer_id` 要过可见性判定,
- * 手输别人的客户只会拿到 `11104`)。建单口只收故障/售后两类(create.rs `CREATE_TYPES`),
- * 开户/到期停机/服务开通由对应业务动作生成,在此提交会被服务端拒。
- */
- const CREATABLE = [
- { code: "fault", label: "故障报修", Icon: Wrench },
- { code: "after_sale", label: "售后服务", Icon: Headphones },
- ] as const;
- type TicketCustomer = { customer_id: string; customer_name: string | null };
- type TicketLookupState = "loading" | "ready" | "error";
- function TicketCreateDialog({ onClose, onCreated }: { onClose: () => void; onCreated: (message: string) => void }) {
- const id = useId();
- const customerTrigger = useRef<HTMLButtonElement>(null);
- const searchInput = useRef<HTMLInputElement>(null);
- const customerList = useRef<HTMLUListElement>(null);
- const submit = useSubmit();
- const [ticketType, setTicketType] = useState<(typeof CREATABLE)[number]["code"]>("fault");
- const [keyword, setKeyword] = useState("");
- const [customer, setCustomer] = useState<TicketCustomer | null>(null);
- const [orderId, setOrderId] = useState("");
- const [title, setTitle] = useState("");
- const [detail, setDetail] = useState("");
- const [customers, setCustomers] = useState<TicketCustomer[]>([]);
- const [customerLookup, setCustomerLookup] = useState<TicketLookupState>("loading");
- const [customerOpen, setCustomerOpen] = useState(false);
- const [activeCustomer, setActiveCustomer] = useState(0);
- const [subscriptions, setSubscriptions] = useState<{ value: string; label: string }[]>([]);
- const [subscriptionLookup, setSubscriptionLookup] = useState<TicketLookupState>("loading");
- const [invalid, setInvalid] = useState<"customer" | "title" | null>(null);
- const customerId = customer?.customer_id ?? "";
- const customerPopupId = `${id}-customer-picker`;
- const customerOptionListId = `${id}-customer-options`;
- const customerHints = { loading: "正在查找客户…", error: "客户读取失败,请重新搜索", ready: "没有找到客户" };
- const subscriptionHints = { loading: "正在读取订阅…", error: "订阅读取失败", ready: subscriptions.length ? "不关联订阅" : "该客户暂无订阅" };
- const subscriptionPlaceholder = customerId ? subscriptionHints[subscriptionLookup] : "请先选择归属客户";
- const selectedSubscription = subscriptions.find((item) => item.value === orderId);
- function pickCustomer(next: TicketCustomer | null) {
- closeCustomerPicker();
- if (next?.customer_id === customer?.customer_id) return;
- setCustomer(next);
- setOrderId("");
- setSubscriptions([]);
- setSubscriptionLookup("loading");
- if (invalid === "customer") setInvalid(null);
- }
- function searchCustomers(value: string) {
- setActiveCustomer(0);
- if (value === keyword) return;
- setKeyword(value);
- setCustomers([]);
- setCustomerLookup("loading");
- }
- function openCustomerPicker() {
- searchCustomers("");
- setCustomerOpen(true);
- }
- function closeCustomerPicker() {
- setCustomerOpen(false);
- customerTrigger.current?.focus({ preventScroll: true });
- }
- function handleCustomerKeys(event: KeyboardEvent<HTMLInputElement>) {
- if (isImeComposing(event)) return;
- if (event.key === "ArrowDown" || event.key === "ArrowUp") {
- event.preventDefault();
- if (!customers.length) return;
- const step = event.key === "ArrowDown" ? 1 : -1;
- const next = (activeCustomer + step + customers.length) % customers.length;
- setActiveCustomer(next);
- customerList.current?.children[next]?.scrollIntoView({ block: "nearest" });
- } else if (event.key === "Enter") {
- event.preventDefault();
- const next = customers[activeCustomer];
- if (next) pickCustomer(next);
- }
- }
- useEffect(() => { customerTrigger.current?.focus({ preventScroll: true }); }, []);
- useEffect(() => { if (customerOpen) searchInput.current?.focus({ preventScroll: true }); }, [customerOpen]);
- 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) return;
- setCustomers(rowsOf(r));
- setCustomerLookup("ready");
- } catch {
- if (!alive) return;
- setCustomers([]);
- setCustomerLookup("error");
- }
- }, 300);
- return () => { alive = false; window.clearTimeout(timer); };
- }, [keyword]);
- useEffect(() => {
- if (!customerId) return;
- let alive = true;
- fetchAllPages((page, page_size) => orderGetList({ customer_id: customerId, page, page_size }), { pageSize: LIST_PAGE_SIZE })
- .then((r) => {
- if (!alive) return;
- setSubscriptions(r.items.map((item) => ({
- value: item.subscription_id,
- label: [item.plan_name ?? item.subscription_id, item.contract_no].filter(Boolean).join(" · "),
- })));
- setSubscriptionLookup("ready");
- })
- .catch(() => { if (alive) setSubscriptionLookup("error"); });
- return () => { alive = false; };
- }, [customerId]);
- async function submitForm(event: FormEvent<HTMLFormElement>) {
- event.preventDefault();
- if (submit.busy) return;
- submit.clear();
- if (!customerId) {
- setInvalid("customer");
- customerTrigger.current?.focus();
- return;
- }
- if (title.trim().length < 2) { setInvalid("title"); return; }
- setInvalid(null);
- 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} 已创建。`)));
- }
- const failure = submit.error ? classifyTicketError(submit.error) : null;
- const error = invalid === "customer" ? "请选择归属客户。" : invalid === "title" ? "事项标题至少填写 2 个字。" : failure?.message;
- return <OpsDialog title="代客建单" className="ticket-create-dialog" onClose={onClose}>
- <form onSubmit={submitForm} aria-busy={submit.busy}>
- <div className="ticket-create-body">
- <section className="ticket-create-section" aria-label="客户与订阅">
- <div className="ticket-create-customer-fields">
- <div className="ticket-create-field" onBlur={(event) => {
- if (!event.currentTarget.contains(event.relatedTarget)) setCustomerOpen(false);
- }}>
- <span id={`${id}-customer-label`} className="field-label-title">归属客户<em aria-hidden="true">*</em></span>
- <div className="ticket-create-picker">
- <button type="button" ref={customerTrigger} className="ticket-create-select" data-placeholder={!customerId || undefined}
- aria-labelledby={`${id}-customer-label ${id}-customer-value`} aria-haspopup="dialog" aria-expanded={customerOpen}
- aria-controls={customerOpen ? customerPopupId : undefined} aria-invalid={invalid === "customer" || undefined}
- aria-describedby={invalid === "customer" ? `${id}-error` : undefined} title={customer?.customer_name || customerId || undefined}
- onClick={() => { if (customerOpen) closeCustomerPicker(); else openCustomerPicker(); }}
- onKeyDown={(event) => {
- if (event.key !== "ArrowDown" && event.key !== "ArrowUp") return;
- event.preventDefault();
- openCustomerPicker();
- }}>
- <span className="ticket-create-select-value" id={`${id}-customer-value`}>{customer?.customer_name || customerId || "请选择客户"}</span>
- </button>
- {customerOpen && <div id={customerPopupId} className="ticket-create-customer-popup" role="dialog" aria-label="选择归属客户"
- onKeyDown={(event) => {
- if (event.key !== "Escape" || isImeComposing(event)) return;
- event.preventDefault();
- event.stopPropagation();
- closeCustomerPicker();
- }}>
- <div className="ticket-create-search">
- <Search size={15} aria-hidden="true" />
- <Input ref={searchInput} role="combobox" aria-label="搜索客户" aria-autocomplete="list" aria-expanded="true" aria-controls={customerOptionListId}
- aria-activedescendant={customers[activeCustomer] ? `${customerOptionListId}-${activeCustomer}` : undefined}
- autoComplete="off" maxLength={50} placeholder="输入客户名称或编号" value={keyword}
- onChange={(event) => searchCustomers(event.target.value)} onKeyDown={handleCustomerKeys} />
- </div>
- <div className="ticket-create-customer-results">
- <ul ref={customerList} id={customerOptionListId} role="listbox" aria-label="客户搜索结果">
- {customers.map((item, index) => <li key={item.customer_id} id={`${customerOptionListId}-${index}`} role="option"
- aria-selected={index === activeCustomer} onMouseEnter={() => setActiveCustomer(index)}
- onMouseDown={(event) => event.preventDefault()} onClick={() => pickCustomer(item)}>
- <span>{item.customer_name || item.customer_id}</span>
- {item.customer_name && <small>{item.customer_id}</small>}
- </li>)}
- </ul>
- {!customers.length && <p role="status">{customerHints[customerLookup]}</p>}
- </div>
- {customer && <button type="button" className="ticket-create-search-clear" onClick={() => pickCustomer(null)}>清除选择</button>}
- </div>}
- </div>
- </div>
- <FieldLabel className="ticket-create-field" label="关联订阅">
- <span className="ticket-create-select" data-placeholder={!selectedSubscription || undefined} title={selectedSubscription?.label}>
- <span className="ticket-create-select-value" aria-hidden="true">{selectedSubscription?.label ?? subscriptionPlaceholder}</span>
- <select value={orderId} disabled={!customerId || subscriptionLookup !== "ready" || subscriptions.length === 0}
- onChange={(event) => setOrderId(event.target.value)}>
- <option value="">{subscriptionPlaceholder}</option>
- {subscriptions.map((item) => <option key={item.value} value={item.value}>{item.label}</option>)}
- </select>
- </span>
- </FieldLabel>
- </div>
- </section>
- <section className="ticket-create-section" aria-label="工单信息">
- <div className="ticket-create-information-fields">
- <fieldset className="ticket-create-field">
- <legend>工单类型</legend>
- <div className="ticket-create-types">
- {CREATABLE.map(({ code, label, Icon }) => <label key={code}>
- <input type="radio" className="sr-only" name="ticketType" value={code} checked={ticketType === code} onChange={() => setTicketType(code)} />
- <span><Icon size={16} aria-hidden="true" />{label}</span>
- </label>)}
- </div>
- </fieldset>
- <FieldLabel className="ticket-create-field" label="事项标题" required>
- <Input required maxLength={100} placeholder="用一句话概括客户诉求" value={title}
- aria-invalid={invalid === "title" || undefined} aria-describedby={invalid === "title" ? `${id}-error` : undefined}
- onChange={(event) => { setTitle(event.target.value); if (invalid === "title") setInvalid(null); }} />
- </FieldLabel>
- <FieldLabel className="ticket-create-field" label="详细描述">
- <textarea className="ticket-create-control" maxLength={1000} rows={4} placeholder="补充问题现象、影响范围或期望完成时间"
- value={detail} onChange={(event) => setDetail(event.target.value)} />
- </FieldLabel>
- </div>
- </section>
- </div>
- <footer>
- {error && <p className="ops-form-error" id={`${id}-error`} role="alert">{error}</p>}
- <div className="ticket-create-actions">
- <Button variant="outline" type="button" onClick={onClose}>取消</Button>
- <Button type="submit" disabled={submit.busy}>{submit.busy ? "正在创建…" : "创建工单"}</Button>
- </div>
- </footer>
- </form>
- </OpsDialog>;
- }
- /** 逗号分隔的多值参数(`type`/`status` 支持多选;Tab 与下拉框都写这一份)。 */
- function multiOf(params: URLSearchParams, key: string): string[] {
- return (params.get(key) ?? "").split(",").map((v) => v.trim()).filter(Boolean);
- }
- /** 全部工单台账(真接口:`/ticket/list@v1` 服务端分页+`/ticket/todo_counts@v1`)。 */
- export function WorkOrderLedgerPage() {
- const identity = useDemoIdentity();
- /**
- * 客户角色(enterprise/sub)在**路由层**就被 `/workspace/progress` 接走(`app/App.tsx`
- * 的 `CustomerTicketListOnly`):客户的工单列表只有一张,⛔ 在运营台账上再裁一份。
- * 下面的分支是第二道防线(旧深链/守卫被绕过时不把责任人、团队、下一步、待办计数摊给客户)。
- */
- const clientView = identity?.role === "enterprise" || identity?.role === "sub";
- const [params, setParams] = useSearchParams();
- const location = useLocation();
- const navigate = useNavigate();
- const [editorOpen, setEditorOpen] = useState(false);
- const editorTrigger = useRef<HTMLButtonElement>(null);
- const [notice, setNotice] = useState("");
- function closeEditor() {
- setEditorOpen(false);
- window.requestAnimationFrame(() => editorTrigger.current?.focus({ preventScroll: true }));
- }
- const query = params.get("q") ?? "";
- const types = multiOf(params, "type");
- const statuses = multiOf(params, "status");
- const from = params.get("from") ?? "";
- const to = params.get("to") ?? "";
- const [startDate, endDate] = from && to && from > to ? [to, from] : [from, to];
- const page = Math.max(1, Number(params.get("page")) || 1);
- const list = useTicketList(
- {
- keyword: query.trim() || undefined,
- ticket_types: types.length ? types : undefined,
- statuses: statuses.length ? statuses : undefined,
- date_from: startDate || undefined,
- date_to: endDate || undefined,
- },
- page,
- );
- /**
- * Wave F:主列表先占 UDS;待办计数/状态 Tab 角标 idle 后再拉(改前=进页并行
- * list+todo_counts+5×status count,争用把单次 list 顶到数百 ms)。
- * 客户角色不发 todo_counts(服务端 60058)。
- */
- const [deferSecondary, setDeferSecondary] = useState(false);
- useEffect(() => {
- const win = window as Window & { requestIdleCallback?: (cb: () => void, opts?: { timeout: number }) => number; cancelIdleCallback?: (id: number) => void };
- if (typeof win.requestIdleCallback === "function") {
- const id = win.requestIdleCallback(() => setDeferSecondary(true), { timeout: 800 });
- return () => win.cancelIdleCallback?.(id);
- }
- const t = window.setTimeout(() => setDeferSecondary(true), 0);
- return () => window.clearTimeout(t);
- }, []);
- const counts = useTodoCounts(!clientView && deferSecondary);
- const statusCounts = useTicketStatusCounts(deferSecondary && !clientView ? TAB_ORDER : []);
- const reloadAll = () => { list.reload(); counts.reload(); statusCounts.reload(); };
- useEffect(() => {
- const ticket = params.get("ticket");
- if (!ticket) return;
- const returnQuery = new URLSearchParams(params);
- returnQuery.delete("ticket");
- const search = returnQuery.size ? `?${returnQuery}` : "";
- navigate(`/work-orders/${encodeURIComponent(ticket)}`, {
- replace: true,
- state: detailLinkState(location.pathname + search + location.hash, location.state),
- });
- }, [navigate, params, location.pathname, location.hash, location.state]);
- /** 更新多值筛选并回到第 1 页。 */
- function setMulti(key: string, values: string[]) {
- const next = new URLSearchParams(params);
- next.delete(key);
- if (values.length) next.set(key, values.join(","));
- next.delete("page");
- setParams(next);
- }
- function patchParams(key: string, values: string[]) {
- const next = new URLSearchParams(params);
- next.delete(key);
- values.forEach((value) => { if (value) next.append(key, value); });
- if (key !== "page") next.delete("page");
- setParams(next);
- }
- const rows = list.data?.rows ?? [];
- const total = list.data?.total ?? 0;
- const pages = Math.max(1, Math.ceil(total / TICKET_PAGE_SIZE));
- const currentPage = Math.min(page, pages);
- const fail = list.error ? classifyTicketError(list.error) : null;
- const summary = counts.error ? null : counts.data;
- const visibleCounts = statusCounts.error ? null : statusCounts.data;
- const overdue = typeof summary?.item_1_pending_exec_overdue === "number" && typeof summary.item_2_service_open_incomplete === "number"
- ? summary.item_1_pending_exec_overdue + summary.item_2_service_open_incomplete
- : undefined;
- const messagePending = summary?.item_4_message_pending;
- const activeTab = statuses.length === 1 ? statuses[0] : "";
- const filtered = Boolean(query || types.length || statuses.length || from || to);
- const numberOf = (value: number | undefined, loading: boolean) =>
- typeof value === "number" && Number.isSafeInteger(value) && value >= 0
- ? value.toLocaleString("zh-CN")
- : loading ? "…" : "—";
- const allCount = numberOf(visibleCounts?.total, statusCounts.loading);
- const listState = list.loading ? (
- <div className="order-empty" role="status">正在读取工单台账…</div>
- ) : fail ? (
- <TicketState fail={fail} onRetry={list.reload} />
- ) : !rows.length ? (
- <div className="order-empty">
- <Search size={26} aria-hidden="true" />
- <h3>{filtered ? "没有匹配的工单" : "暂无工单"}</h3>
- {filtered && <Button variant="ghost" size="sm" onClick={() => setParams(new URLSearchParams())}>重置筛选</Button>}
- </div>
- ) : null;
- return <section className="order-page work-order-ledger page-fill page-fill-window">
- <header className="order-heading">
- <div><h1>{clientView ? "工单进度" : "全部工单"}</h1><PageIntro>{clientView ? "跟进已提交的服务申请或故障报修,了解处理到了哪一步。" : "查询工单进度、责任团队和处理期限,从列表进入下一步办理。"}</PageIntro></div>
- {!clientView && <Button ref={editorTrigger} onClick={() => setEditorOpen(true)}><Plus size={17} />代客建单</Button>}
- </header>
- {!clientView && <div className="work-order-ledger-summary" role="group" aria-label="当前账号可见范围内的工单统计">
- <div className="work-order-metric work-order-metric-total">
- <span className="work-order-metric-icon"><ClipboardList size={19} aria-hidden="true" /></span>
- <span className="work-order-metric-body"><span>工单总量</span><strong>{allCount}</strong><small>当前账号可见范围</small></span>
- </div>
- <Link className="work-order-metric" to="/work-orders/overview" data-tone={overdue ? "warning" : undefined}>
- <span className="work-order-metric-icon"><Clock3 size={18} aria-hidden="true" /></span>
- <span className="work-order-metric-body"><span>超期未完成</span><strong>{numberOf(overdue, counts.loading)}</strong><small>开停未回填及超期开通单</small></span>
- <ArrowRight className="work-order-metric-arrow" size={14} aria-hidden="true" />
- </Link>
- <button className="work-order-metric" type="button" onClick={() => setMulti("status", ["completed"])} aria-pressed={activeTab === "completed"}>
- <span className="work-order-metric-icon"><ClipboardCheck size={18} aria-hidden="true" /></span>
- <span className="work-order-metric-body"><span>待确认</span><strong>{numberOf(visibleCounts?.completed, statusCounts.loading)}</strong><small>等运营商回执或提交方确认</small></span>
- <ArrowRight className="work-order-metric-arrow" size={14} aria-hidden="true" />
- </button>
- <Link className="work-order-metric" to="/work-orders/delivery?tab=messages" data-tone={messagePending ? "danger" : undefined}>
- <span className="work-order-metric-icon"><Inbox size={18} aria-hidden="true" /></span>
- <span className="work-order-metric-body"><span>待处置报文</span><strong>{numberOf(messagePending, counts.loading)}</strong><small>未归集或待确认</small></span>
- <ArrowRight className="work-order-metric-arrow" size={14} aria-hidden="true" />
- </Link>
- </div>}
- <div className="order-list-shell list-shell-fill">
- <div className="order-tabs" role="group" aria-label="按工单状态筛选" aria-describedby={clientView ? undefined : "work-order-count-scope"}>
- {!clientView && <span id="work-order-count-scope" className="sr-only">角标为当前账号可见范围内的工单数,列表筛选结果以分页总数为准。</span>}
- <button type="button" aria-pressed={!statuses.length} className={!statuses.length ? "active" : ""} onClick={() => setMulti("status", [])}>
- 全部状态{!clientView && <span>{allCount}</span>}
- </button>
- {TAB_ORDER.map((status) => (
- <button key={status} type="button" aria-pressed={activeTab === status} className={activeTab === status ? "active" : ""} title={status === "completed" ? COMPLETED_SCOPE_HINT : undefined} onClick={() => setMulti("status", [status])}>
- {statusFilterLabel(status)}{!clientView && <span>{numberOf(visibleCounts?.[status], statusCounts.loading)}</span>}
- </button>
- ))}
- </div>
- <div className="ops-toolbar order-filters">
- <label className="ops-search order-search"><Search size={17} /><SearchInput aria-label="搜索工单" placeholder="搜索工单号、工单ID、标题或客户" value={query} onCommit={(value) => patchParams("q", [value])} />{query && <button type="button" aria-label="清空搜索" onClick={() => patchParams("q", [])}><X size={15} /></button>}</label>
- <FilterSelect icon="type" aria-label="工单类型筛选" value={types.length === 1 ? types[0] : ""} onChange={(event) => setMulti("type", event.target.value ? [...new Set([...types, event.target.value])] : [])}>
- <option value="">{types.length > 1 ? `已选 ${types.length} 个类型` : "全部类型"}</option>
- {TICKET_TYPES.map((t) => <option key={t} value={t}>{typeLabel(t)}</option>)}
- </FilterSelect>
- <FilterSelect icon="status" aria-label="工单状态筛选" value={activeTab} onChange={(event) => setMulti("status", event.target.value ? [event.target.value] : [])}>
- <option value="">{statuses.length > 1 ? `已选 ${statuses.length} 个状态` : "全部状态"}</option>
- {TICKET_STATUSES.map((s) => <option key={s} value={s} title={s === "completed" ? COMPLETED_SCOPE_HINT : undefined}>{statusFilterLabel(s)}</option>)}
- </FilterSelect>
- <DateRangeFilter label="创建时间" from={from} to={to} onChange={(key, value) => patchParams(key, [value])} />
- {filtered && <Button variant="ghost" size="sm" onClick={() => setParams(new URLSearchParams())}>重置筛选</Button>}
- </div>
- {/* 多值时下拉框只能显示"已选 N 个",被选中的到底是哪几个必须逐项可见、可单独摘掉。 */}
- {(types.length > 1 || statuses.length > 1) && <div className="work-order-view-chips" aria-label="当前筛选视图">
- <span>当前视图</span>
- {types.map((t) => <button key={`t-${t}`} type="button" onClick={() => setMulti("type", types.filter((v) => v !== t))}>{typeLabel(t)}<X size={13} /></button>)}
- {statuses.map((s) => <button key={`s-${s}`} type="button" onClick={() => setMulti("status", statuses.filter((v) => v !== s))}>{statusFilterLabel(s)}<X size={13} /></button>)}
- <button type="button" className="is-clear" onClick={() => { const next = new URLSearchParams(); setParams(next); }}>清除全部</button>
- </div>}
- <WorkOrderLedgerList rows={rows} label="工单列表" fallback={listState} clientView={clientView} />
- {!list.loading && !fail && <ListPager total={total} page={currentPage - 1} pageSize={TICKET_PAGE_SIZE} unit="张" onPageChange={(next) => patchParams("page", [String(next + 1)])} />}
- </div>
- {notice && <OpsNotice message={notice} onClose={() => setNotice("")} />}
- {editorOpen && <TicketCreateDialog onClose={closeEditor} onCreated={(message) => { closeEditor(); setNotice(message); reloadAll(); }} />}
- </section>;
- }
|