|
|
@@ -10,7 +10,7 @@
|
|
|
* - 附件:`material_grant` 要 `ticket_id`,建单前拿不到上传凭证,
|
|
|
* ⛔ 把未上传的文件名随单提交,材料在建单后到工单详情直传(§5.8)。
|
|
|
*/
|
|
|
-import { useCallback, useEffect, useRef, useState, type FormEvent } from "react";
|
|
|
+import { useCallback, useEffect, useId, useState, type FormEvent } from "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";
|
|
|
@@ -23,12 +23,12 @@ 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, OpsTableColumns } from "../components/OperationsKit";
|
|
|
+import { OpsDialog, 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, TICKET_TYPES, statusLabel, nonMainlineStatusLabel, typeLabel, ticketConfirmClose, ticketWithdraw } from "../lib/api/ticket";
|
|
|
+import { ticketCreate, TICKET_STATUSES, TICKET_TYPES, 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";
|
|
|
@@ -276,7 +276,7 @@ function CustomerTicketProgressLedger() {
|
|
|
<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>}
|
|
|
+ {(gate.confirmClose || gate.withdraw || gate.needsDetail) && <button className="ops-table-action" type="button" onClick={() => setActive({ ...item, submitter_type: submitterType })}>{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>;
|
|
|
@@ -286,7 +286,7 @@ function CustomerTicketProgressLedger() {
|
|
|
{!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); reloadProgress(); }} />}
|
|
|
+ {active && <CustomerTicketActionDialog row={active} onClose={() => setActive(null)} onResolved={rememberSubmitter} onDone={(message) => { setActive(null); setNotice(message); reloadProgress(); }} />}
|
|
|
</section>;
|
|
|
}
|
|
|
|
|
|
@@ -294,15 +294,9 @@ function CustomerTicketProgressLedger() {
|
|
|
const SUBMITTER_NAMES: Record<string, string> = { customer: "本人提交", ops: "运维代建", system: "系统生成", unicom: "运营商报文" };
|
|
|
|
|
|
/**
|
|
|
- * 「办理」弹框:先就该单取**一次**详情定闸门,再给「确认完成,关闭工单」/「撤回」。
|
|
|
- *
|
|
|
- * `read_event=false`:客户只是来看进度并确认结果,⛔ 一次查看就把待处理单推进成处理中
|
|
|
- * (那是运维接手的语义,服务端按 `read_event` 决定是否记接手事件)。
|
|
|
- * 撤回原因必填=`finalize.rs` 的 `WithdrawReq`(`reason` 为空回参数校验失败)。
|
|
|
- * `expected_version`=详情头的 `row_version`(乐观锁):并发下版本不符由服务端拒,
|
|
|
- * 回执经 `classifyTicketError` 原样显示,⛔ 静默重试覆盖对方。
|
|
|
+ * 先读取该工单的最新状态和提交方,确认可用操作。读取详情时不触发运维接手事件。
|
|
|
*/
|
|
|
-function CustomerTicketActionSheet({ row, onClose, onResolved, onDone }: {
|
|
|
+function CustomerTicketActionDialog({ row, onClose, onResolved, onDone }: {
|
|
|
row: TicketListItem;
|
|
|
onClose: () => void;
|
|
|
onResolved: (ticketId: string, submitterType: string | null) => void;
|
|
|
@@ -311,57 +305,108 @@ function CustomerTicketActionSheet({ row, onClose, onResolved, onDone }: {
|
|
|
const detail = useTicketDetail(row.ticket_id, false);
|
|
|
const submit = useSubmit();
|
|
|
const location = useLocation();
|
|
|
+ const reasonId = useId();
|
|
|
const [reason, setReason] = useState("");
|
|
|
- const ref = useRef<HTMLDialogElement>(null);
|
|
|
const head = detail.data?.ticket ?? null;
|
|
|
- /** 「查看完整记录」=从本弹框(仍在本列表页)进详情,返回目标就是这张列表。 */
|
|
|
const detailState = detailLinkState(location.pathname + location.search + location.hash, location.state);
|
|
|
|
|
|
- useEffect(() => {
|
|
|
- const el = ref.current;
|
|
|
- if (!el) return;
|
|
|
- // ⚠️ 属性 `open` 与 showModal() ⛔ 同时置:React 先把 open 写进 DOM,effect 再调 showModal()
|
|
|
- // 会抛 InvalidStateError(2026-11-13 实测抽屉打不开)。已开就跳过。
|
|
|
- if (el.open) return;
|
|
|
- if (typeof el.showModal === "function") el.showModal();
|
|
|
- else el.open = true;
|
|
|
- }, []);
|
|
|
-
|
|
|
const submitterType = head?.submitter_type ?? null;
|
|
|
- useEffect(() => { if (submitterType) onResolved(row.ticket_id, submitterType); }, [onResolved, row.ticket_id, submitterType]);
|
|
|
+ useEffect(() => {
|
|
|
+ if (submitterType) onResolved(row.ticket_id, submitterType);
|
|
|
+ }, [onResolved, row.ticket_id, submitterType]);
|
|
|
|
|
|
- const gate = head ? customerLiveTicketActions({ status: head.status, ticket_type: head.ticket_type, submitter_type: head.submitter_type }) : null;
|
|
|
const detailFail = detail.error ? classifyTicketError(detail.error) : null;
|
|
|
+ const gate = head && !detailFail ? customerLiveTicketActions(head) : null;
|
|
|
+ const displayedAction = gate ?? customerLiveTicketActions(row);
|
|
|
+ const title = displayedAction.withdraw ? "撤回工单" : displayedAction.confirmClose ? "确认工单完成" : "工单办理";
|
|
|
+ const ticket = head ?? row;
|
|
|
const tip = submit.error ? classifyTicketError(submit.error).message : "";
|
|
|
+ const canSubmit = gate?.confirmClose || (gate?.withdraw && Boolean(reason.trim()));
|
|
|
+
|
|
|
+ function close() {
|
|
|
+ if (!submit.busy) onClose();
|
|
|
+ }
|
|
|
+
|
|
|
+ async function act(event: FormEvent<HTMLFormElement>) {
|
|
|
+ event.preventDefault();
|
|
|
+ if (!head || !canSubmit || submit.busy) return;
|
|
|
|
|
|
- async function act(kind: "confirm" | "withdraw") {
|
|
|
- if (!head) return;
|
|
|
+ const withdrawing = gate?.withdraw === true;
|
|
|
const version = Number(head.row_version);
|
|
|
- const ok = await submit.run(() => kind === "confirm"
|
|
|
- ? ticketConfirmClose({ ticket_id: head.ticket_id, expected_version: Number.isFinite(version) ? version : undefined })
|
|
|
- : ticketWithdraw({ ticket_id: head.ticket_id, reason: reason.trim() }));
|
|
|
- if (ok) onDone(kind === "confirm" ? `工单 ${head.ticket_no} 已确认完成并关闭。` : `工单 ${head.ticket_no} 已撤回并关闭。`);
|
|
|
+ const ok = await submit.run(() => withdrawing
|
|
|
+ ? ticketWithdraw({ ticket_id: head.ticket_id, reason: reason.trim() })
|
|
|
+ : ticketConfirmClose({ ticket_id: head.ticket_id, expected_version: Number.isFinite(version) ? version : undefined }));
|
|
|
+ if (ok) onDone(withdrawing ? `工单 ${head.ticket_no} 已撤回并关闭。` : `工单 ${head.ticket_no} 已确认完成并关闭。`);
|
|
|
}
|
|
|
|
|
|
- return <dialog ref={ref} className="work-order-drawer" aria-label="工单办理" onCancel={onClose} onClick={(event) => { if (event.target === ref.current) onClose(); }}>
|
|
|
- <header><div><p className="work-order-eyebrow"><span /> CUSTOMER SUPPORT / 工单办理</p><h2>{row.ticket_no ?? "工单办理"}</h2><p>{typeLabel(row.ticket_type)} · {row.title}</p></div><button type="button" aria-label="关闭" onClick={onClose}><X size={17} /></button></header>
|
|
|
- <div className="work-order-editor">
|
|
|
- {detail.loading && !head && <div className="work-order-empty"><RefreshCw size={27} /><h3>正在核对可执行的操作…</h3></div>}
|
|
|
- {detailFail && <TicketState fail={detailFail} onRetry={detail.reload} />}
|
|
|
- {head && gate && <>
|
|
|
- <div className="work-order-editor-note"><Info size={17} /><span>当前状态:{statusLabel(head.status, head.ticket_type)} · 提交方:{SUBMITTER_NAMES[head.submitter_type ?? ""] ?? head.submitter_type ?? "未回传"} · 要求完成 {head.expected_done_date ? head.expected_done_date.slice(0, 10) : "—"} · 竣工 {fmtTime(head.completed_at)}{head.confirm_deadline ? ` · 自动关闭期限 ${fmtTime(head.confirm_deadline)}` : ""}</span></div>
|
|
|
- {gate.confirmClose && <div className="work-order-editor-note"><Check size={17} /><span>运维已标记完成,等您确认:确认后工单立即关闭;按手册 P7,7 天内未确认由系统自动关闭。</span></div>}
|
|
|
- {gate.withdraw && <div className="work-order-editor-note"><Clock3 size={17} /><span>该单仍在处理中,可以撤回:撤回即关闭工单,请填写原因(工单§5.1.9:原因必填)。</span></div>}
|
|
|
- {gate.blockedReason && <div className="work-order-editor-note"><CircleAlert size={17} /><span>{gate.blockedReason}</span></div>}
|
|
|
- {gate.withdraw && <form className="work-order-form-grid" onSubmit={(event: FormEvent) => { event.preventDefault(); void act("withdraw"); }}><label className="wide">撤回原因 <em>*</em><textarea rows={3} maxLength={500} value={reason} placeholder="例如:故障已自行恢复,无需处理" onChange={(event) => setReason(event.target.value)} /></label></form>}
|
|
|
- {tip && <p className="work-order-form-error" role="alert">{tip}</p>}
|
|
|
- <div className="work-order-detail-actions">
|
|
|
- <Button variant="ghost" size="sm" onClick={onClose}>返回</Button>
|
|
|
- <Link to={`/work-orders/${encodeURIComponent(row.ticket_no ?? row.ticket_id)}`} state={detailState}><Button variant="ghost" size="sm"><FileText size={15} />查看完整记录</Button></Link>
|
|
|
- {gate.confirmClose && <Button size="sm" disabled={submit.busy} onClick={() => void act("confirm")}><Check size={15} />确认完成,关闭工单</Button>}
|
|
|
- {gate.withdraw && <Button size="sm" disabled={submit.busy || !reason.trim()} onClick={() => void act("withdraw")}><X size={15} />撤回并关闭</Button>}
|
|
|
+ return (
|
|
|
+ <OpsDialog title={title} className="customer-ticket-action-dialog" onClose={close}>
|
|
|
+ <form onSubmit={(event) => void act(event)} aria-busy={submit.busy}>
|
|
|
+ <div className="customer-ticket-action-body">
|
|
|
+ <section className="customer-ticket-action-summary" aria-label="工单摘要">
|
|
|
+ <div className="customer-ticket-action-identity">
|
|
|
+ <span className="customer-ticket-action-icon"><FileText size={20} aria-hidden="true" /></span>
|
|
|
+ <div>
|
|
|
+ <div className="customer-ticket-action-reference">
|
|
|
+ <span>{ticket.ticket_no || "工单摘要"}</span>
|
|
|
+ <TicketTypeTag type={ticket.ticket_type} />
|
|
|
+ </div>
|
|
|
+ <p>{ticket.title || "未填写标题"}</p>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <TicketStatusTag status={ticket.status} type={ticket.ticket_type} />
|
|
|
+ </section>
|
|
|
+
|
|
|
+ {detail.loading && !head && <p className="customer-ticket-action-loading" role="status">正在核对工单状态…</p>}
|
|
|
+ {detailFail && <TicketState fail={detailFail} onRetry={detail.reload} />}
|
|
|
+ {gate?.withdraw && <>
|
|
|
+ <p id={`${reasonId}-hint`} className="customer-ticket-action-note" data-withdraw>
|
|
|
+ <CircleAlert size={16} aria-hidden="true" />
|
|
|
+ <span>撤回后,工单将关闭,运维团队将停止处理。</span>
|
|
|
+ </p>
|
|
|
+ <div className="customer-ticket-action-field">
|
|
|
+ <label htmlFor={reasonId}>撤回原因 <span aria-hidden="true">*</span></label>
|
|
|
+ <textarea
|
|
|
+ id={reasonId}
|
|
|
+ rows={4}
|
|
|
+ maxLength={500}
|
|
|
+ required
|
|
|
+ disabled={submit.busy}
|
|
|
+ value={reason}
|
|
|
+ aria-describedby={`${reasonId}-hint`}
|
|
|
+ placeholder="请简要说明撤回原因"
|
|
|
+ onChange={(event) => setReason(event.target.value)}
|
|
|
+ />
|
|
|
+ <small>{reason.length} / 500</small>
|
|
|
+ </div>
|
|
|
+ </>}
|
|
|
+ {gate?.confirmClose && <p className="customer-ticket-action-note">
|
|
|
+ <Info size={16} aria-hidden="true" />
|
|
|
+ <span>运维团队已标记完成,确认后工单将关闭。{head?.confirm_deadline && `自动关闭时间为 ${fmtTime(head.confirm_deadline)}。`}</span>
|
|
|
+ </p>}
|
|
|
+ {gate && !gate.withdraw && !gate.confirmClose && <p className="customer-ticket-action-note">
|
|
|
+ <Info size={16} aria-hidden="true" />
|
|
|
+ <span>{gate.blockedReason ?? "当前没有可办理的操作。"}</span>
|
|
|
+ </p>}
|
|
|
+ {tip && <p className="ops-form-error" role="alert">{tip}</p>}
|
|
|
</div>
|
|
|
- </>}
|
|
|
- </div>
|
|
|
- </dialog>;
|
|
|
+
|
|
|
+ <footer className="customer-ticket-action-footer">
|
|
|
+ {!submit.busy && <Link className="ops-table-action" to={`/work-orders/${encodeURIComponent(ticket.ticket_no ?? row.ticket_id)}`} state={detailState}>
|
|
|
+ 查看工单详情<ArrowRight size={14} aria-hidden="true" />
|
|
|
+ </Link>}
|
|
|
+ <div>
|
|
|
+ <Button variant="outline" type="button" disabled={submit.busy} onClick={close}>取消</Button>
|
|
|
+ {(gate?.withdraw || gate?.confirmClose) && <Button
|
|
|
+ type="submit"
|
|
|
+ variant={gate.withdraw ? "destructive" : "default"}
|
|
|
+ disabled={submit.busy || !canSubmit}
|
|
|
+ >
|
|
|
+ {submit.busy ? (gate.withdraw ? "撤回中…" : "确认中…") : gate.withdraw ? "确认撤回" : "确认完成"}
|
|
|
+ </Button>}
|
|
|
+ </div>
|
|
|
+ </footer>
|
|
|
+ </form>
|
|
|
+ </OpsDialog>
|
|
|
+ );
|
|
|
}
|