فهرست منبع

feat(web): 重设计账单明细详情布局

sy 2 روز پیش
والد
کامیت
afe94e94b3

+ 170 - 178
web-scaffold/src/pages/SettlementRecordPages.tsx

@@ -8,9 +8,9 @@
  * 「分成方式与取值」列走 ../lib/settle-text 单源(册 4 settle_text,⛔ 本册自造分成取值文案)。
  * 禁项:⛔「按金额分成本期不计算」「未对账」「已打回」字样;⛔ 出账状态与批次状态混列;⛔ history.back()。
  */
-import { useEffect, useId, useState, type FormEvent } from "react";
+import { useEffect, useId, useState, type FormEvent, type ReactNode } from "react";
 import { PageIntro } from "../components/PageIntro";
-import { ArrowLeft, ArrowRight, CalendarClock, ChevronDown, Download, FileSpreadsheet, ListFilter, RefreshCw, Search, TriangleAlert, X } from "lucide-react";
+import { ArrowLeft, ArrowRight, Building2, Calculator, CalendarClock, CalendarDays, ChevronDown, CircleDollarSign, Download, 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";
@@ -18,9 +18,10 @@ import { FilterSelect } from "../components/ui/filter-select";
 import { MonthFilter } from "../components/ui/month-filter";
 import { ServerListPager } from "../components/ListPager";
 import { OpsDialog, OpsNotice, OpsStatus, OpsTableColumns, OpsTableEmpty, OpsTag, type OpsTone } from "../components/OperationsKit";
+import { RecordTabs } from "../components/RecordTabs";
 import { useDemoIdentity } from "../lib/demo-session";
 import { entTeamGetList, operatorGetList, partnerGetList, reconExportDetail, reconExportList } from "../lib/api/bos";
-import type { HolderType, ReconBatchStatus, ReconcileStatus, ReconDetailResult } from "../lib/api/types";
+import type { BillDetailResult, HolderType, ReconBatchStatus, ReconcileStatus, ReconDetailResult } from "../lib/api/types";
 import type { StatusTone } from "../domain/statuses";
 import { WORD_FETCH_FAILED } from "../lib/api/lockedCopy";
 import { settleTextFromSnapshot } from "../lib/settle-text";
@@ -877,13 +878,153 @@ export function SettlementBillListPage() {
   );
 }
 
