Эх сурвалжийг харах

feat(web): 重设计对账清单详情页

sy 2 өдөр өмнө
parent
commit
575df1de86

+ 0 - 1
web-scaffold/src/lib/copy-billing.ts

@@ -193,7 +193,6 @@ export function saveReconExportCsv(r: ReconExportResult): boolean {
 
 /** 「本批仍有未完成开户工单」格文案(0 个缺口与取数失败是两格,A25)。 */
 export const TICKET_GAP_LABEL = "本批仍有未完成开户工单";
-export const ticketGapText = (n: number): string => `${n} 个`;
 
 /** ③-1 期次出账进度展开开关文案。 */
 export const PROGRESS_EXPAND = "展开各分成方明细";

+ 219 - 186
web-scaffold/src/pages/SettlementRecordPages.tsx

@@ -10,7 +10,7 @@
  */
 import { useEffect, useId, useState, type FormEvent, type ReactNode } from "react";
 import { PageIntro } from "../components/PageIntro";
-import { ArrowLeft, ArrowRight, Building2, Calculator, CalendarClock, CalendarDays, ChevronDown, CircleDollarSign, Download, FileSpreadsheet, ListFilter, Receipt, RefreshCw, ScrollText, Search, TriangleAlert, X } from "lucide-react";
+import { ArrowLeft, ArrowRight, Building2, Calculator, CalendarClock, CalendarDays, ChevronDown, CircleDollarSign, ClipboardList, Download, FilePenLine, FileSpreadsheet, ListFilter, Receipt, RefreshCw, ScrollText, Search, TriangleAlert, X } from "lucide-react";
 import { Link, useLocation, useNavigate, useParams, useSearchParams } from "react-router";
 import { Button } from "../components/ui/button";
 import { SearchInput } from "../components/ui/search-input";
@@ -59,7 +59,6 @@ import {
   saveReconExportCsv,
   STAT_CARDS,
   TICKET_GAP_LABEL,
-  ticketGapText,
   TRIGGER_TYPE_TEXT,
   VOIDED_BY_PREFIX,
   ZERO_NOTE_TEXT,
@@ -546,224 +545,258 @@ export function SettlementStatementListPage() {
 
 /* ── 批次详情(14.2) ───────────────────────────────────────────── */
 
+const batchRecordTabs = [
+  { id: "overview", label: "批次概况" },
+  { id: "bills", label: "账单明细" },
+  { id: "execution", label: "执行与追溯" },
+] as const;
+type BatchRecordTab = typeof batchRecordTabs[number]["id"];
+
 export function SettlementStatementRecordPage() {
+  const { no } = useParams();
+  return <BatchRecordPage key={no} no={no} />;
+}
+
+function BatchRecordPage({ no }: { no?: string }) {
   const identity = useDemoIdentity();
   const navigate = useNavigate();
   const location = useLocation();
-  const outgoingState = useDetailLinkState();
-  const { no } = useParams();
   const back = detailBack(location.state, "/settlement-batches", BACK_TO_RECON_LIST);
+  const [tab, setTab] = useState<BatchRecordTab>(() =>
+    batchRecordTabs.find(({ id }) => id === location.state?.statementTab)?.id ?? "overview");
+  const outgoingState = detailLinkState(location.pathname + location.search + location.hash, { ...location.state, statementTab: tab });
 
   const detail = useReconDetail(no ?? null);
-  const d = detail.data;
+  const batch = detail.data;
   const wiring = detail.fail?.kind === "wiring";
   const isAdmin = !identity || identity.role === "admin";
+  const flagsPending = batch != null && (batch.can_export == null || (isAdmin && (batch.can_rerun == null || batch.can_correct == null)));
 
   const [confirmRerun, setConfirmRerun] = useState(false);
   const [rerunError, setRerunError] = useState("");
-  const [busy, setBusy] = useState(false);
+  const [rerunning, setRerunning] = useState(false);
+  const [exporting, setExporting] = useState(false);
   const [notice, setNotice] = useState("");
 
-  function runRerun() {
-    if (!d) return;
-    setBusy(true);
+  async function runRerun(event: FormEvent<HTMLFormElement>) {
+    event.preventDefault();
+    if (!batch || !isAdmin || batch.can_rerun !== true || rerunning) return;
+    setRerunning(true);
     setRerunError("");
-    submitReconRerun({ holder_type: d.holder_type, holder_id: d.holder_id, period: d.period })
-      .then((res) => {
-        setConfirmRerun(false);
-        // 补跑成功 ⇒ 原批次作废、生成新批;直接落到新批详情(来路保留)。
-        navigate(batchPath(d.holder_id, res.batch_no), { state: outgoingState });
-      })
-      .catch((e: unknown) => {
-        // 四道闸(60502→60503→60504→60506)/KLT-S407:文案直读后端 message。
-        setRerunError(e instanceof Error && e.message ? e.message : "补跑失败,请重试。");
-        setBusy(false);
-      });
+    try {
+      const result = await submitReconRerun({ holder_type: batch.holder_type, holder_id: batch.holder_id, period: batch.period });
+      setConfirmRerun(false);
+      navigate(batchPath(batch.holder_id, result.batch_no), { state: outgoingState });
+    } catch (error) {
+      setRerunError(error instanceof Error && error.message ? error.message : "补跑失败,请重试。");
+    } finally {
+      setRerunning(false);
+    }
+  }
+
+  async function exportDetail() {
+    if (!batch || batch.can_export !== true || exporting) return;
+    setExporting(true);
+    try {
+      const result = await reconExportDetail({ batch_id: batch.batch_no });
+      setNotice(saveReconExportCsv(result) ? exportResultNote(result) : EXPORT_EMPTY_NOTE);
+    } catch (error) {
+      setNotice(error instanceof Error && error.message ? error.message : WORD_FETCH_FAILED);
+    } finally {
+      setExporting(false);
+    }
   }
 
-  function exportDetail() {
-    if (!d) return;
-    reconExportDetail({ batch_id: d.batch_no })
-      .then((res) => setNotice(saveReconExportCsv(res) ? exportResultNote(res) : EXPORT_EMPTY_NOTE))
-      .catch((e: unknown) => setNotice(e instanceof Error && e.message ? e.message : WORD_FETCH_FAILED));
+  function closeRerun() {
+    if (!rerunning) setConfirmRerun(false);
   }
 
+  const batchNumber = batch?.batch_no ?? no;
   return (
-    <article className="ops-page reconcile-record">
+    <article className="ops-page ops-record-page record-detail batch-record">
       <Link className="ops-back-link" to={back.to} state={back.state}><ArrowLeft size={16} aria-hidden="true" />{back.label.replace(/^←\s*/, "")}</Link>
+      <header className="customer-record-masthead batch-record-masthead">
+        <div className="customer-hero-symbol" aria-hidden="true"><FileSpreadsheet size={26} /></div>
+        <div className="customer-hero-copy">
+          <p className="customer-record-id">RECONCILIATION{batchNumber && <><span aria-hidden="true">·</span><span>{batchNumber}</span></>}</p>
+          <h1 className="customer-record-title">对账清单详情</h1>
+          {batch && <div className="customer-record-tags batch-record-context">
+            <OpsStatus tone={batchTone[batch.status]}>{BATCH_STATUS_TEXT[batch.status]}</OpsStatus>
+            <span className="customer-record-meta">
+              <OpsTag tone={holderTone[batch.holder_type]}>{HOLDER_TYPE_TEXT[batch.holder_type]}</OpsTag>
+              {batch.holder_name && <strong>{batch.holder_name}</strong>}
+            </span>
+            <span className="customer-record-meta"><CalendarDays size={14} aria-hidden="true" /><span>自然月 {batch.period}</span></span>
+          </div>}
+        </div>
+        {batch && <div className="batch-record-actions">
+          <Button variant="outline" onClick={exportDetail} disabled={batch.can_export !== true || exporting}
+            title={batch.can_export == null ? ACTION_FLAG_PENDING_NOTE : undefined}>
+            <Download size={15} aria-hidden="true" />{exporting ? "正在导出…" : "导出本批账单明细"}
+          </Button>
+          {isAdmin && <>
+            <Button variant="outline" disabled={batch.can_rerun !== true}
+              title={batch.can_rerun == null ? ACTION_FLAG_PENDING_NOTE : undefined}
+              onClick={() => { setRerunError(""); setConfirmRerun(true); }}>
+              <RefreshCw size={15} aria-hidden="true" />人工补跑
+            </Button>
+            <Button variant="outline" disabled={batch.can_correct !== true}
+              title={batch.can_correct == null ? ACTION_FLAG_PENDING_NOTE : undefined}
+              onClick={() => navigate("/correction-notes", { state: { ...outgoingState, ref: batch.batch_no } })}>
+              <FilePenLine size={15} aria-hidden="true" />登记更正
+            </Button>
+          </>}
+        </div>}
+      </header>
 
       {wiring && <p className="ops-import-note" role="status">{RECON_WIRING_NOTE}</p>}
-      {detail.fail && !wiring && (
-        <p className="ops-form-error" role="alert">{detail.fail.message} <Button variant="ghost" size="sm" onClick={detail.reload}>重试</Button></p>
-      )}
-
-      {/* 契约占位分支:八字段头结构落位、值格「后端未下发」。 */}
-      {(wiring || (!d && detail.loading)) && (
-        <header className="reconcile-record-hero">
-          <div className="reconcile-record-symbol"><FileSpreadsheet size={27} /></div>
-          <div>
-            <span className="reconcile-record-eyebrow">RECONCILIATION / {no}</span>
-            <h1>批次详情</h1>
-            <p>{detail.loading && !wiring ? "加载中…" : BACKEND_NOT_WIRED}</p>
-          </div>
-        </header>
-      )}
-
-      {d && <BatchDetailBody
-        d={d}
-        isAdmin={isAdmin}
-        onRerun={() => { setRerunError(""); setConfirmRerun(true); }}
-        onExport={exportDetail}
-        onCorrect={() => navigate("/correction-notes", { state: { ...outgoingState, ref: d.batch_no } })}
-        lineState={outgoingState}
-      />}
-
-      {confirmRerun && d && (
-        <div className="ops-confirm-backdrop" role="presentation" onMouseDown={() => !busy && setConfirmRerun(false)}>
-          <div className="ops-confirm" role="alertdialog" aria-modal="true" aria-labelledby="rerun-confirm-title" onMouseDown={(event) => event.stopPropagation()}>
-            <h2 id="rerun-confirm-title">{RERUN_DIALOG_TITLE}</h2>
-            <p>{rerunScopeLine(d.holder_name, d.period)}</p>
-            {/* failed 批补跑区追加句(§8.6 界面唯一落点之一)。 */}
-            {d.status === "failed" && <p>{RERUN_VOID_NOTE}</p>}
-            {rerunError && <p className="ops-form-error" role="alert">{rerunError}</p>}
-            <div>
-              <Button variant="outline" onClick={() => setConfirmRerun(false)} disabled={busy}>取消</Button>
-              <Button onClick={runRerun} disabled={busy}>{busy ? "提交中…" : RERUN_SUBMIT}</Button>
+      {detail.fail && !wiring && <p className="ops-form-error" role="alert">
+        {detail.fail.message} <Button variant="ghost" size="sm" onClick={detail.reload}>重试</Button>
+      </p>}
+      {!batch && detail.loading && !wiring && <p className="batch-record-note" role="status">正在读取对账批次…</p>}
+      {batch && <BatchRecordContent batch={batch} tab={tab} onTabChange={setTab} linkState={outgoingState} flagsPending={flagsPending} />}
+
+      {confirmRerun && batch && <OpsDialog title={RERUN_DIALOG_TITLE} className="statement-run-dialog" onClose={closeRerun}>
+        <form onSubmit={runRerun} aria-busy={rerunning}>
+          <div className="statement-run-body">
+            <div className="statement-run-scope">
+              <CalendarClock size={19} aria-hidden="true" />
+              <strong>{rerunScopeLine(batch.holder_name, batch.period)}</strong>
             </div>
+            {batch.status === "failed" && <div className="statement-run-impact">
+              <TriangleAlert size={16} aria-hidden="true" /><p>{RERUN_VOID_NOTE}</p>
+            </div>}
+            {rerunError && <p className="ops-form-error statement-run-error" role="alert">{rerunError}</p>}
           </div>
-        </div>
-      )}
+          <footer>
+            <Button variant="outline" type="button" onClick={closeRerun} disabled={rerunning}>取消</Button>
+            <Button type="submit" disabled={rerunning || batch.can_rerun !== true}>{rerunning ? "正在补跑…" : RERUN_SUBMIT}</Button>
+          </footer>
+        </form>
+      </OpsDialog>}
       {notice && <OpsNotice message={notice} onClose={() => setNotice("")} />}
     </article>
   );
 }
 
-function BatchDetailBody({ d, isAdmin, onRerun, onExport, onCorrect, lineState }: {
-  d: ReconDetailResult;
-  isAdmin: boolean;
-  onRerun: () => void;
-  onExport: () => void;
-  onCorrect: () => void;
-  lineState: DetailLinkState;
-}) {
-  // 动作可用性=服务端布尔位(与对账§5.5.4 同源常量;⚠️ 前端按角色自猜=第二套判据)。
-  // null ⇒ 后端未下发 ⇒ 禁用+「可操作性位后端未下发」说明。
-  const rerunEnabled = isAdmin && d.can_rerun === true;
-  const exportEnabled = d.can_export === true;
-  const correctEnabled = isAdmin && d.can_correct === true;
-  const flagPending = d.can_rerun == null || d.can_export == null || d.can_correct == null;
-  return (
-    <>
-      <header className="reconcile-record-hero">
-        <div className="reconcile-record-symbol"><FileSpreadsheet size={27} /></div>
-        <div>
-          <span className="reconcile-record-eyebrow">RECONCILIATION / {d.batch_no}</span>
-          <h1>批次详情</h1>
-          <p>
-            <strong>{d.holder_name}</strong>
-            <span>{HOLDER_TYPE_TEXT[d.holder_type]}</span>
-            <span>自然月 {d.period}</span>
-            <span>{TRIGGER_TYPE_TEXT[d.trigger_type]}触发 · {executorText(d)}执行</span>
-          </p>
-          <div className="reconcile-hero-pills">
-            <OpsStatus tone={batchTone[d.status]}>{BATCH_STATUS_TEXT[d.status]}</OpsStatus>
-            <OpsTag tone={d.trigger_type === "manual" ? "warning" : "neutral"}>{TRIGGER_TYPE_TEXT[d.trigger_type]}触发</OpsTag>
-          </div>
-        </div>
-      </header>
+function BatchRecordPanel({ tab, active, children }: { tab: BatchRecordTab; active: BatchRecordTab; children: ReactNode }) {
+  return <section className="ops-record-card record-tab-panel batch-record-panel" id={`batch-record-panel-${tab}`}
+    role="tabpanel" aria-labelledby={`batch-record-tab-${tab}`} tabIndex={0} hidden={active !== tab}>
+    {children}
+  </section>;
+}
 
-      <div className="reconcile-record-stats">
-        <div><span>明细条数</span><strong>{d.detail_count}</strong><small>本批有效行现算,作废行不计</small></div>
-        <div><span>总金额</span><strong>{moneyFromCents(d.base_cents)}</strong><small>本批有效行应收基数合计</small></div>
-        <div><span>分成金额</span><strong>{moneyFromCents(d.share_cents)}</strong><small>本批有效行分成金额合计</small></div>
-        <div>
-          <span>{TICKET_GAP_LABEL}</span>
-          <strong>{d.ticket_gap_failed ? WORD_FETCH_FAILED : d.ticket_gap_count == null ? BACKEND_NOT_WIRED : ticketGapText(d.ticket_gap_count)}</strong>
-          <small>{TICKET_GAP_LABEL}按工单台账现算(0 个缺口与取数失败是两回事)</small>
-        </div>
+function BatchRecordContent({ batch, tab, onTabChange, linkState, flagsPending }: {
+  batch: ReconDetailResult;
+  tab: BatchRecordTab;
+  onTabChange: (tab: BatchRecordTab) => void;
+  linkState: DetailLinkState;
+  flagsPending: boolean;
+}) {
+  const missing = <span className="table-placeholder">—</span>;
+  const gapText = batch.ticket_gap_failed ? WORD_FETCH_FAILED : BACKEND_NOT_WIRED;
+  const gapCount = batch.ticket_gap_failed ? null : batch.ticket_gap_count;
+  const tabs = batchRecordTabs.map((item) => ({ ...item, count: item.id === "bills" ? batch.detail_count : undefined }));
+  return <>
+    <dl className="customer-record-metrics batch-record-metrics" aria-label="批次统计">
+      <div>
+        <dt><ClipboardList size={16} aria-hidden="true" />明细条数</dt>
+        <dd><strong>{batch.detail_count}</strong><span className="batch-record-unit">条</span></dd>
       </div>
+      <div>
+        <dt><Receipt size={16} aria-hidden="true" />总金额</dt>
+        <dd><strong>{moneyFromCents(batch.base_cents)}</strong><small>本批有效账单的分成基数合计</small></dd>
+      </div>
+      <div className="batch-record-metric-primary">
+        <dt><CircleDollarSign size={16} aria-hidden="true" />分成金额</dt>
+        <dd><strong>{moneyFromCents(batch.share_cents)}</strong></dd>
+      </div>
+      <div>
+        <dt><ScrollText size={16} aria-hidden="true" />{TICKET_GAP_LABEL}</dt>
+        <dd>{gapCount == null ? <span className="batch-record-unavailable">{gapText}</span>
+          : <><strong>{gapCount}</strong><span className="batch-record-unit">个</span></>}</dd>
+      </div>
+    </dl>
 
-      <section className="reconcile-record-section">
-        <div className="reconcile-record-section-head">
-          <div><h2>执行结果</h2><p>批次动作与执行说明。</p></div>
-          <div style={{ display: "flex", gap: 8 }}>
-            {isAdmin && (
-              <Button variant="outline" onClick={onRerun} disabled={!rerunEnabled} title={d.can_rerun == null ? ACTION_FLAG_PENDING_NOTE : undefined}>人工补跑</Button>
-            )}
-            <Button variant="outline" onClick={onExport} disabled={!exportEnabled} title={d.can_export == null ? ACTION_FLAG_PENDING_NOTE : undefined}>
-              <Download size={15} />导出本批账单明细
-            </Button>
-            {isAdmin && (
-              <Button variant="outline" onClick={onCorrect} disabled={!correctEnabled} title={d.can_correct == null ? ACTION_FLAG_PENDING_NOTE : undefined}>登记更正</Button>
-            )}
-          </div>
-        </div>
-        {flagPending && <p className="reconcile-footnote">{ACTION_FLAG_PENDING_NOTE},动作暂不可用。</p>}
-        {/* 失败原因只在 failed/voided 时渲染;voided 必带「由哪一次补跑作废」链接。 */}
-        {(d.status === "failed" || d.status === "voided") && d.fail_reason && (
-          <p className="ops-form-error" role="alert">{d.fail_reason}</p>
-        )}
-        {d.status === "voided" && d.voided_by_batch_no && (
-          <p className="reconcile-footnote">
-            {VOIDED_BY_PREFIX}
-            <Link className="ops-table-action" to={batchPath(d.holder_id, d.voided_by_batch_no)} state={lineState}>{d.voided_by_batch_no} <ArrowRight size={14} /></Link>
-            作废。
-          </p>
-        )}
-        {/* 成本未配置提示一行(不发通知、不建提醒表;不说"异常")。 */}
-        {d.cost_unconfigured.length > 0 && (
-          <p className="reconcile-footnote">{COST_UNCONFIGURED_NOTE}:{d.cost_unconfigured.join("、")}</p>
-        )}
-      </section>
-
-      <section className="reconcile-record-section">
-        <div className="reconcile-record-section-head">
-          <span>01</span>
-          <div><h2>本批账单明细</h2><p>{d.holder_name} · {d.period} · {d.detail_count} 条</p></div>
-        </div>
-        <div className="ops-table-wrap">
-          <table className="ops-table" style={{ minWidth: 980 }}>
-            <thead><tr><th>客户</th><th>订阅标识</th><th>应收金额</th><th>分成基数</th><th>分成方式与取值</th><th>本方分成金额</th><th>恒 0 说明</th><th>操作</th></tr></thead>
-            <tbody>
-              {d.items.map((line) => (
-                <tr key={line.bill_detail_id}>
-                  <td><strong>{line.customer_name}</strong></td>
-                  <td>{line.subscription_label}</td>
-                  <td><span className="ops-money">{moneyFromCents(line.receivable_cents)}</span></td>
-                  <td><span className="ops-money">{moneyFromCents(line.share_base_cents)}</span></td>
-                  <td className="table-number">{settleTextFromSnapshot(line.share_mode, line.share_value)}</td>
-                  <td><strong className="reconcile-money">{moneyFromCents(line.share_amount_cents)}</strong></td>
-                  {/* zero_note 如实展示并解释为什么是 0(⛔ 隐藏 0 金额行)。 */}
-                  <td>{line.zero_note ? ZERO_NOTE_TEXT[line.zero_note] : <span className="table-placeholder">—</span>}</td>
-                  <td>
-                    <Link className="ops-table-action" to={`/settlement-bills/${encodeURIComponent(line.bill_detail_id)}`} state={lineState}>
-                      详情
-                    </Link>
-                  </td>
-                </tr>
-              ))}
-              {!d.items.length && <OpsTableEmpty colSpan={8}>本批无明细行。</OpsTableEmpty>}
-            </tbody>
-          </table>
-        </div>
-      </section>
-
-      <section className="reconcile-record-section">
-        <div className="reconcile-record-section-head"><span>02</span><div><h2>执行与口径</h2><p>批次八字段头与状态说明。</p></div></div>
-        <dl className="reconcile-record-facts">
-          <div><dt>对账单号</dt><dd>{d.batch_no}</dd></div>
-          <div><dt>分成方</dt><dd>{d.holder_name} · {HOLDER_TYPE_TEXT[d.holder_type]}</dd></div>
-          <div><dt>自然月</dt><dd>{d.period}</dd></div>
-          <div><dt>应出账日期</dt><dd title="该分成方该自然月的应出账日期=自然月次月的对账日;「每月 N 日」的对账日口径见「出账配置」">{d.recon_date ?? "—"}</dd></div>
-          <div><dt>批次状态</dt><dd>{BATCH_STATUS_TEXT[d.status]}</dd></div>
-          <div><dt>执行人</dt><dd title={d.operator_user_id ?? undefined}>{executorText(d)}</dd></div>
-          <div><dt>执行时间</dt><dd title={d.executed_at ?? undefined}>{d.executed_at ? localTime(d.executed_at) : "—"}</dd></div>
-          <div><dt>触发方式</dt><dd>{TRIGGER_TYPE_TEXT[d.trigger_type]}</dd></div>
+    <div className="record-tabs-frame">
+      <RecordTabs prefix="batch-record" label="对账清单详情视图" tabs={tabs} active={tab} onChange={onTabChange} />
+      <BatchRecordPanel tab="overview" active={tab}>
+        <dl className="ops-record-summary batch-record-facts">
+          <div><dt>对账单号</dt><dd>{batch.batch_no}</dd></div>
+          <div><dt>分成方</dt><dd>{batch.holder_name || missing}</dd></div>
+          <div><dt>自然月</dt><dd>{batch.period}</dd></div>
+          <div><dt>应出账日期</dt><dd title="该自然月次月的对账日">{batch.recon_date || missing}</dd></div>
         </dl>
-        <p className="reconcile-footnote">状态以批次当前记录为准。执行失败的批次由总运营补跑;账单差错通过出账更正登记。</p>
-      </section>
-    </>
-  );
+        {batch.cost_unconfigured.length > 0 && <div className="batch-record-note batch-record-note-warning" role="note">
+          <TriangleAlert size={16} aria-hidden="true" />
+          <p>{COST_UNCONFIGURED_NOTE}:{batch.cost_unconfigured.join("、")}</p>
+        </div>}
+      </BatchRecordPanel>
+
+      <BatchRecordPanel tab="bills" active={tab}>
+        <BatchBillingTable items={batch.items} linkState={linkState} />
+      </BatchRecordPanel>
+
+      <BatchRecordPanel tab="execution" active={tab}>
+        <dl className="ops-record-summary batch-record-facts">
+          <div><dt>批次状态</dt><dd><OpsStatus tone={batchTone[batch.status]}>{BATCH_STATUS_TEXT[batch.status]}</OpsStatus></dd></div>
+          <div><dt>触发方式</dt><dd>{TRIGGER_TYPE_TEXT[batch.trigger_type]}</dd></div>
+          <div><dt>执行人</dt><dd title={batch.operator_user_id ?? undefined}>{executorText(batch)}</dd></div>
+          <div><dt>执行时间</dt><dd title={batch.executed_at ?? undefined}>{batch.executed_at ? localTime(batch.executed_at) : missing}</dd></div>
+        </dl>
+        {(batch.status === "failed" || batch.status === "voided") && batch.fail_reason && <div className="batch-record-note batch-record-note-error" role="alert">
+          <TriangleAlert size={16} aria-hidden="true" /><p>{batch.fail_reason}</p>
+        </div>}
+        {batch.status === "voided" && batch.voided_by_batch_no && <div className="batch-record-note" role="note">
+          <p>{VOIDED_BY_PREFIX} <Link className="ops-table-action" to={batchPath(batch.holder_id, batch.voided_by_batch_no)} state={linkState}>
+            {batch.voided_by_batch_no}<ArrowRight size={14} aria-hidden="true" />
+          </Link> 作废。</p>
+        </div>}
+        {flagsPending && <div className="batch-record-note" role="note"><p>{ACTION_FLAG_PENDING_NOTE},动作暂不可用。</p></div>}
+      </BatchRecordPanel>
+    </div>
+  </>;
+}
+
+const batchBillColumns: readonly SettlementLedgerColumn[] = [
+  { label: "客户", width: 160 },
+  { label: "订阅标识", width: 180 },
+  { label: "应收金额", width: 104, numeric: true },
+  { label: "分成基数", width: 104, numeric: true },
+  { label: "分成方式与取值", width: 124 },
+  { label: "本方分成金额", width: 120, numeric: true },
+  { label: "恒 0 说明", width: 132 },
+];
+
+function BatchBillingTable({ items, linkState }: { items: ReconDetailResult["items"]; linkState: DetailLinkState }) {
+  const table = useSettlementLedgerTable(batchBillColumns);
+  return <div className={`${table.className} batch-record-table`} role="region" aria-label="本批账单明细,可横向滚动查看字段" tabIndex={0} ref={table.ref}>
+    <table className="ops-table settlement-ledger" style={{ minWidth: table.minWidth }} aria-label="本批账单明细">
+      <OpsTableColumns widths={table.widths} />
+      <SettlementLedgerHead columns={batchBillColumns} />
+      <tbody>
+        {items.map((line) => {
+          const shareRule = settleTextFromSnapshot(line.share_mode, line.share_value);
+          const zeroNote = line.zero_note ? ZERO_NOTE_TEXT[line.zero_note] : undefined;
+          return <tr key={line.bill_detail_id}>
+            <td><strong className="table-cell-title" title={line.customer_name}>{line.customer_name}</strong></td>
+            <td><strong className="table-cell-title" title={line.subscription_label}>{line.subscription_label}</strong></td>
+            <td className="settlement-ledger-number"><span className="ops-money">{moneyFromCents(line.receivable_cents)}</span></td>
+            <td className="settlement-ledger-number"><span className="ops-money">{moneyFromCents(line.share_base_cents)}</span></td>
+            <td className="table-number" title={shareRule}>{shareRule}</td>
+            <td className="settlement-ledger-number"><span className="ops-money settlement-ledger-share">{moneyFromCents(line.share_amount_cents)}</span></td>
+            <td title={zeroNote}>{zeroNote ?? <span className="table-placeholder">—</span>}</td>
+            <td className="settlement-ledger-action">
+              <Link className="ops-table-action" to={`/settlement-bills/${encodeURIComponent(line.bill_detail_id)}`} state={linkState}>
+                详情<ArrowRight size={14} aria-hidden="true" />
+              </Link>
+            </td>
+          </tr>;
+        })}
+        {!items.length && <OpsTableEmpty colSpan={table.widths.length}>本批无明细行。</OpsTableEmpty>}
+      </tbody>
+    </table>
+  </div>;
 }
 
 /* ── FN-08 账单明细(14.3 列表) ─────────────────────────────────── */

+ 102 - 0
web-scaffold/src/pages/__tests__/settlement-statement-record.test.tsx

@@ -0,0 +1,102 @@
+import { cleanup, fireEvent, render, screen, waitFor, within } from "@testing-library/react";
+import { MemoryRouter, Route, Routes } from "react-router";
+import { afterEach, beforeEach, expect, it, vi } from "vitest";
+import { billGetDetail, reconGetDetail, reconRerun } from "../../lib/api/bos";
+import type { ReconDetailResult } from "../../lib/api/types";
+import { SettlementBillRecordPage, SettlementStatementRecordPage } from "../SettlementRecordPages";
+
+vi.mock("../../lib/api/bos", async (load) => ({
+  ...await load<typeof import("../../lib/api/bos")>(),
+  billGetDetail: vi.fn(),
+  reconGetDetail: vi.fn(),
+  reconRerun: vi.fn(),
+}));
+
+const batch: ReconDetailResult = {
+  batch_no: "RECON-001", holder_type: "operator", holder_id: "OP-1", holder_name: "华东运营商",
+  period: "2026-10", recon_date: "2026-11-05", status: "executed", operator_user_id: null,
+  executed_at: "2026-11-05T03:00:00+08:00", fail_reason: null, voided_by_batch_no: null, trigger_type: "auto",
+  detail_count: 1, base_cents: 120000, share_cents: 0, can_rerun: false, can_export: true, can_correct: true,
+  ticket_gap_count: 0, ticket_gap_failed: false, cost_unconfigured: ["线路成本"],
+  items: [{
+    bill_detail_id: "BILL-001", customer_name: "客户甲", subscription_label: "标准套餐", receivable_cents: 130000,
+    share_base_cents: 120000, share_mode: "per_account", share_value: 10, share_amount_cents: 0,
+    zero_note: "no_in_period_account",
+  }],
+};
+
+const { showModal, close } = HTMLDialogElement.prototype;
+beforeEach(() => {
+  vi.stubGlobal("ResizeObserver", class {
+    observe() {}
+    disconnect() {}
+  });
+  Object.assign(HTMLDialogElement.prototype, {
+    showModal(this: HTMLDialogElement) { this.open = true; },
+    close(this: HTMLDialogElement) { this.open = false; },
+  });
+  vi.mocked(billGetDetail).mockImplementation(() => new Promise(() => {}));
+});
+afterEach(() => {
+  cleanup();
+  vi.resetAllMocks();
+  vi.unstubAllGlobals();
+  Object.assign(HTMLDialogElement.prototype, { showModal, close });
+});
+
+function renderBatch() {
+  render(<MemoryRouter initialEntries={[{
+    pathname: "/settlement-batches/OP-1/RECON-001",
+    state: { from: "/settlement-batches?month=2026-10&page=3" },
+  }]}>
+    <Routes>
+      <Route path="/settlement-batches/:partyId/:no" element={<SettlementStatementRecordPage />} />
+      <Route path="/settlement-bills/:index" element={<SettlementBillRecordPage />} />
+    </Routes>
+  </MemoryRouter>);
+  return screen.findByRole("tablist", { name: "对账清单详情视图" });
+}
+
+it("按页签查看批次和账单,从账单详情回到同一页签并保留清单筛选", async () => {
+  vi.mocked(reconGetDetail).mockResolvedValue(batch);
+  const tabs = within(await renderBatch());
+  const overview = tabs.getByRole("tab", { name: "批次概况" });
+  expect(overview.getAttribute("aria-selected")).toBe("true");
+  expect(within(screen.getByRole("tabpanel", { name: "批次概况" })).getByText(/线路成本/)).toBeTruthy();
+  const stats = within(screen.getByLabelText("批次统计"));
+  expect(stats.getByText("0")).toBeTruthy();
+  expect(screen.queryByRole("table", { name: "本批账单明细" })).toBeNull();
+
+  fireEvent.keyDown(overview, { key: "ArrowRight" });
+  const bills = within(screen.getByRole("table", { name: "本批账单明细" }));
+  expect(bills.getByText("按每账号分成,本期无在期分账号")).toBeTruthy();
+  fireEvent.click(bills.getByRole("link", { name: "详情" }));
+  fireEvent.click(await screen.findByRole("link", { name: "返回批次详情" }));
+  expect(await screen.findByRole("tabpanel", { name: /账单明细/ })).toBeTruthy();
+  expect(screen.getByRole("link", { name: "返回对账清单" }).getAttribute("href")).toBe("/settlement-batches?month=2026-10&page=3");
+});
+
+it("用服务端动作位控制按钮,补跑失败可重试,成功后从新批次返回执行页签", async () => {
+  vi.mocked(reconGetDetail).mockImplementation(async (number) => number === "RECON-001" ? {
+    ...batch, status: "failed", fail_reason: "本批读取账单失败", ticket_gap_count: null, ticket_gap_failed: true,
+    can_rerun: true, can_export: null, can_correct: false,
+  } : { ...batch, batch_no: number });
+  vi.mocked(reconRerun).mockRejectedValueOnce(new Error("当前不能补跑")).mockResolvedValueOnce({ batch_no: "RECON-002" });
+  const tabs = within(await renderBatch());
+  expect(screen.getByRole<HTMLButtonElement>("button", { name: "导出本批账单明细" }).disabled).toBe(true);
+  expect(screen.getByRole<HTMLButtonElement>("button", { name: "登记更正" }).disabled).toBe(true);
+  expect(screen.getByText("取数失败")).toBeTruthy();
+
+  fireEvent.click(tabs.getByRole("tab", { name: "执行与追溯" }));
+  expect(screen.getByRole("alert").textContent).toBe("本批读取账单失败");
+  fireEvent.click(screen.getByRole("button", { name: "人工补跑" }));
+  const dialog = within(screen.getByRole("dialog", { name: "确认人工补跑" }));
+  expect(dialog.getByText(/华东运营商.*2026-10/)).toBeTruthy();
+  fireEvent.click(dialog.getByRole("button", { name: "确认补跑" }));
+  expect((await dialog.findByRole("alert")).textContent).toBe("当前不能补跑");
+  fireEvent.click(dialog.getByRole("button", { name: "确认补跑" }));
+  await waitFor(() => expect(reconGetDetail).toHaveBeenLastCalledWith("RECON-002"));
+  expect(reconRerun).toHaveBeenLastCalledWith({ holder_type: "operator", holder_id: "OP-1", period: "2026-10" });
+  fireEvent.click(screen.getByRole("link", { name: "返回批次详情" }));
+  expect(await screen.findByRole("tabpanel", { name: "执行与追溯" })).toBeTruthy();
+});

+ 56 - 35
web-scaffold/src/styles/settlement-records.css

@@ -1,4 +1,4 @@
-.reconcile-index,.bill-index,.reconcile-record { display: grid; gap: 14px; min-width: 0; padding-bottom: 28px; }
+.reconcile-index,.bill-index { display: grid; gap: 14px; min-width: 0; padding-bottom: 28px; }
 /* 锁高页(`.page-fill-window`):网格的自动行不会把剩余高度让给台账,改为纵向 flex,
    台账 `.list-shell-fill` 才能真正 flex:1 吃满一屏、表体内滚(与「运营商管理」同形)。
    `gap` 沿用上一条声明的 14px,flex 下同样生效。 */
@@ -117,36 +117,57 @@
 .reconcile-ledger .ops-table th { white-space: nowrap; }
 .reconcile-money { color: var(--primary); font-variant-numeric: tabular-nums; white-space: nowrap; }
 .reconcile-footnote { margin: 0; padding: 13px 20px 17px; color: var(--text-secondary); font-size: var(--type-support); line-height: 1.6; }
-.reconcile-record > .ops-back-link { width: max-content; margin-bottom: 0; }
-.reconcile-record-hero { display: flex; align-items: center; gap: 18px; min-width: 0; padding: 22px 26px; border: 1px solid var(--border); border-radius: var(--radius-card); background: linear-gradient(180deg, #fcfdfe, var(--card)); box-shadow: var(--shadow-card); }
-.reconcile-record-symbol { display: grid; place-items: center; flex: none; width: 54px; height: 54px; border-radius: 14px; background: var(--primary); color: var(--primary-foreground); }
-.reconcile-record-hero > div:last-child { min-width: 0; }
-.reconcile-record-eyebrow { color: var(--primary); font-size: var(--type-support); font-weight: 750; letter-spacing: .08em; }
-.reconcile-record-hero h1 { margin: 4px 0 8px; font-size: clamp(24px, 2vw, 31px); line-height: 1.2; }
-.reconcile-record-hero p { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 9px; margin: 0 0 10px; color: var(--text-secondary); font-size: var(--type-body); }
-.reconcile-record-hero p strong { color: var(--foreground); }
-.reconcile-record-hero p span { padding-left: 9px; border-left: 1px solid var(--border); }
-.reconcile-hero-pills { display: flex; flex-wrap: wrap; gap: 7px; }
-.reconcile-record-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
-.reconcile-record-stats > div { display: grid; align-content: start; justify-items: start; gap: 6px; min-width: 0; padding: 17px 19px; border: 1px solid var(--border); border-radius: 9px; background: var(--card); }
-.reconcile-record-stats > div:nth-child(2) { border-color: var(--primary-border); background: var(--primary-soft); }
-.reconcile-record-stats span,.reconcile-record-stats small { color: var(--text-secondary); font-size: var(--type-support); }
-.reconcile-record-stats strong { color: var(--primary); font-size: clamp(21px, 1.6vw, 28px); line-height: 1.2; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
-.reconcile-record-section { min-width: 0; padding: 19px 22px 22px; border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--card); box-shadow: var(--shadow-card); }
-.reconcile-record-section-head { display: flex; align-items: center; gap: 10px; margin-bottom: 17px; }
-.reconcile-record-section-head > span { display: grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 6px; background: var(--primary-soft); color: var(--primary); font-size: var(--type-support); font-weight: 800; }
-.reconcile-record-section-head > div { min-width: 0; }
-.reconcile-record-section-head h2 { margin: 0; font-size: var(--type-section); line-height: 1.25; }
-.reconcile-record-section-head p { margin: 3px 0 0; color: var(--text-secondary); font-size: var(--type-support); }
-.reconcile-record-section-head > button { flex: none; margin-left: auto; }
-.reconcile-record-section .ops-table-wrap { border: 1px solid var(--border); border-radius: 7px; }
-.reconcile-record-section .ops-table { width: 100%; }
-.reconcile-record-section .ops-table td { vertical-align: middle; }
-.reconcile-record-section .reconcile-footnote { padding: 14px 0 0; }
-.reconcile-record-facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 22px; margin: 0; }
-.reconcile-record-facts > div { min-width: 0; padding: 10px 0; border-bottom: 1px solid var(--border); }
-.reconcile-record-facts dt { margin-bottom: 5px; color: var(--text-secondary); font-size: var(--type-support); }
-.reconcile-record-facts dd { margin: 0; overflow-wrap: anywhere; font-size: var(--type-body); font-weight: 650; }
+.batch-record { display: grid; align-content: start; gap: 14px; }
+.batch-record > .ops-back-link { justify-self: start; margin: 0; }
+.batch-record .batch-record-masthead, .batch-record .batch-record-metrics { margin: 0; }
+.batch-record-context { gap: 6px 12px; }
+.batch-record-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
+.batch-record-actions button { background: var(--card); }
+.batch-record-actions button:hover:enabled { background: var(--primary-soft); }
+.batch-record-metrics > div.batch-record-metric-primary { background: var(--primary-soft); }
+.batch-record-metrics > div:not(.batch-record-metric-primary) strong { color: var(--foreground); }
+.batch-record-unit { margin-inline-start: 4px; }
+.batch-record-unit, .batch-record-unavailable { color: var(--muted-foreground); font-size: var(--type-support); }
+.batch-record .record-tab-count { color: var(--primary); }
+.batch-record .batch-record-panel { display: grid; align-content: start; gap: 16px; }
+.batch-record-panel:focus-visible { outline: 2px solid var(--ring); outline-offset: -3px; }
+.batch-record .batch-record-facts { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 22px; }
+.batch-record-facts > div { padding: 8px 0 12px; border-bottom: 1px solid var(--border-subtle); }
+.batch-record-facts dd { font-weight: 550; font-variant-numeric: tabular-nums; }
+.batch-record-facts dd > .table-placeholder { color: var(--muted-foreground); font-size: var(--type-support); font-weight: 400; }
+.batch-record-note {
+  display: flex;
+  align-items: flex-start;
+  gap: 8px;
+  min-width: 0;
+  margin: 0;
+  padding: 11px 14px;
+  border-radius: var(--radius-control);
+  background: var(--surface-subtle);
+  color: var(--text-secondary);
+  font-size: var(--type-support);
+  line-height: 1.6;
+  overflow-wrap: anywhere;
+}
+.batch-record-note > :is(svg, p) { margin: 0; }
+.batch-record-note > svg { flex: none; margin-top: 2px; }
+.batch-record-note > p { min-width: 0; }
+.batch-record-note-warning { background: var(--warning-soft); }
+.batch-record-note-warning > svg { color: var(--warning); }
+.batch-record-note-error { background: var(--destructive-soft); color: var(--destructive); }
+.batch-record-note a { white-space: normal; }
+.batch-record-table { min-width: 0; border: 1px solid var(--border); border-radius: var(--radius-control); }
+.batch-record-table tbody tr:last-child td { border-bottom: 0; }
+
+@media (max-width: 1040px) {
+  .batch-record .batch-record-masthead { grid-template-columns: auto minmax(0, 1fr); }
+  .batch-record-actions { grid-column: 1 / -1; justify-content: flex-start; }
+  .batch-record .batch-record-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
+}
+@media (max-width: 600px) {
+  .batch-record .batch-record-panel { padding-inline: 14px; }
+}
+
 .reconcile-empty,.reconcile-empty-line { padding: 24px; border: 1px dashed var(--border); border-radius: 8px; background: var(--card); color: var(--text-secondary); }
 .reconcile-empty h1 { margin: 0 0 5px; color: var(--foreground); font-size: var(--type-section); }
 .reconcile-empty p,.reconcile-empty-line { margin: 0; }
@@ -155,11 +176,11 @@
 .reconcile-bill-association span { color: var(--text-secondary); font-size: var(--type-support); }
 .reconcile-bill-association a { display: inline-flex; align-items: center; gap: 5px; color: var(--primary); font-weight: 750; text-decoration: none; }
 .reconcile-bill-association a:hover { text-decoration: underline; }
-@media (max-width: 1050px) { .reconcile-record-stats,.bill-index-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
+@media (max-width: 1050px) { .bill-index-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
 @media (max-width: 1100px) { .reconcile-totals { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
-@media (max-width: 780px) { .reconcile-totals { grid-template-columns: 1fr; } .reconcile-record-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
-@media (max-width: 650px) { .reconcile-page-heading { align-items: start; } .reconcile-heading-aside { display: none; } .reconcile-record-hero { align-items: flex-start; padding: 18px; } .reconcile-record-hero p span { padding-left: 0; border-left: 0; } .reconcile-record-section { padding: 17px; } .reconcile-record-section-head { flex-wrap: wrap; } .reconcile-record-section-head > button { margin-left: 38px; } .reconcile-filters { padding: 0 16px 16px; } .reconcile-ledger-heading { padding: 17px 16px 13px; } }
-@media (max-width: 430px) { .reconcile-record-stats,.bill-index-summary,.reconcile-record-facts { grid-template-columns: 1fr; } }
+@media (max-width: 780px) { .reconcile-totals { grid-template-columns: 1fr; } }
+@media (max-width: 650px) { .reconcile-page-heading { align-items: start; } .reconcile-heading-aside { display: none; } .reconcile-filters { padding: 0 16px 16px; } .reconcile-ledger-heading { padding: 17px 16px 13px; } }
+@media (max-width: 430px) { .bill-index-summary { grid-template-columns: 1fr; } }
 
 /* 对账清单:金额列按需伸缩,固定编号及唯一详情入口。 */
 .reconcile-index > .reconcile-ledger > .statement-filters{gap:8px;margin:0;border-bottom:1px solid var(--border-subtle)}