SettlementRecordPages.tsx 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  1. /**
  2. * 册 6《计费与对账出账》四页:FN-05 对账清单(14.1)、批次详情(14.2)、FN-08 账单明细与明细详情(14.3)。
  3. *
  4. * 接线状态(2026-11-11 核实):bos.recon/* 与 bos.bill/* 未在 openapi.yaml 声明 ⇒ 网关 11001 未声明即拒绝。
  5. * 撞 11001 ⇒ 契约占位分支(结构按 14 章落位、横幅标明待接线、数据区「后端未下发」);
  6. * ⛔ 用 settlement-demo/settlement-retries 本地台账冒充真接口(=绕过,本版起不再作为本页数据源)。
  7. * 文案唯一真源 ../lib/copy-billing(逐字复制自册 6 契约 14 章/05 章 §5.1,⛔ 手打转述);
  8. * 「分成方式与取值」列走 ../lib/settle-text 单源(册 4 settle_text,⛔ 本册自造分成取值文案)。
  9. * 禁项:⛔「按金额分成本期不计算」「未对账」「已打回」字样;⛔ 出账状态与批次状态混列;⛔ history.back()。
  10. */
  11. import { useEffect, useState, type FormEvent } from "react";
  12. import { PageIntro } from "../components/PageIntro";
  13. import { ArrowLeft, ArrowRight, Download, FileSpreadsheet, Search, X } from "lucide-react";
  14. import { Link, useLocation, useNavigate, useParams, useSearchParams } from "react-router";
  15. import { Button } from "../components/ui/button";
  16. import { SearchInput } from "../components/ui/search-input";
  17. import { FilterSelect } from "../components/ui/filter-select";
  18. import { MonthFilter } from "../components/ui/month-filter";
  19. import { ServerListPager } from "../components/ListPager";
  20. import { OpsNotice, OpsStatus, OpsTableColumns, OpsTableEmpty, OpsTag, type OpsTone } from "../components/OperationsKit";
  21. import { useDemoIdentity } from "../lib/demo-session";
  22. import { entTeamGetList, operatorGetList, partnerGetList, reconExportDetail, reconExportList } from "../lib/api/bos";
  23. import type { HolderType, ReconBatchStatus, ReconcileStatus, ReconDetailResult } from "../lib/api/types";
  24. import type { StatusTone } from "../domain/statuses";
  25. import { WORD_FETCH_FAILED } from "../lib/api/lockedCopy";
  26. import { settleTextFromSnapshot } from "../lib/settle-text";
  27. import {
  28. lastClosedMonth, submitReconRerun,
  29. useBillDetail, useBillList, useReconDetail, useReconList, useReconPeriods,
  30. } from "../lib/recon";
  31. import {
  32. ACTION_FLAG_PENDING_NOTE,
  33. ALL_PERIODS_LABEL,
  34. BACK_TO_BILL_DETAIL,
  35. BACK_TO_BILL_LIST,
  36. BACK_TO_CORRECTIONS,
  37. BACK_TO_RECON_DETAIL,
  38. BACK_TO_RECON_LIST,
  39. BACKEND_NOT_WIRED,
  40. BASE_FLOOR_NOTE,
  41. BATCH_STATUS_TEXT,
  42. BILL_WIRING_NOTE,
  43. COST_UNCONFIGURED_NOTE,
  44. EXECUTOR_SYSTEM,
  45. EXPORT_EMPTY_NOTE,
  46. exportResultNote,
  47. HOLDER_TYPE_TEXT,
  48. MONTH_NO_BATCH_NOTE,
  49. PERIODS_UNAVAILABLE,
  50. periodProgressLine,
  51. PROGRESS_COLLAPSE,
  52. PROGRESS_EXPAND,
  53. RECON_WIRING_NOTE,
  54. RECONCILE_STATUS_TEXT,
  55. RERUN_DIALOG_TITLE,
  56. RERUN_NO_EMPTY_BATCH_NOTE,
  57. RERUN_SUBMIT,
  58. RERUN_VOID_NOTE,
  59. rerunMonthBoundNote,
  60. rerunScopeLine,
  61. S404_EMPTY_NOTE,
  62. STAT_CARDS,
  63. TICKET_GAP_LABEL,
  64. ticketGapText,
  65. TRIGGER_TYPE_TEXT,
  66. VOIDED_BY_PREFIX,
  67. ZERO_NOTE_TEXT,
  68. } from "../lib/copy-billing";
  69. import "../styles/operations.css";
  70. import "../styles/settlement-records.css";
  71. /* ── 本地小工具 ─────────────────────────────────────────────────── */
  72. /** 金额列以 `_cents`(分)下发;界面统一两位小数元。 */
  73. const moneyFromCents = (cents: number): string =>
  74. `¥${(cents / 100).toLocaleString("zh-CN", { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
  75. /** 三态格:null ⇒ 「取数失败」(KLT-S406 单格语义),⛔ 回落 0。 */
  76. const moneyCell = (cents: number | null): string => (cents == null ? WORD_FETCH_FAILED : moneyFromCents(cents));
  77. const reconcileTone: Record<ReconcileStatus, StatusTone> = { settled: "success", abnormal: "danger", unsettled: "neutral" };
  78. const batchTone: Record<ReconBatchStatus, StatusTone> = { pending: "neutral", executed: "success", failed: "danger", voided: "neutral" };
  79. const holderTone: Record<HolderType, OpsTone> = { operator: "brand", partner: "info", ops_team: "warning" };
  80. /**
  81. * 执行时间本地化:后端 `CAST(executed_at AS TEXT)` 下发 UTC 裸串(`2026-11-13 03:49:40.05+00`),
  82. * 直接入列既难读又与手册「执行时间」口径不符 ⇒ 按浏览器时区显示,原文留 `title` 可核。
  83. */
  84. function localTime(iso: string): string {
  85. const d = new Date(iso.includes("T") ? iso : iso.replace(" ", "T"));
  86. if (Number.isNaN(d.getTime())) return iso;
  87. const p = (n: number) => String(n).padStart(2, "0");
  88. return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`;
  89. }
  90. /**
  91. * 执行人可读化:优先绑定表用户名(`operator_username`);NULL ⇒「系统」(对账§14.2);
  92. * 只有裸 seoh 用户 ID 时标明是 ID,⛔ 把裸 ID 当人名直接渲染。
  93. */
  94. function executorText(e: { operator_user_id: string | null; operator_username?: string | null }): string {
  95. const name = e.operator_username?.trim();
  96. if (name) return name;
  97. return e.operator_user_id ? `用户 ${e.operator_user_id}` : EXECUTOR_SYSTEM;
  98. }
  99. const batchPath = (holderId: string, batchNo: string) =>
  100. `/settlement-batches/${encodeURIComponent(holderId)}/${encodeURIComponent(batchNo)}`;
  101. /** URL 搜索参数筛选(返回列表时保留条件;⛔ 路由级收敛另行处理)。 */
  102. function useListFilters() {
  103. const [params, setParams] = useSearchParams();
  104. const has = (key: string) => params.has(key);
  105. const get = (key: string) => params.get(key) ?? "";
  106. const set = (key: string, value: string) =>
  107. setParams((current) => {
  108. const next = new URLSearchParams(current);
  109. if (value) next.set(key, value);
  110. else next.delete(key);
  111. return next;
  112. }, { replace: true });
  113. const reset = () => setParams({}, { replace: true });
  114. return { has, get, set, reset };
  115. }
  116. /** 失败原因行末红点(fail_reason 原文悬浮;⚠️ 不是 KLT-* 码,对账§7.1 末格)。 */
  117. function FailDot({ reason }: { reason: string | null }) {
  118. if (!reason) return null;
  119. return <span style={{ color: "var(--destructive)", cursor: "help" }} title={reason}> ●</span>;
  120. }
  121. /* ── 人工补跑对话框(14.1 动作矩阵:仅 admin;入参只三件) ────────── */
  122. function RerunDialog({ onClose }: { onClose: () => void }) {
  123. const navigate = useNavigate();
  124. const location = useLocation();
  125. const [holderType, setHolderType] = useState<HolderType>("operator");
  126. const [holders, setHolders] = useState<{ id: string; name: string }[] | null>(null);
  127. const [holdersError, setHoldersError] = useState("");
  128. const [holderId, setHolderId] = useState("");
  129. const [period, setPeriod] = useState(lastClosedMonth());
  130. const [error, setError] = useState("");
  131. const [busy, setBusy] = useState(false);
  132. // 分成方候选=第 1 册三类档案真源列表口(⛔ 本地台账);切换类型时重拉。
  133. useEffect(() => {
  134. let alive = true;
  135. setHolders(null);
  136. setHoldersError("");
  137. setHolderId("");
  138. // ⚠️ bos 列表接口 `page` 以 0 为首页(同 `organization-demo.ts::pagedAll`)⇒ 传 1 会跳过首页,
  139. // dev 数据不足一页时候选恒空(补跑弹窗打不开)。
  140. const load =
  141. holderType === "operator"
  142. ? operatorGetList({ page: 0, page_size: 100 }).then((r) => (r.items ?? []).map((o) => ({ id: o.operator_id, name: o.name })))
  143. : holderType === "partner"
  144. ? partnerGetList({ page: 0, page_size: 100 }).then((r) => (r.items ?? []).map((p) => ({ id: p.partner_id, name: p.name })))
  145. : entTeamGetList({ page: 0, page_size: 100 }).then((r) => (r.items ?? []).map((t) => ({ id: t.team_id, name: t.team_name })));
  146. load
  147. .then((rows) => {
  148. if (!alive) return;
  149. setHolders(rows);
  150. setHolderId(rows[0]?.id ?? "");
  151. })
  152. .catch((e: unknown) => {
  153. if (alive) setHoldersError(e instanceof Error ? e.message : WORD_FETCH_FAILED);
  154. });
  155. return () => {
  156. alive = false;
  157. };
  158. }, [holderType]);
  159. function submit(event: FormEvent) {
  160. event.preventDefault();
  161. if (!holderId || !period) {
  162. setError(!holderId ? "请选择分成方。" : "请选择自然月。");
  163. return;
  164. }
  165. setBusy(true);
  166. setError("");
  167. submitReconRerun({ holder_type: holderType, holder_id: holderId, period })
  168. .then((res) => {
  169. onClose();
  170. navigate(batchPath(holderId, res.batch_no), { state: location.state });
  171. })
  172. .catch((e: unknown) => {
  173. // 四道闸(60502→60503→60504→60506)/KLT-S407:文案直读后端 message(出路句由服务端带出)。
  174. setError(e instanceof Error && e.message ? e.message : "补跑失败,请重试。");
  175. setBusy(false);
  176. });
  177. }
  178. // 弹窗须写明补跑对象(分成方名称+月份),⛔ 只回显 ID。
  179. const holderName = holders?.find((h) => h.id === holderId)?.name ?? holderId;
  180. return (
  181. <div className="ops-confirm-backdrop" role="presentation" onMouseDown={onClose}>
  182. <div className="ops-confirm" role="dialog" aria-modal="true" aria-labelledby="rerun-dialog-title" onMouseDown={(event) => event.stopPropagation()}>
  183. <h2 id="rerun-dialog-title">{RERUN_DIALOG_TITLE}</h2>
  184. <form onSubmit={submit}>
  185. <p style={{ margin: "12px 0" }}>
  186. <FilterSelect icon="type" aria-label="分成方类型" value={holderType} onChange={(event) => { setHolderType(event.target.value as HolderType); }}>
  187. <option value="operator">{HOLDER_TYPE_TEXT.operator}</option>
  188. <option value="partner">{HOLDER_TYPE_TEXT.partner}</option>
  189. <option value="ops_team">{HOLDER_TYPE_TEXT.ops_team}</option>
  190. </FilterSelect>{" "}
  191. {holders ? (
  192. <FilterSelect icon="operator" aria-label="分成方" value={holderId} onChange={(event) => setHolderId(event.target.value)}>
  193. {holders.map((h) => <option key={h.id} value={h.id}>{h.name}</option>)}
  194. {!holders.length && <option value="">(无可选分成方)</option>}
  195. </FilterSelect>
  196. ) : (
  197. <span>{holdersError || "加载中…"}</span>
  198. )}{" "}
  199. {/* 月份上界=上一个已结束自然月(对账§8.3 只可对已结束月份补跑);期次必填 ⇒ ⛔「全部自然月」。 */}
  200. <MonthFilter value={period} onChange={setPeriod} maxMonth={lastClosedMonth()} allowAll={false} />
  201. </p>
  202. <p>{rerunScopeLine(holderName, period)}</p>
  203. <p>{rerunMonthBoundNote(lastClosedMonth())}</p>
  204. <p>{RERUN_NO_EMPTY_BATCH_NOTE}</p>
  205. <p>{RERUN_VOID_NOTE}</p>
  206. {error && <p className="ops-form-error" role="alert">{error}</p>}
  207. <div>
  208. <Button variant="outline" type="button" onClick={onClose} disabled={busy}>取消</Button>
  209. <Button type="submit" disabled={busy || !holders?.length}>{busy ? "提交中…" : RERUN_SUBMIT}</Button>
  210. </div>
  211. </form>
  212. </div>
  213. </div>
  214. );
  215. }
  216. /* ── FN-05 对账清单(14.1) ─────────────────────────────────────── */
  217. export function SettlementStatementListPage() {
  218. const identity = useDemoIdentity();
  219. const location = useLocation();
  220. const filters = useListFilters();
  221. // 导出当前结果(B):admin/opsMain/opsSub(demo 角色无 opsSub);⛔ teamLead/partner/operator。
  222. const canExportAll = !identity || identity.role === "admin" || identity.role === "regAdmin";
  223. const isAdmin = !identity || identity.role === "admin";
  224. const defaultMonth = lastClosedMonth();
  225. // 自然月三态:参数缺席 ⇒ 默认预选 lastClosedMonth();显式 "all" ⇒ 全部自然月(空值项,⛔ 不得删除)。
  226. const monthAll = filters.get("month") === "all";
  227. const month = monthAll ? "" : filters.get("month") || defaultMonth;
  228. const type = filters.get("type");
  229. const party = filters.get("party");
  230. const reconcile = filters.get("reconcile");
  231. const status = filters.get("status");
  232. const trigger = filters.get("trigger");
  233. const zero = filters.get("zero") === "1";
  234. const q = filters.get("q");
  235. const page = Number(filters.get("page") || "1") || 1;
  236. const setMonth = (value: string) => {
  237. filters.set("page", "");
  238. filters.set("month", value === "" ? "all" : value === defaultMonth ? "" : value);
  239. };
  240. const hasFilter = Boolean(monthAll || filters.get("month") || type || party || reconcile || status || trigger || zero || q);
  241. const periodsFetch = useReconPeriods();
  242. // D-19:下拉选项=接口期次 ∪ 上一个已结束自然月(与人工补跑弹窗 `lastClosedMonth()` 同基准)。
  243. // 仅有历史批、尚无「上月」批时,仍须能选上月(可能空表),⛔ 静默退到更早月造成「弹窗说 10 月、清单只到 9 月」。
  244. const periods = (() => {
  245. const raw = periodsFetch.data?.periods ?? null;
  246. if (!raw) return null;
  247. if (raw.includes(defaultMonth)) return raw;
  248. return [defaultMonth, ...raw];
  249. })();
  250. // 仅当**用户显式选了**不在选项内的历史月(例如书签)才纠偏;默认预选月即使暂无批次也保留。
  251. const [monthFallback, setMonthFallback] = useState(false);
  252. useEffect(() => {
  253. if (!periods?.length) return;
  254. if (monthAll) {
  255. setMonthFallback(false);
  256. return;
  257. }
  258. if (!filters.has("month")) {
  259. setMonthFallback(false);
  260. return;
  261. }
  262. if (periods.includes(month)) {
  263. setMonthFallback(false);
  264. return;
  265. }
  266. filters.set("month", periods[0]);
  267. setMonthFallback(true);
  268. // eslint-disable-next-line react-hooks/exhaustive-deps
  269. }, [periods, month, monthAll]);
  270. const list = useReconList({
  271. period: month,
  272. holderType: type,
  273. holderKw: party,
  274. reconcileStatus: reconcile,
  275. batchStatus: status,
  276. trigger,
  277. includeZero: zero,
  278. keyword: q,
  279. page,
  280. });
  281. const data = list.data;
  282. const wiring = list.fail?.kind === "wiring";
  283. const s404 = list.fail?.kind === "s404";
  284. const rows = data?.items ?? [];
  285. const total = data?.total ?? 0;
  286. const pageSize = 20;
  287. const [notice, setNotice] = useState("");
  288. const [runOpen, setRunOpen] = useState(false);
  289. const [progressOpen, setProgressOpen] = useState(false);
  290. function exportAll() {
  291. // 筛选无结果 ⇒ 只提示、不导出、无错误码(14.1 动作矩阵)。
  292. if (!rows.length) {
  293. setNotice(EXPORT_EMPTY_NOTE);
  294. return;
  295. }
  296. reconExportList({ period: month || undefined, holder_type: type || undefined, status: status || undefined })
  297. .then((res) => setNotice(exportResultNote(res)))
  298. .catch((e: unknown) => setNotice(e instanceof Error && e.message ? e.message : WORD_FETCH_FAILED));
  299. }
  300. return (
  301. <section className="ops-page reconcile-index page-fill page-fill-window">
  302. <header className="reconcile-page-heading">
  303. <div>
  304. <p className="ops-eyebrow"><span /> RECONCILIATION / 分成与对账</p>
  305. <h1>对账清单</h1>
  306. <PageIntro>每个账期出账后,按分成方核对批次状态和结算结果。</PageIntro>
  307. </div>
  308. <div className="statement-heading-actions">
  309. {isAdmin && <Button onClick={() => setRunOpen(true)}>人工补跑</Button>}
  310. </div>
  311. </header>
  312. {runOpen && <RerunDialog onClose={() => setRunOpen(false)} />}
  313. {/* 接线占位横幅(klt-bos recon/* 未交付;交付后本分支自然失效) */}
  314. {wiring && <p className="ops-import-note" role="status">{RECON_WIRING_NOTE}</p>}
  315. {periodsFetch.fail && !wiring && <p className="ops-import-note" role="status">{PERIODS_UNAVAILABLE}</p>}
  316. {monthFallback && !rows.length && <p className="ops-import-note" role="status">{MONTH_NO_BATCH_NOTE}</p>}
  317. {/* ② 三统计卡:与列表同一响应同一行集;S404 ⇒ 整体不渲染(不是显示 0);单格 null ⇒「取数失败」。 */}
  318. {!s404 && !wiring && data && (
  319. <div className="reconcile-totals" aria-label="当前筛选结果统计">
  320. {STAT_CARDS.map((card) => {
  321. const value =
  322. card.key === "base" ? data.stats.total_base_cents : card.key === "cost" ? data.stats.total_cost_cents : data.stats.total_share_cents;
  323. return (
  324. <div key={card.key}>
  325. <span>{card.title}</span>
  326. <strong>{moneyCell(value)}</strong>
  327. <small>{card.subtitle}</small>
  328. </div>
  329. );
  330. })}
  331. </div>
  332. )}
  333. {/* 契约占位分支:卡结构落位、值格显式标「后端未下发」(总则§16.9,⛔ 演示例数冒充)。 */}
  334. {wiring && (
  335. <div className="reconcile-totals" aria-label="当前筛选结果统计">
  336. {STAT_CARDS.map((card) => (
  337. <div key={card.key}>
  338. <span>{card.title}</span>
  339. <strong>{BACKEND_NOT_WIRED}</strong>
  340. <small>{card.subtitle}</small>
  341. </div>
  342. ))}
  343. </div>
  344. )}
  345. {/* ③-1 期次出账进度(常驻;只随自然月变化,⛔ 随其余筛选变;后端未下发 ⇒ 不渲)。 */}
  346. {data?.progress && (
  347. <>
  348. <div className="ops-detail-callout" role="status">
  349. <strong>{periodProgressLine(data.progress)}</strong>
  350. <p>
  351. <button type="button" className="ops-table-action" onClick={() => setProgressOpen((v) => !v)}>
  352. {progressOpen ? PROGRESS_COLLAPSE : PROGRESS_EXPAND} <ArrowRight size={13} />
  353. </button>
  354. </p>
  355. </div>
  356. {progressOpen && (
  357. <div className="ops-table-wrap">
  358. <table className="ops-table">
  359. <thead><tr><th>分成方</th><th>建档区域</th><th>对账日</th><th>本期应出账日期</th><th>状态</th><th>对账单号</th></tr></thead>
  360. <tbody>
  361. {data.progress.items.map((item) => (
  362. <tr key={`${item.holder_type}-${item.holder_id}`}>
  363. <td><OpsTag tone={holderTone[item.holder_type]}>{HOLDER_TYPE_TEXT[item.holder_type]}</OpsTag> {item.holder_name}</td>
  364. <td>{item.region_label ?? "—"}</td>
  365. <td>{item.recon_day} 日</td>
  366. <td>{item.expected_date}</td>
  367. <td>{item.status}</td>
  368. <td className="ops-mono">{item.batch_no ?? "—"}</td>
  369. </tr>
  370. ))}
  371. </tbody>
  372. </table>
  373. </div>
  374. )}
  375. </>
  376. )}
  377. {/* ④ 批次清单 */}
  378. <div className="reconcile-ledger list-shell-fill">
  379. {/* ③ 筛选条:自然月(periods 口)/分成方类型/分成方(可搜)/出账状态/批次状态/对账单号关键字/零明细开关/重置筛选。 */}
  380. <div className="reconcile-filters">
  381. <label className="ops-search">
  382. <Search size={17} />
  383. <SearchInput aria-label="搜索对账单号" placeholder="搜索对账单号" value={q}
  384. onCommit={(value) => { filters.set("page", ""); filters.set("q", value); }} />
  385. {q && <button type="button" aria-label="清空搜索" onClick={() => filters.set("q", "")}><X size={15} /></button>}
  386. </label>
  387. <FilterSelect icon="month" aria-label="自然月" value={monthAll ? "" : month} onChange={(event) => setMonth(event.target.value)}>
  388. <option value="">{ALL_PERIODS_LABEL}</option>
  389. {(periods ?? (month ? [month] : [])).map((p) => <option key={p} value={p}>{p}</option>)}
  390. </FilterSelect>
  391. <FilterSelect icon="type" aria-label="分成方类型" value={type} onChange={(event) => { filters.set("page", ""); filters.set("type", event.target.value); }}>
  392. <option value="">全部类型</option>
  393. <option value="operator">{HOLDER_TYPE_TEXT.operator}</option>
  394. <option value="partner">{HOLDER_TYPE_TEXT.partner}</option>
  395. <option value="ops_team">{HOLDER_TYPE_TEXT.ops_team}</option>
  396. </FilterSelect>
  397. <label className="ops-search">
  398. <Search size={17} />
  399. <SearchInput aria-label="搜索分成方" placeholder="搜索分成方" value={party}
  400. onCommit={(value) => { filters.set("page", ""); filters.set("party", value); }} />
  401. </label>
  402. {/* 出账状态与批次状态是两个独立下拉(⚠️ 合并=缺陷);出账状态⛔ 出现「待执行」「已作废」。 */}
  403. <FilterSelect icon="status" aria-label="出账状态" value={reconcile} onChange={(event) => { filters.set("page", ""); filters.set("reconcile", event.target.value); }}>
  404. <option value="">全部出账状态</option>
  405. <option value="settled">{RECONCILE_STATUS_TEXT.settled}</option>
  406. <option value="abnormal">{RECONCILE_STATUS_TEXT.abnormal}</option>
  407. <option value="unsettled">{RECONCILE_STATUS_TEXT.unsettled}</option>
  408. </FilterSelect>
  409. <FilterSelect icon="action" aria-label="批次状态" value={status} onChange={(event) => { filters.set("page", ""); filters.set("status", event.target.value); }}>
  410. <option value="">全部批次状态</option>
  411. <option value="pending">{BATCH_STATUS_TEXT.pending}</option>
  412. <option value="executed">{BATCH_STATUS_TEXT.executed}</option>
  413. <option value="failed">{BATCH_STATUS_TEXT.failed}</option>
  414. <option value="voided">{BATCH_STATUS_TEXT.voided}</option>
  415. </FilterSelect>
  416. {/* 触发方式(手册步序:批次状态之后、关键字之前):只两值,⛔ 第三值。 */}
  417. <FilterSelect icon="action" aria-label="触发方式" value={trigger} onChange={(event) => { filters.set("page", ""); filters.set("trigger", event.target.value); }}>
  418. <option value="">全部触发方式</option>
  419. {(["manual", "auto"] as const).map((key) => <option key={key} value={key}>{TRIGGER_TYPE_TEXT[key]}</option>)}
  420. </FilterSelect>
  421. <Button variant={zero ? "default" : "outline"} size="sm" aria-pressed={zero}
  422. onClick={() => { filters.set("page", ""); filters.set("zero", zero ? "" : "1"); }}>零明细批次</Button>
  423. {hasFilter && <Button variant="ghost" size="sm" onClick={() => { filters.reset(); setMonthFallback(false); }}>重置筛选</Button>}
  424. {canExportAll && <Button variant="outline" size="sm" onClick={exportAll}><Download size={16} />导出当前结果</Button>}
  425. </div>
  426. {/* S404 触顶 ⇒ 不渲染三卡与列表(⚠️ 禁止静默截断)。 */}
  427. {s404 ? (
  428. <p className="ops-import-note" role="alert">{S404_EMPTY_NOTE}</p>
  429. ) : (
  430. <div className="ops-table-wrap">
  431. <table className="ops-table reconcile-table">
  432. <OpsTableColumns widths={[150, 190, 90, 100, 90, 80, 110, 110, 96, 96, 90, 76]} />
  433. <thead>
  434. <tr><th>对账单号</th><th>分成方</th><th>自然月</th><th>应出账日期</th><th>触发方式</th><th>明细条数</th><th>总金额</th><th>分成金额</th><th>出账状态</th><th>批次状态</th><th>执行人</th><th>操作</th></tr>
  435. </thead>
  436. <tbody>
  437. {rows.map((row) => (
  438. <tr key={row.batch_no}>
  439. <td>
  440. <Link className="reconcile-row-link" title={row.batch_no} to={batchPath(row.holder_id, row.batch_no)}
  441. state={{ from: "/settlement-batches", listSearch: location.search }}>
  442. {row.batch_no}<ArrowRight size={14} />
  443. </Link>
  444. </td>
  445. <td><OpsTag tone={holderTone[row.holder_type]}>{HOLDER_TYPE_TEXT[row.holder_type]}</OpsTag> <strong title={row.holder_name}>{row.holder_name}</strong></td>
  446. <td><span className="ops-mono">{row.period}</span></td>
  447. <td>{row.recon_date}</td>
  448. <td><OpsTag tone={row.trigger_type === "manual" ? "warning" : "neutral"}>{TRIGGER_TYPE_TEXT[row.trigger_type]}</OpsTag></td>
  449. <td>{row.detail_count} 条</td>
  450. <td><span className="ops-money">{moneyFromCents(row.base_cents)}</span></td>
  451. <td><strong className="reconcile-money">{moneyFromCents(row.share_cents)}</strong></td>
  452. <td><OpsStatus tone={reconcileTone[row.reconcile_status]}>{RECONCILE_STATUS_TEXT[row.reconcile_status]}</OpsStatus></td>
  453. <td>
  454. <OpsStatus tone={batchTone[row.status]}>{BATCH_STATUS_TEXT[row.status]}</OpsStatus>
  455. {row.status === "failed" && <FailDot reason={row.fail_reason} />}
  456. </td>
  457. <td title={row.operator_user_id ?? undefined}>{executorText(row)}</td>
  458. <td>
  459. <Link className="ops-table-action" to={batchPath(row.holder_id, row.batch_no)}
  460. state={{ from: "/settlement-batches", listSearch: location.search }}>详情</Link>
  461. </td>
  462. </tr>
  463. ))}
  464. {!rows.length && (
  465. <OpsTableEmpty colSpan={12}>
  466. {list.loading ? "加载中…" : wiring ? "对账接口待后端接线,批次数据暂不可读。" : "没有符合筛选条件的对账清单。"}
  467. </OpsTableEmpty>
  468. )}
  469. </tbody>
  470. </table>
  471. </div>
  472. )}
  473. {!s404 && (
  474. <ServerListPager
  475. total={total}
  476. page={page}
  477. pageSize={pageSize}
  478. onPageChange={(next) => filters.set("page", String(next))}
  479. />
  480. )}
  481. </div>
  482. {list.fail && !wiring && !s404 && (
  483. <p className="ops-form-error" role="alert">{list.fail.message} <Button variant="ghost" size="sm" onClick={list.reload}>重试</Button></p>
  484. )}
  485. {notice && <OpsNotice message={notice} onClose={() => setNotice("")} />}
  486. </section>
  487. );
  488. }
  489. /* ── 批次详情(14.2) ───────────────────────────────────────────── */
  490. export function SettlementStatementRecordPage() {
  491. const identity = useDemoIdentity();
  492. const navigate = useNavigate();
  493. const location = useLocation();
  494. const { no } = useParams();
  495. const state = (location.state ?? {}) as { from?: string; listSearch?: string };
  496. // 返回恒回进来那一页(总则§16.11;⛔ history.back())。
  497. const back = state.from === "/correction-notes"
  498. ? { to: "/correction-notes", label: BACK_TO_CORRECTIONS }
  499. : state.from?.startsWith("/settlement-bills/")
  500. ? { to: state.from, label: BACK_TO_BILL_DETAIL }
  501. : state.from === "/settlement-bills"
  502. ? { to: "/settlement-bills", label: BACK_TO_BILL_LIST }
  503. : { to: `/settlement-batches${state.listSearch ?? ""}`, label: BACK_TO_RECON_LIST };
  504. const detail = useReconDetail(no ?? null);
  505. const d = detail.data;
  506. const wiring = detail.fail?.kind === "wiring";
  507. const isAdmin = !identity || identity.role === "admin";
  508. const [confirmRerun, setConfirmRerun] = useState(false);
  509. const [rerunError, setRerunError] = useState("");
  510. const [busy, setBusy] = useState(false);
  511. const [notice, setNotice] = useState("");
  512. function runRerun() {
  513. if (!d) return;
  514. setBusy(true);
  515. setRerunError("");
  516. submitReconRerun({ holder_type: d.holder_type, holder_id: d.holder_id, period: d.period })
  517. .then((res) => {
  518. setConfirmRerun(false);
  519. // 补跑成功 ⇒ 原批次作废、生成新批;直接落到新批详情(来路保留)。
  520. navigate(batchPath(d.holder_id, res.batch_no), { state: location.state, replace: true });
  521. })
  522. .catch((e: unknown) => {
  523. // 四道闸(60502→60503→60504→60506)/KLT-S407:文案直读后端 message。
  524. setRerunError(e instanceof Error && e.message ? e.message : "补跑失败,请重试。");
  525. setBusy(false);
  526. });
  527. }
  528. function exportDetail() {
  529. if (!d) return;
  530. reconExportDetail({ batch_id: d.batch_no })
  531. .then((res) => setNotice(exportResultNote(res)))
  532. .catch((e: unknown) => setNotice(e instanceof Error && e.message ? e.message : WORD_FETCH_FAILED));
  533. }
  534. return (
  535. <article className="ops-page reconcile-record">
  536. <Link className="ops-back-link" to={back.to}><ArrowLeft size={16} />{back.label}</Link>
  537. {wiring && <p className="ops-import-note" role="status">{RECON_WIRING_NOTE}</p>}
  538. {detail.fail && !wiring && (
  539. <p className="ops-form-error" role="alert">{detail.fail.message} <Button variant="ghost" size="sm" onClick={detail.reload}>重试</Button></p>
  540. )}
  541. {/* 契约占位分支:八字段头结构落位、值格「后端未下发」。 */}
  542. {(wiring || (!d && detail.loading)) && (
  543. <header className="reconcile-record-hero">
  544. <div className="reconcile-record-symbol"><FileSpreadsheet size={27} /></div>
  545. <div>
  546. <span className="reconcile-record-eyebrow">RECONCILIATION / {no}</span>
  547. <h1>批次详情</h1>
  548. <p>{detail.loading && !wiring ? "加载中…" : BACKEND_NOT_WIRED}</p>
  549. </div>
  550. </header>
  551. )}
  552. {d && <BatchDetailBody
  553. d={d}
  554. isAdmin={isAdmin}
  555. onRerun={() => { setRerunError(""); setConfirmRerun(true); }}
  556. onExport={exportDetail}
  557. onCorrect={() => navigate("/correction-notes", { state: { ref: d.batch_no } })}
  558. lineState={{ from: location.pathname }}
  559. />}
  560. {confirmRerun && d && (
  561. <div className="ops-confirm-backdrop" role="presentation" onMouseDown={() => !busy && setConfirmRerun(false)}>
  562. <div className="ops-confirm" role="alertdialog" aria-modal="true" aria-labelledby="rerun-confirm-title" onMouseDown={(event) => event.stopPropagation()}>
  563. <h2 id="rerun-confirm-title">{RERUN_DIALOG_TITLE}</h2>
  564. <p>{rerunScopeLine(d.holder_name, d.period)}</p>
  565. {/* failed 批补跑区追加句(§8.6 界面唯一落点之一)。 */}
  566. {d.status === "failed" && <p>{RERUN_VOID_NOTE}</p>}
  567. {rerunError && <p className="ops-form-error" role="alert">{rerunError}</p>}
  568. <div>
  569. <Button variant="outline" onClick={() => setConfirmRerun(false)} disabled={busy}>取消</Button>
  570. <Button onClick={runRerun} disabled={busy}>{busy ? "提交中…" : RERUN_SUBMIT}</Button>
  571. </div>
  572. </div>
  573. </div>
  574. )}
  575. {notice && <OpsNotice message={notice} onClose={() => setNotice("")} />}
  576. </article>
  577. );
  578. }
  579. function BatchDetailBody({ d, isAdmin, onRerun, onExport, onCorrect, lineState }: {
  580. d: ReconDetailResult;
  581. isAdmin: boolean;
  582. onRerun: () => void;
  583. onExport: () => void;
  584. onCorrect: () => void;
  585. lineState: { from: string };
  586. }) {
  587. // 动作可用性=服务端布尔位(与对账§5.5.4 同源常量;⚠️ 前端按角色自猜=第二套判据)。
  588. // null ⇒ 后端未下发 ⇒ 禁用+「可操作性位后端未下发」说明。
  589. const rerunEnabled = isAdmin && d.can_rerun === true;
  590. const exportEnabled = d.can_export === true;
  591. const correctEnabled = isAdmin && d.can_correct === true;
  592. const flagPending = d.can_rerun == null || d.can_export == null || d.can_correct == null;
  593. return (
  594. <>
  595. <header className="reconcile-record-hero">
  596. <div className="reconcile-record-symbol"><FileSpreadsheet size={27} /></div>
  597. <div>
  598. <span className="reconcile-record-eyebrow">RECONCILIATION / {d.batch_no}</span>
  599. <h1>批次详情</h1>
  600. <p>
  601. <strong>{d.holder_name}</strong>
  602. <span>{HOLDER_TYPE_TEXT[d.holder_type]}</span>
  603. <span>自然月 {d.period}</span>
  604. <span>{TRIGGER_TYPE_TEXT[d.trigger_type]}触发 · {executorText(d)}执行</span>
  605. </p>
  606. <div className="reconcile-hero-pills">
  607. <OpsStatus tone={batchTone[d.status]}>{BATCH_STATUS_TEXT[d.status]}</OpsStatus>
  608. <OpsTag tone={d.trigger_type === "manual" ? "warning" : "neutral"}>{TRIGGER_TYPE_TEXT[d.trigger_type]}触发</OpsTag>
  609. </div>
  610. </div>
  611. </header>
  612. <div className="reconcile-record-stats">
  613. <div><span>明细条数</span><strong>{d.detail_count}</strong><small>本批有效行现算,作废行不计</small></div>
  614. <div><span>总金额</span><strong>{moneyFromCents(d.base_cents)}</strong><small>本批有效行应收基数合计</small></div>
  615. <div><span>分成金额</span><strong>{moneyFromCents(d.share_cents)}</strong><small>本批有效行分成金额合计</small></div>
  616. <div>
  617. <span>{TICKET_GAP_LABEL}</span>
  618. <strong>{d.ticket_gap_failed ? WORD_FETCH_FAILED : d.ticket_gap_count == null ? BACKEND_NOT_WIRED : ticketGapText(d.ticket_gap_count)}</strong>
  619. <small>{TICKET_GAP_LABEL}按工单台账现算(0 个缺口与取数失败是两回事)</small>
  620. </div>
  621. </div>
  622. <section className="reconcile-record-section">
  623. <div className="reconcile-record-section-head">
  624. <div><h2>执行结果</h2><p>批次动作与执行说明。</p></div>
  625. <div style={{ display: "flex", gap: 8 }}>
  626. {isAdmin && (
  627. <Button variant="outline" onClick={onRerun} disabled={!rerunEnabled} title={d.can_rerun == null ? ACTION_FLAG_PENDING_NOTE : undefined}>人工补跑</Button>
  628. )}
  629. <Button variant="outline" onClick={onExport} disabled={!exportEnabled} title={d.can_export == null ? ACTION_FLAG_PENDING_NOTE : undefined}>
  630. <Download size={15} />导出本批账单明细
  631. </Button>
  632. {isAdmin && (
  633. <Button variant="outline" onClick={onCorrect} disabled={!correctEnabled} title={d.can_correct == null ? ACTION_FLAG_PENDING_NOTE : undefined}>登记更正</Button>
  634. )}
  635. </div>
  636. </div>
  637. {flagPending && <p className="reconcile-footnote">{ACTION_FLAG_PENDING_NOTE},动作暂不可用。</p>}
  638. {/* 失败原因只在 failed/voided 时渲染;voided 必带「由哪一次补跑作废」链接。 */}
  639. {(d.status === "failed" || d.status === "voided") && d.fail_reason && (
  640. <p className="ops-form-error" role="alert">{d.fail_reason}</p>
  641. )}
  642. {d.status === "voided" && d.voided_by_batch_no && (
  643. <p className="reconcile-footnote">
  644. {VOIDED_BY_PREFIX}
  645. <Link className="ops-table-action" to={batchPath(d.holder_id, d.voided_by_batch_no)}>{d.voided_by_batch_no} <ArrowRight size={14} /></Link>
  646. 作废。
  647. </p>
  648. )}
  649. {/* 成本未配置提示一行(不发通知、不建提醒表;不说"异常")。 */}
  650. {d.cost_unconfigured.length > 0 && (
  651. <p className="reconcile-footnote">{COST_UNCONFIGURED_NOTE}:{d.cost_unconfigured.join("、")}</p>
  652. )}
  653. </section>
  654. <section className="reconcile-record-section">
  655. <div className="reconcile-record-section-head">
  656. <span>01</span>
  657. <div><h2>本批账单明细</h2><p>{d.holder_name} · {d.period} · {d.detail_count} 条</p></div>
  658. </div>
  659. <div className="ops-table-wrap">
  660. <table className="ops-table" style={{ minWidth: 980 }}>
  661. <thead><tr><th>客户</th><th>订阅标识</th><th>应收金额</th><th>分成基数</th><th>分成方式与取值</th><th>本方分成金额</th><th>恒 0 说明</th><th>操作</th></tr></thead>
  662. <tbody>
  663. {d.items.map((line) => (
  664. <tr key={line.bill_detail_id}>
  665. <td><strong>{line.customer_name}</strong></td>
  666. <td>{line.subscription_label}</td>
  667. <td><span className="ops-money">{moneyFromCents(line.receivable_cents)}</span></td>
  668. <td><span className="ops-money">{moneyFromCents(line.share_base_cents)}</span></td>
  669. <td>{settleTextFromSnapshot(line.share_mode, line.share_value)}</td>
  670. <td><strong className="reconcile-money">{moneyFromCents(line.share_amount_cents)}</strong></td>
  671. {/* zero_note 如实展示并解释为什么是 0(⛔ 隐藏 0 金额行)。 */}
  672. <td>{line.zero_note ? ZERO_NOTE_TEXT[line.zero_note] : "—"}</td>
  673. <td>
  674. <Link className="ops-table-action" to={`/settlement-bills/${encodeURIComponent(line.bill_detail_id)}`} state={lineState}>
  675. 详情
  676. </Link>
  677. </td>
  678. </tr>
  679. ))}
  680. {!d.items.length && <OpsTableEmpty colSpan={8}>本批无明细行。</OpsTableEmpty>}
  681. </tbody>
  682. </table>
  683. </div>
  684. </section>
  685. <section className="reconcile-record-section">
  686. <div className="reconcile-record-section-head"><span>02</span><div><h2>执行与口径</h2><p>批次八字段头与状态说明。</p></div></div>
  687. <dl className="reconcile-record-facts">
  688. <div><dt>对账单号</dt><dd>{d.batch_no}</dd></div>
  689. <div><dt>分成方</dt><dd>{d.holder_name} · {HOLDER_TYPE_TEXT[d.holder_type]}</dd></div>
  690. <div><dt>自然月</dt><dd>{d.period}</dd></div>
  691. <div><dt>应出账日期</dt><dd title="该分成方该自然月的应出账日期=自然月次月的对账日;「每月 N 日」的对账日口径见「出账配置」">{d.recon_date ?? "—"}</dd></div>
  692. <div><dt>批次状态</dt><dd>{BATCH_STATUS_TEXT[d.status]}</dd></div>
  693. <div><dt>执行人</dt><dd title={d.operator_user_id ?? undefined}>{executorText(d)}</dd></div>
  694. <div><dt>执行时间</dt><dd title={d.executed_at ?? undefined}>{d.executed_at ? localTime(d.executed_at) : "—"}</dd></div>
  695. <div><dt>触发方式</dt><dd>{TRIGGER_TYPE_TEXT[d.trigger_type]}</dd></div>
  696. </dl>
  697. <p className="reconcile-footnote">状态以批次当前记录为准。执行失败的批次由总运营补跑;账单差错通过出账更正登记。</p>
  698. </section>
  699. </>
  700. );
  701. }
  702. /* ── FN-08 账单明细(14.3 列表) ─────────────────────────────────── */
  703. export function SettlementBillListPage() {
  704. const filters = useListFilters();
  705. const q = filters.get("q");
  706. const type = filters.get("type");
  707. const month = filters.get("month");
  708. const page = Number(filters.get("page") || "1") || 1;
  709. const hasFilter = Boolean(q || type || month);
  710. const periodsFetch = useReconPeriods();
  711. const periods = periodsFetch.data?.periods ?? null;
  712. const list = useBillList({ period: month, holderType: type, keyword: q, page });
  713. const wiring = list.fail?.kind === "wiring";
  714. const rows = list.data?.items ?? [];
  715. const total = list.data?.total ?? 0;
  716. const pageSize = 20;
  717. return (
  718. <section className="ops-page bill-index page-fill page-fill-window">
  719. <header className="reconcile-page-heading">
  720. <div>
  721. <p className="ops-eyebrow"><span /> BILLING LINES / 分成与对账</p>
  722. <h1>账单明细</h1>
  723. <PageIntro>对账有差异时,按客户和账期追到具体订阅,逐项核对应收、成本和分成。</PageIntro>
  724. </div>
  725. </header>
  726. {wiring && <p className="ops-import-note" role="status">{BILL_WIRING_NOTE}</p>}
  727. <div className="reconcile-ledger list-shell-fill">
  728. <div className="reconcile-filters">
  729. <label className="ops-search">
  730. <Search size={17} />
  731. <SearchInput aria-label="搜索账单明细" placeholder="搜索分成方、客户、订阅或单号" value={q}
  732. onCommit={(value) => { filters.set("page", ""); filters.set("q", value); }} />
  733. {q && <button type="button" aria-label="清空搜索" onClick={() => filters.set("q", "")}><X size={15} /></button>}
  734. </label>
  735. <FilterSelect icon="type" aria-label="分成方类型" value={type} onChange={(event) => { filters.set("page", ""); filters.set("type", event.target.value); }}>
  736. <option value="">全部类型</option>
  737. <option value="operator">{HOLDER_TYPE_TEXT.operator}</option>
  738. <option value="partner">{HOLDER_TYPE_TEXT.partner}</option>
  739. <option value="ops_team">{HOLDER_TYPE_TEXT.ops_team}</option>
  740. </FilterSelect>
  741. <FilterSelect icon="month" aria-label="自然月" value={month} onChange={(event) => { filters.set("page", ""); filters.set("month", event.target.value); }}>
  742. <option value="">{ALL_PERIODS_LABEL}</option>
  743. {(periods ?? []).map((p) => <option key={p} value={p}>{p}</option>)}
  744. </FilterSelect>
  745. {hasFilter && <Button variant="ghost" size="sm" onClick={filters.reset}>重置筛选</Button>}
  746. </div>
  747. <div className="ops-table-wrap">
  748. <table className="ops-table">
  749. <OpsTableColumns widths={[180, 90, 170, 200, 90, 120, 130, 160, 76]} />
  750. <thead><tr><th>分成方</th><th>自然月</th><th>客户</th><th>订阅</th><th>计费天数</th><th>分成基数</th><th>本方分成金额</th><th>对账单号</th><th>操作</th></tr></thead>
  751. <tbody>
  752. {rows.map((row) => (
  753. <tr key={row.bill_detail_id}>
  754. <td><OpsTag tone={holderTone[row.holder_type]}>{HOLDER_TYPE_TEXT[row.holder_type]}</OpsTag> <strong>{row.holder_name}</strong></td>
  755. <td><span className="ops-mono">{row.period}</span></td>
  756. <td>{row.customer_name}</td>
  757. <td>{row.subscription_label}</td>
  758. <td>{row.billing_days} 天</td>
  759. <td><span className="ops-money">{moneyFromCents(row.share_base_cents)}</span></td>
  760. <td><strong className="reconcile-money">{moneyFromCents(row.share_amount_cents)}</strong></td>
  761. <td>
  762. <Link className="reconcile-row-link" title={row.batch_no} to={batchPath(row.holder_id, row.batch_no)} state={{ from: "/settlement-bills" }}>
  763. {row.batch_no}<ArrowRight size={14} />
  764. </Link>
  765. </td>
  766. <td>
  767. <Link className="ops-table-action" to={`/settlement-bills/${encodeURIComponent(row.bill_detail_id)}`} state={{ from: "/settlement-bills" }}>
  768. 详情
  769. </Link>
  770. </td>
  771. </tr>
  772. ))}
  773. {!rows.length && (
  774. <OpsTableEmpty colSpan={9}>
  775. {list.loading ? "加载中…" : wiring ? "账单明细接口待后端接线,数据暂不可读。" : "没有符合筛选条件的账单明细。"}
  776. </OpsTableEmpty>
  777. )}
  778. </tbody>
  779. </table>
  780. </div>
  781. <ServerListPager
  782. total={total}
  783. page={page}
  784. pageSize={pageSize}
  785. onPageChange={(next) => filters.set("page", String(next))}
  786. />
  787. </div>
  788. {list.fail && !wiring && (
  789. <p className="ops-form-error" role="alert">{list.fail.message} <Button variant="ghost" size="sm" onClick={list.reload}>重试</Button></p>
  790. )}
  791. </section>
  792. );
  793. }
  794. /* ── FN-08 明细详情(14.3 七段;字段按「钱是怎么来的」排序) ────────── */
  795. export function SettlementBillRecordPage() {
  796. const { index } = useParams();
  797. const location = useLocation();
  798. const state = (location.state ?? {}) as { from?: string };
  799. const back = state.from === "/correction-notes"
  800. ? { to: "/correction-notes", label: BACK_TO_CORRECTIONS }
  801. : state.from?.startsWith("/settlement-batches/")
  802. ? { to: state.from, label: BACK_TO_RECON_DETAIL }
  803. : { to: "/settlement-bills", label: BACK_TO_BILL_LIST };
  804. const detail = useBillDetail(index ?? null);
  805. const d = detail.data;
  806. const wiring = detail.fail?.kind === "wiring";
  807. return (
  808. <article className="ops-page reconcile-record">
  809. <Link className="ops-back-link" to={back.to}><ArrowLeft size={16} />{back.label}</Link>
  810. {wiring && <p className="ops-import-note" role="status">{BILL_WIRING_NOTE}</p>}
  811. {detail.fail && !wiring && (
  812. <p className="ops-form-error" role="alert">{detail.fail.message} <Button variant="ghost" size="sm" onClick={detail.reload}>重试</Button></p>
  813. )}
  814. {(wiring || (!d && detail.loading)) && (
  815. <header className="reconcile-record-hero">
  816. <div className="reconcile-record-symbol"><FileSpreadsheet size={27} /></div>
  817. <div>
  818. <span className="reconcile-record-eyebrow">BILLING LINE / {index}</span>
  819. <h1>明细详情</h1>
  820. <p>{detail.loading && !wiring ? "加载中…" : BACKEND_NOT_WIRED}</p>
  821. </div>
  822. </header>
  823. )}
  824. {d && (
  825. <>
  826. <header className="reconcile-record-hero">
  827. <div className="reconcile-record-symbol"><FileSpreadsheet size={27} /></div>
  828. <div>
  829. <span className="reconcile-record-eyebrow">BILLING LINE / {d.bill_detail_id}</span>
  830. <h1>明细详情</h1>
  831. <p><strong>{d.holder_name}</strong><span>{HOLDER_TYPE_TEXT[d.holder_type]}</span><span>自然月 {d.period}</span><span>{d.customer_name} · {d.subscription_label}</span></p>
  832. </div>
  833. </header>
  834. {/* ① 本期应收口径:pre_align_cents 与 receivable_cents 同屏(缺一=页面缺字段)。 */}
  835. <section className="reconcile-record-section">
  836. <div className="reconcile-record-section-head"><span>01</span><div><h2>本期应收口径</h2><p>尾月对齐前两值必须同屏。</p></div></div>
  837. <dl className="reconcile-record-facts">
  838. <div><dt>尾月对齐前应收</dt><dd>{moneyFromCents(d.pre_align_cents)}</dd></div>
  839. <div><dt>本期应收(对齐后)</dt><dd>{moneyFromCents(d.receivable_cents)}</dd></div>
  840. </dl>
  841. </section>
  842. {/* ② 计费区间与天数、是否不满月。 */}
  843. <section className="reconcile-record-section">
  844. <div className="reconcile-record-section-head"><span>02</span><div><h2>计费依据</h2><p>本期计费区间与天数。</p></div></div>
  845. <dl className="reconcile-record-facts">
  846. <div><dt>计费区间</dt><dd>{d.bill_from} ~ {d.bill_to}</dd></div>
  847. <div><dt>计费天数</dt><dd>{d.billing_days} 天</dd></div>
  848. <div><dt>是否不满月</dt><dd>{d.partial_month ? "是" : "否"}</dd></div>
  849. </dl>
  850. </section>
  851. {/* ③ 成本快照逐条;configured=false ⇒ 标「未配置」。 */}
  852. <section className="reconcile-record-section">
  853. <div className="reconcile-record-section-head"><span>03</span><div><h2>成本快照</h2><p>冻结在本明细行上的成本逐条。</p></div></div>
  854. {d.costs.length ? (
  855. <div className="ops-table-wrap">
  856. <table className="ops-table">
  857. <thead><tr><th>成本项</th><th>金额</th><th>倍率</th><th>折算计</th></tr></thead>
  858. <tbody>
  859. {d.costs.map((cost, i) => (
  860. <tr key={`${cost.item_name}-${i}`}>
  861. <td>{cost.item_name}{!cost.configured && <OpsTag tone="warning">未配置</OpsTag>}</td>
  862. <td><span className="ops-money">{cost.amount_cents == null ? "—" : moneyFromCents(cost.amount_cents)}</span></td>
  863. <td>{cost.multiplier ?? "—"}</td>
  864. <td>{cost.fold == null ? "—" : moneyFromCents(cost.fold)}</td>
  865. </tr>
  866. ))}
  867. </tbody>
  868. </table>
  869. </div>
  870. ) : (
  871. <p className="reconcile-empty-line">本行无成本快照。</p>
  872. )}
  873. </section>
  874. {/* ④ 分成基数;floor 到 0 ⇒ 显式标下限保护(floor 是静默的,不写=藏起一次配置错误)。 */}
  875. <section className="reconcile-record-section">
  876. <div className="reconcile-record-section-head"><span>04</span><div><h2>实际出账口径</h2><p>分成基数与下限保护。</p></div></div>
  877. <dl className="reconcile-record-facts">
  878. <div><dt>分成基数</dt><dd>{moneyFromCents(d.share_base_cents)}</dd></div>
  879. </dl>
  880. {d.base_floor_protected && <p className="reconcile-footnote">{BASE_FLOOR_NOTE}</p>}
  881. </section>
  882. {/* ⑤ 分成方式与取值=当时冻结在明细行上的值(⛔ 读档案现值,I22);文案走册 4 settle_text 单源。 */}
  883. <section className="reconcile-record-section">
  884. <div className="reconcile-record-section-head"><span>05</span><div><h2>分成方式与取值</h2><p>当时冻结在明细行上的值。</p></div></div>
  885. <dl className="reconcile-record-facts">
  886. <div><dt>分成方式与取值</dt><dd>{settleTextFromSnapshot(d.share_mode, d.share_value)}</dd></div>
  887. </dl>
  888. </section>
  889. {/* ⑥ 本方分成金额+恒 0 标注+所属对账单号。 */}
  890. <section className="reconcile-record-section">
  891. <div className="reconcile-record-section-head"><span>06</span><div><h2>对账归属</h2><p>本方分成金额与所属批次。</p></div></div>
  892. <dl className="reconcile-record-facts">
  893. <div><dt>本方分成金额</dt><dd>{moneyFromCents(d.share_amount_cents)}{d.zero_note ? `(${ZERO_NOTE_TEXT[d.zero_note]})` : ""}</dd></div>
  894. <div>
  895. <dt>所属对账单号</dt>
  896. <dd>
  897. <Link className="ops-table-action" to={batchPath(d.holder_id, d.batch_no)} state={{ from: location.pathname }}>
  898. {d.batch_no} <ArrowRight size={14} />
  899. </Link>
  900. </dd>
  901. </div>
  902. </dl>
  903. {/* 其他分成方面板:三类只读身份响应体不出现该字段(⛔ 值为空)。 */}
  904. {d.other_parties != null && d.other_parties.length > 0 && (
  905. <div className="ops-table-wrap" style={{ marginTop: 12 }}>
  906. <table className="ops-table">
  907. <thead><tr><th>其他分成方</th><th>分成金额</th><th>对账单号</th></tr></thead>
  908. <tbody>
  909. {d.other_parties.map((p, i) => (
  910. <tr key={`${p.holder_type}-${p.holder_name}-${i}`}>
  911. <td><OpsTag tone={holderTone[p.holder_type]}>{HOLDER_TYPE_TEXT[p.holder_type]}</OpsTag> {p.holder_name}</td>
  912. <td><span className="ops-money">{moneyFromCents(p.share_amount_cents)}</span></td>
  913. <td className="ops-mono">{p.batch_no ?? "—"}</td>
  914. </tr>
  915. ))}
  916. </tbody>
  917. </table>
  918. </div>
  919. )}
  920. </section>
  921. {/* ⑦ 逐账号在期天数;KLT-S406 ⇒ 该块「取数失败」(⛔ 回落「无开停记录」);未下发 ⇒「后端未下发」。 */}
  922. <section className="reconcile-record-section">
  923. <div className="reconcile-record-section-head"><span>07</span><div><h2>逐账号在期天数</h2><p>按订阅逐分账号统计。</p></div></div>
  924. {d.account_days_failed ? (
  925. <p className="ops-form-error" role="alert">{WORD_FETCH_FAILED}</p>
  926. ) : d.account_days == null ? (
  927. <p className="reconcile-footnote">{BACKEND_NOT_WIRED}</p>
  928. ) : d.account_days.length ? (
  929. <div className="ops-table-wrap">
  930. <table className="ops-table">
  931. <thead><tr><th>分账号</th><th>在期天数</th></tr></thead>
  932. <tbody>
  933. {d.account_days.map((row, i) => (
  934. <tr key={`${row.sub_account_label}-${i}`}><td>{row.sub_account_label}</td><td>{row.in_period_days} 天</td></tr>
  935. ))}
  936. </tbody>
  937. </table>
  938. </div>
  939. ) : (
  940. <p className="reconcile-empty-line">本期无在期分账号。</p>
  941. )}
  942. </section>
  943. </>
  944. )}
  945. </article>
  946. );
  947. }