|
|
@@ -1,13 +1,12 @@
|
|
|
-import { useHorizontalOverflow } from "../lib/use-horizontal-overflow";
|
|
|
import { PageIntro } from "../components/PageIntro";
|
|
|
-import { OpsNotice, OpsTableColumns } from "../components/OperationsKit";
|
|
|
+import { 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 { TicketStatusTag, TicketTypeTag } from "../components/work-order/TicketBadges";
|
|
|
+import { WorkOrderLedgerList } from "../components/work-order/WorkOrderLedgerList";
|
|
|
import { useEffect, useRef, useState, type FormEvent, type ReactNode } from "react";
|
|
|
import {
|
|
|
- Check, Clock3, Info, Plus, Search, X,
|
|
|
+ ArrowRight, Check, ClipboardCheck, ClipboardList, Clock3, Inbox, Info, Plus, Search, X,
|
|
|
} from "lucide-react";
|
|
|
import { Button } from "../components/ui/button";
|
|
|
import { Input } from "../components/ui/input";
|
|
|
@@ -19,22 +18,20 @@ import {
|
|
|
ticketCreate,
|
|
|
TICKET_STATUSES, TICKET_TYPES, typeLabel, statusFilterLabel,
|
|
|
} from "../lib/api/ticket";
|
|
|
-import { classifyTicketError, fmtTime, TICKET_PAGE_SIZE, useTicketList, useTodoCounts } from "../lib/ticket";
|
|
|
+import { classifyTicketError, 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 { ListPager } from "../components/ListPager";
|
|
|
import "../styles/operations.css";
|
|
|
+import "../styles/orders.css";
|
|
|
import "../styles/work-orders.css";
|
|
|
+import "../styles/work-order-ledger.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 行):两类行内叫法
|
|
|
@@ -149,18 +146,6 @@ function multiOf(params: URLSearchParams, key: string): string[] {
|
|
|
|
|
|
/** 全部工单台账(真接口:`/ticket/list@v1` 服务端分页+`/ticket/todo_counts@v1`)。 */
|
|
|
export function WorkOrderLedgerPage() {
|
|
|
- const tableOverflow = useHorizontalOverflow();
|
|
|
- /** 九列:序号、工单/客户、类型、状态、责任人/团队、截止、下一步、创建时间、操作。 */
|
|
|
- const minimumWidths = [56, 230, 110, 116, 150, 112, 168, 128, 84];
|
|
|
- const tableWidth = Math.max(1320, tableOverflow.width);
|
|
|
- const columnAt = (minimum: number, index: number, level: number) => [0, 1, 8].includes(index) ? minimum : Math.max(minimum, level * (index === 1 ? 1.3 : 1));
|
|
|
- let lower = 0, upper = tableWidth;
|
|
|
- for (let step = 0; step < 32; step++) {
|
|
|
- const level = (lower + upper) / 2;
|
|
|
- if (minimumWidths.reduce((total, minimum, index) => total + columnAt(minimum, index, level), 0) > tableWidth) upper = level;
|
|
|
- else lower = level;
|
|
|
- }
|
|
|
- const columnWidths = minimumWidths.map((minimum, index) => columnAt(minimum, index, lower));
|
|
|
const identity = useDemoIdentity();
|
|
|
/**
|
|
|
* 客户角色(enterprise/sub)在**路由层**就被 `/workspace/progress` 接走(`app/App.tsx`
|
|
|
@@ -208,7 +193,7 @@ export function WorkOrderLedgerPage() {
|
|
|
return () => window.clearTimeout(t);
|
|
|
}, []);
|
|
|
const counts = useTodoCounts(!clientView && deferSecondary);
|
|
|
- const statusCounts = useTicketStatusCounts(deferSecondary && !clientView ? COUNTED_STATUSES : []);
|
|
|
+ const statusCounts = useTicketStatusCounts(deferSecondary && !clientView ? TAB_ORDER : []);
|
|
|
const reloadAll = () => { list.reload(); counts.reload(); statusCounts.reload(); };
|
|
|
|
|
|
useEffect(() => {
|
|
|
@@ -216,12 +201,12 @@ export function WorkOrderLedgerPage() {
|
|
|
if (ticket) navigate(`/work-orders/${encodeURIComponent(ticket)}`, { replace: true, state: { from: location.pathname + location.search } });
|
|
|
}, [navigate, params, location.pathname]);
|
|
|
|
|
|
- /** 写多值参数:空数组=删键;`keepPage=false` 时回到第 1 页(换筛选必须回首页)。 */
|
|
|
- function setMulti(key: string, values: string[], keepPage = false) {
|
|
|
+ /** 更新多值筛选并回到第 1 页。 */
|
|
|
+ function setMulti(key: string, values: string[]) {
|
|
|
const next = new URLSearchParams(params);
|
|
|
next.delete(key);
|
|
|
if (values.length) next.set(key, values.join(","));
|
|
|
- if (!keepPage) next.delete("page");
|
|
|
+ next.delete("page");
|
|
|
setParams(next);
|
|
|
}
|
|
|
|
|
|
@@ -238,38 +223,72 @@ export function WorkOrderLedgerPage() {
|
|
|
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.data;
|
|
|
- const messagePending = summary?.item_4_message_pending ?? 0;
|
|
|
+ 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 countOf = (status: string) => statusCounts.data?.[status];
|
|
|
+ const fromList = location.pathname + location.search;
|
|
|
+ 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="work-order-page work-order-ledger-page page-fill page-fill-window">
|
|
|
- <header className="work-order-heading">
|
|
|
- <div><p className="work-order-eyebrow"><span /> SERVICE OPERATIONS / 业务执行</p><h1>{clientView ? "工单进度" : "全部工单"}</h1><PageIntro>{clientView ? "跟进已提交的服务申请或故障报修,了解处理到了哪一步。" : "从派单到完工,随时查到每张工单由谁处理、进行到了哪一步。"}</PageIntro></div>
|
|
|
+ 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 onClick={() => setEditorOpen(true)}><Plus size={17} />代客建单</Button>}
|
|
|
</header>
|
|
|
- {/* 三张卡都是入口:⛔ 只出数字不给去处。报文卡原先开弹窗,现改跳「交付与回执」的报文 Tab。 */}
|
|
|
- {/* 客户角色不渲染(口径与去处都属运营侧):见 `useTodoCounts(!clientView)` 注释。 */}
|
|
|
- {!clientView && <div className="work-order-ledger-alerts" aria-label="工单待办计数">
|
|
|
- <Link className="work-order-alert-link" to="/work-orders/overview" title="开户/到期停机/服务停用/变更协议尚未回填出开停事实,期限日已过(开通类按订阅服务开始日、次日起计;停机类按建单日+7、当天计)"><span>超期未处理完</span><strong>{summary ? summary.item_1_pending_exec_overdue : "—"}</strong><small>开停类逾期未回填 · 去总览</small></Link>
|
|
|
- <Link className="work-order-alert-link" to="/work-orders?type=service_open&status=unassigned,pending,processing" title="超期的开通单(待派单/待处理/处理中)"><span>服务开通在办</span><strong>{summary ? summary.item_2_service_open_incomplete : "—"}</strong><small>超期开通单 · 去筛选</small></Link>
|
|
|
- <Link className={`work-order-alert-link${messagePending > 0 ? " is-danger" : ""}`} to="/work-orders/delivery?tab=messages" title={messagePending > 0 ? "有未归属或待确认的运营商报文,去交付与回执处置" : "当前没有待处置报文"}><span>待处置报文</span><strong>{summary ? summary.item_4_message_pending : "—"}</strong><small>{messagePending > 0 ? "未归集或待确认 · 去处置" : "未归集或待确认"}</small></Link>
|
|
|
+ {!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="work-order-list-shell list-shell-fill">
|
|
|
- {/* 状态=横向 Tab(阶段即导航):点一下就是一次筛选,计数取服务端 total。 */}
|
|
|
- <div className="work-order-tabs" role="tablist" aria-label="按状态筛选">
|
|
|
- <button type="button" role="tab" aria-selected={!activeTab} className={!activeTab ? "active" : ""} onClick={() => setMulti("status", [])}>全部</button>
|
|
|
- {TAB_ORDER.map((status) => {
|
|
|
- const counted = (COUNTED_STATUSES as readonly string[]).includes(status);
|
|
|
- const value = counted ? countOf(status) : undefined;
|
|
|
- return <button key={status} type="button" role="tab" aria-selected={activeTab === status} className={activeTab === status ? "active" : ""} title={status === "completed" ? COMPLETED_SCOPE_HINT : undefined} onClick={() => setMulti("status", activeTab === status ? [] : [status])}>
|
|
|
- {statusFilterLabel(status)}{value !== undefined && <span>{statusCounts.loading ? "…" : value}</span>}
|
|
|
- </button>;
|
|
|
- })}
|
|
|
+ <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="work-order-ledger-filters">
|
|
|
- <label className="work-order-ledger-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>
|
|
|
+ <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>)}
|
|
|
@@ -288,37 +307,9 @@ export function WorkOrderLedgerPage() {
|
|
|
{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>}
|
|
|
- <div ref={tableOverflow.ref} className={`measured-table-scroll work-order-table-wrap ticket-ledger-scroll${tableOverflow.overflow ? " has-horizontal-overflow" : ""}${tableOverflow.width >= 640 ? " can-pin-identity" : ""}${tableOverflow.canScrollLeft ? " can-scroll-left" : ""}${tableOverflow.canScrollRight ? " can-scroll-right" : ""}`} role="region" aria-label="工单列表,可横向滚动查看字段" tabIndex={0}><table className="work-order-ledger-table ticket-ledger"><OpsTableColumns widths={columnWidths} /><thead><tr><th>序号</th><th>工单 / 客户</th><th>类型</th><th>状态</th><th>责任人 / 团队</th><th>截止</th><th>下一步</th><th>创建时间</th><th>操作</th></tr></thead><tbody>{rows.map((item, index) => {
|
|
|
- const step = nextStepOf(item);
|
|
|
- const late = item.overdue_7d;
|
|
|
- // 截止列与「我的待办」同源:有延期显示延期后的生效期限(⛔ 原始 `expected_done_date`,
|
|
|
- // 否则同一张单在两页给出两个日期,而「超期/临期」按服务端真布尔并不亮)。
|
|
|
- const due = todoRowDueOn(item);
|
|
|
- const detailHref = `/work-orders/${encodeURIComponent(item.ticket_id)}${step.action ? `?act=${step.action}` : ""}`;
|
|
|
- return <tr key={item.ticket_id} className={late ? "is-overdue" : undefined}>
|
|
|
- <td className="table-number">{item.seq_no ?? (currentPage - 1) * TICKET_PAGE_SIZE + index + 1}</td>
|
|
|
- <td><strong className="work-order-ticket-number" title={item.ticket_no ?? ""}>{item.ticket_no ?? "-"}</strong><small title={item.customer_name ?? ""}>{item.customer_name ?? "-"}</small></td>
|
|
|
- <td><TicketTypeTag type={item.ticket_type} /></td>
|
|
|
- <td><TicketStatusTag status={item.status} type={item.ticket_type} /></td>
|
|
|
- <td><strong title={item.assignee_name ?? "待分派"}>{item.assignee_name ?? "待分派"}</strong><small title={item.team_name ?? "未分派团队"}>{item.team_name ?? "未分派团队"}</small></td>
|
|
|
- <td><span className={`work-order-date${late ? " is-late" : ""}`}>{due ?? "—"}</span>{item.deferred_until && <small title={`原期限 ${item.expected_done_date?.slice(0, 10) ?? "—"}`}>已延期</small>}{late && <small className="work-order-overdue-text">超期/临期</small>}</td>
|
|
|
- <td className="work-order-next-step-cell">
|
|
|
- {step.label
|
|
|
- ? <Link className={`work-order-next-step tone-${step.tone}`} to={detailHref} state={{ from: location.pathname + location.search }}>{step.label}</Link>
|
|
|
- : <span className={`work-order-next-step is-passive tone-${step.tone}`}>—</span>}
|
|
|
- <small>{step.hint}</small>
|
|
|
- </td>
|
|
|
- <td>{fmtTime(item.created_at)}</td>
|
|
|
- <td><Link className="ops-table-action" to={`/work-orders/${encodeURIComponent(item.ticket_id)}`} state={{ from: location.pathname + location.search }}>详情</Link></td>
|
|
|
- </tr>;
|
|
|
- })}</tbody></table>
|
|
|
- {list.loading && <div className="work-order-empty"><Search size={27} /><h3>正在读取工单台账…</h3></div>}
|
|
|
- {fail && <TicketState fail={fail} onRetry={list.reload} />}
|
|
|
- {!list.loading && !fail && !rows.length && <div className="work-order-empty"><Search size={27} /><h3>{filtered ? "当前筛选没有匹配的工单" : "还没有工单"}</h3><p>{filtered ? "筛选条件可能过窄:试着只保留状态,或清空其余条件。" : "开户、服务开通、到期停机等由业务动作自动建单;故障与售后可在此代客建单。"}</p>{filtered && <Button variant="ghost" size="sm" onClick={() => setParams(new URLSearchParams())}>清除全部筛选</Button>}</div>}
|
|
|
- </div>
|
|
|
- <ServerListPager total={total} page={currentPage} pageSize={TICKET_PAGE_SIZE} unit="张" className="list-pager work-order-ledger-pager" onPageChange={(next) => patchParams("page", [String(next)])} />
|
|
|
+ <WorkOrderLedgerList rows={rows} from={fromList} 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>
|
|
|
- {summary && summary.item_1_pending_exec_overdue > 0 && <div className="work-order-reminder"><Clock3 size={19} /><div><strong>{summary.item_1_pending_exec_overdue} 件开户/停机类工单已过期限日仍未回填出开停事实</strong><p>只提醒负责团队,不自动改变账户状态或计费。</p></div></div>}
|
|
|
{notice && <OpsNotice message={notice} onClose={() => setNotice("")} />}
|
|
|
{editorOpen && <Editor onClose={() => setEditorOpen(false)} onCreated={(message) => { setEditorOpen(false); setNotice(message); reloadAll(); }} />}
|
|
|
</section>;
|