-/* ── FN-08 明细详情(14.3 七段;字段按「钱是怎么来的」排序) ────────── */
+/* ── FN-08 明细详情(14.3) ──────────────────────────────────────── */
+
+const billRecordTabs = [
+  { id: "billing", label: "计费概况" },
+  { id: "costs", label: "成本明细" },
+  { id: "reconciliation", label: "分成与对账" },
+  { id: "accounts", label: "分账号计费" },
+] as const;
+type BillRecordTab = typeof billRecordTabs[number]["id"];
+
+function BillRecordPanel({ tab, active, children }: { tab: BillRecordTab; active: BillRecordTab; children: ReactNode }) {
+  return <section className="ops-record-card record-tab-panel bill-record-panel" id={`bill-record-panel-${tab}`}
+    role="tabpanel" aria-labelledby={`bill-record-tab-${tab}`} tabIndex={0} hidden={active !== tab}>
+    {children}
+  </section>;
+}
+
+function BillBatchLink({ holderId, number, from }: { holderId: string; number: string; from: string }) {
+  return <Link className="ops-table-action bill-record-batch-link" to={batchPath(holderId, number)} state={{ from }}>
+    <span>{number}</span><ArrowRight size={14} aria-hidden="true" />
+  </Link>;
+}
+
+function BillRecordContent({ bill, from }: { bill: BillDetailResult; from: string }) {
+  const [tab, setTab] = useState<BillRecordTab>("billing");
+  const actualCost = bill.cost_deduct_cents ?? (bill.receivable_cents - bill.share_base_cents);
+  const costCapped = bill.base_floor_protected || (
+    bill.cost_should_deduct_cents != null && bill.cost_deduct_cents != null && bill.cost_should_deduct_cents > bill.cost_deduct_cents
+  );
+  const missing = <span className="table-placeholder">—</span>;
+
+  return <>
+    {/* 尾月对齐前后的应收放在同一摘要内,切换页签时仍可对照。 */}
+    <dl className="customer-record-metrics bill-record-metrics" aria-label="账单金额摘要">
+      <div>
+        <dt><Calculator size={16} aria-hidden="true" />尾月对齐前应收</dt>
+        <dd><strong>{moneyFromCents(bill.pre_align_cents)}</strong></dd>
+      </div>
+      <div className="bill-record-metric-primary">
+        <dt><Receipt size={16} aria-hidden="true" />本期应收(对齐后)</dt>
+        <dd><strong>{moneyFromCents(bill.receivable_cents)}</strong></dd>
+      </div>
+      <div>
+        <dt><Calculator size={16} aria-hidden="true" />分成基数</dt>
+        <dd><strong>{moneyFromCents(bill.share_base_cents)}</strong></dd>
+      </div>
+      <div>
+        <dt><CircleDollarSign size={16} aria-hidden="true" />本方分成金额</dt>
+        <dd><strong className="bill-record-share">{moneyFromCents(bill.share_amount_cents)}</strong>
+          {bill.zero_note && <small>{ZERO_NOTE_TEXT[bill.zero_note]}</small>}
+        </dd>
+      </div>
+    </dl>
+
+    <div className="record-tabs-frame">
+      <RecordTabs prefix="bill-record" label="账单明细详情视图" tabs={billRecordTabs} active={tab} onChange={setTab} />
+
+      <BillRecordPanel tab="billing" active={tab}>
+        {bill.receivable_calc && <div className="bill-record-calculation">
+          <Calculator size={17} aria-hidden="true" />
+          <div><h2>应收计算</h2><p>{bill.receivable_calc}</p></div>
+        </div>}
+        <dl className="ops-record-summary bill-record-facts">
+          <div><dt>计费区间</dt><dd>{(bill.bill_from || bill.bill_to) ? `${bill.bill_from || "—"} ~ ${bill.bill_to || "—"}` : missing}</dd></div>
+          <div><dt>计费天数</dt><dd>{bill.billing_days} 天</dd></div>
+          <div><dt>当月天数</dt><dd>{bill.month_days == null ? missing : `${bill.month_days} 天`}</dd></div>
+          <div><dt>是否不满月</dt><dd>{bill.partial_month ? "是" : "否"}</dd></div>
+          <div><dt>计费标准单价</dt><dd>{bill.settle_std_cents == null ? missing : moneyFromCents(bill.settle_std_cents)}</dd></div>
+          <div><dt>订阅份数</dt><dd>{bill.quantity == null ? missing : `${bill.quantity} 份`}</dd></div>
+        </dl>
+      </BillRecordPanel>
+
+      <BillRecordPanel tab="costs" active={tab}>
+        <dl className="ops-record-summary bill-record-facts">
+          <div><dt>成本实扣</dt><dd>{moneyFromCents(actualCost)}</dd></div>
+          {bill.cost_should_deduct_cents != null && <div><dt>成本应扣(封顶前)</dt><dd>{moneyFromCents(bill.cost_should_deduct_cents)}</dd></div>}
+        </dl>
+        {costCapped && <p className="bill-record-note" role="note">成本已按应收封顶(应扣大于实扣时,分成基数按 0 保护)。</p>}
+        <div className="ops-table-wrap bill-record-table">
+          <table className="ops-table" aria-label="成本快照">
+            <OpsTableColumns widths={[40, 22, 14, 24]} />
+            <thead><tr><th scope="col">成本项</th><th scope="col" className="bill-record-number">单价</th><th scope="col" className="bill-record-number">倍率</th><th scope="col" className="bill-record-number">应扣</th></tr></thead>
+            <tbody>
+              {bill.costs.map((cost, i) => {
+                const price = cost.price_cents ?? cost.amount_cents;
+                const should = cost.cost_cents ?? cost.fold;
+                return <tr key={`${cost.item_id ?? cost.item_name}-${i}`}>
+                  <td><div className="bill-record-table-title"><strong className="table-cell-title">{cost.item_name}</strong>{!cost.configured && <OpsTag tone="warning">未配置</OpsTag>}</div></td>
+                  <td className="bill-record-number">{price == null ? missing : <span className="table-number">{moneyFromCents(price)}</span>}</td>
+                  <td className="bill-record-number">{cost.multiplier == null ? missing : <span className="table-number">{cost.multiplier}</span>}</td>
+                  <td className="bill-record-number">{should == null ? missing : <span className="table-number">{moneyFromCents(should)}</span>}</td>
+                </tr>;
+              })}
+              {!bill.costs.length && <OpsTableEmpty colSpan={4}>本行无成本快照。</OpsTableEmpty>}
+            </tbody>
+          </table>
+        </div>
+      </BillRecordPanel>
+
+      <BillRecordPanel tab="reconciliation" active={tab}>
+        <dl className="ops-record-summary bill-record-facts">
+          <div><dt>分成方</dt><dd>{bill.holder_name || missing}</dd></div>
+          <div><dt>分成方式与取值</dt><dd>{settleTextFromSnapshot(bill.share_mode, bill.share_value)}</dd></div>
+          <div><dt>所属对账单号</dt><dd><BillBatchLink holderId={bill.holder_id} number={bill.batch_no} from={from} /></dd></div>
+        </dl>
+        {bill.base_floor_protected && <p className="bill-record-note" role="note">{BASE_FLOOR_NOTE}</p>}
+        {/* 仅在服务端下发其他分成方时展示。 */}
+        {bill.other_parties != null && bill.other_parties.length > 0 && <div className="ops-table-wrap bill-record-table">
+          <table className="ops-table" aria-label="其他分成方">
+            <OpsTableColumns widths={[40, 23, 37]} />
+            <thead><tr><th scope="col">其他分成方</th><th scope="col" className="bill-record-number">分成金额</th><th scope="col">对账单号</th></tr></thead>
+            <tbody>
+              {bill.other_parties.map((party, i) => <tr key={`${party.holder_type}-${party.holder_name}-${i}`}>
+                <td><div className="bill-record-table-title"><strong className="table-cell-title">{party.holder_name}</strong><OpsTag tone={holderTone[party.holder_type]}>{HOLDER_TYPE_TEXT[party.holder_type]}</OpsTag></div></td>
+                <td className="bill-record-number"><span className="table-number">{moneyFromCents(party.share_amount_cents)}</span></td>
+                <td>{party.batch_no && party.holder_id ? <BillBatchLink holderId={party.holder_id} number={party.batch_no} from={from} /> : party.batch_no ?? missing}</td>
+              </tr>)}
+            </tbody>
+          </table>
+        </div>}
+      </BillRecordPanel>
+
+      <BillRecordPanel tab="accounts" active={tab}>
+        {bill.account_days_failed ? <p className="bill-record-note bill-record-error" role="alert">{WORD_FETCH_FAILED}</p>
+          : bill.account_days == null ? <p className="bill-record-placeholder">{BACKEND_NOT_WIRED}</p>
+          : <div className="ops-table-wrap bill-record-table">
+            <table className="ops-table" aria-label="逐账号在期天数">
+              <OpsTableColumns widths={[70, 30]} />
+              <thead><tr><th scope="col">分账号</th><th scope="col" className="bill-record-number">在期天数</th></tr></thead>
+              <tbody>
+                {bill.account_days.map((row, i) => <tr key={`${row.sub_account_label}-${i}`}>
+                  <td><strong className="table-cell-title">{row.sub_account_label}</strong></td>
+                  <td className="bill-record-number"><span className="table-number">{row.in_period_days}</span> 天</td>
+                </tr>)}
+                {!bill.account_days.length && <OpsTableEmpty colSpan={2}>本期无在期分账号。</OpsTableEmpty>}
+              </tbody>
+            </table>
+          </div>}
+      </BillRecordPanel>
+    </div>
+  </>;
+}
 
 export function SettlementBillRecordPage() {
   const { index } = useParams();
   const location = useLocation();
   const state = (location.state ?? {}) as { from?: string; listSearch?: string };
-  // 来自列表时拼回 listSearch,保留筛选(D-2);其它来路仍回进来那一页。
   const back = state.from === "/correction-notes"
     ? { to: "/correction-notes", label: BACK_TO_CORRECTIONS }
     : state.from?.startsWith("/settlement-batches/")
@@ -891,183 +1032,34 @@ export function SettlementBillRecordPage() {
       : { to: `/settlement-bills${state.from === "/settlement-bills" ? (state.listSearch ?? "") : ""}`, label: BACK_TO_BILL_LIST };
 
   const detail = useBillDetail(index ?? null);
-  const d = detail.data;
+  const bill = detail.data;
   const wiring = detail.fail?.kind === "wiring";
 
   return (
-    <article className="ops-page reconcile-record">
-      <Link className="ops-back-link" to={back.to}><ArrowLeft size={16} />{back.label}</Link>
+    <article className="ops-page ops-record-page record-detail bill-record">
+      <Link className="ops-back-link" to={back.to}><ArrowLeft size={16} aria-hidden="true" />{back.label.replace(/^←\s*/, "")}</Link>
+      <header className="customer-record-masthead bill-record-masthead">
+        <div className="customer-hero-symbol" aria-hidden="true"><FileSpreadsheet size={26} /></div>
+        <div className="customer-hero-copy">
+          <p className="customer-record-id">BILLING LINE <span aria-hidden="true">·</span> <span>{bill?.bill_detail_id ?? index}</span></p>
+          <h1 className="customer-record-title">账单明细详情</h1>
+          {bill && <div className="customer-record-tags bill-record-context">
+            <span className="customer-record-meta">
+              <OpsTag tone={holderTone[bill.holder_type]}>{HOLDER_TYPE_TEXT[bill.holder_type]}</OpsTag>
+              {bill.holder_name && <strong>{bill.holder_name}</strong>}
+            </span>
+            <span className="customer-record-meta"><CalendarDays size={14} aria-hidden="true" /><span>自然月 {bill.period}</span></span>
+            {bill.customer_name && <span className="customer-record-meta"><Building2 size={14} aria-hidden="true" /><span>{bill.customer_name}</span></span>}
+            {bill.subscription_label && <span className="customer-record-meta"><ScrollText size={14} aria-hidden="true" /><span>{bill.subscription_label}</span></span>}
+          </div>}
+        </div>
+      </header>
       {wiring && <p className="ops-import-note" role="status">{BILL_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">BILLING LINE / {index}</span>
-            <h1>明细详情</h1>
-            <p>{detail.loading && !wiring ? "加载中…" : BACKEND_NOT_WIRED}</p>
-          </div>
-        </header>
-      )}
-
-      {d && (
-        <>
-          <header className="reconcile-record-hero">
-            <div className="reconcile-record-symbol"><FileSpreadsheet size={27} /></div>
-            <div>
-              <span className="reconcile-record-eyebrow">BILLING LINE / {d.bill_detail_id}</span>
-              <h1>明细详情</h1>
-              <p><strong>{d.holder_name}</strong><span>{HOLDER_TYPE_TEXT[d.holder_type]}</span><span>自然月 {d.period}</span><span>{d.customer_name} · {d.subscription_label}</span></p>
-            </div>
-          </header>
-
-          {/* ① 本期应收口径:pre_align_cents 与 receivable_cents 同屏(缺一=页面缺字段)。 */}
-          <section className="reconcile-record-section">
-            <div className="reconcile-record-section-head"><span>01</span><div><h2>本期应收口径</h2><p>尾月对齐前两值必须同屏。</p></div></div>
-            <dl className="reconcile-record-facts">
-              <div><dt>计费标准单价</dt><dd>{d.settle_std_cents == null ? "—" : moneyFromCents(d.settle_std_cents)}</dd></div>
-              <div><dt>订阅份数</dt><dd>{d.quantity == null ? "—" : d.quantity}</dd></div>
-              <div><dt>尾月对齐前应收</dt><dd>{moneyFromCents(d.pre_align_cents)}</dd></div>
-              <div><dt>本期应收(对齐后)</dt><dd>{moneyFromCents(d.receivable_cents)}</dd></div>
-            </dl>
-            {d.receivable_calc && <p className="reconcile-footnote">{d.receivable_calc}</p>}
-          </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.bill_from || d.bill_to) ? `${d.bill_from || "—"} ~ ${d.bill_to || "—"}` : "—"}</dd></div>
-              <div><dt>计费天数</dt><dd>{d.billing_days} 天</dd></div>
-              <div><dt>当月天数</dt><dd>{d.month_days == null ? "—" : `${d.month_days} 天`}</dd></div>
-              <div><dt>是否不满月</dt><dd>{d.partial_month ? "是" : "否"}</dd></div>
-            </dl>
-          </section>
-
-          {/* ③ 成本:合计取实扣;明细列为应扣;封顶时提示。 */}
-          <section className="reconcile-record-section">
-            <div className="reconcile-record-section-head"><span>03</span><div><h2>成本快照</h2><p>合计为实扣;明细行为应扣(封顶前)。</p></div></div>
-            <dl className="reconcile-record-facts">
-              <div><dt>成本实扣</dt><dd>{moneyFromCents(d.cost_deduct_cents ?? (d.receivable_cents - d.share_base_cents))}</dd></div>
-              {d.cost_should_deduct_cents != null && (
-                <div><dt>成本应扣</dt><dd>{moneyFromCents(d.cost_should_deduct_cents)}</dd></div>
-              )}
-            </dl>
-            {(d.cost_should_deduct_cents != null
-              && d.cost_deduct_cents != null
-              && d.cost_should_deduct_cents > d.cost_deduct_cents)
-              || d.base_floor_protected
-              ? <p className="reconcile-footnote">成本已按应收封顶(应扣大于实扣时,分成基数按 0 保护)。</p>
-              : null}
-            {d.costs.length ? (
-              <div className="ops-table-wrap">
-                <table className="ops-table">
-                    <thead><tr><th>成本项</th><th>单价</th><th>倍率</th><th>应扣</th></tr></thead>
-                  <tbody>
-                    {d.costs.map((cost, i) => {
-                      const price = cost.price_cents ?? cost.amount_cents;
-                      const should = cost.cost_cents ?? cost.fold ?? null;
-                      return (
-                      <tr key={`${cost.item_name}-${i}`}>
-                        <td>{cost.item_name}{!cost.configured && <OpsTag tone="warning">未配置</OpsTag>}</td>
-                        <td><span className="ops-money table-number">{price == null ? <span className="table-placeholder">—</span> : moneyFromCents(price)}</span></td>
-                        <td>{cost.multiplier == null ? <span className="table-placeholder">—</span> : <span className="table-number">{cost.multiplier}</span>}</td>
-                        <td><span className="ops-money table-number">{should == null ? <span className="table-placeholder">—</span> : moneyFromCents(should)}</span></td>
-                      </tr>
-                      );
-                    })}
-                  </tbody>
-                </table>
-              </div>
-            ) : (
-              <p className="reconcile-empty-line">本行无成本快照。</p>
-            )}
-          </section>
-
-          {/* ④ 分成基数;floor 到 0 ⇒ 显式标下限保护(floor 是静默的,不写=藏起一次配置错误)。 */}
-          <section className="reconcile-record-section">
-            <div className="reconcile-record-section-head"><span>04</span><div><h2>实际出账口径</h2><p>分成基数与下限保护。</p></div></div>
-            <dl className="reconcile-record-facts">
-              <div><dt>分成基数</dt><dd>{moneyFromCents(d.share_base_cents)}</dd></div>
-            </dl>
-            {d.base_floor_protected && <p className="reconcile-footnote">{BASE_FLOOR_NOTE}</p>}
-          </section>
-
-          {/* ⑤ 分成方式与取值=当时冻结在明细行上的值(⛔ 读档案现值,I22);文案走册 4 settle_text 单源。 */}
-          <section className="reconcile-record-section">
-            <div className="reconcile-record-section-head"><span>05</span><div><h2>分成方式与取值</h2><p>当时冻结在明细行上的值。</p></div></div>
-            <dl className="reconcile-record-facts">
-              <div><dt>分成方式与取值</dt><dd>{settleTextFromSnapshot(d.share_mode, d.share_value)}</dd></div>
-            </dl>
-          </section>
-
-          {/* ⑥ 本方分成金额+恒 0 标注+所属对账单号。 */}
-          <section className="reconcile-record-section">
-            <div className="reconcile-record-section-head"><span>06</span><div><h2>对账归属</h2><p>本方分成金额与所属批次。</p></div></div>
-            <dl className="reconcile-record-facts">
-              <div><dt>本方分成金额</dt><dd>{moneyFromCents(d.share_amount_cents)}{d.zero_note ? ` · ${ZERO_NOTE_TEXT[d.zero_note]}` : ""}</dd></div>
-              <div>
-                <dt>所属对账单号</dt>
-                <dd>
-                  <Link className="ops-table-action" to={batchPath(d.holder_id, d.batch_no)} state={{ from: location.pathname }}>
-                    {d.batch_no} <ArrowRight size={14} />
-                  </Link>
-                </dd>
-              </div>
-            </dl>
-            {/* 其他分成方面板:三类只读身份响应体不出现该字段(⛔ 值为空)。 */}
-            {d.other_parties != null && d.other_parties.length > 0 && (
-              <div className="ops-table-wrap" style={{ marginTop: 12 }}>
-                <table className="ops-table">
-                  <thead><tr><th>其他分成方</th><th>分成金额</th><th>对账单号</th></tr></thead>
-                  <tbody>
-                    {d.other_parties.map((p, i) => (
-                      <tr key={`${p.holder_type}-${p.holder_name}-${i}`}>
-                        <td><OpsTag tone={holderTone[p.holder_type]}>{HOLDER_TYPE_TEXT[p.holder_type]}</OpsTag> {p.holder_name}</td>
-                        <td><span className="ops-money">{moneyFromCents(p.share_amount_cents)}</span></td>
-                        <td>
-                          {p.batch_no && p.holder_id ? (
-                            <Link className="ops-table-action" to={batchPath(p.holder_id, p.batch_no)} state={{ from: location.pathname }}>
-                              {p.batch_no} <ArrowRight size={14} />
-                            </Link>
-                          ) : (
-                            <span className="ops-mono">{p.batch_no ?? <span className="table-placeholder">—</span>}</span>
-                          )}
-                        </td>
-                      </tr>
-                    ))}
-                  </tbody>
-                </table>
-              </div>
-            )}
-          </section>
-
-          {/* ⑦ 逐账号在期天数;KLT-S406 ⇒ 该块「取数失败」(⛔ 回落「无开停记录」);未下发 ⇒「后端未下发」。 */}
-          <section className="reconcile-record-section">
-            <div className="reconcile-record-section-head"><span>07</span><div><h2>逐账号在期天数</h2><p>按订阅逐分账号统计。</p></div></div>
-            {d.account_days_failed ? (
-              <p className="ops-form-error" role="alert">{WORD_FETCH_FAILED}</p>
-            ) : d.account_days == null ? (
-              <p className="reconcile-footnote">{BACKEND_NOT_WIRED}</p>
-            ) : d.account_days.length ? (
-              <div className="ops-table-wrap">
-                <table className="ops-table">
-                  <thead><tr><th>分账号</th><th>在期天数</th></tr></thead>
-                  <tbody>
-                    {d.account_days.map((row, i) => (
-                      <tr key={`${row.sub_account_label}-${i}`}><td>{row.sub_account_label}</td><td className="table-number">{row.in_period_days} 天</td></tr>
-                    ))}
-                  </tbody>
-                </table>
-              </div>
-            ) : (
-              <p className="reconcile-empty-line">本期无在期分账号。</p>
-            )}
-          </section>
-        </>
-      )}
+      {detail.fail && !wiring && <p className="ops-form-error" role="alert">
+        {detail.fail.message} <Button variant="ghost" size="sm" onClick={detail.reload}>重试</Button>
+      </p>}
+      {!bill && detail.loading && <p className="bill-record-placeholder" role="status">正在读取账单明细…</p>}
+      {bill && <BillRecordContent key={bill.bill_detail_id} bill={bill} from={location.pathname} />}
     </article>
   );
 }

