PartyViewPages.tsx 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013
  1. /**
  2. * 册 8《合伙人与运营商只读视图》页面族(视图§14 页面契约逐页)。
  3. *
  4. * 路由与菜单契约(视图§3.4/§14.1,⛔ 三身份路由前缀不同、组件不复用路由):
  5. * partnerAcct ⇒ /bos/pv/*(V-P1 合并页/V-P2 客户/V-P3 合同);
  6. * opAcct ⇒ /bos/ov/*(V-P5 对账清单/V-P6 账单明细/V-P7 客户/V-P8 合同);
  7. * teamLead ⇒ /bos/tv/recon(V-P1b,复用 V-P1 合并页组件——⚠️ 仅此两页允许共用;
  8. * V-P5/V-P6 与合并页内两表「同名不同路由」,⛔ 合并组件靠 props 抹平差异,A51)。
  9. * 变更记录 V-P4/V-P9 三条路由 /bos/{pv,ov,tv}/n 建在册 10:读口就绪位 `audit_read_ready=true` ⇒ 入口渲染(视图§3.4 纪律 1)。
  10. *
  11. * 接线状态(2026-11-18):bos.view/partner_recon@v1 已在 openapi.yaml 声明并由
  12. * billing::view_partner_recon 实现(六段一次返回)⇒ 合并页走真数据;
  13. * 11001 占位分支仅作契约兜底保留。opAcct 两页复用对账§同名口(R1/R2,reconGetList/billGetList);
  14. * 单批导出复用对账§ reconExportDetail(R4,本册⛔ 自立导出口)。
  15. *
  16. * 硬纪律:⛔「无权限」字样(U-68/总则§16.4);⛔ history.back()(14.6);
  17. * ⛔ 列表级导出/批量操作/人工补跑/已读异议按钮(14.5 白名单);
  18. * ⛔「涉及分成方」卡与「同一张应收上其他分成方」面板(14.5,服务端亦不返回);
  19. * 金额整数分传输、前端不做浮点运算;月份默认预选 lastClosedMonth()(U-67 定案,三身份同口径)。
  20. */
  21. import { useCallback, useEffect, useRef, useState } from "react";
  22. import { PageIntro } from "../components/PageIntro";
  23. import { Download, Search, X } from "lucide-react";
  24. import { Link, useParams } from "react-router";
  25. import { ServerListPager } from "../components/ListPager";
  26. import { Button } from "../components/ui/button";
  27. import { Input } from "../components/ui/input";
  28. import { FilterSelect } from "../components/ui/filter-select";
  29. import { OpsNotice, OpsStatus, OpsTableEmpty, OpsTag } from "../components/OperationsKit";
  30. import { Tri } from "../components/triState";
  31. import { CONTRACT_TYPE_LABEL } from "../domain/contract-draft";
  32. import { hasBizCode } from "../lib/api/http";
  33. import {
  34. billGetDetail,
  35. billGetList,
  36. contractGet,
  37. contractGetList,
  38. customerGet,
  39. customerGetList,
  40. reconExportDetail,
  41. reconGetList,
  42. reconGetPeriods,
  43. viewPartnerRecon,
  44. } from "../lib/api/bos";
  45. import type {
  46. BillDetailResult,
  47. ContractRow,
  48. ViewBillDetailRow,
  49. ViewPartnerReconResult,
  50. ViewReconBatchRow,
  51. } from "../lib/api/types";
  52. import { WORD_FETCH_FAILED, WORD_NOT_PROVIDED, WORD_UNCONFIGURED } from "../lib/api/lockedCopy";
  53. import { ACCT_STATUS, SUBJECT_TYPE, label } from "../lib/api/labels";
  54. import { settleTextFromSnapshot } from "../lib/settle-text";
  55. import { lastClosedMonth } from "../lib/recon";
  56. import { ALL_PERIODS_LABEL, BACKEND_NOT_WIRED, BATCH_STATUS_TEXT, EXPORT_EMPTY_NOTE, RECONCILE_STATUS_TEXT, exportResultNote, saveReconExportCsv } from "../lib/copy-billing";
  57. import {
  58. BACK_TO_BILL_DETAIL_LIST,
  59. BACK_TO_CONTRACT_LIST,
  60. BACK_TO_CUSTOMER_LIST,
  61. BACK_TO_REGION_RECON,
  62. BACK_TO_SELF_RECON,
  63. CARD1_TITLE,
  64. CARD_SNAPSHOT_TITLE,
  65. OWNERSHIP_CHANGED,
  66. VIEW_ALL_PERIODS_NOTE,
  67. VIEW_BINDING_FAILED,
  68. VIEW_CONFIG_UNSET,
  69. VIEW_DEFAULT_PAY_CYCLE,
  70. VIEW_DETAIL_ONLY_SETTLED,
  71. VIEW_EXPORT_EXPIRED,
  72. VIEW_FILTER_INCOMPLETE,
  73. VIEW_KEYWORD_FILTER_NOTE,
  74. VIEW_LIST_EMPTY,
  75. VIEW_MONTH_NO_BATCH,
  76. VIEW_NOT_FOUND,
  77. VIEW_ROLE_FORBIDDEN,
  78. VIEW_SNAPSHOT_NOT_READY,
  79. VIEW_WIRING_NOTE,
  80. viewExportOverLimit,
  81. viewMonthTruncated,
  82. } from "../lib/copy-views";
  83. import "../styles/operations.css";
  84. import "../styles/settlement-records.css";
  85. /* ── 本地小工具 ─────────────────────────────────────────────────── */
  86. type ViewKind = "partner" | "operator" | "team";
  87. const kindPrefix = (kind: ViewKind) => (kind === "partner" ? "/bos/pv" : kind === "operator" ? "/bos/ov" : "/bos/tv");
  88. /** 金额列以 `_cents`(分)下发;界面统一两位小数元。 */
  89. const moneyFromCents = (cents: number): string =>
  90. `¥${(cents / 100).toLocaleString("zh-CN", { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
  91. /** 三态格:null ⇒「取数失败」(KLT-S406 单格语义),⛔ 回落 ¥0(视图§4.6)。 */
  92. const moneyCell = (cents: number | null): string => (cents == null ? WORD_FETCH_FAILED : moneyFromCents(cents));
  93. /** 视图侧失败分类(14.7 全量;11001=未接线占位)。 */
  94. type ViewFail =
  95. | { kind: "wiring" }
  96. | { kind: "snapshot" } /* KLT-O20703 整页态(月份选择器仍可用) */
  97. | { kind: "binding" } /* KLT-O20701 整页态,⚠️ 不提供重试 */
  98. | { kind: "forbidden" } /* KLT-P301,与 11001 分文案 */
  99. | { kind: "notfound" } /* 11104 详情空态 */
  100. | { kind: "param" } /* 11103 筛选入参 */
  101. | { kind: "fail"; message: string };
  102. function classifyViewError(e: unknown): ViewFail {
  103. if (hasBizCode(e, "11001")) return { kind: "wiring" };
  104. if (hasBizCode(e, "KLT-O20703")) return { kind: "snapshot" };
  105. if (hasBizCode(e, "KLT-O20701")) return { kind: "binding" };
  106. if (hasBizCode(e, "KLT-P301")) return { kind: "forbidden" };
  107. if (hasBizCode(e, "11104")) return { kind: "notfound" };
  108. if (hasBizCode(e, "11103")) return { kind: "param" };
  109. return { kind: "fail", message: e instanceof Error && e.message ? e.message : WORD_FETCH_FAILED };
  110. }
  111. /** 通用取数 hook(依赖数组由调用方给稳态键)。 */
  112. function useViewFetch<T>(fn: () => Promise<T>, deps: readonly unknown[]): {
  113. data: T | null;
  114. loading: boolean;
  115. fail: ViewFail | null;
  116. reload: () => void;
  117. } {
  118. const [data, setData] = useState<T | null>(null);
  119. const [loading, setLoading] = useState(true);
  120. const [fail, setFail] = useState<ViewFail | null>(null);
  121. const [tick, setTick] = useState(0);
  122. // eslint-disable-next-line react-hooks/exhaustive-deps
  123. const run = useCallback(fn, deps);
  124. useEffect(() => {
  125. let alive = true;
  126. setLoading(true);
  127. run()
  128. .then((res) => {
  129. if (!alive) return;
  130. setData(res);
  131. setFail(null);
  132. })
  133. .catch((e: unknown) => {
  134. if (!alive) return;
  135. setData(null);
  136. setFail(classifyViewError(e));
  137. })
  138. .finally(() => {
  139. if (alive) setLoading(false);
  140. });
  141. }, [run, tick]);
  142. return { data, loading, fail, reload: () => setTick((t) => t + 1) };
  143. }
  144. /** 单批导出(三身份唯一写副作用,R4 复用对账§口;O20702 只有一句提示,⛔ 转异步/轮询)。 */
  145. function useExportBatch(setNotice: (m: string) => void) {
  146. return (batchId: string) => {
  147. reconExportDetail({ batch_id: batchId })
  148. .then((res) => setNotice(saveReconExportCsv(res) ? exportResultNote(res) : EXPORT_EMPTY_NOTE))
  149. .catch((e: unknown) => {
  150. if (hasBizCode(e, "KLT-O20702")) setNotice(viewExportOverLimit(null));
  151. else if (hasBizCode(e, "S407")) setNotice(VIEW_EXPORT_EXPIRED);
  152. else setNotice(e instanceof Error && e.message ? e.message : WORD_FETCH_FAILED);
  153. });
  154. };
  155. }
  156. /** 整页态面板(绑定失败⛔重试;快照未建立/角色拒⇒给重试入口)。 */
  157. function FullPageState({ text, retry }: { text: string; retry?: () => void }) {
  158. return (
  159. <div className="ops-detail-callout" role="alert" style={{ textAlign: "center", padding: "48px 24px" }}>
  160. <strong>{text}</strong>
  161. {retry && (
  162. <p>
  163. <Button variant="outline" size="sm" onClick={retry}>重试</Button>
  164. </p>
  165. )}
  166. </div>
  167. );
  168. }
  169. /* ── V-P1/V-P1b 合并页(六段一次请求,⛔ 分段懒加载) ────────────────────── */
  170. function PartyReconMergedPage({ kind }: { kind: "partner" | "team" }) {
  171. const title = kind === "partner" ? "本运营区域对账" : "本方对账";
  172. const prefix = kindPrefix(kind);
  173. const [month, setMonth] = useState(lastClosedMonth());
  174. const [keyword, setKeyword] = useState("");
  175. const [page, setPage] = useState(1);
  176. const [notice, setNotice] = useState("");
  177. const detailRef = useRef<HTMLDivElement>(null);
  178. const exportBatch = useExportBatch(setNotice);
  179. const fetchState = useViewFetch<ViewPartnerReconResult>(
  180. // 对外分页 0 基(总则§16.5;组件页码 1 基,只在请求边界换算)。
  181. () => viewPartnerRecon({ month: month || undefined, keyword, page: Math.max(0, page - 1), page_size: 20 }),
  182. [month, keyword, page],
  183. );
  184. const { data, fail } = fetchState;
  185. const wiring = fail?.kind === "wiring";
  186. // 快照未建立=整页态(KLT-O20703):200 响应仍带数据骨架,⛔ 渲染成空表或 0。
  187. const snapshotNotReady = data?.snapshot_state === "not_ready";
  188. const monthOptions = data && data.month_options !== "failed" ? data.month_options : null;
  189. const monthOptionsFailed = data?.month_options === "failed";
  190. // C35:预选月不在 month_options 内 ⇒ 退回首项 month_options[0](⛔ 停在空月份静默成「筛选无结果」)。
  191. useEffect(() => {
  192. if (!monthOptions?.length || !month) return;
  193. if (!monthOptions.some((o) => o.period === month)) setMonth(monthOptions[0].period);
  194. }, [monthOptions, month]);
  195. const monthFallback = Boolean(monthOptions?.length && month && !monthOptions.some((o) => o.period === month));
  196. function resetFilter() {
  197. setKeyword("");
  198. setMonth(lastClosedMonth());
  199. setPage(1);
  200. }
  201. /** 表 1「查看明细」=页内锚点定位表 2 并自动填筛选(不跳页,视图§4.1.2)。 */
  202. function drillBatch(batchNo: string) {
  203. setKeyword(batchNo);
  204. setPage(1);
  205. detailRef.current?.scrollIntoView({ behavior: "smooth", block: "start" });
  206. }
  207. const config = data?.config ?? null;
  208. const settle = data?.settle ?? null;
  209. const batches = data?.batches ?? [];
  210. const details = data?.details ?? [];
  211. const pageSize = 20;
  212. return (
  213. <section className="ops-page reconcile-index page-fill">
  214. <header className="reconcile-page-heading">
  215. <div>
  216. <p className="ops-eyebrow"><span /> READONLY / 只读视图</p>
  217. <h1>{title}</h1>
  218. <PageIntro>从每个账期的对账批次查到本方参与的结算和分成。</PageIntro>
  219. </div>
  220. </header>
  221. {notice && <OpsNotice message={notice} onClose={() => setNotice("")} />}
  222. {wiring && <p className="ops-import-note" role="status">{VIEW_WIRING_NOTE}</p>}
  223. {/* 一份筛选条,两表共用(视图§4.2 条 5);重置=清关键字+回默认预选 lastClosedMonth()。 */}
  224. <div className="reconcile-filters">
  225. <label className="ops-search">
  226. <Search size={17} />
  227. <Input
  228. aria-label="搜索对账单号或明细号"
  229. placeholder="搜索对账单号/明细号"
  230. value={keyword}
  231. onChange={(event) => { setKeyword(event.target.value); setPage(1); }}
  232. />
  233. {keyword && <button type="button" aria-label="清空搜索" onClick={() => { setKeyword(""); setPage(1); }}><X size={15} /></button>}
  234. </label>
  235. {/* 月份选项=两表 distinct 并集(A52);failed/未接线 ⇒ 禁用下拉,⛔ 回落「近 12 个月」。 */}
  236. <FilterSelect
  237. icon="month"
  238. aria-label="自然月"
  239. value={month}
  240. disabled={!monthOptions}
  241. onChange={(event) => { setMonth(event.target.value); setPage(1); }}
  242. >
  243. <option value="">{ALL_PERIODS_LABEL}</option>
  244. {(monthOptions ?? (month ? [{ period: month, has_batch: false, has_detail: false }] : [])).map((o) => (
  245. <option key={o.period} value={o.period}>{o.period}</option>
  246. ))}
  247. </FilterSelect>
  248. <Button variant="ghost" size="sm" onClick={resetFilter}>重置筛选</Button>
  249. </div>
  250. <p className="ops-import-note" role="note">{VIEW_KEYWORD_FILTER_NOTE}</p>
  251. {monthFallback && <p className="ops-import-note" role="status">{VIEW_MONTH_NO_BATCH}</p>}
  252. {data?.month_options_truncated && <p className="ops-import-note" role="status">{viewMonthTruncated(monthOptions?.length ?? 0)}</p>}
  253. {monthOptionsFailed && <p className="ops-import-note" role="status">{WORD_FETCH_FAILED}:月份选项暂不可用。</p>}
  254. {/* 整页态:KLT-O20701(⛔ 重试)/KLT-O20703(筛选条保留,①—⑥ 全替换,⛔ 渲染空表)/KLT-P301。 */}
  255. {fail?.kind === "binding" && <FullPageState text={VIEW_BINDING_FAILED} />}
  256. {fail?.kind === "snapshot" && <FullPageState text={VIEW_SNAPSHOT_NOT_READY} retry={fetchState.reload} />}
  257. {snapshotNotReady && <FullPageState text={VIEW_SNAPSHOT_NOT_READY} retry={fetchState.reload} />}
  258. {fail?.kind === "forbidden" && <FullPageState text={VIEW_ROLE_FORBIDDEN} />}
  259. {fail?.kind === "param" && <FullPageState text={VIEW_FILTER_INCOMPLETE} />}
  260. {fail?.kind === "fail" && <FullPageState text={fail.message} retry={fetchState.reload} />}
  261. {(wiring || (data && !snapshotNotReady)) && (
  262. <>
  263. {/* ① 页顶配置卡(V6,当前):两格都给**生效的具体取值**(✅ 2026-11-18:
  264. 付款周期不再渲染「留空=跟随默认」——那不是取值),对账日缺失才回落原标题。 */}
  265. <div className="reconcile-totals" aria-label="本方对账配置">
  266. <div>
  267. <span>本方对账日</span>
  268. <strong>{wiring ? BACKEND_NOT_WIRED : config ? (config.recon_day == null ? VIEW_CONFIG_UNSET : `每月 ${config.recon_day} 日`) : BACKEND_NOT_WIRED}</strong>
  269. <small>当前生效配置</small>
  270. </div>
  271. <div>
  272. <span>付款周期</span>
  273. <strong>{wiring ? BACKEND_NOT_WIRED : config ? (config.pay_cycle ?? VIEW_DEFAULT_PAY_CYCLE) : BACKEND_NOT_WIRED}</strong>
  274. <small>当前生效配置</small>
  275. </div>
  276. </div>
  277. {/* ② 卡 1:标题固定(14.2②);未配 ⇒「未配置」,⛔ 显 0/空白。 */}
  278. <div className="reconcile-totals" aria-label={CARD1_TITLE}>
  279. <div>
  280. <span>{CARD1_TITLE}</span>
  281. <strong>
  282. {wiring ? <Tri tone="missing" text={BACKEND_NOT_WIRED} />
  283. : settle && (settle.mode != null || settle.value != null)
  284. ? settleTextFromSnapshot(settle.mode, settle.value)
  285. : WORD_UNCONFIGURED}
  286. </strong>
  287. <small>档案现值,不按客户配</small>
  288. </div>
  289. </div>
  290. {/* ③ 卡 2/3:标题固定「本期按账期快照」+副标题账期(与②「(现行)」同屏共存=时点口径对外声明)。 */}
  291. <p className="ops-eyebrow" style={{ marginTop: 8 }}>
  292. {CARD_SNAPSHOT_TITLE}(账期 {month || ALL_PERIODS_LABEL})
  293. </p>
  294. <div className="reconcile-totals" aria-label={CARD_SNAPSHOT_TITLE}>
  295. <div>
  296. <span>本方对账清单</span>
  297. <strong>{wiring ? BACKEND_NOT_WIRED : `${data?.batch_total ?? 0} 批`}</strong>
  298. <small>{wiring ? "—" : `当前显示 ${data?.batch_shown ?? 0} 批`}</small>
  299. </div>
  300. <div>
  301. <span>本方账单明细</span>
  302. <strong>{wiring ? BACKEND_NOT_WIRED : `${data?.detail_total ?? 0} 条`}</strong>
  303. <small>{wiring ? "—" : `当前显示 ${data?.detail_shown ?? 0} 条`}</small>
  304. </div>
  305. {/* ④ 卡 4:当前筛选合计+本方全部合计双值常驻(视图§4.2 条 7);null ⇒ 取数失败 ⛔ 显 ¥0。 */}
  306. <div>
  307. <span>本方分成合计</span>
  308. <strong>{wiring ? BACKEND_NOT_WIRED : moneyCell(data?.share_sum ?? null)}</strong>
  309. <small>{wiring ? "—" : `本方全部合计 ${moneyCell(data?.share_sum_all ?? null)}`}</small>
  310. </div>
  311. </div>
  312. {/* ⑤ 表 1 本方对账清单(出账状态与批次状态两维度两列并排)。 */}
  313. <div className="reconcile-ledger list-shell-fill">
  314. <div className="ops-table-wrap">
  315. <table className="ops-table">
  316. <thead><tr><th>对账单号</th><th>自然月</th><th>出账状态</th><th>批次状态</th><th>明细条数</th><th>本方分成金额</th><th>操作</th></tr></thead>
  317. <tbody>
  318. {wiring ? (
  319. <tr><td colSpan={7}><Tri tone="missing" text={BACKEND_NOT_WIRED} /></td></tr>
  320. ) : (
  321. batches.map((row: ViewReconBatchRow) => (
  322. <tr key={row.batch_no}>
  323. <td className="ops-mono">{row.batch_no}</td>
  324. <td>{row.period}</td>
  325. <td><OpsStatus tone={row.reconcile_status === "settled" ? "success" : row.reconcile_status === "abnormal" ? "danger" : "neutral"}>{RECONCILE_STATUS_TEXT[row.reconcile_status]}</OpsStatus></td>
  326. <td><OpsStatus tone={row.status === "executed" ? "success" : row.status === "failed" ? "danger" : "neutral"}>{BATCH_STATUS_TEXT[row.status]}</OpsStatus></td>
  327. <td className="table-number">{row.detail_count}</td>
  328. <td><strong className="table-number">{moneyFromCents(row.share_cents)}</strong></td>
  329. <td>
  330. {/* 无明细 ⇒ 导出按钮整块不渲染(⚠️ 不是禁用,总则§16.9;KLT-H205xx 仅直调防护)。 */}
  331. {row.has_detail && (
  332. <button type="button" className="ops-table-action" onClick={() => exportBatch(row.batch_no)}>
  333. <Download size={13} /> 导出本批账单明细
  334. </button>
  335. )}{" "}
  336. <button type="button" className="ops-table-action" onClick={() => drillBatch(row.batch_no)}>查看明细</button>
  337. </td>
  338. </tr>
  339. ))
  340. )}
  341. {!wiring && !batches.length && (
  342. <OpsTableEmpty colSpan={7}>
  343. {VIEW_LIST_EMPTY}{!month && `;${VIEW_ALL_PERIODS_NOTE}`}
  344. </OpsTableEmpty>
  345. )}
  346. </tbody>
  347. </table>
  348. </div>
  349. {!wiring && (
  350. <ServerListPager
  351. total={data?.batch_total ?? 0}
  352. page={page}
  353. pageSize={pageSize}
  354. onPageChange={setPage}
  355. unit="批"
  356. />
  357. )}
  358. </div>
  359. {/* ⑥ 表 2 本方账单明细(A18:只列已出账明细;灰底提示必显)。 */}
  360. <div className="reconcile-ledger list-shell-fill" ref={detailRef}>
  361. <p className="ops-import-note" role="note">{VIEW_DETAIL_ONLY_SETTLED}</p>
  362. <div className="ops-table-wrap">
  363. <table className="ops-table">
  364. <thead><tr><th>账单明细号</th><th>客户名称</th><th>应收单号</th><th>自然月</th><th>应结金额</th><th>对账单号</th><th>操作</th></tr></thead>
  365. <tbody>
  366. {wiring ? (
  367. <tr><td colSpan={7}><Tri tone="missing" text={BACKEND_NOT_WIRED} /></td></tr>
  368. ) : (
  369. details.map((row: ViewBillDetailRow) => (
  370. <tr key={row.bill_detail_id}>
  371. <td className="ops-mono">{row.bill_detail_id}</td>
  372. <td>
  373. {/* C76:当前归属≠我 ⇒ 纯文本无链接+「归属已变更」;teamLead 无客户详情页 ⇒ 恒纯文本。 */}
  374. {kind === "partner" && row.customer_visible ? (
  375. <Link className="workspace-link" to={`${prefix}/customer/${encodeURIComponent(row.customer_id)}`}>{row.customer_name}</Link>
  376. ) : (
  377. <span>{row.customer_name}{!row.customer_visible && <OpsTag tone="neutral">{OWNERSHIP_CHANGED}</OpsTag>}</span>
  378. )}
  379. </td>
  380. <td className="ops-mono">{row.receivable_no}</td>
  381. <td>{row.period}</td>
  382. <td><strong className="table-number">{moneyFromCents(row.receivable_cents)}</strong></td>
  383. {/* 批次详情宿主路由未在 14.1 路由表声明(仅 14.6 返回链路提及)⇒ 纯文本,缺口已登记。 */}
  384. <td className="ops-mono">{row.batch_no}</td>
  385. <td><Link className="workspace-link" to={`${prefix}/bill-detail/${encodeURIComponent(row.bill_detail_id)}`}>查看详情</Link></td>
  386. </tr>
  387. ))
  388. )}
  389. {!wiring && !details.length && (
  390. <OpsTableEmpty colSpan={7}>
  391. {VIEW_LIST_EMPTY}{!month && `;${VIEW_ALL_PERIODS_NOTE}`}
  392. </OpsTableEmpty>
  393. )}
  394. </tbody>
  395. </table>
  396. </div>
  397. {!wiring && (
  398. <ServerListPager
  399. total={data?.detail_total ?? 0}
  400. page={page}
  401. pageSize={pageSize}
  402. onPageChange={setPage}
  403. />
  404. )}
  405. </div>
  406. </>
  407. )}
  408. </section>
  409. );
  410. }
  411. export function PartnerReconPage() {
  412. return <PartyReconMergedPage kind="partner" />;
  413. }
  414. export function TeamReconPage() {
  415. return <PartyReconMergedPage kind="team" />;
  416. }
  417. /* ── V-P5 运营商「本方对账清单」(⚠️ 独立组件,⛔ 与 V-P1 合并靠 props 抹平,A51) ── */
  418. export function OperatorReconPage() {
  419. const [month, setMonth] = useState(lastClosedMonth());
  420. const [keyword, setKeyword] = useState("");
  421. const [page, setPage] = useState(1);
  422. const [notice, setNotice] = useState("");
  423. const exportBatch = useExportBatch(setNotice);
  424. const periodsFetch = useViewFetch(() => reconGetPeriods(), []);
  425. const periods = periodsFetch.data?.periods ?? null;
  426. const fetchState = useViewFetch(
  427. // 分页器是 1 基、后端 `page` 是 0 基(openapi:页码 0 基索引)⇒ 只在请求边界换算。
  428. () => reconGetList({ page: Math.max(0, page - 1), page_size: 20, period: month || undefined, keyword: keyword.trim() || undefined }),
  429. [month, keyword, page],
  430. );
  431. const { data, fail } = fetchState;
  432. const wiring = fail?.kind === "wiring";
  433. const rows = data?.items ?? [];
  434. useEffect(() => {
  435. if (!periods?.length || !month) return;
  436. if (!periods.includes(month)) setMonth(periods[0]);
  437. }, [periods, month]);
  438. const monthFallback = Boolean(periods?.length && month && !periods.includes(month));
  439. const selfConfig = data?.self_config ?? null;
  440. const total = data?.total ?? 0;
  441. const pageSize = 20;
  442. return (
  443. <section className="ops-page reconcile-index page-fill">
  444. <header className="reconcile-page-heading">
  445. <div>
  446. <p className="ops-eyebrow"><span /> READONLY / 只读视图</p>
  447. <h1>本方对账清单</h1>
  448. <PageIntro>核对本方各账期的出账进度和应结分成。</PageIntro>
  449. </div>
  450. </header>
  451. {notice && <OpsNotice message={notice} onClose={() => setNotice("")} />}
  452. {wiring && <p className="ops-import-note" role="status">{VIEW_WIRING_NOTE}</p>}
  453. {/* V6 页顶两卡(随 recon/list 响应 self_config 附带,只读身份⛔ 授配置读键)。 */}
  454. <div className="reconcile-totals" aria-label="本方对账配置">
  455. <div>
  456. <span>本方对账日</span>
  457. <strong>{wiring ? BACKEND_NOT_WIRED : selfConfig ? `每月 ${selfConfig.recon_day} 日` : BACKEND_NOT_WIRED}</strong>
  458. <small>当前生效配置</small>
  459. </div>
  460. <div>
  461. <span>付款周期</span>
  462. <strong>{wiring ? BACKEND_NOT_WIRED : selfConfig ? (selfConfig.pay_cycle ?? VIEW_DEFAULT_PAY_CYCLE) : BACKEND_NOT_WIRED}</strong>
  463. <small>当前生效配置</small>
  464. </div>
  465. </div>
  466. {/* 筛选条:自然月+对账单号关键字(⛔ 分成方/区域等范围类筛选,I30)。 */}
  467. <div className="reconcile-filters">
  468. <label className="ops-search">
  469. <Search size={17} />
  470. <Input
  471. aria-label="搜索对账单号"
  472. placeholder="搜索对账单号"
  473. value={keyword}
  474. onChange={(event) => { setKeyword(event.target.value); setPage(1); }}
  475. />
  476. {keyword && <button type="button" aria-label="清空搜索" onClick={() => { setKeyword(""); setPage(1); }}><X size={15} /></button>}
  477. </label>
  478. <FilterSelect
  479. icon="month"
  480. aria-label="自然月"
  481. value={month}
  482. disabled={!periods}
  483. onChange={(event) => { setMonth(event.target.value); setPage(1); }}
  484. >
  485. <option value="">{ALL_PERIODS_LABEL}</option>
  486. {(periods ?? (month ? [month] : [])).map((p) => <option key={p} value={p}>{p}</option>)}
  487. </FilterSelect>
  488. <Button variant="ghost" size="sm" onClick={() => { setKeyword(""); setMonth(lastClosedMonth()); setPage(1); }}>重置筛选</Button>
  489. </div>
  490. {monthFallback && <p className="ops-import-note" role="status">{VIEW_MONTH_NO_BATCH}</p>}
  491. {fail?.kind === "binding" && <FullPageState text={VIEW_BINDING_FAILED} />}
  492. {fail?.kind === "forbidden" && <FullPageState text={VIEW_ROLE_FORBIDDEN} />}
  493. {fail?.kind === "fail" && <FullPageState text={fail.message} retry={fetchState.reload} />}
  494. {(wiring || data) && (
  495. <div className="reconcile-ledger list-shell-fill">
  496. <div className="ops-table-wrap">
  497. <table className="ops-table">
  498. <thead><tr><th>对账单号</th><th>自然月</th><th>出账状态</th><th>批次状态</th><th>明细条数</th><th>本方分成金额</th><th>操作</th></tr></thead>
  499. <tbody>
  500. {wiring ? (
  501. <tr><td colSpan={7}><Tri tone="missing" text={BACKEND_NOT_WIRED} /></td></tr>
  502. ) : (
  503. rows.map((row) => (
  504. <tr key={row.batch_no}>
  505. <td className="ops-mono">{row.batch_no}</td>
  506. <td>{row.period}</td>
  507. <td><OpsStatus tone={row.reconcile_status === "settled" ? "success" : row.reconcile_status === "abnormal" ? "danger" : "neutral"}>{RECONCILE_STATUS_TEXT[row.reconcile_status]}</OpsStatus></td>
  508. <td><OpsStatus tone={row.status === "executed" ? "success" : row.status === "failed" ? "danger" : "neutral"}>{BATCH_STATUS_TEXT[row.status]}</OpsStatus></td>
  509. <td className="table-number">{row.detail_count}</td>
  510. <td><strong className="table-number">{moneyFromCents(row.share_cents)}</strong></td>
  511. <td>
  512. {/* 本批无明细 ⇒ 按钮整块不渲染;「查看明细」→ V-P6 按对账单号过滤(14.3 筛选行)。 */}
  513. {row.detail_count > 0 && (
  514. <button type="button" className="ops-table-action" onClick={() => exportBatch(row.batch_no)}>
  515. <Download size={13} /> 导出本批账单明细
  516. </button>
  517. )}{" "}
  518. <Link className="workspace-link" to={`/bos/ov/bill-detail?batch=${encodeURIComponent(row.batch_no)}`}>查看明细</Link>
  519. </td>
  520. </tr>
  521. ))
  522. )}
  523. {!wiring && !rows.length && (
  524. <OpsTableEmpty colSpan={7}>
  525. {VIEW_LIST_EMPTY}{!month && `;${VIEW_ALL_PERIODS_NOTE}`}
  526. </OpsTableEmpty>
  527. )}
  528. </tbody>
  529. </table>
  530. </div>
  531. {!wiring && (
  532. <ServerListPager total={total} page={page} pageSize={pageSize} onPageChange={setPage} unit="批" />
  533. )}
  534. </div>
  535. )}
  536. </section>
  537. );
  538. }
  539. /* ── V-P6 运营商「账单明细」(⛔ 导出按钮——导出单位是批次;⛔「涉及分成方」卡) ────── */
  540. export function OperatorBillDetailPage() {
  541. const [month, setMonth] = useState(lastClosedMonth());
  542. const [batchKw, setBatchKw] = useState("");
  543. const [customerKw, setCustomerKw] = useState("");
  544. const [page, setPage] = useState(1);
  545. const periodsFetch = useViewFetch(() => reconGetPeriods(), []);
  546. const periods = periodsFetch.data?.periods ?? null;
  547. const fetchState = useViewFetch(
  548. () => billGetList({ page: Math.max(0, page - 1), page_size: 20, period: month || undefined, keyword: batchKw.trim() || undefined, customer_kw: customerKw.trim() || undefined }),
  549. [month, batchKw, customerKw, page],
  550. );
  551. const { data, fail } = fetchState;
  552. const wiring = fail?.kind === "wiring";
  553. const rows = data?.items ?? [];
  554. const total = data?.total ?? 0;
  555. const pageSize = 20;
  556. useEffect(() => {
  557. if (!periods?.length || !month) return;
  558. if (!periods.includes(month)) setMonth(periods[0]);
  559. }, [periods, month]);
  560. // 表 1「查看明细」跳入:`?batch=` 预选对账单号筛选。
  561. useEffect(() => {
  562. const initial = new URLSearchParams(window.location.search).get("batch");
  563. if (initial) setBatchKw(initial);
  564. // eslint-disable-next-line react-hooks/exhaustive-deps
  565. }, []);
  566. return (
  567. <section className="ops-page reconcile-index page-fill">
  568. <header className="reconcile-page-heading">
  569. <div>
  570. <p className="ops-eyebrow"><span /> READONLY / 只读视图</p>
  571. <h1>账单明细</h1>
  572. <PageIntro>沿账单追到具体客户和订阅,核对本方每笔分成。</PageIntro>
  573. </div>
  574. </header>
  575. {wiring && <p className="ops-import-note" role="status">{VIEW_WIRING_NOTE}</p>}
  576. <div className="reconcile-filters">
  577. <label className="ops-search">
  578. <Search size={17} />
  579. <Input
  580. aria-label="搜索对账单号"
  581. placeholder="搜索对账单号"
  582. value={batchKw}
  583. onChange={(event) => { setBatchKw(event.target.value); setPage(1); }}
  584. />
  585. {batchKw && <button type="button" aria-label="清空搜索" onClick={() => { setBatchKw(""); setPage(1); }}><X size={15} /></button>}
  586. </label>
  587. <label className="ops-search">
  588. <Search size={17} />
  589. <Input
  590. aria-label="搜索客户"
  591. placeholder="搜索客户"
  592. value={customerKw}
  593. onChange={(event) => { setCustomerKw(event.target.value); setPage(1); }}
  594. />
  595. {customerKw && <button type="button" aria-label="清空搜索" onClick={() => { setCustomerKw(""); setPage(1); }}><X size={15} /></button>}
  596. </label>
  597. <FilterSelect
  598. icon="month"
  599. aria-label="自然月"
  600. value={month}
  601. disabled={!periods}
  602. onChange={(event) => { setMonth(event.target.value); setPage(1); }}
  603. >
  604. <option value="">{ALL_PERIODS_LABEL}</option>
  605. {(periods ?? (month ? [month] : [])).map((p) => <option key={p} value={p}>{p}</option>)}
  606. </FilterSelect>
  607. <Button variant="ghost" size="sm" onClick={() => { setBatchKw(""); setCustomerKw(""); setMonth(lastClosedMonth()); setPage(1); }}>重置筛选</Button>
  608. </div>
  609. <p className="ops-import-note" role="note">{VIEW_KEYWORD_FILTER_NOTE};{VIEW_DETAIL_ONLY_SETTLED}</p>
  610. {fail?.kind === "binding" && <FullPageState text={VIEW_BINDING_FAILED} />}
  611. {fail?.kind === "forbidden" && <FullPageState text={VIEW_ROLE_FORBIDDEN} />}
  612. {fail?.kind === "fail" && <FullPageState text={fail.message} retry={fetchState.reload} />}
  613. {(wiring || data) && (
  614. <div className="reconcile-ledger list-shell-fill">
  615. <div className="ops-table-wrap">
  616. <table className="ops-table">
  617. {/* ⚠️ 应收单号/应结金额两列待 R2 真源(对账§6 明细列表口)补列 ⇒ 暂以分成基数/本方分成呈现,缺口已登记。 */}
  618. <thead><tr><th>账单明细号</th><th>客户名称</th><th>自然月</th><th>分成基数</th><th>本方分成金额</th><th>对账单号</th><th>操作</th></tr></thead>
  619. <tbody>
  620. {wiring ? (
  621. <tr><td colSpan={7}><Tri tone="missing" text={BACKEND_NOT_WIRED} /></td></tr>
  622. ) : (
  623. rows.map((row) => (
  624. <tr key={row.bill_detail_id}>
  625. <td className="ops-mono">{row.bill_detail_id}</td>
  626. <td>{row.customer_name}</td>
  627. <td>{row.period}</td>
  628. <td className="table-number">{moneyFromCents(row.share_base_cents)}</td>
  629. <td><strong className="table-number">{moneyFromCents(row.share_amount_cents)}</strong></td>
  630. <td className="ops-mono">{row.batch_no}</td>
  631. <td><Link className="workspace-link" to={`/bos/ov/bill-detail/${encodeURIComponent(row.bill_detail_id)}`}>查看详情</Link></td>
  632. </tr>
  633. ))
  634. )}
  635. {!wiring && !rows.length && (
  636. <OpsTableEmpty colSpan={7}>
  637. {VIEW_LIST_EMPTY}{!month && `;${VIEW_ALL_PERIODS_NOTE}`}
  638. </OpsTableEmpty>
  639. )}
  640. </tbody>
  641. </table>
  642. </div>
  643. {!wiring && (
  644. <ServerListPager total={total} page={page} pageSize={pageSize} onPageChange={setPage} />
  645. )}
  646. </div>
  647. )}
  648. </section>
  649. );
  650. }
  651. /* ── V-P2/V-P7 本方客户清单(同组件两路由;形态 D 列待客户§登记) ────────────── */
  652. export function PartyCustomerListPage({ kind }: { kind: "partner" | "operator" }) {
  653. const prefix = kindPrefix(kind);
  654. const [keyword, setKeyword] = useState("");
  655. const [page, setPage] = useState(1);
  656. // ⛔ 前端下传 partner_id/operator_id(总则§16.1:范围在服务端谓词层展开)。
  657. const fetchState = useViewFetch(
  658. // 分页器是 1 基、后端 `page` 是 0 基(openapi:页码 0 基索引)⇒ 只在请求边界换算。
  659. () => customerGetList({ page: Math.max(0, page - 1), page_size: 20, keyword: keyword.trim() || undefined }),
  660. [keyword, page],
  661. );
  662. const { data, fail } = fetchState;
  663. const rows = data?.items ?? [];
  664. const total = data?.total ?? 0;
  665. const pageSize = 20;
  666. return (
  667. <section className="ops-page reconcile-index page-fill">
  668. <header className="reconcile-page-heading">
  669. <div>
  670. <p className="ops-eyebrow"><span /> READONLY / 只读视图</p>
  671. <h1>客户清单</h1>
  672. <PageIntro>查找与本方业务相关的客户,确认客户归属和服务情况。</PageIntro>
  673. </div>
  674. </header>
  675. <div className="reconcile-filters">
  676. <label className="ops-search">
  677. <Search size={17} />
  678. <Input
  679. aria-label="搜索客户"
  680. placeholder="客户名称模糊/识别号精确"
  681. value={keyword}
  682. onChange={(event) => { setKeyword(event.target.value); setPage(1); }}
  683. />
  684. {keyword && <button type="button" aria-label="清空搜索" onClick={() => { setKeyword(""); setPage(1); }}><X size={15} /></button>}
  685. </label>
  686. </div>
  687. {fail?.kind === "fail" && <FullPageState text={fail.message} retry={fetchState.reload} />}
  688. {fail && fail.kind !== "fail" && <FullPageState text={fail.kind === "forbidden" ? VIEW_ROLE_FORBIDDEN : fail.kind === "wiring" ? VIEW_WIRING_NOTE : VIEW_LIST_EMPTY} />}
  689. {!fail && (
  690. <div className="reconcile-ledger list-shell-fill">
  691. <div className="ops-table-wrap">
  692. <table className="ops-table">
  693. {/* 形态 D 列=客户名称/识别号/服务开通状态/所属区域/生效套餐摘要(视图§5.1);
  694. 识别号│区域路径│套餐名均随 `/customer/get_list@v1` 下发(D-71 三态:键缺失=未下发,
  695. `null`/空=未登记│未挂载│无在用订阅)。 */}
  696. <thead><tr><th>客户名称</th><th>客户识别号</th><th>服务开通状态</th><th>所属区域</th><th>生效套餐摘要</th><th>操作</th></tr></thead>
  697. <tbody>
  698. {rows.map((row) => (
  699. <tr key={row.customer_id}>
  700. <td>{row.customer_name}</td>
  701. {/* 识别号:列表口下发 `identity_no_masked`(keybox 解密后脱敏);`null`=未登记,键缺失才标未下发。 */}
  702. <td>{row.identity_no_masked === undefined ? <Tri tone="fail" text={WORD_NOT_PROVIDED} title="客户列表口未下发 identity_no_masked" /> : row.identity_no_masked ? <span className="ops-mono">{row.identity_no_masked}</span> : <Tri tone="missing" text="未登记" />}</td>
  703. {/* 三态原样渲染(客户§2 acct_status,库内英文码 ⇒ 按字典转中文),⛔ 重算/派生第四态。 */}
  704. <td><OpsTag tone={row.acct_status === "in_use" || row.acct_status === "在用" ? "success" : row.acct_status === "stopped" || row.acct_status === "停用" ? "warning" : "neutral"}>{label(ACCT_STATUS, row.acct_status)}</OpsTag></td>
  705. {/* 所属区域:后端 `region_path` 取层级真源 `bos_region_meta.path_name`(未定级回落节点 ID);
  706. 键缺失=未下发,空=未挂载(⛔ 把「无挂载」说成「未下发」)。 */}
  707. <td>{row.region_path === undefined ? <Tri tone="fail" text={WORD_NOT_PROVIDED} title="客户列表口未下发 region_path" /> : row.region_path ? row.region_path : <Tri tone="missing" text="未挂载区域" />}</td>
  708. {/* 生效套餐摘要:后端 `plan_names`(在用订阅的套餐名,status ∈ pending/active)。 */}
  709. <td>{row.plan_names === undefined ? <Tri tone="fail" text={WORD_NOT_PROVIDED} title="客户列表口未下发 plan_names" /> : row.plan_names.length ? row.plan_names.join("、") : <Tri tone="missing" text="无在用订阅" />}</td>
  710. <td><Link className="workspace-link" to={`${prefix}/customer/${encodeURIComponent(row.customer_id)}`}>查看</Link></td>
  711. </tr>
  712. ))}
  713. {!rows.length && <OpsTableEmpty colSpan={6}>{VIEW_LIST_EMPTY}</OpsTableEmpty>}
  714. </tbody>
  715. </table>
  716. </div>
  717. <ServerListPager total={total} page={page} pageSize={pageSize} onPageChange={setPage} unit="家" />
  718. </div>
  719. )}
  720. </section>
  721. );
  722. }
  723. /* ── V-P3/V-P8 本方合同清单(行末只有查看) ─────────────────────────────── */
  724. /**
  725. * 「合同名称」列取值:合同数据模型**不存名称列**(第 3 册订阅§5「合同条目不存名」)
  726. * ⇒ 按本合同服务条目的套餐现名/派生档名汇总(真值派生,⛔ 造名)。
  727. * 条目存在但两枚名字都取不到(档位被删)=「未配置」,无条目也=「未配置」。
  728. */
  729. function contractNameOf(row: ContractRow) {
  730. const items = row.service_items ?? [];
  731. const names = items
  732. .map((item) => item.plan_name)
  733. .filter((name): name is string => Boolean(name && name.trim()));
  734. if (!names.length) return <Tri tone="missing" text={WORD_UNCONFIGURED} title="本合同未登记服务条目,无法从条目汇总名称(合同数据模型不存名称列)" />;
  735. return (
  736. <span title="合同数据模型不存名称列(第 3 册:合同条目不存名);此处按本合同服务条目的套餐名汇总">
  737. {[...new Set(names)].join("、")}
  738. </span>
  739. );
  740. }
  741. export function PartyContractListPage({ kind }: { kind: "partner" | "operator" }) {
  742. const prefix = kindPrefix(kind);
  743. const [keyword, setKeyword] = useState("");
  744. const [page, setPage] = useState(1);
  745. // 行集=本方客户集合传导(SQL-2 第二段);⛔ 前端下传范围入参。
  746. const fetchState = useViewFetch(
  747. // 分页器是 1 基、后端 `page` 是 0 基(openapi:页码 0 基索引)⇒ 只在请求边界换算。
  748. () => contractGetList({ page: Math.max(0, page - 1), page_size: 20, keyword: keyword.trim() || undefined }),
  749. [keyword, page],
  750. );
  751. const { data, fail } = fetchState;
  752. const rows = data?.items ?? [];
  753. const total = data?.total ?? rows.length;
  754. const pageSize = 20;
  755. return (
  756. <section className="ops-page reconcile-index page-fill">
  757. <header className="reconcile-page-heading">
  758. <div>
  759. <p className="ops-eyebrow"><span /> READONLY / 只读视图</p>
  760. <h1>合同清单</h1>
  761. <PageIntro>按客户查找与本方业务相关的合同,核对服务期限和开通情况。</PageIntro>
  762. </div>
  763. </header>
  764. <div className="reconcile-filters">
  765. <label className="ops-search">
  766. <Search size={17} />
  767. <Input
  768. aria-label="搜索合同"
  769. placeholder="搜索合同编号"
  770. value={keyword}
  771. onChange={(event) => { setKeyword(event.target.value); setPage(1); }}
  772. />
  773. {keyword && <button type="button" aria-label="清空搜索" onClick={() => { setKeyword(""); setPage(1); }}><X size={15} /></button>}
  774. </label>
  775. </div>
  776. {fail?.kind === "fail" && <FullPageState text={fail.message} retry={fetchState.reload} />}
  777. {fail && fail.kind !== "fail" && <FullPageState text={fail.kind === "forbidden" ? VIEW_ROLE_FORBIDDEN : fail.kind === "wiring" ? VIEW_WIRING_NOTE : VIEW_LIST_EMPTY} />}
  778. {!fail && (
  779. <div className="reconcile-ledger list-shell-fill">
  780. <div className="ops-table-wrap">
  781. <table className="ops-table">
  782. {/*
  783. 合同名称列:合同数据模型**不存名称列**(第 3 册「合同条目不存名」)⇒ 按本合同
  784. 服务条目的套餐现名汇总显示(真值派生,⛔ 造名)。无条目时标「未配置」,⛔ 标「后端未下发」。
  785. */}
  786. <thead><tr><th>合同编号</th><th>合同名称</th><th>客户名称</th><th>合同期间</th><th>状态</th><th>操作</th></tr></thead>
  787. <tbody>
  788. {rows.map((row) => (
  789. <tr key={row.contract_id}>
  790. <td className="ops-mono">{row.contract_no}</td>
  791. <td>{contractNameOf(row)}</td>
  792. <td>{row.customer_name ?? <Tri tone="missing" text={WORD_NOT_PROVIDED} />}</td>
  793. <td>{row.start_date ?? <span className="table-placeholder">—</span>} ~ {row.end_date ?? <span className="table-placeholder">—</span>}</td>
  794. <td><OpsTag tone="neutral">{row.status}</OpsTag></td>
  795. <td><Link className="workspace-link" to={`${prefix}/contract/${encodeURIComponent(row.contract_id)}`}>查看</Link></td>
  796. </tr>
  797. ))}
  798. {!rows.length && <OpsTableEmpty colSpan={6}>{VIEW_LIST_EMPTY}</OpsTableEmpty>}
  799. </tbody>
  800. </table>
  801. </div>
  802. <ServerListPager total={total} page={page} pageSize={pageSize} onPageChange={setPage} unit="份" />
  803. </div>
  804. )}
  805. </section>
  806. );
  807. }
  808. /* ── V-D1 详情宿主层(返回链路固定文案+显式路由,⛔ history.back()) ────────── */
  809. /** 11104 ⇒ 空态卡片「数据不存在或归属已变更」+「刷新列表」(⚠️⛔「无权限」字样)。 */
  810. function DetailNotFound({ backTo, backText }: { backTo: string; backText: string }) {
  811. return (
  812. <div className="ops-detail-callout" role="alert" style={{ textAlign: "center", padding: "48px 24px" }}>
  813. <strong>{VIEW_NOT_FOUND}</strong>
  814. <p><Link className="workspace-link" to={backTo}>刷新列表({backText.replace("← ", "")})</Link></p>
  815. </div>
  816. );
  817. }
  818. function DetailHeader({ title, backTo, backText }: { title: string; backTo: string; backText: string }) {
  819. return (
  820. <header className="reconcile-page-heading">
  821. <div>
  822. <p className="ops-eyebrow"><span /> READONLY / 只读视图</p>
  823. <h1>{title}</h1>
  824. <p><Link className="workspace-link" to={backTo}>{backText}</Link></p>
  825. </div>
  826. </header>
  827. );
  828. }
  829. /** V9 客户详情(⛔「关联工单」卡片,14.5 白名单第 2 项)。 */
  830. export function PartyCustomerDetailPage({ kind }: { kind: "partner" | "operator" }) {
  831. const prefix = kindPrefix(kind);
  832. const { id = "" } = useParams();
  833. const fetchState = useViewFetch(() => customerGet({ customer_id: id }), [id]);
  834. const { data, fail } = fetchState;
  835. return (
  836. <section className="ops-page reconcile-index">
  837. <DetailHeader title="客户详情" backTo={`${prefix}/customer`} backText={BACK_TO_CUSTOMER_LIST} />
  838. {fail?.kind === "notfound" && <DetailNotFound backTo={`${prefix}/customer`} backText={BACK_TO_CUSTOMER_LIST} />}
  839. {fail && fail.kind !== "notfound" && <FullPageState text={fail.kind === "fail" ? fail.message : VIEW_WIRING_NOTE} retry={fail.kind === "fail" ? fetchState.reload : undefined} />}
  840. {data && (
  841. <div className="ops-table-wrap">
  842. <table className="ops-table">
  843. <tbody>
  844. <tr><th>客户名称</th><td>{data.customer.customer_name}</td></tr>
  845. <tr><th>主体类型</th><td>{label(SUBJECT_TYPE, data.customer.subject_type)}</td></tr>
  846. <tr><th>服务开通状态</th><td>{label(ACCT_STATUS, data.customer.acct_status)}</td></tr>
  847. <tr><th>归属运营商</th><td>{data.customer.operator_name ?? <span className="table-placeholder">—</span>}</td></tr>
  848. <tr><th>归属合伙人</th><td>{data.customer.partner_name ?? <span className="table-placeholder">—</span>}</td></tr>
  849. <tr><th>下属分账号</th><td className="table-number">{data.sub_account_count}</td></tr>
  850. <tr><th>建档时间</th><td>{data.customer.created_at ?? <span className="table-placeholder">—</span>}</td></tr>
  851. </tbody>
  852. </table>
  853. </div>
  854. )}
  855. </section>
  856. );
  857. }
  858. /** V11 合同详情(⛔「关联工单」卡片;⛔ 编辑入口)。 */
  859. export function PartyContractDetailPage({ kind }: { kind: "partner" | "operator" }) {
  860. const prefix = kindPrefix(kind);
  861. const { id = "" } = useParams();
  862. const fetchState = useViewFetch(() => contractGet({ contract_id: id }), [id]);
  863. const { data, fail } = fetchState;
  864. return (
  865. <section className="ops-page reconcile-index">
  866. <DetailHeader title="合同详情" backTo={`${prefix}/contract`} backText={BACK_TO_CONTRACT_LIST} />
  867. {fail?.kind === "notfound" && <DetailNotFound backTo={`${prefix}/contract`} backText={BACK_TO_CONTRACT_LIST} />}
  868. {fail && fail.kind !== "notfound" && <FullPageState text={fail.kind === "fail" ? fail.message : VIEW_WIRING_NOTE} retry={fail.kind === "fail" ? fetchState.reload : undefined} />}
  869. {data && (
  870. <div className="ops-table-wrap">
  871. <table className="ops-table">
  872. <tbody>
  873. <tr><th>合同编号</th><td className="ops-mono">{data.contract_no}</td></tr>
  874. <tr><th>客户名称</th><td>{data.customer_name ?? <span className="table-placeholder">—</span>}</td></tr>
  875. <tr><th>合同期间</th><td>{data.start_date ?? <span className="table-placeholder">—</span>} ~ {data.end_date ?? <span className="table-placeholder">—</span>}</td></tr>
  876. <tr><th>状态</th><td>{data.status}</td></tr>
  877. <tr><th>合同类型</th><td>{data.contract_type ? (CONTRACT_TYPE_LABEL[data.contract_type] ?? data.contract_type) : <span className="table-placeholder">—</span>}</td></tr>
  878. <tr><th>签署日期</th><td>{data.sign_date ?? <span className="table-placeholder">—</span>}</td></tr>
  879. <tr><th>服务期(月)</th><td>{data.service_months ?? <span className="table-placeholder">—</span>}</td></tr>
  880. <tr><th>合同金额</th><td className="table-number">{moneyFromCents(data.contract_amount_cents)}</td></tr>
  881. </tbody>
  882. </table>
  883. </div>
  884. )}
  885. </section>
  886. );
  887. }
  888. /**
  889. * V12 账单明细详情(对账§14.3 七段同源一个接口);
  890. * ⛔「同一张应收上其他分成方」面板——三身份一律不渲染(14.5 第 3 项,服务端亦不返回)。
  891. */
  892. export function PartyBillDetailPage({ kind }: { kind: ViewKind }) {
  893. const { id = "" } = useParams();
  894. const back =
  895. kind === "partner"
  896. ? { to: "/bos/pv/recon", text: BACK_TO_REGION_RECON }
  897. : kind === "team"
  898. ? { to: "/bos/tv/recon", text: BACK_TO_SELF_RECON }
  899. : { to: "/bos/ov/bill-detail", text: BACK_TO_BILL_DETAIL_LIST };
  900. const fetchState = useViewFetch<BillDetailResult>(() => billGetDetail(id), [id]);
  901. const { data, fail } = fetchState;
  902. return (
  903. <section className="ops-page reconcile-index">
  904. <DetailHeader title="账单明细详情" backTo={back.to} backText={back.text} />
  905. {fail?.kind === "notfound" && <DetailNotFound backTo={back.to} backText={back.text} />}
  906. {fail && fail.kind !== "notfound" && (
  907. <FullPageState
  908. text={fail.kind === "wiring" ? VIEW_WIRING_NOTE : fail.kind === "snapshot" ? VIEW_SNAPSHOT_NOT_READY : fail.kind === "forbidden" ? VIEW_ROLE_FORBIDDEN : fail.kind === "fail" ? fail.message : VIEW_LIST_EMPTY}
  909. retry={fail.kind === "fail" || fail.kind === "snapshot" ? fetchState.reload : undefined}
  910. />
  911. )}
  912. {data && (
  913. <div className="ops-table-wrap">
  914. <table className="ops-table">
  915. <tbody>
  916. <tr><th>账单明细号</th><td className="ops-mono">{data.bill_detail_id}</td></tr>
  917. <tr><th>所属对账单号</th><td className="ops-mono">{data.batch_no}</td></tr>
  918. <tr><th>自然月</th><td>{data.period}</td></tr>
  919. <tr><th>客户名称</th><td>{data.customer_name}</td></tr>
  920. <tr><th>套餐</th><td>{data.subscription_label}</td></tr>
  921. {/* ① 尾月对齐前后两值同屏 */}
  922. <tr><th>计费标准单价</th><td className="table-number">{data.settle_std_cents == null ? <span className="table-placeholder">—</span> : moneyFromCents(data.settle_std_cents)}</td></tr>
  923. <tr><th>订阅份数</th><td className="table-number">{data.quantity == null ? <span className="table-placeholder">—</span> : data.quantity}</td></tr>
  924. <tr><th>尾月对齐前</th><td className="table-number">{moneyFromCents(data.pre_align_cents)}</td></tr>
  925. <tr><th>应结金额(对齐后)</th><td><strong className="table-number">{moneyFromCents(data.receivable_cents)}</strong></td></tr>
  926. {/* ② 计费区间与天数 */}
  927. <tr><th>计费区间</th><td>{(data.bill_from || data.bill_to) ? `${data.bill_from || "—"} ~ ${data.bill_to || "—"}` : <span className="table-placeholder">—</span>}({data.billing_days} 天{data.month_days != null ? `/${data.month_days}` : ""}{data.partial_month ? ",不满月" : ""})</td></tr>
  928. <tr><th>成本实扣</th><td>{moneyFromCents(data.cost_deduct_cents ?? (data.receivable_cents - data.share_base_cents))}{(data.cost_should_deduct_cents != null && data.cost_deduct_cents != null && data.cost_should_deduct_cents > data.cost_deduct_cents) || data.base_floor_protected ? "(已按应收封顶)" : ""}</td></tr>
  929. {/* ④ 分成基数 */}
  930. <tr><th>分成基数</th><td><span className="table-number">{moneyFromCents(data.share_base_cents)}</span>{data.base_floor_protected ? "(已按下限保护取 0)" : ""}</td></tr>
  931. {/* ⑤ 当时冻结的分成方式与取值(⛔ 读档案现值,I22) */}
  932. <tr><th>分成方式与取值</th><td className="table-number">{settleTextFromSnapshot(data.share_mode, data.share_value)}</td></tr>
  933. {/* ⑥ 本方分成金额 */}
  934. <tr><th>本方分成金额</th><td><strong className="table-number">{moneyFromCents(data.share_amount_cents)}</strong></td></tr>
  935. {/* ⑦ 逐账号在期天数:failed ⇒ 取数失败(⛔ 回落「无开停记录」) */}
  936. <tr>
  937. <th>逐账号在期天数</th>
  938. <td>
  939. {data.account_days_failed
  940. ? WORD_FETCH_FAILED
  941. : data.account_days == null
  942. ? WORD_NOT_PROVIDED
  943. : data.account_days.length
  944. ? data.account_days.map((a) => `${a.sub_account_label} ${a.in_period_days} 天`).join(";")
  945. : <span className="table-placeholder">—</span>}
  946. </td>
  947. </tr>
  948. </tbody>
  949. </table>
  950. </div>
  951. )}
  952. </section>
  953. );
  954. }