WorkOrderManagementPage.tsx 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. import { detailLinkState } from "../lib/detail-navigation";
  2. import { isImeComposing } from "../lib/ime";
  3. import { PageIntro } from "../components/PageIntro";
  4. import { OpsDialog, OpsNotice } from "../components/OperationsKit";
  5. import { FilterSelect } from "../components/ui/filter-select";
  6. import { DateRangeFilter } from "../components/ui/date-range-filter";
  7. import { TicketState } from "../components/ticketState";
  8. import { WorkOrderLedgerList } from "../components/work-order/WorkOrderLedgerList";
  9. import { useEffect, useId, useRef, useState, type FormEvent, type KeyboardEvent } from "react";
  10. import {
  11. ArrowRight, ClipboardCheck, ClipboardList, Clock3, Headphones, Inbox, Plus, Search, Wrench, X,
  12. } from "lucide-react";
  13. import { Button } from "../components/ui/button";
  14. import { Input } from "../components/ui/input";
  15. import { SearchInput } from "../components/ui/search-input";
  16. import { FieldLabel } from "../components/ui/field-label";
  17. import { Link, useLocation, useNavigate, useSearchParams } from "react-router";
  18. import { customerGetList, orderGetList, rowsOf } from "../lib/api/bos";
  19. import {
  20. ticketCreate,
  21. TICKET_STATUSES, TICKET_TYPES, typeLabel, statusFilterLabel,
  22. } from "../lib/api/ticket";
  23. import { classifyTicketError, TICKET_PAGE_SIZE, useTicketList, useTodoCounts } from "../lib/ticket";
  24. import { useTicketStatusCounts } from "../lib/work-order-counts";
  25. import { useSubmit } from "../lib/useLoad";
  26. import { fetchAllPages } from "../lib/fetch-all-pages";
  27. import { LIST_PAGE_SIZE } from "../lib/list-paging";
  28. import { useDemoIdentity } from "../lib/demo-session";
  29. import { ListPager } from "../components/ListPager";
  30. import "../styles/operations.css";
  31. import "../styles/orders.css";
  32. import "../styles/work-orders.css";
  33. import "../styles/work-order-ledger.css";
  34. /** 状态页签按处理阶段排列,终态放最后。 */
  35. const TAB_ORDER = ["unassigned", "pending", "processing", "completed", "rejected", "settled", "terminated"] as const;
  36. /**
  37. * `completed` 在跨类型视图(状态 Tab/筛选器/当前视图 chip)里只写短名「待确认」
  38. * (业主 2026-11-18 二次定案:两半全名拼起来撑破 Tab 行):两类行内叫法
  39. * 「已完成待确认」(主线,等运营商回执)/「已处理待确认」(故障、售后,等提交方确认)
  40. * 留在徽标与这行悬停说明里,⛔ 在筛选维度上只写其中一半。
  41. */
  42. const COMPLETED_SCOPE_HINT = "同一状态码 completed,两类都不是终态:主线=已完成待确认(等运营商回执);故障/售后=已处理待确认(等提交方确认)";
  43. /**
  44. * 代客建单(`/ticket/create@v1`)。
  45. *
  46. * 客户与订阅都从真接口选(⛔ 手输 ID:建单口的 `customer_id` 要过可见性判定,
  47. * 手输别人的客户只会拿到 `11104`)。建单口只收故障/售后两类(create.rs `CREATE_TYPES`),
  48. * 开户/到期停机/服务开通由对应业务动作生成,在此提交会被服务端拒。
  49. */
  50. const CREATABLE = [
  51. { code: "fault", label: "故障报修", Icon: Wrench },
  52. { code: "after_sale", label: "售后服务", Icon: Headphones },
  53. ] as const;
  54. type TicketCustomer = { customer_id: string; customer_name: string | null };
  55. type TicketLookupState = "loading" | "ready" | "error";
  56. function TicketCreateDialog({ onClose, onCreated }: { onClose: () => void; onCreated: (message: string) => void }) {
  57. const id = useId();
  58. const customerTrigger = useRef<HTMLButtonElement>(null);
  59. const searchInput = useRef<HTMLInputElement>(null);
  60. const customerList = useRef<HTMLUListElement>(null);
  61. const submit = useSubmit();
  62. const [ticketType, setTicketType] = useState<(typeof CREATABLE)[number]["code"]>("fault");
  63. const [keyword, setKeyword] = useState("");
  64. const [customer, setCustomer] = useState<TicketCustomer | null>(null);
  65. const [orderId, setOrderId] = useState("");
  66. const [title, setTitle] = useState("");
  67. const [detail, setDetail] = useState("");
  68. const [customers, setCustomers] = useState<TicketCustomer[]>([]);
  69. const [customerLookup, setCustomerLookup] = useState<TicketLookupState>("loading");
  70. const [customerOpen, setCustomerOpen] = useState(false);
  71. const [activeCustomer, setActiveCustomer] = useState(0);
  72. const [subscriptions, setSubscriptions] = useState<{ value: string; label: string }[]>([]);
  73. const [subscriptionLookup, setSubscriptionLookup] = useState<TicketLookupState>("loading");
  74. const [invalid, setInvalid] = useState<"customer" | "title" | null>(null);
  75. const customerId = customer?.customer_id ?? "";
  76. const customerPopupId = `${id}-customer-picker`;
  77. const customerOptionListId = `${id}-customer-options`;
  78. const customerHints = { loading: "正在查找客户…", error: "客户读取失败,请重新搜索", ready: "没有找到客户" };
  79. const subscriptionHints = { loading: "正在读取订阅…", error: "订阅读取失败", ready: subscriptions.length ? "不关联订阅" : "该客户暂无订阅" };
  80. const subscriptionPlaceholder = customerId ? subscriptionHints[subscriptionLookup] : "请先选择归属客户";
  81. const selectedSubscription = subscriptions.find((item) => item.value === orderId);
  82. function pickCustomer(next: TicketCustomer | null) {
  83. closeCustomerPicker();
  84. if (next?.customer_id === customer?.customer_id) return;
  85. setCustomer(next);
  86. setOrderId("");
  87. setSubscriptions([]);
  88. setSubscriptionLookup("loading");
  89. if (invalid === "customer") setInvalid(null);
  90. }
  91. function searchCustomers(value: string) {
  92. setActiveCustomer(0);
  93. if (value === keyword) return;
  94. setKeyword(value);
  95. setCustomers([]);
  96. setCustomerLookup("loading");
  97. }
  98. function openCustomerPicker() {
  99. searchCustomers("");
  100. setCustomerOpen(true);
  101. }
  102. function closeCustomerPicker() {
  103. setCustomerOpen(false);
  104. customerTrigger.current?.focus({ preventScroll: true });
  105. }
  106. function handleCustomerKeys(event: KeyboardEvent<HTMLInputElement>) {
  107. if (isImeComposing(event)) return;
  108. if (event.key === "ArrowDown" || event.key === "ArrowUp") {
  109. event.preventDefault();
  110. if (!customers.length) return;
  111. const step = event.key === "ArrowDown" ? 1 : -1;
  112. const next = (activeCustomer + step + customers.length) % customers.length;
  113. setActiveCustomer(next);
  114. customerList.current?.children[next]?.scrollIntoView({ block: "nearest" });
  115. } else if (event.key === "Enter") {
  116. event.preventDefault();
  117. const next = customers[activeCustomer];
  118. if (next) pickCustomer(next);
  119. }
  120. }
  121. useEffect(() => { customerTrigger.current?.focus({ preventScroll: true }); }, []);
  122. useEffect(() => { if (customerOpen) searchInput.current?.focus({ preventScroll: true }); }, [customerOpen]);
  123. useEffect(() => {
  124. let alive = true;
  125. const timer = window.setTimeout(async () => {
  126. try {
  127. const r = await customerGetList({ page: 0, page_size: 20, keyword: keyword.trim() || undefined });
  128. if (!alive) return;
  129. setCustomers(rowsOf(r));
  130. setCustomerLookup("ready");
  131. } catch {
  132. if (!alive) return;
  133. setCustomers([]);
  134. setCustomerLookup("error");
  135. }
  136. }, 300);
  137. return () => { alive = false; window.clearTimeout(timer); };
  138. }, [keyword]);
  139. useEffect(() => {
  140. if (!customerId) return;
  141. let alive = true;
  142. fetchAllPages((page, page_size) => orderGetList({ customer_id: customerId, page, page_size }), { pageSize: LIST_PAGE_SIZE })
  143. .then((r) => {
  144. if (!alive) return;
  145. setSubscriptions(r.items.map((item) => ({
  146. value: item.subscription_id,
  147. label: [item.plan_name ?? item.subscription_id, item.contract_no].filter(Boolean).join(" · "),
  148. })));
  149. setSubscriptionLookup("ready");
  150. })
  151. .catch(() => { if (alive) setSubscriptionLookup("error"); });
  152. return () => { alive = false; };
  153. }, [customerId]);
  154. async function submitForm(event: FormEvent<HTMLFormElement>) {
  155. event.preventDefault();
  156. if (submit.busy) return;
  157. submit.clear();
  158. if (!customerId) {
  159. setInvalid("customer");
  160. customerTrigger.current?.focus();
  161. return;
  162. }
  163. if (title.trim().length < 2) { setInvalid("title"); return; }
  164. setInvalid(null);
  165. await submit.run(() => ticketCreate({
  166. ticket_type: ticketType,
  167. customer_id: customerId,
  168. title: title.trim(),
  169. detail: detail.trim() || undefined,
  170. subscription_id: orderId || undefined,
  171. }).then((r) => onCreated(`工单 ${r.ticket_no} 已创建。`)));
  172. }
  173. const failure = submit.error ? classifyTicketError(submit.error) : null;
  174. const error = invalid === "customer" ? "请选择归属客户。" : invalid === "title" ? "事项标题至少填写 2 个字。" : failure?.message;
  175. return <OpsDialog title="代客建单" className="ticket-create-dialog" onClose={onClose}>
  176. <form onSubmit={submitForm} aria-busy={submit.busy}>
  177. <div className="ticket-create-body">
  178. <section className="ticket-create-section" aria-label="客户与订阅">
  179. <div className="ticket-create-customer-fields">
  180. <div className="ticket-create-field" onBlur={(event) => {
  181. if (!event.currentTarget.contains(event.relatedTarget)) setCustomerOpen(false);
  182. }}>
  183. <span id={`${id}-customer-label`} className="field-label-title">归属客户<em aria-hidden="true">*</em></span>
  184. <div className="ticket-create-picker">
  185. <button type="button" ref={customerTrigger} className="ticket-create-select" data-placeholder={!customerId || undefined}
  186. aria-labelledby={`${id}-customer-label ${id}-customer-value`} aria-haspopup="dialog" aria-expanded={customerOpen}
  187. aria-controls={customerOpen ? customerPopupId : undefined} aria-invalid={invalid === "customer" || undefined}
  188. aria-describedby={invalid === "customer" ? `${id}-error` : undefined} title={customer?.customer_name || customerId || undefined}
  189. onClick={() => { if (customerOpen) closeCustomerPicker(); else openCustomerPicker(); }}
  190. onKeyDown={(event) => {
  191. if (event.key !== "ArrowDown" && event.key !== "ArrowUp") return;
  192. event.preventDefault();
  193. openCustomerPicker();
  194. }}>
  195. <span className="ticket-create-select-value" id={`${id}-customer-value`}>{customer?.customer_name || customerId || "请选择客户"}</span>
  196. </button>
  197. {customerOpen && <div id={customerPopupId} className="ticket-create-customer-popup" role="dialog" aria-label="选择归属客户"
  198. onKeyDown={(event) => {
  199. if (event.key !== "Escape" || isImeComposing(event)) return;
  200. event.preventDefault();
  201. event.stopPropagation();
  202. closeCustomerPicker();
  203. }}>
  204. <div className="ticket-create-search">
  205. <Search size={15} aria-hidden="true" />
  206. <Input ref={searchInput} role="combobox" aria-label="搜索客户" aria-autocomplete="list" aria-expanded="true" aria-controls={customerOptionListId}
  207. aria-activedescendant={customers[activeCustomer] ? `${customerOptionListId}-${activeCustomer}` : undefined}
  208. autoComplete="off" maxLength={50} placeholder="输入客户名称或编号" value={keyword}
  209. onChange={(event) => searchCustomers(event.target.value)} onKeyDown={handleCustomerKeys} />
  210. </div>
  211. <div className="ticket-create-customer-results">
  212. <ul ref={customerList} id={customerOptionListId} role="listbox" aria-label="客户搜索结果">
  213. {customers.map((item, index) => <li key={item.customer_id} id={`${customerOptionListId}-${index}`} role="option"
  214. aria-selected={index === activeCustomer} onMouseEnter={() => setActiveCustomer(index)}
  215. onMouseDown={(event) => event.preventDefault()} onClick={() => pickCustomer(item)}>
  216. <span>{item.customer_name || item.customer_id}</span>
  217. {item.customer_name && <small>{item.customer_id}</small>}
  218. </li>)}
  219. </ul>
  220. {!customers.length && <p role="status">{customerHints[customerLookup]}</p>}
  221. </div>
  222. {customer && <button type="button" className="ticket-create-search-clear" onClick={() => pickCustomer(null)}>清除选择</button>}
  223. </div>}
  224. </div>
  225. </div>
  226. <FieldLabel className="ticket-create-field" label="关联订阅">
  227. <span className="ticket-create-select" data-placeholder={!selectedSubscription || undefined} title={selectedSubscription?.label}>
  228. <span className="ticket-create-select-value" aria-hidden="true">{selectedSubscription?.label ?? subscriptionPlaceholder}</span>
  229. <select value={orderId} disabled={!customerId || subscriptionLookup !== "ready" || subscriptions.length === 0}
  230. onChange={(event) => setOrderId(event.target.value)}>
  231. <option value="">{subscriptionPlaceholder}</option>
  232. {subscriptions.map((item) => <option key={item.value} value={item.value}>{item.label}</option>)}
  233. </select>
  234. </span>
  235. </FieldLabel>
  236. </div>
  237. </section>
  238. <section className="ticket-create-section" aria-label="工单信息">
  239. <div className="ticket-create-information-fields">
  240. <fieldset className="ticket-create-field">
  241. <legend>工单类型</legend>
  242. <div className="ticket-create-types">
  243. {CREATABLE.map(({ code, label, Icon }) => <label key={code}>
  244. <input type="radio" className="sr-only" name="ticketType" value={code} checked={ticketType === code} onChange={() => setTicketType(code)} />
  245. <span><Icon size={16} aria-hidden="true" />{label}</span>
  246. </label>)}
  247. </div>
  248. </fieldset>
  249. <FieldLabel className="ticket-create-field" label="事项标题" required>
  250. <Input required maxLength={100} placeholder="用一句话概括客户诉求" value={title}
  251. aria-invalid={invalid === "title" || undefined} aria-describedby={invalid === "title" ? `${id}-error` : undefined}
  252. onChange={(event) => { setTitle(event.target.value); if (invalid === "title") setInvalid(null); }} />
  253. </FieldLabel>
  254. <FieldLabel className="ticket-create-field" label="详细描述">
  255. <textarea className="ticket-create-control" maxLength={1000} rows={4} placeholder="补充问题现象、影响范围或期望完成时间"
  256. value={detail} onChange={(event) => setDetail(event.target.value)} />
  257. </FieldLabel>
  258. </div>
  259. </section>
  260. </div>
  261. <footer>
  262. {error && <p className="ops-form-error" id={`${id}-error`} role="alert">{error}</p>}
  263. <div className="ticket-create-actions">
  264. <Button variant="outline" type="button" onClick={onClose}>取消</Button>
  265. <Button type="submit" disabled={submit.busy}>{submit.busy ? "正在创建…" : "创建工单"}</Button>
  266. </div>
  267. </footer>
  268. </form>
  269. </OpsDialog>;
  270. }
  271. /** 逗号分隔的多值参数(`type`/`status` 支持多选;Tab 与下拉框都写这一份)。 */
  272. function multiOf(params: URLSearchParams, key: string): string[] {
  273. return (params.get(key) ?? "").split(",").map((v) => v.trim()).filter(Boolean);
  274. }
  275. /** 全部工单台账(真接口:`/ticket/list@v1` 服务端分页+`/ticket/todo_counts@v1`)。 */
  276. export function WorkOrderLedgerPage() {
  277. const identity = useDemoIdentity();
  278. /**
  279. * 客户角色(enterprise/sub)在**路由层**就被 `/workspace/progress` 接走(`app/App.tsx`
  280. * 的 `CustomerTicketListOnly`):客户的工单列表只有一张,⛔ 在运营台账上再裁一份。
  281. * 下面的分支是第二道防线(旧深链/守卫被绕过时不把责任人、团队、下一步、待办计数摊给客户)。
  282. */
  283. const clientView = identity?.role === "enterprise" || identity?.role === "sub";
  284. const [params, setParams] = useSearchParams();
  285. const location = useLocation();
  286. const navigate = useNavigate();
  287. const [editorOpen, setEditorOpen] = useState(false);
  288. const editorTrigger = useRef<HTMLButtonElement>(null);
  289. const [notice, setNotice] = useState("");
  290. function closeEditor() {
  291. setEditorOpen(false);
  292. window.requestAnimationFrame(() => editorTrigger.current?.focus({ preventScroll: true }));
  293. }
  294. const query = params.get("q") ?? "";
  295. const types = multiOf(params, "type");
  296. const statuses = multiOf(params, "status");
  297. const from = params.get("from") ?? "";
  298. const to = params.get("to") ?? "";
  299. const [startDate, endDate] = from && to && from > to ? [to, from] : [from, to];
  300. const page = Math.max(1, Number(params.get("page")) || 1);
  301. const list = useTicketList(
  302. {
  303. keyword: query.trim() || undefined,
  304. ticket_types: types.length ? types : undefined,
  305. statuses: statuses.length ? statuses : undefined,
  306. date_from: startDate || undefined,
  307. date_to: endDate || undefined,
  308. },
  309. page,
  310. );
  311. /**
  312. * Wave F:主列表先占 UDS;待办计数/状态 Tab 角标 idle 后再拉(改前=进页并行
  313. * list+todo_counts+5×status count,争用把单次 list 顶到数百 ms)。
  314. * 客户角色不发 todo_counts(服务端 60058)。
  315. */
  316. const [deferSecondary, setDeferSecondary] = useState(false);
  317. useEffect(() => {
  318. const win = window as Window & { requestIdleCallback?: (cb: () => void, opts?: { timeout: number }) => number; cancelIdleCallback?: (id: number) => void };
  319. if (typeof win.requestIdleCallback === "function") {
  320. const id = win.requestIdleCallback(() => setDeferSecondary(true), { timeout: 800 });
  321. return () => win.cancelIdleCallback?.(id);
  322. }
  323. const t = window.setTimeout(() => setDeferSecondary(true), 0);
  324. return () => window.clearTimeout(t);
  325. }, []);
  326. const counts = useTodoCounts(!clientView && deferSecondary);
  327. const statusCounts = useTicketStatusCounts(deferSecondary && !clientView ? TAB_ORDER : []);
  328. const reloadAll = () => { list.reload(); counts.reload(); statusCounts.reload(); };
  329. useEffect(() => {
  330. const ticket = params.get("ticket");
  331. if (!ticket) return;
  332. const returnQuery = new URLSearchParams(params);
  333. returnQuery.delete("ticket");
  334. const search = returnQuery.size ? `?${returnQuery}` : "";
  335. navigate(`/work-orders/${encodeURIComponent(ticket)}`, {
  336. replace: true,
  337. state: detailLinkState(location.pathname + search + location.hash, location.state),
  338. });
  339. }, [navigate, params, location.pathname, location.hash, location.state]);
  340. /** 更新多值筛选并回到第 1 页。 */
  341. function setMulti(key: string, values: string[]) {
  342. const next = new URLSearchParams(params);
  343. next.delete(key);
  344. if (values.length) next.set(key, values.join(","));
  345. next.delete("page");
  346. setParams(next);
  347. }
  348. function patchParams(key: string, values: string[]) {
  349. const next = new URLSearchParams(params);
  350. next.delete(key);
  351. values.forEach((value) => { if (value) next.append(key, value); });
  352. if (key !== "page") next.delete("page");
  353. setParams(next);
  354. }
  355. const rows = list.data?.rows ?? [];
  356. const total = list.data?.total ?? 0;
  357. const pages = Math.max(1, Math.ceil(total / TICKET_PAGE_SIZE));
  358. const currentPage = Math.min(page, pages);
  359. const fail = list.error ? classifyTicketError(list.error) : null;
  360. const summary = counts.error ? null : counts.data;
  361. const visibleCounts = statusCounts.error ? null : statusCounts.data;
  362. const overdue = typeof summary?.item_1_pending_exec_overdue === "number" && typeof summary.item_2_service_open_incomplete === "number"
  363. ? summary.item_1_pending_exec_overdue + summary.item_2_service_open_incomplete
  364. : undefined;
  365. const messagePending = summary?.item_4_message_pending;
  366. const activeTab = statuses.length === 1 ? statuses[0] : "";
  367. const filtered = Boolean(query || types.length || statuses.length || from || to);
  368. const numberOf = (value: number | undefined, loading: boolean) =>
  369. typeof value === "number" && Number.isSafeInteger(value) && value >= 0
  370. ? value.toLocaleString("zh-CN")
  371. : loading ? "…" : "—";
  372. const allCount = numberOf(visibleCounts?.total, statusCounts.loading);
  373. const listState = list.loading ? (
  374. <div className="order-empty" role="status">正在读取工单台账…</div>
  375. ) : fail ? (
  376. <TicketState fail={fail} onRetry={list.reload} />
  377. ) : !rows.length ? (
  378. <div className="order-empty">
  379. <Search size={26} aria-hidden="true" />
  380. <h3>{filtered ? "没有匹配的工单" : "暂无工单"}</h3>
  381. {filtered && <Button variant="ghost" size="sm" onClick={() => setParams(new URLSearchParams())}>重置筛选</Button>}
  382. </div>
  383. ) : null;
  384. return <section className="order-page work-order-ledger page-fill page-fill-window">
  385. <header className="order-heading">
  386. <div><h1>{clientView ? "工单进度" : "全部工单"}</h1><PageIntro>{clientView ? "跟进已提交的服务申请或故障报修,了解处理到了哪一步。" : "查询工单进度、责任团队和处理期限,从列表进入下一步办理。"}</PageIntro></div>
  387. {!clientView && <Button ref={editorTrigger} onClick={() => setEditorOpen(true)}><Plus size={17} />代客建单</Button>}
  388. </header>
  389. {!clientView && <div className="work-order-ledger-summary" role="group" aria-label="当前账号可见范围内的工单统计">
  390. <div className="work-order-metric work-order-metric-total">
  391. <span className="work-order-metric-icon"><ClipboardList size={19} aria-hidden="true" /></span>
  392. <span className="work-order-metric-body"><span>工单总量</span><strong>{allCount}</strong><small>当前账号可见范围</small></span>
  393. </div>
  394. <Link className="work-order-metric" to="/work-orders/overview" data-tone={overdue ? "warning" : undefined}>
  395. <span className="work-order-metric-icon"><Clock3 size={18} aria-hidden="true" /></span>
  396. <span className="work-order-metric-body"><span>超期未完成</span><strong>{numberOf(overdue, counts.loading)}</strong><small>开停未回填及超期开通单</small></span>
  397. <ArrowRight className="work-order-metric-arrow" size={14} aria-hidden="true" />
  398. </Link>
  399. <button className="work-order-metric" type="button" onClick={() => setMulti("status", ["completed"])} aria-pressed={activeTab === "completed"}>
  400. <span className="work-order-metric-icon"><ClipboardCheck size={18} aria-hidden="true" /></span>
  401. <span className="work-order-metric-body"><span>待确认</span><strong>{numberOf(visibleCounts?.completed, statusCounts.loading)}</strong><small>等运营商回执或提交方确认</small></span>
  402. <ArrowRight className="work-order-metric-arrow" size={14} aria-hidden="true" />
  403. </button>
  404. <Link className="work-order-metric" to="/work-orders/delivery?tab=messages" data-tone={messagePending ? "danger" : undefined}>
  405. <span className="work-order-metric-icon"><Inbox size={18} aria-hidden="true" /></span>
  406. <span className="work-order-metric-body"><span>待处置报文</span><strong>{numberOf(messagePending, counts.loading)}</strong><small>未归集或待确认</small></span>
  407. <ArrowRight className="work-order-metric-arrow" size={14} aria-hidden="true" />
  408. </Link>
  409. </div>}
  410. <div className="order-list-shell list-shell-fill">
  411. <div className="order-tabs" role="group" aria-label="按工单状态筛选" aria-describedby={clientView ? undefined : "work-order-count-scope"}>
  412. {!clientView && <span id="work-order-count-scope" className="sr-only">角标为当前账号可见范围内的工单数,列表筛选结果以分页总数为准。</span>}
  413. <button type="button" aria-pressed={!statuses.length} className={!statuses.length ? "active" : ""} onClick={() => setMulti("status", [])}>
  414. 全部状态{!clientView && <span>{allCount}</span>}
  415. </button>
  416. {TAB_ORDER.map((status) => (
  417. <button key={status} type="button" aria-pressed={activeTab === status} className={activeTab === status ? "active" : ""} title={status === "completed" ? COMPLETED_SCOPE_HINT : undefined} onClick={() => setMulti("status", [status])}>
  418. {statusFilterLabel(status)}{!clientView && <span>{numberOf(visibleCounts?.[status], statusCounts.loading)}</span>}
  419. </button>
  420. ))}
  421. </div>
  422. <div className="ops-toolbar order-filters">
  423. <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>
  424. <FilterSelect icon="type" aria-label="工单类型筛选" value={types.length === 1 ? types[0] : ""} onChange={(event) => setMulti("type", event.target.value ? [...new Set([...types, event.target.value])] : [])}>
  425. <option value="">{types.length > 1 ? `已选 ${types.length} 个类型` : "全部类型"}</option>
  426. {TICKET_TYPES.map((t) => <option key={t} value={t}>{typeLabel(t)}</option>)}
  427. </FilterSelect>
  428. <FilterSelect icon="status" aria-label="工单状态筛选" value={activeTab} onChange={(event) => setMulti("status", event.target.value ? [event.target.value] : [])}>
  429. <option value="">{statuses.length > 1 ? `已选 ${statuses.length} 个状态` : "全部状态"}</option>
  430. {TICKET_STATUSES.map((s) => <option key={s} value={s} title={s === "completed" ? COMPLETED_SCOPE_HINT : undefined}>{statusFilterLabel(s)}</option>)}
  431. </FilterSelect>
  432. <DateRangeFilter label="创建时间" from={from} to={to} onChange={(key, value) => patchParams(key, [value])} />
  433. {filtered && <Button variant="ghost" size="sm" onClick={() => setParams(new URLSearchParams())}>重置筛选</Button>}
  434. </div>
  435. {/* 多值时下拉框只能显示"已选 N 个",被选中的到底是哪几个必须逐项可见、可单独摘掉。 */}
  436. {(types.length > 1 || statuses.length > 1) && <div className="work-order-view-chips" aria-label="当前筛选视图">
  437. <span>当前视图</span>
  438. {types.map((t) => <button key={`t-${t}`} type="button" onClick={() => setMulti("type", types.filter((v) => v !== t))}>{typeLabel(t)}<X size={13} /></button>)}
  439. {statuses.map((s) => <button key={`s-${s}`} type="button" onClick={() => setMulti("status", statuses.filter((v) => v !== s))}>{statusFilterLabel(s)}<X size={13} /></button>)}
  440. <button type="button" className="is-clear" onClick={() => { const next = new URLSearchParams(); setParams(next); }}>清除全部</button>
  441. </div>}
  442. <WorkOrderLedgerList rows={rows} label="工单列表" fallback={listState} clientView={clientView} />
  443. {!list.loading && !fail && <ListPager total={total} page={currentPage - 1} pageSize={TICKET_PAGE_SIZE} unit="张" onPageChange={(next) => patchParams("page", [String(next + 1)])} />}
  444. </div>
  445. {notice && <OpsNotice message={notice} onClose={() => setNotice("")} />}
  446. {editorOpen && <TicketCreateDialog onClose={closeEditor} onCreated={(message) => { closeEditor(); setNotice(message); reloadAll(); }} />}
  447. </section>;
  448. }