+ 97 - 0
web-scaffold/src/pages/__tests__/settlement-bill-record.test.tsx

@@ -0,0 +1,97 @@
+import { cleanup, fireEvent, render, screen, within } from "@testing-library/react";
+import { MemoryRouter, Route, Routes } from "react-router";
+import { afterEach, expect, it, vi } from "vitest";
+import { billGetDetail } from "../../lib/api/bos";
+import type { BillDetailResult } from "../../lib/api/types";
+import { SettlementBillRecordPage } from "../SettlementRecordPages";
+
+vi.mock("../../lib/api/bos", async (load) => ({
+  ...await load<typeof import("../../lib/api/bos")>(),
+  billGetDetail: vi.fn(),
+}));
+
+const bill: BillDetailResult = {
+  bill_detail_id: "BILL-001",
+  batch_no: "RECON-001",
+  holder_type: "operator",
+  holder_id: "OP-1",
+  holder_name: "华东运营商",
+  period: "2026-10",
+  customer_name: "客户甲",
+  subscription_label: "标准套餐",
+  pre_align_cents: 12100,
+  receivable_cents: 12000,
+  settle_std_cents: 15000,
+  quantity: 1,
+  receivable_calc: "按计费天数计算",
+  bill_from: "2026-10-08",
+  bill_to: "2026-10-31",
+  billing_days: 24,
+  month_days: 31,
+  partial_month: true,
+  costs: [{ item_name: "线路成本", price_cents: 12000, cost_cents: 14000, multiplier: 1, configured: true }],
+  cost_should_deduct_cents: 14000,
+  cost_deduct_cents: 12000,
+  share_base_cents: 0,
+  base_floor_protected: true,
+  share_mode: "ratio",
+  share_value: 0.5,
+  share_amount_cents: 0,
+  zero_note: "base_zero",
+  other_parties: [{ holder_type: "partner", holder_id: "PARTNER-1", holder_name: "渠道伙伴", share_amount_cents: 0, batch_no: "RECON-002" }],
+  account_days: [{ sub_account_label: "分账号 A", in_period_days: 24 }],
+  account_days_failed: false,
+};
+
+function renderBill(detail: BillDetailResult) {
+  vi.mocked(billGetDetail).mockResolvedValueOnce(detail);
+  render(<MemoryRouter initialEntries={[{
+    pathname: "/settlement-bills/BILL-001",
+    state: { from: "/settlement-bills", listSearch: "?month=2026-10" },
+  }]}>
+    <Routes><Route path="/settlement-bills/:index" element={<SettlementBillRecordPage />} /></Routes>
+  </MemoryRouter>);
+  return screen.findByRole("tablist", { name: "账单明细详情视图" });
+}
+
+afterEach(() => {
+  cleanup();
+  vi.mocked(billGetDetail).mockReset();
+});
+
+it("对齐前后应收始终可见,并按页签查看成本、分成和分账号计费", async () => {
+  const tabs = within(await renderBill(bill));
+  const summary = within(screen.getByLabelText("账单金额摘要"));
+  expect(summary.getByText("¥121.00")).toBeTruthy();
+  expect(summary.getByText("¥120.00")).toBeTruthy();
+  expect(summary.getByText("分成基数为 0(成本 ≥ 应收)")).toBeTruthy();
+  expect(screen.getByRole("link", { name: "返回账单明细" }).getAttribute("href")).toBe("/settlement-bills?month=2026-10");
+  expect(screen.getByRole("tabpanel", { name: "计费概况" }).textContent).toContain("按计费天数计算");
+
+  fireEvent.keyDown(tabs.getByRole("tab", { name: "计费概况" }), { key: "ArrowRight" });
+  const costs = within(screen.getByRole("tabpanel", { name: "成本明细" }));
+  expect(costs.getByRole("table", { name: "成本快照" }).textContent).toContain("线路成本");
+  expect(costs.getByRole("note").textContent).toContain("成本已按应收封顶");
+
+  fireEvent.click(tabs.getByRole("tab", { name: "分成与对账" }));
+  const reconciliation = within(screen.getByRole("tabpanel", { name: "分成与对账" }));
+  expect(reconciliation.getByText("按比例 50%")).toBeTruthy();
+  expect(reconciliation.getByRole("link", { name: "RECON-001" }).getAttribute("href")).toBe("/settlement-batches/OP-1/RECON-001");
+  expect(reconciliation.getByRole("table", { name: "其他分成方" }).textContent).toContain("渠道伙伴");
+
+  fireEvent.click(tabs.getByRole("tab", { name: "分账号计费" }));
+  expect(screen.getByRole("table", { name: "逐账号在期天数" }).textContent).toContain("分账号 A");
+  expect(summary.getByText("¥120.00")).toBeTruthy();
+});
+
+it.each([
+  { failed: true, rows: null, message: "取数失败" },
+  { failed: false, rows: null, message: "后端未下发" },
+  { failed: false, rows: [], message: "本期无在期分账号。" },
+])("区分分账号计费的失败、未下发和空数据($message)", async ({ failed, rows, message }) => {
+  const tabs = within(await renderBill({ ...bill, account_days_failed: failed, account_days: rows, other_parties: null }));
+  fireEvent.click(tabs.getByRole("tab", { name: "分成与对账" }));
+  expect(screen.queryByRole("table", { name: "其他分成方" })).toBeNull();
+  fireEvent.click(tabs.getByRole("tab", { name: "分账号计费" }));
+  expect(within(screen.getByRole("tabpanel", { name: "分账号计费" })).getByText(message)).toBeTruthy();
+});

