PartyViewPages.tsx 58 KB

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