| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079 |
- /**
- * 册 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, 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";
- 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 { detailBack, detailLinkState, useDetailLinkState, type DetailLinkState } from "../lib/detail-navigation";
- import {
- lastClosedMonth, submitReconRerun,
- useBillDetail, useBillList, useReconDetail, useReconList,
- } from "../lib/recon";
- import {
- ACTION_FLAG_PENDING_NOTE,
- BACK_TO_BILL_LIST,
- 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,
- 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,
- 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 { state } = useLocation();
- 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, state });
- const reset = () => setParams({}, { replace: true, state });
- 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 returnState = useDetailLinkState();
- 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: returnState,
- });
- })
- .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) ─────────────────────────────────────── */
- type SettlementLedgerColumn = { label: string; width: number; numeric?: boolean };
- const settlementActionWidth = 84;
- const statementColumns: readonly SettlementLedgerColumn[] = [
- { label: "对账单号", width: 172 }, { label: "分成方", width: 180 },
- { label: "自然月", width: 80 }, { label: "应出账日期", width: 104 },
- { label: "触发方式", width: 88 }, { label: "明细条数", width: 86, numeric: true },
- { label: "总金额", width: 112, numeric: true }, { label: "分成金额", width: 116, numeric: true },
- { label: "出账状态", width: 98 }, { label: "批次状态", width: 104 },
- { label: "执行人", width: 106 },
- ];
- const billColumns: readonly SettlementLedgerColumn[] = [
- { label: "分成方", width: 164 }, { label: "自然月", width: 80 },
- { label: "客户", width: 180 }, { label: "订阅", width: 192 },
- { label: "计费天数", width: 90, numeric: true }, { label: "分成基数", width: 112, numeric: true },
- { label: "本方分成金额", width: 124, numeric: true }, { label: "对账单号", width: 164 },
- ];
- function useSettlementLedgerTable(columns: readonly SettlementLedgerColumn[]) {
- const { ref, width, overflow, canScrollLeft, canScrollRight } = useHorizontalOverflow();
- const minContentWidth = columns.reduce((sum, column) => sum + column.width, 0);
- const contentWidth = Math.max(minContentWidth, width - settlementActionWidth);
- const widths = columns.map((column) => contentWidth * (column.width / minContentWidth)).concat(settlementActionWidth);
- const className = [
- "measured-table-scroll ops-table-wrap settlement-ledger-scroll",
- overflow && "has-horizontal-overflow",
- width >= 900 && "can-pin-identity",
- canScrollLeft && "can-scroll-left",
- canScrollRight && "can-scroll-right",
- ].filter(Boolean).join(" ");
- return { ref, className, widths, minWidth: minContentWidth + settlementActionWidth };
- }
- function SettlementLedgerHead({ columns }: { columns: readonly SettlementLedgerColumn[] }) {
- return <thead><tr>
- {columns.map(({ label, numeric }) => <th key={label} scope="col" className={numeric ? "settlement-ledger-number" : undefined}>{label}</th>)}
- <th scope="col" className="settlement-ledger-action">操作</th>
- </tr></thead>;
- }
- function SettlementHolderCell({ name, type }: { name: string; type: HolderType }) {
- return <td>
- <strong className="table-cell-title" title={name}>{name || <span className="table-placeholder">—</span>}</strong>
- <div className="settlement-ledger-holder-type"><OpsTag tone={holderTone[type]}>{HOLDER_TYPE_TEXT[type]}</OpsTag></div>
- </td>;
- }
- export function SettlementStatementListPage() {
- const identity = useDemoIdentity();
- const listState = useDetailLinkState();
- const back = detailBack(listState.previousState, "/settlement-batches", BACK_TO_RECON_LIST);
- const filters = useListFilters();
- const table = useSettlementLedgerTable(statementColumns);
- 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 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 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);
- 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">
- {back.to !== "/settlement-batches" && <Link className="ops-back-link self-start" to={back.to} state={back.state}><ArrowLeft size={16} aria-hidden="true" />{back.label}</Link>}
- <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>}
- {/* ② 三统计卡:与列表同一响应同一行集;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">
- {/* ③ 筛选条:自然月/分成方类型/分成方(可搜)/出账状态/批次状态/对账单号关键字/零明细开关/重置筛选。 */}
- <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} 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}>重置筛选</Button>}
- </div>
- {/* S404 触顶 ⇒ 不渲染三卡与列表(⚠️ 禁止静默截断)。 */}
- <div className={table.className} ref={table.ref} role="region" aria-label="对账批次,可横向滚动查看字段" tabIndex={0}>
- {s404 ? <p className="ops-import-note" role="alert">{S404_EMPTY_NOTE}</p> : (
- <table className="ops-table settlement-ledger statement-ledger" style={{ minWidth: table.minWidth }}>
- <OpsTableColumns widths={table.widths} />
- <SettlementLedgerHead columns={statementColumns} />
- <tbody>
- {rows.map((row) => (
- <tr key={row.batch_no}>
- <td>
- <span className="table-cell-title" title={row.batch_no}>{row.batch_no}</span>
- </td>
- <SettlementHolderCell name={row.holder_name} type={row.holder_type} />
- <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 className="settlement-ledger-number"><span className="table-number">{row.detail_count}</span><span className="settlement-ledger-unit"> 条</span></td>
- <td className="settlement-ledger-number"><span className="ops-money" title={moneyFromCents(row.base_cents)}>{moneyFromCents(row.base_cents)}</span></td>
- <td className="settlement-ledger-number"><span className="ops-money settlement-ledger-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 className="settlement-ledger-action">
- <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={table.widths.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) ───────────────────────────────────────────── */
- 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 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 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 [rerunning, setRerunning] = useState(false);
- const [exporting, setExporting] = useState(false);
- const [notice, setNotice] = useState("");
- async function runRerun(event: FormEvent<HTMLFormElement>) {
- event.preventDefault();
- if (!batch || !isAdmin || batch.can_rerun !== true || rerunning) return;
- setRerunning(true);
- setRerunError("");
- 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 closeRerun() {
- if (!rerunning) setConfirmRerun(false);
- }
- const batchNumber = batch?.batch_no ?? no;
- return (
- <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>}
- {!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>
- <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 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>;
- }
- 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>
- <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>
- {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 列表) ─────────────────────────────────── */
- export function SettlementBillListPage() {
- const listNavState = useDetailLinkState();
- const filters = useListFilters();
- const table = useSettlementLedgerTable(billColumns);
- const q = filters.get("q");
- const type = filters.get("type");
- const monthParam = filters.get("month");
- const month = monthParam === "all" ? "" : monthParam;
- const page = Number(filters.get("page") || "1") || 1;
- const hasFilter = Boolean(q || type || month);
- 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="ops-heading">
- <div>
- <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>
- <MonthFilter value={month} onChange={(value) => filters.set("month", value, true)} />
- {hasFilter && <Button variant="ghost" size="sm" onClick={filters.reset}>重置筛选</Button>}
- </div>
- <div className={table.className} ref={table.ref} role="region" aria-label="账单明细,可横向滚动查看字段" tabIndex={0}>
- <table className="ops-table settlement-ledger" style={{ minWidth: table.minWidth }}>
- <OpsTableColumns widths={table.widths} />
- <SettlementLedgerHead columns={billColumns} />
- <tbody>
- {rows.map((row) => (
- <tr key={row.bill_detail_id}>
- <SettlementHolderCell name={row.holder_name} type={row.holder_type} />
- <td><span className="ops-mono">{row.period}</span></td>
- <td><strong className="table-cell-title" title={row.customer_name}>{row.customer_name}</strong></td>
- <td><strong className="table-cell-title" title={row.subscription_label}>{row.subscription_label}</strong></td>
- <td className="settlement-ledger-number"><span className="table-number">{row.billing_days}</span><span className="settlement-ledger-unit"> 天</span></td>
- <td className="settlement-ledger-number"><span className="ops-money" title={moneyFromCents(row.share_base_cents)}>{moneyFromCents(row.share_base_cents)}</span></td>
- <td className="settlement-ledger-number"><span className="ops-money settlement-ledger-share" title={moneyFromCents(row.share_amount_cents)}>{moneyFromCents(row.share_amount_cents)}</span></td>
- <td>
- <Link className="ops-table-action settlement-ledger-batch-link" title={row.batch_no} to={batchPath(row.holder_id, row.batch_no)} state={listNavState}>
- <span>{row.batch_no}</span><ArrowRight size={14} aria-hidden="true" />
- </Link>
- </td>
- <td className="settlement-ledger-action">
- <Link className="ops-table-action" to={`/settlement-bills/${encodeURIComponent(row.bill_detail_id)}`} state={listNavState}>
- 详情<ArrowRight size={14} aria-hidden="true" />
- </Link>
- </td>
- </tr>
- ))}
- {!rows.length && (
- <OpsTableEmpty colSpan={table.widths.length}>
- {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, linkState }: { holderId: string; number: string; linkState: DetailLinkState }) {
- return <Link className="ops-table-action bill-record-batch-link" to={batchPath(holderId, number)} state={linkState}>
- <span>{number}</span><ArrowRight size={14} aria-hidden="true" />
- </Link>;
- }
- function BillRecordContent({ bill }: { bill: BillDetailResult }) {
- const location = useLocation();
- const [tab, setTab] = useState<BillRecordTab>(() => billRecordTabs.find(({ id }) => id === location.state?.billTab)?.id ?? "billing");
- const outgoingState = detailLinkState(location.pathname + location.search + location.hash, { ...location.state, billTab: tab });
- 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} linkState={outgoingState} /></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} linkState={outgoingState} /> : 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 back = detailBack(location.state, "/settlement-bills", 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} state={back.state}><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} />}
- </article>
- );
- }
|