+ 37 - 0
web-scaffold/src/styles/settlement-records.css

@@ -193,6 +193,43 @@
   .statement-filters .ops-search{flex:1 1 130px;min-width:min(130px,100%)}
 }
 
+/* 账单明细详情 */
+.bill-record { display: grid; align-content: start; gap: 14px; }
+.bill-record > .ops-back-link { justify-self: start; margin: 0; }
+.bill-record .bill-record-masthead { grid-template-columns: auto minmax(0, 1fr); margin: 0; }
+.bill-record-context { column-gap: 12px; }
+.bill-record .bill-record-metrics { margin: 0; }
+.bill-record-metrics > div.bill-record-metric-primary { background: var(--primary-soft); }
+.bill-record-metrics > div:not(.bill-record-metric-primary) strong:not(.bill-record-share) { color: var(--foreground); }
+.bill-record .bill-record-panel { display: grid; align-content: start; gap: 16px; }
+.bill-record-panel:focus-visible { outline: 2px solid var(--ring); outline-offset: -3px; }
+.bill-record .bill-record-facts { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 22px; }
+.bill-record-facts > div { padding: 8px 0 12px; border-bottom: 1px solid var(--border-subtle); }
+.bill-record-facts dd { font-weight: 550; font-variant-numeric: tabular-nums; }
+.bill-record-facts dd > .table-placeholder { color: var(--muted-foreground); font-size: var(--type-support); font-weight: 400; }
+.bill-record-calculation { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: var(--radius-control); background: var(--primary-soft); }
+.bill-record-calculation > svg { flex: none; color: var(--primary-soft-foreground); }
+.bill-record-calculation h2 { margin: 0 0 4px; color: var(--primary-soft-foreground); font-size: var(--type-support); }
+.bill-record-calculation p { margin: 0; font-size: var(--type-body); line-height: 1.6; overflow-wrap: anywhere; white-space: pre-wrap; }
+.bill-record .bill-record-note, .bill-record .bill-record-placeholder { 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; }
+.bill-record .bill-record-error { background: var(--destructive-soft); color: var(--destructive); }
+.bill-record-table { min-width: 0; border: 1px solid var(--border); border-radius: var(--radius-control); }
+.bill-record-table .ops-table { min-width: 0; table-layout: fixed; }
+.bill-record-table .ops-table :is(th, td) { padding-inline: 12px; white-space: normal; overflow-wrap: anywhere; }
+.bill-record-table .ops-table .bill-record-number { text-align: right; font-variant-numeric: tabular-nums; }
+.bill-record-table tbody tr:last-child td { border-bottom: 0; }
+.bill-record-table-title { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; }
+.bill-record .bill-record-batch-link { max-width: 100%; min-height: 0; padding: 0; white-space: normal; overflow-wrap: anywhere; }
+.bill-record-batch-link > svg { flex: none; }
+
+@media (max-width: 900px) {
+  .bill-record .bill-record-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
+}
+@media (max-width: 600px) {
+  .bill-record .bill-record-panel { padding-inline: 14px; }
+  .bill-record-table .ops-table :is(th, td) { padding-inline: 8px; }
+}
+
 /* 账单明细:长名称及关联单号适度加宽,其余均衡,天数/操作保持紧凑。 */
 .bill-ledger-scroll{position:relative;overflow-x:auto;overflow-y:hidden;scrollbar-gutter:stable;overscroll-behavior-x:contain}
 .bill-ledger-scroll:focus-visible{outline:2px solid var(--primary);outline-offset:-2px}