| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065 |
- /**
- * 册 6《计费与对账出账》四页:FN-05 对账清单(14.1)、批次详情(14.2)、FN-08 账单明细与明细详情(14.3)。
- *
- * 接线状态(2026-11-11 核实):bos.recon/* 与 bos.bill/* 未在 openapi.yaml 声明 ⇒ 网关 11001 未声明即拒绝。
- * 撞 11001 ⇒ 契约占位分支(结构按 14 章落位、横幅标明待接线、数据区「后端未下发」);
- * ⛔ 用 settlement-demo/settlement-retries 本地台账冒充真接口(=绕过,本版起不再作为本页数据源)。
- * 文案唯一真源 ../lib/copy-billing(逐字复制自册 6 契约 14 章/05 章 §5.1,⛔ 手打转述);
- * 「分成方式与取值」列走 ../lib/settle-text 单源(册 4 settle_text,⛔ 本册自造分成取值文案)。
- * 禁项:⛔「按金额分成本期不计算」「未对账」「已打回」字样;⛔ 出账状态与批次状态混列;⛔ history.back()。
- */
- 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 { Link, useLocation, useNavigate, useParams, useSearchParams } from "react-router";
- import { Button } from "../components/ui/button";
- import { SearchInput } from "../components/ui/search-input";
- import { FilterSelect } from "../components/ui/filter-select";
- import { 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 { 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";
- import { useHorizontalOverflow } from "../lib/use-horizontal-overflow";
- import {
- lastClosedMonth, submitReconRerun,
- useBillDetail, useBillList, useReconDetail, useReconList, useReconPeriods,
- } from "../lib/recon";
- import {
- ACTION_FLAG_PENDING_NOTE,
- ALL_PERIODS_LABEL,
- BACK_TO_BILL_DETAIL,
- BACK_TO_BILL_LIST,
- BACK_TO_CORRECTIONS,
- BACK_TO_RECON_DETAIL,
- BACK_TO_RECON_LIST,
- BACKEND_NOT_WIRED,
- BASE_FLOOR_NOTE,
- BATCH_STATUS_TEXT,
- BILL_WIRING_NOTE,
- COST_UNCONFIGURED_NOTE,
- EXECUTOR_SYSTEM,
- EXPORT_EMPTY_NOTE,
- exportResultNote,
- HOLDER_TYPE_TEXT,
- MONTH_NO_BATCH_NOTE,
- PERIODS_UNAVAILABLE,
- periodProgressLine,
- PROGRESS_COLLAPSE,
- PROGRESS_EXPAND,
- RECON_WIRING_NOTE,
- RECONCILE_STATUS_TEXT,
- RERUN_DIALOG_TITLE,
- RERUN_NO_EMPTY_BATCH_NOTE,
- RERUN_SUBMIT,
- RERUN_VOID_NOTE,
- rerunMonthBoundNote,
- rerunScopeLine,
- S404_EMPTY_NOTE,
- saveReconExportCsv,
- STAT_CARDS,
- TICKET_GAP_LABEL,
- ticketGapText,
- TRIGGER_TYPE_TEXT,
- VOIDED_BY_PREFIX,
- ZERO_NOTE_TEXT,
- } from "../lib/copy-billing";
- import "../styles/operations.css";
- import "../styles/settlement-records.css";
- /* ── 本地小工具 ─────────────────────────────────────────────────── */
- /** 金额列以 `_cents`(分)下发;界面统一两位小数元。 */
- const moneyFromCents = (cents: number): string =>
- `¥${(cents / 100).toLocaleString("zh-CN", { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
- /** 三态格:null ⇒ 「取数失败」(KLT-S406 单格语义),⛔ 回落 0。 */
- const moneyCell = (cents: number | null): string => (cents == null ? WORD_FETCH_FAILED : moneyFromCents(cents));
- const reconcileTone: Record<ReconcileStatus, StatusTone> = { settled: "success", abnormal: "danger", unsettled: "neutral" };
- const batchTone: Record<ReconBatchStatus, StatusTone> = { pending: "neutral", executed: "success", failed: "danger", voided: "neutral" };
- const holderTone: Record<HolderType, OpsTone> = { operator: "brand", partner: "info", ops_team: "warning" };
- /**
- * 执行时间本地化:后端 `CAST(executed_at AS TEXT)` 下发 UTC 裸串(`2026-11-13 03:49:40.05+00`),
- * 直接入列既难读又与手册「执行时间」口径不符 ⇒ 按浏览器时区显示,原文留 `title` 可核。
- */
- function localTime(iso: string): string {
- const d = new Date(iso.includes("T") ? iso : iso.replace(" ", "T"));
- if (Number.isNaN(d.getTime())) return iso;
- const p = (n: number) => String(n).padStart(2, "0");
- return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`;
- }
- /**
- * 执行人可读化:优先绑定表用户名(`operator_username`);NULL ⇒「系统」(对账§14.2);
- * 只有裸 seoh 用户 ID 时标明是 ID,⛔ 把裸 ID 当人名直接渲染。
- */
- function executorText(e: { operator_user_id: string | null; operator_username?: string | null }): string {
- const name = e.operator_username?.trim();
- if (name) return name;
- return e.operator_user_id ? `用户 ${e.operator_user_id}` : EXECUTOR_SYSTEM;
- }
- const batchPath = (holderId: string, batchNo: string) =>
- `/settlement-batches/${encodeURIComponent(holderId)}/${encodeURIComponent(batchNo)}`;
- /** URL 搜索参数筛选(返回列表时保留条件;⛔ 路由级收敛另行处理)。 */
- function useListFilters() {
- const [params, setParams] = useSearchParams();
- const get = (key: string) => params.get(key) ?? "";
- const set = (key: string, value: string, resetPage = false) =>
- setParams((current) => {
- const next = new URLSearchParams(current);
- if (resetPage) next.delete("page");
- if (value) next.set(key, value);
- else next.delete(key);
- return next;
- }, { replace: true });
- const reset = () => setParams({}, { replace: true });
- return { get, set, reset };
- }
- /** 失败原因行末红点(fail_reason 原文悬浮;⚠️ 不是 KLT-* 码,对账§7.1 末格)。 */
- function FailDot({ reason }: { reason: string | null }) {
- if (!reason) return null;
- return <span className="statement-failure-mark" title={reason} aria-label={reason}>●</span>;
- }
- /* ── 人工补跑对话框(14.1 动作矩阵:仅 admin;入参只三件) ────────── */
- function RerunDialog({ onClose }: { onClose: () => void }) {
- const navigate = useNavigate();
- const location = useLocation();
- const typeId = useId();
- const holderInputId = useId();
- const [maxMonth] = useState(lastClosedMonth);
- const [holderType, setHolderType] = useState<HolderType>("operator");
- const [holders, setHolders] = useState<{ id: string; name: string }[] | null>(null);
- const [holdersError, setHoldersError] = useState("");
- const [holderId, setHolderId] = useState("");
- const [period, setPeriod] = useState(maxMonth);
- const [error, setError] = useState("");
- const [busy, setBusy] = useState(false);
- const [holderRetry, setHolderRetry] = useState(0);
- // 分成方候选=第 1 册三类档案真源列表口(⛔ 本地台账);切换类型时重拉。
- useEffect(() => {
- let alive = true;
- setHolders(null);
- setHoldersError("");
- setHolderId("");
- // ⚠️ bos 列表接口 `page` 以 0 为首页(同 `organization-demo.ts::pagedAll`)⇒ 传 1 会跳过首页,
- // dev 数据不足一页时候选恒空(补跑弹窗打不开)。
- const load =
- holderType === "operator"
- ? operatorGetList({ page: 0, page_size: 100 }).then((r) => (r.items ?? []).map((o) => ({ id: o.operator_id, name: o.name })))
- : holderType === "partner"
- ? partnerGetList({ page: 0, page_size: 100 }).then((r) => (r.items ?? []).map((p) => ({ id: p.partner_id, name: p.name })))
- : entTeamGetList({ page: 0, page_size: 100 }).then((r) => (r.items ?? []).map((t) => ({ id: t.team_id, name: t.team_name })));
- load
- .then((rows) => {
- if (!alive) return;
- setHolders(rows);
- setHolderId(rows[0]?.id ?? "");
- })
- .catch((e: unknown) => {
- if (alive) setHoldersError(e instanceof Error ? e.message : WORD_FETCH_FAILED);
- });
- return () => {
- alive = false;
- };
- }, [holderType, holderRetry]);
- function submit(event: FormEvent) {
- event.preventDefault();
- if (busy) return;
- if (!holderId || !period) {
- setError(!holderId ? "请选择分成方。" : "请选择自然月。");
- return;
- }
- setBusy(true);
- setError("");
- submitReconRerun({ holder_type: holderType, holder_id: holderId, period })
- .then((res) => {
- onClose();
- navigate(batchPath(holderId, res.batch_no), {
- state: { from: location.pathname, listSearch: location.search },
- });
- })
- .catch((e: unknown) => {
- // 四道闸(60502→60503→60504→60506)/KLT-S407:文案直读后端 message(出路句由服务端带出)。
- setError(e instanceof Error && e.message ? e.message : "补跑失败,请重试。");
- setBusy(false);
- });
- }
- // 弹窗须写明补跑对象(分成方名称+月份),⛔ 只回显 ID。
- const holderName = holders?.find((h) => h.id === holderId)?.name;
- const close = () => { if (!busy) onClose(); };
- return (
- <OpsDialog title={RERUN_DIALOG_TITLE} className="statement-run-dialog" onClose={close}>
- <form onSubmit={submit}>
- <div className="statement-run-body">
- <fieldset className="statement-run-fields" aria-label="补跑条件" disabled={busy}>
- <div className="statement-run-field">
- <label htmlFor={typeId}>分成方类型</label>
- <FilterSelect id={typeId} icon="type" value={holderType} onChange={(event) => {
- setError("");
- setHolderType(event.target.value as HolderType);
- }}>
- <option value="operator">{HOLDER_TYPE_TEXT.operator}</option>
- <option value="partner">{HOLDER_TYPE_TEXT.partner}</option>
- <option value="ops_team">{HOLDER_TYPE_TEXT.ops_team}</option>
- </FilterSelect>
- </div>
- <div className="statement-run-field">
- <span>账期</span>
- <MonthFilter value={period} onChange={(value) => { setPeriod(value); setError(""); }} maxMonth={maxMonth} allowAll={false} />
- </div>
- <div className="statement-run-field statement-run-party">
- <label htmlFor={holderInputId}>分成方</label>
- <FilterSelect id={holderInputId} icon="operator" value={holderId} placeholder={!holderId} disabled={!holders?.length}
- onChange={(event) => { setHolderId(event.target.value); setError(""); }}>
- {!holders?.length && <option value="">{holdersError ? "分成方加载失败" : holders ? "暂无可选分成方" : "正在加载分成方…"}</option>}
- {holders?.map((h) => <option key={h.id} value={h.id}>{h.name}</option>)}
- </FilterSelect>
- {holdersError && <div className="statement-run-load-error">
- <p role="alert">{holdersError}</p>
- <Button variant="ghost" size="sm" onClick={() => setHolderRetry((value) => value + 1)}>重试</Button>
- </div>}
- </div>
- </fieldset>
- <div className="statement-run-scope">
- <CalendarClock size={19} aria-hidden="true" />
- <div>
- <strong>{holderName ? rerunScopeLine(holderName, period) : "选择分成方后即可确认补跑范围"}</strong>
- <p>{rerunMonthBoundNote(maxMonth)}</p>
- </div>
- </div>
- <div className="statement-run-impact">
- <TriangleAlert size={16} aria-hidden="true" />
- <div><p>{RERUN_VOID_NOTE}</p><p>{RERUN_NO_EMPTY_BATCH_NOTE}</p></div>
- </div>
- {error && <p className="ops-form-error statement-run-error" role="alert">{error}</p>}
- </div>
- <footer>
- <Button variant="outline" type="button" onClick={close} disabled={busy}>取消</Button>
- <Button type="submit" disabled={busy || !holderId || !period}>{busy ? "正在补跑…" : RERUN_SUBMIT}</Button>
- </footer>
- </form>
- </OpsDialog>
- );
- }
- /* ── FN-05 对账清单(14.1) ─────────────────────────────────────── */
- const statementColumns = [
- { label: "对账单号", width: 168 }, { label: "分成方", width: 190 },
- { label: "自然月", width: 86 }, { label: "应出账日期", width: 108 },
- { label: "触发方式", width: 92 }, { label: "明细条数", width: 84 },
- { label: "总金额", width: 112 }, { label: "分成金额", width: 116 },
- { label: "出账状态", width: 98 }, { label: "批次状态", width: 114 },
- { label: "执行人", width: 100 }, { label: "操作", width: 80 },
- ];
- const statementTableWidth = statementColumns.reduce((sum, column) => sum + column.width, 0);
- export function SettlementStatementListPage() {
- const identity = useDemoIdentity();
- const location = useLocation();
- const filters = useListFilters();
- const tableOverflow = useHorizontalOverflow();
- const progressId = useId();
- // 导出当前结果(B):admin/opsMain/opsSub(demo 角色无 opsSub);⛔ teamLead/partner/operator。
- const canExportAll = !identity || identity.role === "admin" || identity.role === "regAdmin";
- const isAdmin = !identity || identity.role === "admin";
- const lastClosedPeriod = lastClosedMonth();
- const monthParam = filters.get("month");
- // 无参数时显示全部自然月,同时兼容旧链接的 month=all。
- const month = monthParam === "all" ? "" : monthParam;
- const type = filters.get("type");
- const party = filters.get("party");
- const reconcile = filters.get("reconcile");
- const status = filters.get("status");
- const trigger = filters.get("trigger");
- const zero = filters.get("zero") === "1";
- const q = filters.get("q");
- const page = Number(filters.get("page") || "1") || 1;
- const hasFilter = Boolean(month || type || party || reconcile || status || trigger || zero || q);
- const periodsFetch = useReconPeriods();
- // D-19:下拉选项=接口期次 ∪ 上一个已结束自然月(与人工补跑弹窗 `lastClosedMonth()` 同基准)。
- // 仅有历史批、尚无「上月」批时,仍须能选上月(可能空表),⛔ 静默退到更早月造成「弹窗说 10 月、清单只到 9 月」。
- const periods = (() => {
- const raw = periodsFetch.data?.periods ?? null;
- if (!raw) return null;
- if (raw.includes(lastClosedPeriod)) return raw;
- return [lastClosedPeriod, ...raw];
- })();
- // 仅纠正不在选项内的显式月份(例如旧书签中的月份)。
- const [monthFallback, setMonthFallback] = useState(false);
- useEffect(() => {
- if (!periods?.length) return;
- if (!month || periods.includes(month)) {
- setMonthFallback(false);
- return;
- }
- filters.set("month", periods[0], true);
- setMonthFallback(true);
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [periods, month]);
- const list = useReconList({
- period: month,
- holderType: type,
- holderKw: party,
- reconcileStatus: reconcile,
- batchStatus: status,
- trigger,
- includeZero: zero,
- keyword: q,
- page,
- });
- const data = list.data;
- const wiring = list.fail?.kind === "wiring";
- const s404 = list.fail?.kind === "s404";
- const rows = data?.items ?? [];
- const total = data?.total ?? 0;
- const pageSize = 20;
- const [notice, setNotice] = useState("");
- const [runOpen, setRunOpen] = useState(false);
- const [progressOpen, setProgressOpen] = useState(false);
- const [exporting, setExporting] = useState(false);
- const tableClass = [
- "measured-table-scroll ops-table-wrap statement-ledger-scroll",
- tableOverflow.overflow && "has-horizontal-overflow",
- tableOverflow.width >= 900 && "can-pin-identity",
- tableOverflow.canScrollLeft && "can-scroll-left",
- tableOverflow.canScrollRight && "can-scroll-right",
- ].filter(Boolean).join(" ");
- const listState = { from: "/settlement-batches", listSearch: location.search };
- async function exportAll() {
- if (exporting || list.loading) return;
- // 筛选无结果 ⇒ 只提示、不导出、无错误码(14.1 动作矩阵)。
- if (!rows.length) {
- setNotice(EXPORT_EMPTY_NOTE);
- return;
- }
- setExporting(true);
- try {
- const result = await reconExportList({ period: month || undefined, holder_type: type || undefined, status: status || undefined });
- setNotice(saveReconExportCsv(result) ? exportResultNote(result) : EXPORT_EMPTY_NOTE);
- } catch (e: unknown) {
- setNotice(e instanceof Error && e.message ? e.message : WORD_FETCH_FAILED);
- } finally {
- setExporting(false);
- }
- }
- return (
- <section className="ops-page reconcile-index page-fill page-fill-window">
- <header className="ops-heading statement-heading">
- <div>
- <h1>对账清单</h1>
- <PageIntro>每个账期出账后,按分成方核对批次状态和结算结果。</PageIntro>
- </div>
- {(canExportAll || isAdmin) && <div className="statement-heading-actions">
- {canExportAll && <Button variant="outline" disabled={list.loading || exporting} onClick={exportAll}>
- <Download size={16} aria-hidden="true" />{exporting ? "正在导出…" : "导出当前结果"}
- </Button>}
- {isAdmin && <Button onClick={() => setRunOpen(true)}><RefreshCw size={16} aria-hidden="true" />人工补跑</Button>}
- </div>}
- </header>
- {runOpen && <RerunDialog onClose={() => setRunOpen(false)} />}
- {/* 接线占位横幅(klt-bos recon/* 未交付;交付后本分支自然失效) */}
- {wiring && <p className="ops-import-note" role="status">{RECON_WIRING_NOTE}</p>}
- {periodsFetch.fail && !wiring && <p className="ops-import-note" role="status">{PERIODS_UNAVAILABLE}</p>}
- {monthFallback && !rows.length && <p className="ops-import-note" role="status">{MONTH_NO_BATCH_NOTE}</p>}
- {/* ② 三统计卡:与列表同一响应同一行集;S404 ⇒ 整体不渲染(不是显示 0);单格 null ⇒「取数失败」。 */}
- {!s404 && (wiring || data) && (
- <div className="statement-totals" role="group" aria-label="当前筛选结果统计">
- {STAT_CARDS.map((card) => {
- const value = data?.stats[`total_${card.key}_cents`] ?? null;
- return (
- <div key={card.key} data-total={card.key}>
- <span>{card.title}</span>
- <strong className={wiring || value == null ? "statement-total-empty" : undefined}>{wiring ? BACKEND_NOT_WIRED : moneyCell(value)}</strong>
- <small>{card.subtitle}</small>
- </div>
- );
- })}
- </div>
- )}
- {/* ③-1 期次出账进度(常驻;只随自然月变化,⛔ 随其余筛选变;后端未下发 ⇒ 不渲)。 */}
- {data?.progress && (
- <section className="statement-progress" aria-label="期次出账进度">
- <div className="statement-progress-line">
- <CalendarClock size={18} aria-hidden="true" />
- <p role="status">{periodProgressLine(data.progress)}</p>
- <Button variant="ghost" size="sm" aria-expanded={progressOpen} aria-controls={progressId} onClick={() => setProgressOpen((v) => !v)}>
- {progressOpen ? PROGRESS_COLLAPSE : PROGRESS_EXPAND}<ChevronDown size={14} aria-hidden="true" />
- </Button>
- </div>
- <div id={progressId} hidden={!progressOpen} className="ops-table-wrap statement-progress-table">
- {progressOpen && (
- <table className="ops-table">
- <thead><tr><th>分成方</th><th>建档区域</th><th>对账日</th><th>本期应出账日期</th><th>状态</th><th>对账单号</th></tr></thead>
- <tbody>
- {data.progress.items.map((item) => (
- <tr key={`${item.holder_type}-${item.holder_id}`}>
- <td>
- <strong className="table-cell-title" title={item.holder_name}>{item.holder_name}</strong>
- <OpsTag tone={holderTone[item.holder_type]}>{HOLDER_TYPE_TEXT[item.holder_type]}</OpsTag>
- </td>
- <td>{item.region_label ?? <span className="table-placeholder">—</span>}</td>
- <td>{item.recon_day} 日</td>
- <td>{item.expected_date}</td>
- <td>{item.status}</td>
- <td className="ops-mono">{item.batch_no ?? <span className="table-placeholder">—</span>}</td>
- </tr>
- ))}
- </tbody>
- </table>
- )}
- </div>
- </section>
- )}
- {/* ④ 批次清单 */}
- <div className="reconcile-ledger list-shell-fill">
- {/* ③ 筛选条:自然月(periods 口)/分成方类型/分成方(可搜)/出账状态/批次状态/对账单号关键字/零明细开关/重置筛选。 */}
- <div className="ops-toolbar reconcile-filters statement-filters" role="group" aria-label="对账清单筛选">
- <label className="ops-search">
- <Search size={17} aria-hidden="true" />
- <SearchInput aria-label="搜索对账单号" placeholder="搜索对账单号" value={q}
- onCommit={(value) => filters.set("q", value, true)} />
- {q && <button type="button" aria-label="清空对账单号" onClick={() => filters.set("q", "", true)}><X size={15} aria-hidden="true" /></button>}
- </label>
- <label className="ops-search">
- <Search size={17} aria-hidden="true" />
- <SearchInput aria-label="搜索分成方" placeholder="搜索分成方" value={party}
- onCommit={(value) => filters.set("party", value, true)} />
- {party && <button type="button" aria-label="清空分成方" onClick={() => filters.set("party", "", true)}><X size={15} aria-hidden="true" /></button>}
- </label>
- <MonthFilter value={month} availableMonths={periods ?? (month ? [month] : [])} onChange={(value) => filters.set("month", value, true)} />
- <FilterSelect icon="type" aria-label="分成方类型" value={type} onChange={(event) => filters.set("type", event.target.value, true)}>
- <option value="">全部类型</option>
- <option value="operator">{HOLDER_TYPE_TEXT.operator}</option>
- <option value="partner">{HOLDER_TYPE_TEXT.partner}</option>
- <option value="ops_team">{HOLDER_TYPE_TEXT.ops_team}</option>
- </FilterSelect>
- {/* 出账状态与批次状态是两个独立下拉(⚠️ 合并=缺陷);出账状态⛔ 出现「待执行」「已作废」。 */}
- <FilterSelect icon="status" aria-label="出账状态" value={reconcile} onChange={(event) => filters.set("reconcile", event.target.value, true)}>
- <option value="">全部出账状态</option>
- <option value="settled">{RECONCILE_STATUS_TEXT.settled}</option>
- <option value="abnormal">{RECONCILE_STATUS_TEXT.abnormal}</option>
- <option value="unsettled">{RECONCILE_STATUS_TEXT.unsettled}</option>
- </FilterSelect>
- <FilterSelect icon="task" aria-label="批次状态" value={status} onChange={(event) => filters.set("status", event.target.value, true)}>
- <option value="">全部批次状态</option>
- <option value="pending">{BATCH_STATUS_TEXT.pending}</option>
- <option value="executed">{BATCH_STATUS_TEXT.executed}</option>
- <option value="failed">{BATCH_STATUS_TEXT.failed}</option>
- <option value="voided">{BATCH_STATUS_TEXT.voided}</option>
- </FilterSelect>
- {/* 触发方式(手册步序:批次状态之后、关键字之前):只两值,⛔ 第三值。 */}
- <FilterSelect icon="action" aria-label="触发方式" value={trigger} onChange={(event) => filters.set("trigger", event.target.value, true)}>
- <option value="">全部触发方式</option>
- {(["manual", "auto"] as const).map((key) => <option key={key} value={key}>{TRIGGER_TYPE_TEXT[key]}</option>)}
- </FilterSelect>
- <Button variant={zero ? "default" : "outline"} size="sm" className="h-[38px] shrink-0" aria-pressed={zero}
- onClick={() => filters.set("zero", zero ? "" : "1", true)}><ListFilter size={15} aria-hidden="true" />零明细批次</Button>
- {hasFilter && <Button variant="ghost" size="sm" onClick={() => { filters.reset(); setMonthFallback(false); }}>重置筛选</Button>}
- </div>
- {/* S404 触顶 ⇒ 不渲染三卡与列表(⚠️ 禁止静默截断)。 */}
- <div className={tableClass} ref={tableOverflow.ref} role="region" aria-label="对账批次,可横向滚动查看字段" tabIndex={0}>
- {s404 ? <p className="ops-import-note" role="alert">{S404_EMPTY_NOTE}</p> : (
- <table className="ops-table statement-ledger" style={{ minWidth: statementTableWidth }}>
- <OpsTableColumns widths={statementColumns.map(({ width }) => width)} />
- <thead>
- <tr>{statementColumns.map(({ label }) => <th key={label} scope="col">{label}</th>)}</tr>
- </thead>
- <tbody>
- {rows.map((row) => (
- <tr key={row.batch_no}>
- <td>
- <span className="table-cell-title" title={row.batch_no}>{row.batch_no}</span>
- </td>
- <td><strong className="table-cell-title" title={row.holder_name}>{row.holder_name}</strong>
- <div className="statement-holder-type"><OpsTag tone={holderTone[row.holder_type]}>{HOLDER_TYPE_TEXT[row.holder_type]}</OpsTag></div>
- </td>
- <td><span className="ops-mono">{row.period}</span></td>
- <td>{row.recon_date}</td>
- <td><OpsTag tone={row.trigger_type === "manual" ? "warning" : "neutral"}>{TRIGGER_TYPE_TEXT[row.trigger_type]}</OpsTag></td>
- <td><span className="table-number">{row.detail_count}</span><span className="statement-unit"> 条</span></td>
- <td><span className="table-number" title={moneyFromCents(row.base_cents)}>{moneyFromCents(row.base_cents)}</span></td>
- <td><span className="table-number statement-share" title={moneyFromCents(row.share_cents)}>{moneyFromCents(row.share_cents)}</span></td>
- <td><OpsStatus tone={reconcileTone[row.reconcile_status]}>{RECONCILE_STATUS_TEXT[row.reconcile_status]}</OpsStatus></td>
- <td>
- <div className="statement-batch-status">
- <OpsStatus tone={batchTone[row.status]}>{BATCH_STATUS_TEXT[row.status]}</OpsStatus>
- {row.status === "failed" && <FailDot reason={row.fail_reason} />}
- </div>
- </td>
- <td title={executorText(row)}>{executorText(row)}</td>
- <td>
- <Link className="ops-table-action" to={batchPath(row.holder_id, row.batch_no)} state={listState}>
- 详情<ArrowRight size={14} aria-hidden="true" />
- </Link>
- </td>
- </tr>
- ))}
- {!rows.length && (
- <OpsTableEmpty colSpan={statementColumns.length}>
- {list.loading ? "加载中…" : wiring ? "对账接口待后端接线,批次数据暂不可读。" : "没有符合筛选条件的对账清单。"}
- </OpsTableEmpty>
- )}
- </tbody>
- </table>
- )}
- </div>
- {!s404 && (
- <ServerListPager
- total={total}
- page={page}
- pageSize={pageSize}
- onPageChange={(next) => filters.set("page", String(next))}
- />
- )}
- </div>
- {list.fail && !wiring && !s404 && (
- <p className="ops-form-error" role="alert">{list.fail.message} <Button variant="ghost" size="sm" onClick={list.reload}>重试</Button></p>
- )}
- {notice && <OpsNotice message={notice} onClose={() => setNotice("")} />}
- </section>
- );
- }
- /* ── 批次详情(14.2) ───────────────────────────────────────────── */
- export function SettlementStatementRecordPage() {
- const identity = useDemoIdentity();
- const navigate = useNavigate();
- const location = useLocation();
- const { no } = useParams();
- const state = (location.state ?? {}) as { from?: string; listSearch?: string };
- // 返回恒回进来那一页(总则§16.11;⛔ history.back());账单明细来路带 listSearch 保留筛选。
- const back = state.from === "/correction-notes"
- ? { to: "/correction-notes", label: BACK_TO_CORRECTIONS }
- : state.from?.startsWith("/settlement-bills/")
- ? { to: state.from, label: BACK_TO_BILL_DETAIL }
- : state.from === "/settlement-bills"
- ? { to: `/settlement-bills${state.listSearch ?? ""}`, label: BACK_TO_BILL_LIST }
- : { to: `/settlement-batches${state.listSearch ?? ""}`, label: BACK_TO_RECON_LIST };
- const detail = useReconDetail(no ?? null);
- const d = detail.data;
- const wiring = detail.fail?.kind === "wiring";
- const isAdmin = !identity || identity.role === "admin";
- const [confirmRerun, setConfirmRerun] = useState(false);
- const [rerunError, setRerunError] = useState("");
- const [busy, setBusy] = useState(false);
- const [notice, setNotice] = useState("");
- function runRerun() {
- if (!d) return;
- setBusy(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: location.state, replace: true });
- })
- .catch((e: unknown) => {
- // 四道闸(60502→60503→60504→60506)/KLT-S407:文案直读后端 message。
- setRerunError(e instanceof Error && e.message ? e.message : "补跑失败,请重试。");
- setBusy(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));
- }
- return (
- <article className="ops-page reconcile-record">
- <Link className="ops-back-link" to={back.to}><ArrowLeft size={16} />{back.label}</Link>
- {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: { ref: d.batch_no } })}
- lineState={{ from: location.pathname }}
- />}
- {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>
- </div>
- </div>
- </div>
- )}
- {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: { from: string };
- }) {
- // 动作可用性=服务端布尔位(与对账§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>
- <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>
- </div>
- <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)}>{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>
- </dl>
- <p className="reconcile-footnote">状态以批次当前记录为准。执行失败的批次由总运营补跑;账单差错通过出账更正登记。</p>
- </section>
- </>
- );
- }
- /* ── FN-08 账单明细(14.3 列表) ─────────────────────────────────── */
- export function SettlementBillListPage() {
- const location = useLocation();
- const filters = useListFilters();
- const q = filters.get("q");
- const type = filters.get("type");
- const month = filters.get("month");
- const page = Number(filters.get("page") || "1") || 1;
- const hasFilter = Boolean(q || type || month);
- // 详情/批次返回时拼回本串,保留筛选(D-2;对齐对账清单 listSearch)。
- const listNavState = { from: "/settlement-bills" as const, listSearch: location.search };
- const periodsFetch = useReconPeriods();
- const periods = periodsFetch.data?.periods ?? null;
- const list = useBillList({ period: month, holderType: type, keyword: q, page });
- const wiring = list.fail?.kind === "wiring";
- const rows = list.data?.items ?? [];
- const total = list.data?.total ?? 0;
- const pageSize = 20;
- return (
- <section className="ops-page bill-index page-fill page-fill-window">
- <header className="reconcile-page-heading">
- <div>
- <p className="ops-eyebrow"><span /> BILLING LINES / 分成与对账</p>
- <h1>账单明细</h1>
- <PageIntro>对账有差异时,按客户和账期追到具体订阅,逐项核对应收、成本和分成。</PageIntro>
- </div>
- </header>
- {wiring && <p className="ops-import-note" role="status">{BILL_WIRING_NOTE}</p>}
- <div className="reconcile-ledger list-shell-fill">
- <div className="reconcile-filters">
- <label className="ops-search">
- <Search size={17} />
- <SearchInput aria-label="搜索账单明细" placeholder="搜索分成方、客户、订阅或单号" value={q}
- onCommit={(value) => { filters.set("page", ""); filters.set("q", value); }} />
- {q && <button type="button" aria-label="清空搜索" onClick={() => filters.set("q", "")}><X size={15} /></button>}
- </label>
- <FilterSelect icon="type" aria-label="分成方类型" value={type} onChange={(event) => { filters.set("page", ""); filters.set("type", event.target.value); }}>
- <option value="">全部类型</option>
- <option value="operator">{HOLDER_TYPE_TEXT.operator}</option>
- <option value="partner">{HOLDER_TYPE_TEXT.partner}</option>
- <option value="ops_team">{HOLDER_TYPE_TEXT.ops_team}</option>
- </FilterSelect>
- <FilterSelect icon="month" aria-label="自然月" value={month} onChange={(event) => { filters.set("page", ""); filters.set("month", event.target.value); }}>
- <option value="">{ALL_PERIODS_LABEL}</option>
- {(periods ?? []).map((p) => <option key={p} value={p}>{p}</option>)}
- </FilterSelect>
- {hasFilter && <Button variant="ghost" size="sm" onClick={filters.reset}>重置筛选</Button>}
- </div>
- <div className="ops-table-wrap">
- <table className="ops-table">
- <OpsTableColumns widths={[180, 90, 170, 200, 90, 120, 130, 160, 76]} />
- <thead><tr><th>分成方</th><th>自然月</th><th>客户</th><th>订阅</th><th>计费天数</th><th>分成基数</th><th>本方分成金额</th><th>对账单号</th><th>操作</th></tr></thead>
- <tbody>
- {rows.map((row) => (
- <tr key={row.bill_detail_id}>
- <td><OpsTag tone={holderTone[row.holder_type]}>{HOLDER_TYPE_TEXT[row.holder_type]}</OpsTag> <strong className="table-cell-title">{row.holder_name}</strong></td>
- <td><span className="ops-mono">{row.period}</span></td>
- <td>{row.customer_name}</td>
- <td>{row.subscription_label}</td>
- <td className="table-number">{row.billing_days} 天</td>
- <td><span className="ops-money">{moneyFromCents(row.share_base_cents)}</span></td>
- <td><strong className="reconcile-money">{moneyFromCents(row.share_amount_cents)}</strong></td>
- <td>
- <Link className="reconcile-row-link" title={row.batch_no} to={batchPath(row.holder_id, row.batch_no)} state={listNavState}>
- {row.batch_no}<ArrowRight size={14} />
- </Link>
- </td>
- <td>
- <Link className="ops-table-action" to={`/settlement-bills/${encodeURIComponent(row.bill_detail_id)}`} state={listNavState}>
- 详情
- </Link>
- </td>
- </tr>
- ))}
- {!rows.length && (
- <OpsTableEmpty colSpan={9}>
- {list.loading ? "加载中…" : wiring ? "账单明细接口待后端接线,数据暂不可读。" : "没有符合筛选条件的账单明细。"}
- </OpsTableEmpty>
- )}
- </tbody>
- </table>
- </div>
- <ServerListPager
- total={total}
- page={page}
- pageSize={pageSize}
- onPageChange={(next) => filters.set("page", String(next))}
- />
- </div>
- {list.fail && !wiring && (
- <p className="ops-form-error" role="alert">{list.fail.message} <Button variant="ghost" size="sm" onClick={list.reload}>重试</Button></p>
- )}
- </section>
- );
- }
- /* ── 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 };
- const back = state.from === "/correction-notes"
- ? { to: "/correction-notes", label: BACK_TO_CORRECTIONS }
- : state.from?.startsWith("/settlement-batches/")
- ? { to: state.from, label: BACK_TO_RECON_DETAIL }
- : { to: `/settlement-bills${state.from === "/settlement-bills" ? (state.listSearch ?? "") : ""}`, label: BACK_TO_BILL_LIST };
- const detail = useBillDetail(index ?? null);
- const bill = detail.data;
- const wiring = detail.fail?.kind === "wiring";
- return (
- <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>}
- {!bill && detail.loading && <p className="bill-record-placeholder" role="status">正在读取账单明细…</p>}
- {bill && <BillRecordContent key={bill.bill_detail_id} bill={bill} from={location.pathname} />}
- </article>
- );
- }
|