|
|
@@ -1,27 +1,35 @@
|
|
|
-/**
|
|
|
- * 运维现场移动端 H5:待办列表/精简详情/全屏回填(与桌面共用 API/回填表单)。
|
|
|
- */
|
|
|
-import { useState } from "react";
|
|
|
-import { Link, Navigate, useLocation, useNavigate, useParams } from "react-router";
|
|
|
-import { ArrowLeft, ArrowRight, Smartphone } from "lucide-react";
|
|
|
+import { useLayoutEffect, useRef, type ReactNode } from "react";
|
|
|
+import { Link, Navigate, useLocation, useNavigate, useParams, useSearchParams } from "react-router";
|
|
|
+import { ArrowLeft, ArrowRight, CalendarDays, CheckCircle2, ChevronDown, ChevronRight, ClipboardCheck, Clock3, MapPin, Monitor, Phone, Smartphone } from "lucide-react";
|
|
|
import { Button } from "../../components/ui/button";
|
|
|
import { TicketStatusTag, TicketTypeTag } from "../../components/work-order/TicketBadges";
|
|
|
import { ConstructionGuidePanel } from "../../components/work-order/ConstructionGuidePanel";
|
|
|
-import type { TicketListItem } from "../../lib/api/ticket";
|
|
|
-import { classifyTicketError, fmtDate, useTicketDetail, useTicketList } from "../../lib/ticket";
|
|
|
+import { classifyTicketError, useTicketDetail, useTicketList } from "../../lib/ticket";
|
|
|
import { nextStepOf } from "../../lib/work-order-next-step";
|
|
|
import { businessToday } from "../../lib/business-date";
|
|
|
-import { groupTodoRows, todoRowSummary } from "../../lib/work-order-todo-row";
|
|
|
+import { groupTodoRows, todoRowDeadline, todoRowSummary } from "../../lib/work-order-todo-row";
|
|
|
import { useDemoIdentity } from "../../lib/demo-session";
|
|
|
-import { detailBack, useDetailLinkState } from "../../lib/detail-navigation";
|
|
|
+import { detailBack, detailLinkState, useDetailLinkState } from "../../lib/detail-navigation";
|
|
|
import { TicketState } from "../../components/ticketState";
|
|
|
-import { TicketActionSheet } from "../WorkOrderRecordPage";
|
|
|
+import { LogPanel, TicketActionSheet } from "../WorkOrderRecordPage";
|
|
|
import "../../styles/work-order-guide.css";
|
|
|
import "../../styles/work-orders.css";
|
|
|
import "../../styles/work-order-record.css";
|
|
|
+import "../../styles/mobile-work-orders.css";
|
|
|
|
|
|
const MINE_STATUSES = ["unassigned", "pending", "processing", "completed", "rejected"];
|
|
|
const MINE_ROLES = ["admin", "regAdmin", "teamLead", "ops", "worker"];
|
|
|
+const deadlineLabels = { planned: "计划执行", deferred: "延期至", due: "截止" };
|
|
|
+const pageSize = 100;
|
|
|
+// 浏览器后退与页面返回按钮共用原列表的位置,只在本次浏览中保留。
|
|
|
+let lastListPosition: { key: string; y: number } | undefined;
|
|
|
+
|
|
|
+function MobileHeader({ title, backLabel, onBack, children }: { title: string; backLabel?: string; onBack?: () => void; children?: ReactNode }) {
|
|
|
+ return <header className="field-top">
|
|
|
+ {onBack && <Button variant="ghost" size="icon" aria-label={backLabel} onClick={onBack}><ArrowLeft size={20} /></Button>}
|
|
|
+ <h1>{title}</h1>{children}
|
|
|
+ </header>;
|
|
|
+}
|
|
|
|
|
|
export function MobileWorkOrderMinePage() {
|
|
|
const identity = useDemoIdentity();
|
|
|
@@ -30,49 +38,62 @@ export function MobileWorkOrderMinePage() {
|
|
|
}
|
|
|
|
|
|
function MobileMineInner() {
|
|
|
- const list = useTicketList({ statuses: MINE_STATUSES, assignee: "me" }, 1, 100);
|
|
|
- const fail = list.error ? classifyTicketError(list.error) : null;
|
|
|
- const rows = list.data?.rows ?? [];
|
|
|
- const groups = groupTodoRows(rows, businessToday());
|
|
|
-
|
|
|
- return (
|
|
|
- <div className="wo-m-page">
|
|
|
- <header className="wo-m-top">
|
|
|
- <h1>待办工单</h1>
|
|
|
- <Link to="/work-orders/mine" style={{ marginLeft: "auto", fontSize: 13 }}>桌面版</Link>
|
|
|
- </header>
|
|
|
- {list.loading && <p className="wo-m-body">加载中…</p>}
|
|
|
- {fail && <div className="wo-m-body"><TicketState fail={fail} onRetry={list.reload} /></div>}
|
|
|
- {!list.loading && !fail && (
|
|
|
- <div className="wo-m-list">
|
|
|
- {groups.map((g) => (
|
|
|
- <div key={g.id}>
|
|
|
- <p className="work-order-eyebrow" style={{ margin: "8px 2px" }}>{g.title}</p>
|
|
|
- {g.rows.map((row) => <MobileTodoCard key={row.ticket_id} row={row} />)}
|
|
|
+ const location = useLocation();
|
|
|
+ const [params, setParams] = useSearchParams();
|
|
|
+ const rawPage = Number(params.get("page"));
|
|
|
+ const page = Number.isSafeInteger(rawPage) && rawPage > 0 ? rawPage : 1;
|
|
|
+ const list = useTicketList({ statuses: MINE_STATUSES, assignee: "me" }, page, pageSize);
|
|
|
+ const today = businessToday();
|
|
|
+ const groups = groupTodoRows(list.data?.rows ?? [], today);
|
|
|
+ const total = list.data?.total;
|
|
|
+ const pages = Math.ceil((total ?? 0) / pageSize);
|
|
|
+ const restoredKey = useRef("");
|
|
|
+ useLayoutEffect(() => {
|
|
|
+ if (!list.data || restoredKey.current === location.key) return;
|
|
|
+ restoredKey.current = location.key;
|
|
|
+ if (lastListPosition && [location.key, location.state?.mineKey].includes(lastListPosition.key)) {
|
|
|
+ window.scrollTo(0, lastListPosition.y);
|
|
|
+ }
|
|
|
+ }, [list.data, location.key, location.state]);
|
|
|
+ const linkState = detailLinkState(location.pathname + location.search, { mineKey: location.key });
|
|
|
+ function changePage(next: number) {
|
|
|
+ setParams(next > 1 ? { page: String(next) } : {});
|
|
|
+ window.scrollTo(0, 0);
|
|
|
+ }
|
|
|
+ return <main className="field-page">
|
|
|
+ <MobileHeader title="待办工单"><Link className="field-desktop" to="/work-orders/mine"><Monitor size={16} />桌面版</Link></MobileHeader>
|
|
|
+ <div className="field-content">
|
|
|
+ <section className="field-brief" aria-label="待办概况">
|
|
|
+ <div><p>分派给我的工单</p><strong>{total ?? "—"}<small>单</small></strong></div>
|
|
|
+ <time dateTime={today}><CalendarDays size={16} />{today.replaceAll("-", ".")}</time>
|
|
|
+ </section>
|
|
|
+ {list.loading && <p className="field-state" role="status">正在读取待办工单…</p>}
|
|
|
+ {list.error && <TicketState fail={classifyTicketError(list.error)} onRetry={list.reload} />}
|
|
|
+ {list.data && !list.error && groups.map((group) => <section className="field-group" data-tone={group.tone} key={group.id}>
|
|
|
+ <h2>{group.id === "waiting" ? "等待确认" : group.title}<small>{group.rows.length}</small></h2>
|
|
|
+ <ul>{group.rows.map((row) => {
|
|
|
+ const summary = todoRowSummary(row);
|
|
|
+ const step = nextStepOf(row);
|
|
|
+ const deadline = todoRowDeadline(row);
|
|
|
+ return <li key={row.ticket_id}><Link to={`/m/work-orders/${encodeURIComponent(row.ticket_id)}`} state={linkState}
|
|
|
+ onClick={() => { lastListPosition = { key: location.key, y: window.scrollY }; }}>
|
|
|
+ <div className="field-row-meta"><TicketTypeTag type={row.ticket_type} /><TicketStatusTag status={row.status} type={row.ticket_type} /></div>
|
|
|
+ <div className="field-row-title"><strong>{summary.title}</strong><ChevronRight size={17} aria-hidden="true" /></div>
|
|
|
+ <p className="field-meta">{summary.meta}</p>
|
|
|
+ <div className="field-row-foot">
|
|
|
+ {deadline.date && <span><Clock3 size={14} />{deadlineLabels[deadline.kind]} {deadline.date}</span>}
|
|
|
+ <span>{step.passiveLabel ?? step.label}</span>
|
|
|
</div>
|
|
|
- ))}
|
|
|
- {rows.length === 0 && <p className="wo-m-body">暂无待办。</p>}
|
|
|
- </div>
|
|
|
- )}
|
|
|
+ </Link></li>;
|
|
|
+ })}</ul>
|
|
|
+ </section>)}
|
|
|
+ {!list.loading && !list.error && !groups.length && <div className="field-empty"><ClipboardCheck size={30} /><h2>暂无待办工单</h2><p>新分派的工单会显示在这里。</p></div>}
|
|
|
+ {(pages > 1 || page > 1) && <nav className="field-pager" aria-label="待办分页">
|
|
|
+ <Button variant="outline" disabled={page <= 1} onClick={() => changePage(page - 1)}>上一页</Button>
|
|
|
+ <span>第 {page} 页</span><Button variant="outline" disabled={page >= pages} onClick={() => changePage(page + 1)}>下一页</Button>
|
|
|
+ </nav>}
|
|
|
</div>
|
|
|
- );
|
|
|
-}
|
|
|
-
|
|
|
-function MobileTodoCard({ row }: { row: TicketListItem }) {
|
|
|
- const linkState = useDetailLinkState();
|
|
|
- const step = nextStepOf(row);
|
|
|
- const summary = todoRowSummary(row);
|
|
|
- return (
|
|
|
- <Link className="wo-m-card" to={`/m/work-orders/${encodeURIComponent(row.ticket_id)}`} state={linkState}>
|
|
|
- <strong>{summary.title}</strong>
|
|
|
- <small>
|
|
|
- <TicketTypeTag type={row.ticket_type} />{" "}
|
|
|
- <TicketStatusTag status={row.status} type={row.ticket_type} />
|
|
|
- </small>
|
|
|
- <small>{summary.meta}</small>
|
|
|
- {step && <small>下一步:{step.label}</small>}
|
|
|
- </Link>
|
|
|
- );
|
|
|
+ </main>;
|
|
|
}
|
|
|
|
|
|
export function MobileWorkOrderDetailPage() {
|
|
|
@@ -83,65 +104,55 @@ export function MobileWorkOrderDetailPage() {
|
|
|
if (identity && !MINE_ROLES.includes(identity.role)) return <Navigate to="/work-orders" replace />;
|
|
|
if (!id) return <Navigate to="/m/work-orders/mine" replace />;
|
|
|
const back = detailBack(location.state, "/m/work-orders/mine", "返回移动端待办");
|
|
|
- return <MobileDetailInner id={id} backLabel={back.label} onBack={() => navigate(back.to, { state: back.state })} />;
|
|
|
+ return <MobileDetailInner key={id} id={id} backLabel={back.label} onBack={() => navigate(back.to, { state: back.state })} />;
|
|
|
}
|
|
|
|
|
|
function MobileDetailInner({ id, backLabel, onBack }: { id: string; backLabel: string; onBack: () => void }) {
|
|
|
- const navigate = useNavigate();
|
|
|
const linkState = useDetailLinkState();
|
|
|
+ const location = useLocation();
|
|
|
const detail = useTicketDetail(id, true);
|
|
|
- const fail = detail.error ? classifyTicketError(detail.error) : null;
|
|
|
const d = detail.data;
|
|
|
const t = d?.ticket;
|
|
|
- const can = d?.actions;
|
|
|
- const backfillReady = Boolean(can?.backfill || can?.check_and_backfill);
|
|
|
-
|
|
|
- return (
|
|
|
- <div className="wo-m-page">
|
|
|
- <header className="wo-m-top">
|
|
|
- <Button variant="ghost" size="sm" type="button" aria-label={backLabel} onClick={onBack}><ArrowLeft size={16} aria-hidden="true" /></Button>
|
|
|
- <h1>工单详情</h1>
|
|
|
- </header>
|
|
|
- {detail.loading && <p className="wo-m-body">加载中…</p>}
|
|
|
- {fail && <div className="wo-m-body"><TicketState fail={fail} onRetry={detail.reload} /></div>}
|
|
|
- {t && d && (
|
|
|
- <>
|
|
|
- <div className="wo-m-body">
|
|
|
- <div>
|
|
|
- <strong style={{ fontSize: 18 }}>{t.ticket_no}</strong>
|
|
|
- <div style={{ marginTop: 6, display: "flex", gap: 6, flexWrap: "wrap" }}>
|
|
|
- <TicketTypeTag type={t.ticket_type} />
|
|
|
- <TicketStatusTag status={t.status} type={t.ticket_type} />
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- <div className="work-order-summary-grid">
|
|
|
- <div><span>客户</span><strong>{d.customer?.customer_name ?? t.customer_id ?? "—"}</strong></div>
|
|
|
- <div><span>地址</span><strong>{d.customer?.address ?? "—"}</strong></div>
|
|
|
- <div><span>联系人</span><strong>{[d.customer?.contact_name, d.customer?.contact_mobile].filter(Boolean).join(" / ") || "—"}</strong></div>
|
|
|
- <div><span>计划执行日</span><strong>{t.execution_not_before ? fmtDate(t.execution_not_before) : (t.expected_done_date ? fmtDate(t.expected_done_date) : "—")}</strong></div>
|
|
|
- </div>
|
|
|
- <p style={{ margin: 0, lineHeight: 1.5 }}>{t.detail || t.title || "无描述"}</p>
|
|
|
- <ConstructionGuidePanel guide={d.construction_guide} />
|
|
|
- </div>
|
|
|
- <div className="wo-m-bar">
|
|
|
- {backfillReady ? (
|
|
|
- <Button onClick={() => navigate(`/m/work-orders/${encodeURIComponent(id)}/backfill`, { state: linkState })}>
|
|
|
- {can?.check_and_backfill ? "核对并回填" : "施工回填"}
|
|
|
- <ArrowRight size={16} />
|
|
|
- </Button>
|
|
|
- ) : (
|
|
|
- <Button variant="outline" onClick={() => navigate(`/work-orders/${encodeURIComponent(id)}`, { state: linkState })}>
|
|
|
- 打开完整详情
|
|
|
- </Button>
|
|
|
- )}
|
|
|
- </div>
|
|
|
- </>
|
|
|
- )}
|
|
|
+ const canBackfill = d?.actions.backfill || d?.actions.check_and_backfill;
|
|
|
+ const deadline = t && todoRowDeadline(t);
|
|
|
+ const fullPhone = d?.customer?.contact_mobile_full?.trim();
|
|
|
+ return <main className="field-page">
|
|
|
+ <MobileHeader title="工单详情" backLabel={backLabel} onBack={onBack} />
|
|
|
+ <div className="field-content">
|
|
|
+ {location.state?.notice && <p className="field-notice" role="status"><CheckCircle2 size={17} />{location.state.notice}</p>}
|
|
|
+ {detail.loading && <p className="field-state" role="status">正在读取工单…</p>}
|
|
|
+ {detail.error && <TicketState fail={classifyTicketError(detail.error)} onRetry={detail.reload} />}
|
|
|
+ {t && d && !detail.error && <>
|
|
|
+ <section className="field-ticket">
|
|
|
+ <div className="field-row-meta"><TicketTypeTag type={t.ticket_type} /><TicketStatusTag status={t.status} type={t.ticket_type} /></div>
|
|
|
+ <h2>{t.title || d.customer?.customer_name || "工单详情"}</h2>
|
|
|
+ <p className="field-serial">{t.ticket_no}</p>
|
|
|
+ {deadline?.date && <p className="field-date"><CalendarDays size={16} />{deadlineLabels[deadline.kind]}<time dateTime={deadline.date}>{deadline.date}</time></p>}
|
|
|
+ </section>
|
|
|
+ <section className="field-panel"><h2><MapPin size={17} />现场信息</h2>
|
|
|
+ <dl><div><dt>客户</dt><dd>{d.customer?.customer_name || t.customer_id || "—"}</dd></div>
|
|
|
+ <div><dt>施工地址</dt><dd>{d.customer?.address || "未登记"}</dd></div>
|
|
|
+ <div><dt>联系人</dt><dd>{d.customer?.contact_name || "未登记"}
|
|
|
+ {fullPhone && /^[+\d][\d ()-]+$/.test(fullPhone)
|
|
|
+ ? <a className="field-phone" href={`tel:${fullPhone.replace(/[ ()-]/g, "")}`}><Phone size={15} />{fullPhone}</a>
|
|
|
+ : d.customer?.contact_mobile && <span className="field-contact">{d.customer.contact_mobile}</span>}
|
|
|
+ </dd></div></dl>
|
|
|
+ </section>
|
|
|
+ {t.detail && <section className="field-panel"><h2>事项描述</h2><p className="field-description">{t.detail}</p></section>}
|
|
|
+ {d.construction_guide && <details className="field-fold"><summary>施工指导<ChevronDown size={17} /></summary><ConstructionGuidePanel guide={d.construction_guide} /></details>}
|
|
|
+ <details className="field-fold"><summary>处理记录 <small>{d.process_logs.length} 条</small><ChevronDown size={17} /></summary>
|
|
|
+ {d.process_logs.length ? <LogPanel logs={d.process_logs} /> : <p className="field-meta">暂无处理记录</p>}
|
|
|
+ </details>
|
|
|
+ </>}
|
|
|
</div>
|
|
|
- );
|
|
|
+ {d && !detail.error && <footer className="field-bar">
|
|
|
+ <Link className={canBackfill ? "field-secondary" : "field-primary"} to={`/work-orders/${encodeURIComponent(id)}`} state={linkState}>打开完整详情</Link>
|
|
|
+ {canBackfill && <Link className="field-primary" to={`/m/work-orders/${encodeURIComponent(id)}/backfill`} state={linkState}>
|
|
|
+ {d.actions.check_and_backfill ? "核对并回填" : "施工回填"}<ArrowRight size={17} /></Link>}
|
|
|
+ </footer>}
|
|
|
+ </main>;
|
|
|
}
|
|
|
|
|
|
-/** 全屏回填:无 AppShell,直接挂桌面回填表单(`presentation=page`),⛔ 再嵌一整页桌面详情。 */
|
|
|
export function MobileWorkOrderBackfillPage() {
|
|
|
const location = useLocation();
|
|
|
const { id } = useParams();
|
|
|
@@ -150,73 +161,27 @@ export function MobileWorkOrderBackfillPage() {
|
|
|
if (identity && !MINE_ROLES.includes(identity.role)) return <Navigate to="/work-orders" replace />;
|
|
|
if (!id) return <Navigate to="/m/work-orders/mine" replace />;
|
|
|
const back = detailBack(location.state, `/m/work-orders/${encodeURIComponent(id)}`, "返回详情");
|
|
|
- return <MobileBackfillInner id={id} onLeave={(msg) => {
|
|
|
+ return <MobileBackfillInner key={id} id={id} onLeave={(msg) => {
|
|
|
navigate(back.to, { replace: true, state: msg ? { ...(back.state as object | null), notice: msg } : back.state });
|
|
|
}} />;
|
|
|
}
|
|
|
|
|
|
function MobileBackfillInner({ id, onLeave }: { id: string; onLeave: (msg?: string) => void }) {
|
|
|
const detail = useTicketDetail(id, true);
|
|
|
- const [notice, setNotice] = useState("");
|
|
|
- const fail = detail.error ? classifyTicketError(detail.error) : null;
|
|
|
const d = detail.data;
|
|
|
- const can = d?.actions;
|
|
|
- const backfillReady = Boolean(can?.backfill || can?.check_and_backfill);
|
|
|
-
|
|
|
- if (detail.loading) {
|
|
|
- return (
|
|
|
- <div className="wo-m-page">
|
|
|
- <header className="wo-m-top">
|
|
|
- <Button variant="ghost" size="sm" type="button" onClick={() => onLeave()}><ArrowLeft size={16} /></Button>
|
|
|
- <h1>施工回填</h1>
|
|
|
- </header>
|
|
|
- <p className="wo-m-body">加载中…</p>
|
|
|
- </div>
|
|
|
- );
|
|
|
- }
|
|
|
- if (fail || !d) {
|
|
|
- return (
|
|
|
- <div className="wo-m-page">
|
|
|
- <header className="wo-m-top">
|
|
|
- <Button variant="ghost" size="sm" type="button" onClick={() => onLeave()}><ArrowLeft size={16} /></Button>
|
|
|
- <h1>施工回填</h1>
|
|
|
- </header>
|
|
|
- <div className="wo-m-body">{fail && <TicketState fail={fail} onRetry={detail.reload} />}</div>
|
|
|
- </div>
|
|
|
- );
|
|
|
- }
|
|
|
- if (!backfillReady) {
|
|
|
- return (
|
|
|
- <div className="wo-m-page">
|
|
|
- <header className="wo-m-top">
|
|
|
- <Button variant="ghost" size="sm" type="button" onClick={() => onLeave()}><ArrowLeft size={16} /></Button>
|
|
|
- <h1>施工回填</h1>
|
|
|
- </header>
|
|
|
- <div className="wo-m-body">
|
|
|
- <p>该动作当前不可执行(服务端未开放)。</p>
|
|
|
- <Button variant="outline" onClick={() => onLeave()}>返回详情</Button>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- );
|
|
|
+ if (d && !detail.error && (d.actions.backfill || d.actions.check_and_backfill)) {
|
|
|
+ return <main className="field-page wo-m-backfill-host">
|
|
|
+ <TicketActionSheet action="backfill" detail={d} presentation="page" onReload={detail.reload} onClose={() => onLeave()} onDone={onLeave} />
|
|
|
+ </main>;
|
|
|
}
|
|
|
-
|
|
|
- return (
|
|
|
- <div className="wo-m-page wo-m-backfill-host">
|
|
|
- {notice && <p className="wo-m-body" role="status" style={{ paddingBottom: 0 }}>{notice}</p>}
|
|
|
- <TicketActionSheet
|
|
|
- action="backfill"
|
|
|
- detail={d}
|
|
|
- presentation="page"
|
|
|
- onReload={detail.reload}
|
|
|
- onClose={() => onLeave()}
|
|
|
- onDone={(msg) => {
|
|
|
- setNotice(msg);
|
|
|
- detail.reload();
|
|
|
- onLeave(msg);
|
|
|
- }}
|
|
|
- />
|
|
|
+ return <main className="field-page">
|
|
|
+ <MobileHeader title="施工回填" backLabel="返回详情" onBack={() => onLeave()} />
|
|
|
+ <div className="field-content">
|
|
|
+ {detail.loading ? <p className="field-state" role="status">正在读取施工资料…</p>
|
|
|
+ : detail.error ? <TicketState fail={classifyTicketError(detail.error)} onRetry={detail.reload} />
|
|
|
+ : <p className="field-state">当前工单暂不可回填。</p>}
|
|
|
</div>
|
|
|
- );
|
|
|
+ </main>;
|
|
|
}
|
|
|
|
|
|
/** 桌面「我的待办」入口提示。 */
|