|
|
@@ -11,26 +11,33 @@
|
|
|
* ⛔ 把未上传的文件名随单提交,材料在建单后到工单详情直传(§5.8)。
|
|
|
*/
|
|
|
import { useCallback, useEffect, useRef, useState, type FormEvent } from "react";
|
|
|
-import { ArrowRight, Check, CircleAlert, ClipboardList, Clock3, FileText, Info, RefreshCw, Search, Send, X } from "lucide-react";
|
|
|
+import { ArrowRight, Check, CircleAlert, ClipboardCheck, ClipboardList, Clock3, FileText, Info, RefreshCw, Search, Send, X } from "lucide-react";
|
|
|
import { Link, useLocation, useSearchParams } from "react-router";
|
|
|
import { Button } from "../components/ui/button";
|
|
|
import { SearchInput } from "../components/ui/search-input";
|
|
|
import { FilterSelect } from "../components/ui/filter-select";
|
|
|
+import { DateRangeFilter } from "../components/ui/date-range-filter";
|
|
|
import { FieldHint } from "../components/ui/field-hint";
|
|
|
import { ServerListPager } from "../components/ListPager";
|
|
|
import { TicketState } from "../components/ticketState";
|
|
|
+import { TicketStatusTag, TicketTypeTag } from "../components/work-order/TicketBadges";
|
|
|
+import { PageIntro } from "../components/PageIntro";
|
|
|
import { WorkspaceEmpty, WorkspaceHeading, WorkspacePanel } from "../components/RoleWorkspaceKit";
|
|
|
-import { OpsNotice } from "../components/OperationsKit";
|
|
|
+import { OpsNotice, OpsTableColumns } from "../components/OperationsKit";
|
|
|
import { useDemoIdentity } from "../lib/demo-session";
|
|
|
import { readCustomers } from "../lib/customer-records";
|
|
|
import { detailLinkState } from "../lib/detail-navigation";
|
|
|
import { classifyTicketError, fmtTime, TICKET_PAGE_SIZE, useTicketDetail, useTicketList } from "../lib/ticket";
|
|
|
-import { ticketCreate, TICKET_STATUSES, statusLabel, nonMainlineStatusLabel, typeLabel, ticketConfirmClose, ticketWithdraw } from "../lib/api/ticket";
|
|
|
+import { ticketCreate, TICKET_STATUSES, TICKET_TYPES, statusLabel, nonMainlineStatusLabel, typeLabel, ticketConfirmClose, ticketWithdraw } from "../lib/api/ticket";
|
|
|
import type { TicketListItem } from "../lib/api/ticket";
|
|
|
import { useSubmit } from "../lib/useLoad";
|
|
|
import { customerLiveTicketActions } from "../lib/customer-workspace";
|
|
|
+import { useHorizontalOverflow } from "../lib/use-horizontal-overflow";
|
|
|
+import { useTicketStatusCounts } from "../lib/work-order-counts";
|
|
|
import "../styles/operations.css";
|
|
|
+import "../styles/orders.css";
|
|
|
import "../styles/work-orders.css";
|
|
|
+import "../styles/work-order-ledger.css";
|
|
|
|
|
|
export function CustomerSubmitPage() {
|
|
|
const location = useLocation();
|
|
|
@@ -110,14 +117,18 @@ export function CustomerSubmitPage() {
|
|
|
* 也没有「确认完成,关闭工单」和「撤回」的任何入口⇒ 手册要求的客户侧闭环断在这一步。
|
|
|
* 这里⛔ 复用运营台账页(那会把客户/团队/责任人这些客户不该关心的口径一起摊开,
|
|
|
* 也⛔ 复制一份 900 行台账),只走真实接口:
|
|
|
- * - 行集=`POST /ticket/list@v1`(`read.rs` 对该口⛔ 角色闸门,只按数据范围把行收到
|
|
|
- * 本客户名下),单次服务端分页查询,⛔ 前端拼接多次请求补齐(契约 14.3);
|
|
|
+ * - 行集与状态统计=`POST /ticket/list@v1`,服务端按会话控制可见范围。
|
|
|
* - 操作=`POST /ticket/confirm_close@v1`/`POST /ticket/withdraw@v1`(`finalize.rs`)。
|
|
|
* ⛔ 调 `/ticket/confirm_done@v1`:后端没有这条路由,网关按「未声明即拒绝」拦(C-5)。
|
|
|
* ⛔ 把本件的按钮判定当权限边界:闸门在 `finalize.rs`,这里只是⛔ 给客户无效点击。
|
|
|
*/
|
|
|
export function CustomerTicketProgressPage() {
|
|
|
const identity = useDemoIdentity();
|
|
|
+ if (identity?.role !== "enterprise" && identity?.role !== "sub") return <WorkspaceEmpty title="请切换到客户账号" description="工单进度面向企业客户与子账号;运维请到「工单管理」。" />;
|
|
|
+ return <CustomerTicketProgressLedger key={identity.customerNo} />;
|
|
|
+}
|
|
|
+
|
|
|
+function CustomerTicketProgressLedger() {
|
|
|
/**
|
|
|
* 筛选与页码落在 URL 上(`?q=&status=&page=`),⛔ 只放组件内 state。
|
|
|
*
|
|
|
@@ -129,6 +140,9 @@ export function CustomerTicketProgressPage() {
|
|
|
const location = useLocation();
|
|
|
const keyword = searchParams.get("q") ?? "";
|
|
|
const status = searchParams.get("status") ?? "";
|
|
|
+ const type = searchParams.get("type") ?? "";
|
|
|
+ const from = searchParams.get("from") ?? "";
|
|
|
+ const to = searchParams.get("to") ?? "";
|
|
|
const page = Math.max(1, Number(searchParams.get("page")) || 1);
|
|
|
const [notice, setNotice] = useState("");
|
|
|
const [active, setActive] = useState<TicketListItem | null>(null);
|
|
|
@@ -142,7 +156,15 @@ export function CustomerTicketProgressPage() {
|
|
|
if (!submitterType) return;
|
|
|
setSubmitterById((prev) => (prev[ticketId] === submitterType ? prev : { ...prev, [ticketId]: submitterType }));
|
|
|
}, []);
|
|
|
- const list = useTicketList({ keyword: keyword.trim() || undefined, statuses: status ? [status] : undefined }, page);
|
|
|
+ const list = useTicketList({
|
|
|
+ keyword: keyword.trim() || undefined,
|
|
|
+ statuses: status ? [status] : undefined,
|
|
|
+ ticket_types: type ? [type] : undefined,
|
|
|
+ date_from: from || undefined,
|
|
|
+ date_to: to || undefined,
|
|
|
+ }, page);
|
|
|
+ const counts = useTicketStatusCounts(TICKET_STATUSES);
|
|
|
+ const tableOverflow = useHorizontalOverflow();
|
|
|
|
|
|
/** 写 URL:空值删键;换筛选(未显式给 `page`)一律回第 1 页。 */
|
|
|
function patchParams(patch: Record<string, string>) {
|
|
|
@@ -152,8 +174,6 @@ export function CustomerTicketProgressPage() {
|
|
|
setSearchParams(next);
|
|
|
}
|
|
|
|
|
|
- if (!identity || !["enterprise", "sub"].includes(identity.role)) return <WorkspaceEmpty title="请切换到客户账号" description="工单进度面向企业客户与子账号;运维请到「工单管理」。" />;
|
|
|
-
|
|
|
const rows = list.data?.rows ?? [];
|
|
|
const total = list.data?.total ?? 0;
|
|
|
const pages = Math.max(1, Math.ceil(total / TICKET_PAGE_SIZE));
|
|
|
@@ -162,63 +182,117 @@ export function CustomerTicketProgressPage() {
|
|
|
/** 进详情的「来路」=本页当前 URL(含筛选与页码),返回时逐字复原。 */
|
|
|
const detailState = detailLinkState(location.pathname + location.search + location.hash, location.state);
|
|
|
|
|
|
- return <section className="work-order-page work-order-ledger-page page-fill">
|
|
|
- <header className="work-order-heading"><div><p className="work-order-eyebrow"><span /> CUSTOMER SUPPORT / 我的工单</p><h1>工单进度</h1></div><Link to="/workspace/submit"><Button><FileText size={17} />提交故障或售后</Button></Link></header>
|
|
|
- <div className="work-order-list-shell list-shell-fill">
|
|
|
- <div className="work-order-ledger-filters">
|
|
|
- <label className="work-order-ledger-search"><Search size={17} /><SearchInput aria-label="搜索我的工单" placeholder="搜索工单号或事项标题" value={keyword} onCommit={(value) => patchParams({ q: value })} />{keyword && <button type="button" aria-label="清空搜索" onClick={() => patchParams({ q: "" })}><X size={15} /></button>}</label>
|
|
|
- <FilterSelect icon="status" aria-label="工单状态筛选" value={status} onChange={(event) => patchParams({ status: event.target.value })}><option value="">全部状态</option>{TICKET_STATUSES.map((item) => <option key={item} value={item}>{customerStatusLabel(item)}</option>)}</FilterSelect>
|
|
|
- <Button variant="ghost" size="sm" onClick={() => list.reload()}><RefreshCw size={15} />刷新</Button>
|
|
|
- {(keyword || status) ? <Button variant="ghost" size="sm" onClick={() => setSearchParams(new URLSearchParams())}>重置筛选</Button> : null}
|
|
|
- </div>
|
|
|
- <div className="measured-table-scroll work-order-table-wrap" role="region" aria-label="我的工单列表,可横向滚动查看字段" tabIndex={0}><table className="work-order-ledger-table"><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) => {
|
|
|
- const submitterType = item.submitter_type ?? submitterById[item.ticket_id] ?? null;
|
|
|
- const gate = customerLiveTicketActions({ status: item.status, ticket_type: item.ticket_type, submitter_type: submitterType });
|
|
|
- const label = gate.confirmClose ? "确认完成,关闭工单" : gate.withdraw ? "撤回" : "办理";
|
|
|
- return <tr key={item.ticket_id}>
|
|
|
- <td><strong className="work-order-ticket-number" title={item.ticket_no ?? ""}>{item.ticket_no ?? "-"}</strong></td>
|
|
|
- <td>{typeLabel(item.ticket_type)}</td>
|
|
|
- <td><span title={item.title ?? undefined}>{item.title}</span></td>
|
|
|
- <td><CustomerStatusTag status={item.status} type={item.ticket_type} /></td>
|
|
|
- <td>{submitterType ? SUBMITTER_NAMES[submitterType] ?? submitterType : <span className="table-placeholder" title="列表未回提交方,需要确认时点「办理」查看该单详情">未回传</span>}</td>
|
|
|
- <td>{item.expected_done_date ? item.expected_done_date.slice(0, 10) : <span className="table-placeholder">—</span>}</td>
|
|
|
- <td>{fmtTime(item.completed_at)}</td>
|
|
|
- <td>{fmtTime(item.created_at)}</td>
|
|
|
- <td className="work-order-row-actions">
|
|
|
- {(gate.confirmClose || gate.withdraw || gate.needsDetail) && <Button variant="outline" size="sm" onClick={() => setActive(item)}>{label}</Button>}
|
|
|
- {/* 客户侧 URL 只走业务工单号(`ticket_no`):内部主键⛔ 出现在客户地址里。 */}
|
|
|
- <Link className="ops-table-action" to={`/work-orders/${encodeURIComponent(item.ticket_no ?? item.ticket_id)}`} state={detailState}>详情</Link>
|
|
|
- </td>
|
|
|
- </tr>;
|
|
|
- })}</tbody></table>
|
|
|
- {list.loading && <div className="work-order-empty"><RefreshCw size={27} /><h3>正在读取工单…</h3></div>}
|
|
|
- {fail && <TicketState fail={fail} onRetry={list.reload} />}
|
|
|
- {!list.loading && !fail && !rows.length && <div className="work-order-empty"><ClipboardList size={27} /><h3>还没有工单</h3><p>需要报修或咨询,请到「提交故障或售后」建单。</p><Link to="/workspace/submit"><Button variant="ghost" size="sm">去提交</Button></Link></div>}
|
|
|
+ const filtered = Boolean(keyword || status || type || from || to);
|
|
|
+ const visibleCounts = counts.error ? null : counts.data;
|
|
|
+ const displayCount = (key: string) => visibleCounts?.[key]?.toLocaleString("zh-CN") ?? (counts.loading ? "…" : "—");
|
|
|
+ const metrics = [
|
|
|
+ { title: "工单总量", key: "total", icon: ClipboardList },
|
|
|
+ { title: "处理中", key: "processing", icon: Clock3 },
|
|
|
+ { title: "待确认", key: "completed", icon: ClipboardCheck },
|
|
|
+ { title: "已办结", key: "settled", icon: Check },
|
|
|
+ ];
|
|
|
+
|
|
|
+ function reloadProgress() {
|
|
|
+ list.reload();
|
|
|
+ counts.reload();
|
|
|
+ }
|
|
|
+
|
|
|
+ return <section className="order-page work-order-ledger customer-ticket-progress page-fill page-fill-window">
|
|
|
+ <header className="order-heading">
|
|
|
+ <div>
|
|
|
+ <h1>工单进度</h1>
|
|
|
+ <PageIntro>跟进工单处理进度,查看处理结果并确认办结。</PageIntro>
|
|
|
</div>
|
|
|
- <ServerListPager total={total} page={currentPage} pageSize={TICKET_PAGE_SIZE} unit="张" className="list-pager work-order-ledger-pager" onPageChange={(next) => patchParams({ page: next > 1 ? String(next) : "" })} />
|
|
|
+ <Link className="customer-progress-submit" to="/workspace/submit"><FileText size={17} aria-hidden="true" />提交故障或售后</Link>
|
|
|
+ </header>
|
|
|
+
|
|
|
+ <div className="work-order-ledger-summary" role="group" aria-label="工单统计">
|
|
|
+ {metrics.map(({ title, key, icon: Icon }) => (
|
|
|
+ <div className={key === "total" ? "work-order-metric work-order-metric-total" : "work-order-metric"} key={key}>
|
|
|
+ <span className="work-order-metric-icon"><Icon size={18} aria-hidden="true" /></span>
|
|
|
+ <span className="work-order-metric-body"><span>{title}</span><strong>{displayCount(key)}</strong></span>
|
|
|
+ </div>
|
|
|
+ ))}
|
|
|
</div>
|
|
|
+
|
|
|
+ <section className="order-list-shell list-shell-fill" aria-label="工单列表">
|
|
|
+ <div className="order-tabs" role="group" aria-label="按工单状态筛选" aria-describedby="customer-progress-count-scope">
|
|
|
+ <span className="sr-only" id="customer-progress-count-scope">角标为当前账号可见的工单数量。</span>
|
|
|
+ <button type="button" className={!status ? "active" : ""} aria-pressed={!status} onClick={() => patchParams({ status: "" })}>
|
|
|
+ 全部状态<span>{displayCount("total")}</span>
|
|
|
+ </button>
|
|
|
+ {TICKET_STATUSES.map((code) => (
|
|
|
+ <button key={code} type="button" className={status === code ? "active" : ""} aria-pressed={status === code} onClick={() => patchParams({ status: code })}>
|
|
|
+ {code === "completed" ? "待确认" : nonMainlineStatusLabel(code)}<span>{displayCount(code)}</span>
|
|
|
+ </button>
|
|
|
+ ))}
|
|
|
+ </div>
|
|
|
+ <div className="ops-toolbar order-filters">
|
|
|
+ <label className="ops-search order-search">
|
|
|
+ <Search size={17} aria-hidden="true" />
|
|
|
+ <SearchInput aria-label="搜索我的工单" placeholder="搜索工单号或事项标题" value={keyword} onCommit={(value) => patchParams({ q: value })} />
|
|
|
+ {keyword && <button type="button" aria-label="清空搜索" onClick={() => patchParams({ q: "" })}><X size={15} /></button>}
|
|
|
+ </label>
|
|
|
+ <FilterSelect icon="type" aria-label="工单类型筛选" value={type} onChange={(event) => patchParams({ type: event.target.value })}>
|
|
|
+ <option value="">全部类型</option>
|
|
|
+ {TICKET_TYPES.map((code) => <option key={code} value={code}>{typeLabel(code)}</option>)}
|
|
|
+ </FilterSelect>
|
|
|
+ <DateRangeFilter label="提交时间" from={from} to={to} constrainRange onChange={(key, value) => patchParams({ [key]: value })} />
|
|
|
+ {filtered && <Button variant="ghost" size="sm" onClick={() => setSearchParams(new URLSearchParams())}>重置筛选</Button>}
|
|
|
+ <Button className="customer-progress-refresh" variant="ghost" size="sm" onClick={reloadProgress}><RefreshCw size={15} />刷新</Button>
|
|
|
+ </div>
|
|
|
+ <div
|
|
|
+ ref={tableOverflow.ref}
|
|
|
+ className={`measured-table-scroll order-ledger-scroll${tableOverflow.overflow ? " has-horizontal-overflow" : ""}${tableOverflow.canScrollLeft ? " can-scroll-left" : ""}${tableOverflow.canScrollRight ? " can-scroll-right" : ""}`}
|
|
|
+ role="region"
|
|
|
+ aria-label="我的工单列表,可横向滚动查看字段"
|
|
|
+ tabIndex={0}
|
|
|
+ >
|
|
|
+ {list.loading ? <div className="order-empty" role="status">正在读取工单…</div>
|
|
|
+ : fail ? <TicketState fail={fail} onRetry={reloadProgress} />
|
|
|
+ : !rows.length ? <div className="order-empty">
|
|
|
+ {filtered ? <Search size={26} aria-hidden="true" /> : <ClipboardList size={26} aria-hidden="true" />}
|
|
|
+ <h3>{filtered ? "没有匹配的工单" : "暂无工单"}</h3>
|
|
|
+ {filtered
|
|
|
+ ? <Button variant="ghost" size="sm" onClick={() => setSearchParams(new URLSearchParams())}>重置筛选</Button>
|
|
|
+ : <Link className="ops-table-action" to="/workspace/submit">提交故障或售后<ArrowRight size={14} aria-hidden="true" /></Link>}
|
|
|
+ </div> : <table className="order-table order-ledger customer-progress-table">
|
|
|
+ <OpsTableColumns widths={[250, 112, 122, 100, 115, 132, 132, 155]} />
|
|
|
+ <thead><tr>{["事项 / 工单号", "类型", "状态", "提交方", "要求完成", "竣工时间", "提交时间", "操作"].map((column) => <th key={column} scope="col">{column}</th>)}</tr></thead>
|
|
|
+ <tbody>{rows.map((item) => {
|
|
|
+ const submitterType = item.submitter_type ?? submitterById[item.ticket_id] ?? null;
|
|
|
+ const gate = customerLiveTicketActions({ status: item.status, ticket_type: item.ticket_type, submitter_type: submitterType });
|
|
|
+ const actionLabel = gate.confirmClose ? "确认关闭" : gate.withdraw ? "撤回" : "办理";
|
|
|
+ const number = item.ticket_no ?? item.ticket_id;
|
|
|
+ return <tr key={item.ticket_id}>
|
|
|
+ <td>
|
|
|
+ <strong className="table-cell-title" title={item.title ?? undefined}>{item.title || <span className="table-placeholder">未填写标题</span>}</strong>
|
|
|
+ <small title={item.ticket_no ?? undefined}>{item.ticket_no || "—"}</small>
|
|
|
+ </td>
|
|
|
+ <td><TicketTypeTag type={item.ticket_type} /></td>
|
|
|
+ <td><TicketStatusTag status={item.status} type={item.ticket_type} /></td>
|
|
|
+ <td>{submitterType ? SUBMITTER_NAMES[submitterType] ?? submitterType : <span className="table-placeholder">未回传</span>}</td>
|
|
|
+ <td className="order-date">{item.expected_done_date?.slice(0, 10) || <span className="table-placeholder">—</span>}</td>
|
|
|
+ <td className="order-date">{item.completed_at ? fmtTime(item.completed_at) : <span className="table-placeholder">—</span>}</td>
|
|
|
+ <td className="order-date">{item.created_at ? fmtTime(item.created_at) : <span className="table-placeholder">—</span>}</td>
|
|
|
+ <td><div className="ops-inline-actions">
|
|
|
+ {(gate.confirmClose || gate.withdraw || gate.needsDetail) && <button className="ops-table-action" type="button" onClick={() => setActive(item)}>{actionLabel}</button>}
|
|
|
+ <Link className="ops-table-action" to={`/work-orders/${encodeURIComponent(number)}`} state={detailState} aria-label={`查看工单 ${number} 详情`}>详情<ArrowRight size={14} aria-hidden="true" /></Link>
|
|
|
+ </div></td>
|
|
|
+ </tr>;
|
|
|
+ })}</tbody>
|
|
|
+ </table>}
|
|
|
+ </div>
|
|
|
+ {!list.loading && !fail && <ServerListPager total={total} page={currentPage} pageSize={TICKET_PAGE_SIZE} unit="张" onPageChange={(next) => patchParams({ page: next > 1 ? String(next) : "" })} />}
|
|
|
+ </section>
|
|
|
{notice && <OpsNotice message={notice} onClose={() => setNotice("")} />}
|
|
|
- {active && <CustomerTicketActionSheet row={active} onClose={() => setActive(null)} onResolved={rememberSubmitter} onDone={(message) => { setActive(null); setNotice(message); list.reload(); }} />}
|
|
|
+ {active && <CustomerTicketActionSheet row={active} onClose={() => setActive(null)} onResolved={rememberSubmitter} onDone={(message) => { setActive(null); setNotice(message); reloadProgress(); }} />}
|
|
|
</section>;
|
|
|
}
|
|
|
|
|
|
/** 提交方显示名(`tickets.submitter_type` 口径见 `docs/需求文档/14-API接口契约.md`)。 */
|
|
|
const SUBMITTER_NAMES: Record<string, string> = { customer: "本人提交", ops: "运维代建", system: "系统生成", unicom: "运营商报文" };
|
|
|
|
|
|
-/** 状态徽标沿用台账类名(`work-orders.css`),⛔ 另起一套配色体系。 */
|
|
|
-function CustomerStatusTag({ status, type }: { status: string; type: string }) {
|
|
|
- const tone: Record<string, string> = { unassigned: "pending", pending: "pending", processing: "doing", completed: "done", rejected: "doing", settled: "done", terminated: "closed" };
|
|
|
- return <span className={`work-order-status status-${tone[status] ?? "pending"}`}><i />{statusLabel(status, type)}</span>;
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * 客户侧的状态筛选器文案:门户只受理故障/售后(EP-03),没有主线单,
|
|
|
- * ⇒ `completed` 一律按非主线叫法「已处理待确认」(该态等本人确认或超时自动闭环,不是终态)。
|
|
|
- * ⚠️ 与行内徽标 `statusLabel(status, ticket_type)` 同源,⛔ 在这里另抄一份中文名。
|
|
|
- */
|
|
|
-const customerStatusLabel = (status: string) => nonMainlineStatusLabel(status);
|
|
|
-
|
|
|
/**
|
|
|
* 「办理」弹框:先就该单取**一次**详情定闸门,再给「确认完成,关闭工单」/「撤回」。
|
|
|
*
|