| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077 |
- /**
- * 册 8《合伙人与运营商只读视图》页面族(视图§14 页面契约逐页)。
- *
- * 路由与菜单契约(视图§3.4/§14.1,⛔ 三身份路由前缀不同、组件不复用路由):
- * partnerAcct ⇒ /bos/pv/*(V-P1 合并页/V-P2 客户/V-P3 合同);
- * opAcct ⇒ /bos/ov/*(V-P5 对账清单/V-P6 账单明细/V-P7 客户/V-P8 合同);
- * teamLead ⇒ /bos/tv/recon(V-P1b,复用 V-P1 合并页组件——⚠️ 仅此两页允许共用;
- * V-P5/V-P6 与合并页内两表「同名不同路由」,⛔ 合并组件靠 props 抹平差异,A51)。
- * 变更记录 V-P4/V-P9 三条路由 /bos/{pv,ov,tv}/n 建在册 10:读口就绪位 `audit_read_ready=true` ⇒ 入口渲染(视图§3.4 纪律 1)。
- *
- * 接线状态(2026-11-18):bos.view/partner_recon@v1 已在 openapi.yaml 声明并由
- * billing::view_partner_recon 实现(六段一次返回)⇒ 合并页走真数据;
- * 11001 占位分支仅作契约兜底保留。opAcct 两页复用对账§同名口(R1/R2,reconGetList/billGetList);
- * 单批导出复用对账§ reconExportDetail(R4,本册⛔ 自立导出口)。
- *
- * 硬纪律:⛔「无权限」字样(U-68/总则§16.4);⛔ history.back()(14.6);
- * ⛔ 列表级导出/批量操作/人工补跑/已读异议按钮(14.5 白名单);
- * ⛔「涉及分成方」卡与「同一张应收上其他分成方」面板(14.5,服务端亦不返回);
- * 金额整数分传输、前端不做浮点运算;月份默认预选 lastClosedMonth()(U-67 定案,三身份同口径)。
- */
- import { useCallback, useEffect, useRef, useState } from "react";
- import { PageIntro } from "../components/PageIntro";
- import { ArrowDown, ArrowRight, Download, Info, Search, X } from "lucide-react";
- import { Link, useLocation, useParams } from "react-router";
- import { detailBack, detailLinkState } from "../lib/detail-navigation";
- import { ServerListPager } from "../components/ListPager";
- import { Button } from "../components/ui/button";
- import { Input } from "../components/ui/input";
- import { FilterSelect } from "../components/ui/filter-select";
- import { OpsNotice, OpsStatus, OpsTableColumns, OpsTableEmpty, OpsTag } from "../components/OperationsKit";
- import { Tri } from "../components/triState";
- import { CONTRACT_TYPE_LABEL } from "../domain/contract-draft";
- import { hasBizCode } from "../lib/api/http";
- import {
- billGetDetail,
- billGetList,
- contractGet,
- contractGetList,
- customerGet,
- customerGetList,
- reconExportDetail,
- reconGetList,
- reconGetPeriods,
- viewPartnerRecon,
- } from "../lib/api/bos";
- import type {
- BillDetailResult,
- ContractRow,
- ViewBillDetailRow,
- ViewPartnerReconResult,
- ViewReconBatchRow,
- } from "../lib/api/types";
- import { WORD_FETCH_FAILED, WORD_NOT_PROVIDED, WORD_UNCONFIGURED } from "../lib/api/lockedCopy";
- import { ACCT_STATUS, SUBJECT_TYPE, label } from "../lib/api/labels";
- import { settleTextFromSnapshot } from "../lib/settle-text";
- import { lastClosedMonth } from "../lib/recon";
- import { ALL_PERIODS_LABEL, BACKEND_NOT_WIRED, BATCH_STATUS_TEXT, EXPORT_EMPTY_NOTE, RECONCILE_STATUS_TEXT, exportResultNote, saveReconExportCsv } from "../lib/copy-billing";
- import {
- BACK_TO_BILL_DETAIL_LIST,
- BACK_TO_CONTRACT_LIST,
- BACK_TO_CUSTOMER_LIST,
- BACK_TO_REGION_RECON,
- BACK_TO_SELF_RECON,
- CARD1_TITLE,
- CARD_SNAPSHOT_TITLE,
- OWNERSHIP_CHANGED,
- VIEW_ALL_PERIODS_NOTE,
- VIEW_BINDING_FAILED,
- VIEW_CONFIG_UNSET,
- VIEW_DEFAULT_PAY_CYCLE,
- VIEW_DETAIL_ONLY_SETTLED,
- VIEW_EXPORT_EXPIRED,
- VIEW_FILTER_INCOMPLETE,
- VIEW_KEYWORD_FILTER_NOTE,
- VIEW_LIST_EMPTY,
- VIEW_MONTH_NO_BATCH,
- VIEW_NOT_FOUND,
- VIEW_ROLE_FORBIDDEN,
- VIEW_SNAPSHOT_NOT_READY,
- VIEW_WIRING_NOTE,
- viewExportOverLimit,
- viewMonthTruncated,
- } from "../lib/copy-views";
- import "../styles/operations.css";
- import "../styles/settlement-records.css";
- /* ── 本地小工具 ─────────────────────────────────────────────────── */
- type ViewKind = "partner" | "operator" | "team";
- const kindPrefix = (kind: ViewKind) => (kind === "partner" ? "/bos/pv" : kind === "operator" ? "/bos/ov" : "/bos/tv");
- /** 金额列以 `_cents`(分)下发;界面统一两位小数元。 */
- const moneyFromCents = (cents: number): string =>
- `¥${(cents / 100).toLocaleString("zh-CN", { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
- /** 三态格:null ⇒「取数失败」(KLT-S406 单格语义),⛔ 回落 ¥0(视图§4.6)。 */
- const moneyCell = (cents: number | null): string => (cents == null ? WORD_FETCH_FAILED : moneyFromCents(cents));
- /** 视图侧失败分类(14.7 全量;11001=未接线占位)。 */
- type ViewFail =
- | { kind: "wiring" }
- | { kind: "snapshot" } /* KLT-O20703 整页态(月份选择器仍可用) */
- | { kind: "binding" } /* KLT-O20701 整页态,⚠️ 不提供重试 */
- | { kind: "forbidden" } /* KLT-P301,与 11001 分文案 */
- | { kind: "notfound" } /* 11104 详情空态 */
- | { kind: "param" } /* 11103 筛选入参 */
- | { kind: "fail"; message: string };
- function classifyViewError(e: unknown): ViewFail {
- if (hasBizCode(e, "11001")) return { kind: "wiring" };
- if (hasBizCode(e, "KLT-O20703")) return { kind: "snapshot" };
- if (hasBizCode(e, "KLT-O20701")) return { kind: "binding" };
- if (hasBizCode(e, "KLT-P301")) return { kind: "forbidden" };
- if (hasBizCode(e, "11104")) return { kind: "notfound" };
- if (hasBizCode(e, "11103")) return { kind: "param" };
- return { kind: "fail", message: e instanceof Error && e.message ? e.message : WORD_FETCH_FAILED };
- }
- /** 通用取数 hook(依赖数组由调用方给稳态键)。 */
- function useViewFetch<T>(fn: () => Promise<T>, deps: readonly unknown[]): {
- data: T | null;
- loading: boolean;
- fail: ViewFail | null;
- reload: () => void;
- } {
- const [data, setData] = useState<T | null>(null);
- const [loading, setLoading] = useState(true);
- const [fail, setFail] = useState<ViewFail | null>(null);
- const [tick, setTick] = useState(0);
- // eslint-disable-next-line react-hooks/exhaustive-deps
- const run = useCallback(fn, deps);
- useEffect(() => {
- let alive = true;
- setLoading(true);
- run()
- .then((res) => {
- if (!alive) return;
- setData(res);
- setFail(null);
- })
- .catch((e: unknown) => {
- if (!alive) return;
- setData(null);
- setFail(classifyViewError(e));
- })
- .finally(() => {
- if (alive) setLoading(false);
- });
- }, [run, tick]);
- return { data, loading, fail, reload: () => setTick((t) => t + 1) };
- }
- /** 单批导出(三身份唯一写副作用,R4 复用对账§口;O20702 只有一句提示,⛔ 转异步/轮询)。 */
- function useExportBatch(setNotice: (m: string) => void) {
- return (batchId: string) => {
- reconExportDetail({ batch_id: batchId })
- .then((res) => setNotice(saveReconExportCsv(res) ? exportResultNote(res) : EXPORT_EMPTY_NOTE))
- .catch((e: unknown) => {
- if (hasBizCode(e, "KLT-O20702")) setNotice(viewExportOverLimit(null));
- else if (hasBizCode(e, "S407")) setNotice(VIEW_EXPORT_EXPIRED);
- else setNotice(e instanceof Error && e.message ? e.message : WORD_FETCH_FAILED);
- });
- };
- }
- /** 整页态面板(绑定失败⛔重试;快照未建立/角色拒⇒给重试入口)。 */
- function FullPageState({ text, retry }: { text: string; retry?: () => void }) {
- return (
- <div className="ops-detail-callout" role="alert" style={{ textAlign: "center", padding: "48px 24px" }}>
- <strong>{text}</strong>
- {retry && (
- <p>
- <Button variant="outline" size="sm" onClick={retry}>重试</Button>
- </p>
- )}
- </div>
- );
- }
- /* ── V-P1/V-P1b 合并页(六段一次请求,⛔ 分段懒加载) ────────────────────── */
- type PartyListView = { page: number; month?: string; keyword?: string; batchKw?: string; customerKw?: string };
- function usePartyListReturn() {
- const location = useLocation();
- const saved = location.state?.partyList as PartyListView | undefined;
- const stateFor = (partyList: PartyListView) => detailLinkState(location.pathname + location.search + location.hash, { ...location.state, partyList });
- return { location, saved, stateFor };
- }
- function PartyReconMergedPage({ kind }: { kind: "partner" | "team" }) {
- const teamView = kind === "team";
- const title = kind === "partner" ? "本运营区域对账" : "本方对账";
- const prefix = kindPrefix(kind);
- const { saved, stateFor } = usePartyListReturn();
- const [month, setMonth] = useState(saved?.month ?? lastClosedMonth());
- const [keyword, setKeyword] = useState(saved?.keyword ?? "");
- const [page, setPage] = useState(saved?.page ?? 1);
- const linkState = stateFor({ month, keyword, page });
- const [notice, setNotice] = useState("");
- const detailRef = useRef<HTMLDivElement>(null);
- const exportBatch = useExportBatch(setNotice);
- const fetchState = useViewFetch<ViewPartnerReconResult>(
- // 对外分页 0 基(总则§16.5;组件页码 1 基,只在请求边界换算)。
- () => viewPartnerRecon({ month: month || undefined, keyword, page: Math.max(0, page - 1), page_size: 20 }),
- [month, keyword, page],
- );
- const { data, fail } = fetchState;
- const wiring = fail?.kind === "wiring";
- // 快照未建立=整页态(KLT-O20703):200 响应仍带数据骨架,⛔ 渲染成空表或 0。
- const snapshotNotReady = data?.snapshot_state === "not_ready";
- const monthOptions = data && data.month_options !== "failed" ? data.month_options : null;
- const monthOptionsFailed = data?.month_options === "failed";
- // C35:预选月不在 month_options 内 ⇒ 退回首项 month_options[0](⛔ 停在空月份静默成「筛选无结果」)。
- useEffect(() => {
- if (!monthOptions?.length || !month) return;
- if (!monthOptions.some((o) => o.period === month)) setMonth(monthOptions[0].period);
- }, [monthOptions, month]);
- const monthFallback = Boolean(monthOptions?.length && month && !monthOptions.some((o) => o.period === month));
- function resetFilter() {
- setKeyword("");
- setMonth(lastClosedMonth());
- setPage(1);
- }
- /** 表 1「查看明细」=页内锚点定位表 2 并自动填筛选(不跳页,视图§4.1.2)。 */
- function drillBatch(batchNo: string) {
- setKeyword(batchNo);
- setPage(1);
- if (teamView) detailRef.current?.focus({ preventScroll: true });
- detailRef.current?.scrollIntoView({ behavior: "smooth", block: "start" });
- }
- const config = data?.config ?? null;
- const settle = data?.settle ?? null;
- const batches = data?.batches ?? [];
- const details = data?.details ?? [];
- const reconDay = !wiring && config ? (config.recon_day == null ? VIEW_CONFIG_UNSET : `每月 ${config.recon_day} 日`) : BACKEND_NOT_WIRED;
- const payCycle = !wiring && config ? (config.pay_cycle ?? VIEW_DEFAULT_PAY_CYCLE) : BACKEND_NOT_WIRED;
- const settlementRule = wiring ? <Tri tone="missing" text={BACKEND_NOT_WIRED} />
- : settle && (settle.mode != null || settle.value != null) ? settleTextFromSnapshot(settle.mode, settle.value) : WORD_UNCONFIGURED;
- const batchTotal = wiring ? BACKEND_NOT_WIRED : `${data?.batch_total ?? 0} 批`;
- const detailTotal = wiring ? BACKEND_NOT_WIRED : `${data?.detail_total ?? 0} 条`;
- const shareTotal = wiring ? BACKEND_NOT_WIRED : moneyCell(data?.share_sum ?? null);
- const allShares = wiring ? "—" : `本方全部合计 ${moneyCell(data?.share_sum_all ?? null)}`;
- const showLedger = wiring || (data && !snapshotNotReady);
- const pageSize = 20;
- const filters = <>
- <div className={teamView ? "ops-toolbar team-recon-toolbar" : "reconcile-filters"}>
- <label className="ops-search">
- <Search size={17} aria-hidden="true" />
- <Input
- aria-label="搜索对账单号或明细号"
- placeholder="搜索对账单号/明细号"
- value={keyword}
- onChange={(event) => { setKeyword(event.target.value); setPage(1); }}
- />
- {keyword && <button type="button" aria-label="清空搜索" onClick={() => { setKeyword(""); setPage(1); }}><X size={15} aria-hidden="true" /></button>}
- </label>
- {/* 月份选项取接口返回的两表并集。 */}
- <FilterSelect
- icon="month"
- aria-label="自然月"
- value={month}
- disabled={!monthOptions}
- onChange={(event) => { setMonth(event.target.value); setPage(1); }}
- >
- <option value="">{ALL_PERIODS_LABEL}</option>
- {(monthOptions ?? (month ? [{ period: month }] : [])).map((o) => <option key={o.period} value={o.period}>{o.period}</option>)}
- </FilterSelect>
- <Button variant="ghost" size="sm" onClick={resetFilter}>重置筛选</Button>
- {teamView && <span className="team-recon-filter-hint" role={fetchState.loading && data ? "status" : "note"}>
- <Info size={14} aria-hidden="true" />{fetchState.loading && data ? "正在更新筛选结果…" : VIEW_KEYWORD_FILTER_NOTE}
- </span>}
- </div>
- {!teamView && <p className="ops-import-note" role="note">{VIEW_KEYWORD_FILTER_NOTE}</p>}
- {monthFallback && <p className="ops-import-note" role="status">{VIEW_MONTH_NO_BATCH}</p>}
- {data?.month_options_truncated && <p className="ops-import-note" role="status">{viewMonthTruncated(monthOptions?.length ?? 0)}</p>}
- {monthOptionsFailed && <p className="ops-import-note" role="status">{WORD_FETCH_FAILED}:月份选项暂不可用。</p>}
- </>;
- return (
- <section className={`ops-page reconcile-index ${teamView ? "team-recon-view" : "page-fill"}`}>
- <header className={teamView ? "ops-heading statement-heading" : "reconcile-page-heading"}>
- <div>
- {!teamView && <p className="ops-eyebrow"><span /> READONLY / 只读视图</p>}
- <h1>{title}</h1>
- <PageIntro>{teamView ? "按账期查看团队的对账批次、已出账明细和分成金额。" : "从每个账期的对账批次查到本方参与的结算和分成。"}</PageIntro>
- </div>
- </header>
- {notice && <OpsNotice message={notice} onClose={() => setNotice("")} />}
- {wiring && <p className="ops-import-note" role="status">{VIEW_WIRING_NOTE}</p>}
- {teamView && showLedger && <>
- <dl className="team-recon-config" aria-label="本方对账配置">
- <div><dt>本方对账日</dt><dd>{reconDay}</dd></div>
- <div><dt>付款周期</dt><dd>{payCycle}</dd></div>
- <div><dt>{CARD1_TITLE}</dt><dd>{settlementRule}</dd></div>
- </dl>
- <section className="team-recon-snapshot" aria-labelledby="team-recon-snapshot-title">
- <header>
- <h2 id="team-recon-snapshot-title">{CARD_SNAPSHOT_TITLE}</h2>
- <span>账期 {month || ALL_PERIODS_LABEL}</span>
- </header>
- <div className="statement-totals">
- <div data-total="share">
- <span>本方分成合计</span>
- <strong className={wiring || data?.share_sum == null ? "statement-total-empty" : undefined}>{shareTotal}</strong>
- <small>{allShares}</small>
- </div>
- <div><span>本方对账清单</span><strong>{batchTotal}</strong>{!wiring && <small>当前显示 {data?.batch_shown ?? 0} 批</small>}</div>
- <div><span>本方账单明细</span><strong>{detailTotal}</strong>{!wiring && <small>当前显示 {data?.detail_shown ?? 0} 条</small>}</div>
- </div>
- </section>
- </>}
- {teamView ? <div className="ops-list-shell team-recon-filters">{filters}</div> : filters}
- {teamView && fetchState.loading && !data && !fail && <p className="ops-list-shell team-recon-loading" role="status">正在读取本方对账…</p>}
- {/* 整页态:KLT-O20701(⛔ 重试)/KLT-O20703(筛选条保留,①—⑥ 全替换,⛔ 渲染空表)/KLT-P301。 */}
- {fail?.kind === "binding" && <FullPageState text={VIEW_BINDING_FAILED} />}
- {fail?.kind === "snapshot" && <FullPageState text={VIEW_SNAPSHOT_NOT_READY} retry={fetchState.reload} />}
- {snapshotNotReady && <FullPageState text={VIEW_SNAPSHOT_NOT_READY} retry={fetchState.reload} />}
- {fail?.kind === "forbidden" && <FullPageState text={VIEW_ROLE_FORBIDDEN} />}
- {fail?.kind === "param" && <FullPageState text={VIEW_FILTER_INCOMPLETE} />}
- {fail?.kind === "fail" && <FullPageState text={fail.message} retry={fetchState.reload} />}
- {showLedger && (
- <>
- {!teamView && <>
- {/* ① 页顶配置卡(V6,当前):两格都给**生效的具体取值**(✅ 2026-11-18:
- 付款周期不再渲染「留空=跟随默认」——那不是取值),对账日缺失才回落原标题。 */}
- <div className="reconcile-totals" aria-label="本方对账配置">
- <div>
- <span>本方对账日</span>
- <strong>{reconDay}</strong>
- <small>当前生效配置</small>
- </div>
- <div>
- <span>付款周期</span>
- <strong>{payCycle}</strong>
- <small>当前生效配置</small>
- </div>
- </div>
- {/* ② 卡 1:标题固定(14.2②);未配 ⇒「未配置」,⛔ 显 0/空白。 */}
- <div className="reconcile-totals" aria-label={CARD1_TITLE}>
- <div>
- <span>{CARD1_TITLE}</span>
- <strong>{settlementRule}</strong>
- <small>档案现值,不按客户配</small>
- </div>
- </div>
- {/* ③ 卡 2/3:标题固定「本期按账期快照」+副标题账期(与②「(现行)」同屏共存=时点口径对外声明)。 */}
- <p className="ops-eyebrow" style={{ marginTop: 8 }}>
- {CARD_SNAPSHOT_TITLE}(账期 {month || ALL_PERIODS_LABEL})
- </p>
- <div className="reconcile-totals" aria-label={CARD_SNAPSHOT_TITLE}>
- <div>
- <span>本方对账清单</span>
- <strong>{batchTotal}</strong>
- <small>{wiring ? "—" : `当前显示 ${data?.batch_shown ?? 0} 批`}</small>
- </div>
- <div>
- <span>本方账单明细</span>
- <strong>{detailTotal}</strong>
- <small>{wiring ? "—" : `当前显示 ${data?.detail_shown ?? 0} 条`}</small>
- </div>
- {/* ④ 卡 4:当前筛选合计+本方全部合计双值常驻(视图§4.2 条 7);null ⇒ 取数失败 ⛔ 显 ¥0。 */}
- <div>
- <span>本方分成合计</span>
- <strong>{shareTotal}</strong>
- <small>{allShares}</small>
- </div>
- </div>
- </>}
- {/* ⑤ 表 1 本方对账清单(出账状态与批次状态两维度两列并排)。 */}
- <div className={teamView ? "ops-list-shell team-recon-ledger" : "reconcile-ledger list-shell-fill"}>
- {teamView && <header className="team-recon-ledger-heading"><h2 id="team-recon-batches">对账清单</h2></header>}
- <div className="ops-table-wrap" role={teamView ? "region" : undefined} aria-labelledby={teamView ? "team-recon-batches" : undefined} tabIndex={teamView ? 0 : undefined}>
- <table className="ops-table" aria-labelledby={teamView ? "team-recon-batches" : undefined} aria-busy={teamView ? fetchState.loading : undefined}>
- {teamView && <OpsTableColumns widths={[210, 102, 112, 112, 100, 145, 286]} />}
- <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>
- <tbody>
- {wiring ? (
- <tr><td colSpan={7}><Tri tone="missing" text={BACKEND_NOT_WIRED} /></td></tr>
- ) : (
- batches.map((row: ViewReconBatchRow) => (
- <tr key={row.batch_no}>
- <td className="ops-mono" title={teamView ? row.batch_no : undefined}>{row.batch_no}</td>
- <td>{row.period}</td>
- <td><OpsStatus tone={row.reconcile_status === "settled" ? "success" : row.reconcile_status === "abnormal" ? "danger" : "neutral"}>{RECONCILE_STATUS_TEXT[row.reconcile_status]}</OpsStatus></td>
- <td><OpsStatus tone={row.status === "executed" ? "success" : row.status === "failed" ? "danger" : "neutral"}>{BATCH_STATUS_TEXT[row.status]}</OpsStatus></td>
- <td className="table-number">{row.detail_count}</td>
- <td><strong className={teamView ? "reconcile-money table-number" : "table-number"}>{moneyFromCents(row.share_cents)}</strong></td>
- <td>
- {/* 无明细 ⇒ 导出按钮整块不渲染(⚠️ 不是禁用,总则§16.9;KLT-H205xx 仅直调防护)。 */}
- {row.has_detail && (
- <button type="button" className="ops-table-action" onClick={() => exportBatch(row.batch_no)}>
- <Download size={14} aria-hidden="true" /> 导出本批账单明细
- </button>
- )}{" "}
- <button type="button" className="ops-table-action" onClick={() => drillBatch(row.batch_no)}>查看明细{teamView && <ArrowDown size={14} aria-hidden="true" />}</button>
- </td>
- </tr>
- ))
- )}
- {!wiring && !batches.length && (
- <OpsTableEmpty colSpan={7}>
- {VIEW_LIST_EMPTY}{!month && `;${VIEW_ALL_PERIODS_NOTE}`}
- </OpsTableEmpty>
- )}
- </tbody>
- </table>
- </div>
- {!wiring && (
- <ServerListPager
- total={data?.batch_total ?? 0}
- page={page}
- pageSize={pageSize}
- onPageChange={setPage}
- unit="批"
- />
- )}
- </div>
- {/* ⑥ 表 2 本方账单明细(A18:只列已出账明细;灰底提示必显)。 */}
- <div className={teamView ? "ops-list-shell team-recon-ledger team-recon-details" : "reconcile-ledger list-shell-fill"} ref={detailRef} tabIndex={teamView ? -1 : undefined}>
- {teamView ? <header className="team-recon-ledger-heading">
- <h2 id="team-recon-bills">账单明细</h2>
- <p className="team-recon-detail-note" role="note"><Info size={14} aria-hidden="true" />{VIEW_DETAIL_ONLY_SETTLED}</p>
- </header> : <p className="ops-import-note" role="note">{VIEW_DETAIL_ONLY_SETTLED}</p>}
- <div className="ops-table-wrap" role={teamView ? "region" : undefined} aria-labelledby={teamView ? "team-recon-bills" : undefined} tabIndex={teamView ? 0 : undefined}>
- <table className="ops-table" aria-labelledby={teamView ? "team-recon-bills" : undefined} aria-busy={teamView ? fetchState.loading : undefined}>
- {teamView && <OpsTableColumns widths={[200, 210, 155, 102, 138, 170, 126]} />}
- <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>
- <tbody>
- {wiring ? (
- <tr><td colSpan={7}><Tri tone="missing" text={BACKEND_NOT_WIRED} /></td></tr>
- ) : (
- details.map((row: ViewBillDetailRow) => (
- <tr key={row.bill_detail_id}>
- <td className="ops-mono" title={teamView ? row.bill_detail_id : undefined}>{row.bill_detail_id}</td>
- <td>
- {/* C76:当前归属≠我 ⇒ 纯文本无链接+「归属已变更」;teamLead 无客户详情页 ⇒ 恒纯文本。 */}
- {kind === "partner" && row.customer_visible ? (
- <Link className="workspace-link" to={`${prefix}/customer/${encodeURIComponent(row.customer_id)}`} state={linkState}>{row.customer_name}</Link>
- ) : (
- <span className={teamView ? "table-cell-title" : undefined} title={teamView ? row.customer_name : undefined}>
- {row.customer_name}{!row.customer_visible && <OpsTag tone="neutral">{OWNERSHIP_CHANGED}</OpsTag>}
- </span>
- )}
- </td>
- <td className="ops-mono" title={teamView ? row.receivable_no : undefined}>{row.receivable_no}</td>
- <td>{row.period}</td>
- <td><strong className={teamView ? "reconcile-money table-number" : "table-number"}>{moneyFromCents(row.receivable_cents)}</strong></td>
- {/* 批次详情宿主路由未在 14.1 路由表声明(仅 14.6 返回链路提及)⇒ 纯文本,缺口已登记。 */}
- <td className="ops-mono" title={teamView ? row.batch_no : undefined}>{row.batch_no}</td>
- <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>
- </tr>
- ))
- )}
- {!wiring && !details.length && (
- <OpsTableEmpty colSpan={7}>
- {VIEW_LIST_EMPTY}{!month && `;${VIEW_ALL_PERIODS_NOTE}`}
- </OpsTableEmpty>
- )}
- </tbody>
- </table>
- </div>
- {!wiring && (
- <ServerListPager
- total={data?.detail_total ?? 0}
- page={page}
- pageSize={pageSize}
- onPageChange={setPage}
- />
- )}
- </div>
- </>
- )}
- </section>
- );
- }
- export function PartnerReconPage() {
- return <PartyReconMergedPage kind="partner" />;
- }
- export function TeamReconPage() {
- return <PartyReconMergedPage kind="team" />;
- }
- /* ── V-P5 运营商「本方对账清单」(⚠️ 独立组件,⛔ 与 V-P1 合并靠 props 抹平,A51) ── */
- export function OperatorReconPage() {
- const { saved, stateFor } = usePartyListReturn();
- const [month, setMonth] = useState(saved?.month ?? lastClosedMonth());
- const [keyword, setKeyword] = useState(saved?.keyword ?? "");
- const [page, setPage] = useState(saved?.page ?? 1);
- const linkState = stateFor({ month, keyword, page });
- const [notice, setNotice] = useState("");
- const exportBatch = useExportBatch(setNotice);
- const periodsFetch = useViewFetch(() => reconGetPeriods(), []);
- const periods = periodsFetch.data?.periods ?? null;
- const fetchState = useViewFetch(
- // 分页器是 1 基、后端 `page` 是 0 基(openapi:页码 0 基索引)⇒ 只在请求边界换算。
- () => reconGetList({ page: Math.max(0, page - 1), page_size: 20, period: month || undefined, keyword: keyword.trim() || undefined }),
- [month, keyword, page],
- );
- const { data, fail } = fetchState;
- const wiring = fail?.kind === "wiring";
- const rows = data?.items ?? [];
- useEffect(() => {
- if (!periods?.length || !month) return;
- if (!periods.includes(month)) setMonth(periods[0]);
- }, [periods, month]);
- const monthFallback = Boolean(periods?.length && month && !periods.includes(month));
- const selfConfig = data?.self_config ?? null;
- const total = data?.total ?? 0;
- const pageSize = 20;
- return (
- <section className="ops-page reconcile-index page-fill">
- <header className="reconcile-page-heading">
- <div>
- <p className="ops-eyebrow"><span /> READONLY / 只读视图</p>
- <h1>本方对账清单</h1>
- <PageIntro>核对本方各账期的出账进度和应结分成。</PageIntro>
- </div>
- </header>
- {notice && <OpsNotice message={notice} onClose={() => setNotice("")} />}
- {wiring && <p className="ops-import-note" role="status">{VIEW_WIRING_NOTE}</p>}
- {/* V6 页顶两卡(随 recon/list 响应 self_config 附带,只读身份⛔ 授配置读键)。 */}
- <div className="reconcile-totals" aria-label="本方对账配置">
- <div>
- <span>本方对账日</span>
- <strong>{wiring ? BACKEND_NOT_WIRED : selfConfig ? `每月 ${selfConfig.recon_day} 日` : BACKEND_NOT_WIRED}</strong>
- <small>当前生效配置</small>
- </div>
- <div>
- <span>付款周期</span>
- <strong>{wiring ? BACKEND_NOT_WIRED : selfConfig ? (selfConfig.pay_cycle ?? VIEW_DEFAULT_PAY_CYCLE) : BACKEND_NOT_WIRED}</strong>
- <small>当前生效配置</small>
- </div>
- </div>
- {/* 筛选条:自然月+对账单号关键字(⛔ 分成方/区域等范围类筛选,I30)。 */}
- <div className="reconcile-filters">
- <label className="ops-search">
- <Search size={17} />
- <Input
- aria-label="搜索对账单号"
- placeholder="搜索对账单号"
- value={keyword}
- onChange={(event) => { setKeyword(event.target.value); setPage(1); }}
- />
- {keyword && <button type="button" aria-label="清空搜索" onClick={() => { setKeyword(""); setPage(1); }}><X size={15} /></button>}
- </label>
- <FilterSelect
- icon="month"
- aria-label="自然月"
- value={month}
- disabled={!periods}
- onChange={(event) => { setMonth(event.target.value); setPage(1); }}
- >
- <option value="">{ALL_PERIODS_LABEL}</option>
- {(periods ?? (month ? [month] : [])).map((p) => <option key={p} value={p}>{p}</option>)}
- </FilterSelect>
- <Button variant="ghost" size="sm" onClick={() => { setKeyword(""); setMonth(lastClosedMonth()); setPage(1); }}>重置筛选</Button>
- </div>
- {monthFallback && <p className="ops-import-note" role="status">{VIEW_MONTH_NO_BATCH}</p>}
- {fail?.kind === "binding" && <FullPageState text={VIEW_BINDING_FAILED} />}
- {fail?.kind === "forbidden" && <FullPageState text={VIEW_ROLE_FORBIDDEN} />}
- {fail?.kind === "fail" && <FullPageState text={fail.message} retry={fetchState.reload} />}
- {(wiring || data) && (
- <div className="reconcile-ledger list-shell-fill">
- <div className="ops-table-wrap">
- <table className="ops-table">
- <thead><tr><th>对账单号</th><th>自然月</th><th>出账状态</th><th>批次状态</th><th>明细条数</th><th>本方分成金额</th><th>操作</th></tr></thead>
- <tbody>
- {wiring ? (
- <tr><td colSpan={7}><Tri tone="missing" text={BACKEND_NOT_WIRED} /></td></tr>
- ) : (
- rows.map((row) => (
- <tr key={row.batch_no}>
- <td className="ops-mono">{row.batch_no}</td>
- <td>{row.period}</td>
- <td><OpsStatus tone={row.reconcile_status === "settled" ? "success" : row.reconcile_status === "abnormal" ? "danger" : "neutral"}>{RECONCILE_STATUS_TEXT[row.reconcile_status]}</OpsStatus></td>
- <td><OpsStatus tone={row.status === "executed" ? "success" : row.status === "failed" ? "danger" : "neutral"}>{BATCH_STATUS_TEXT[row.status]}</OpsStatus></td>
- <td className="table-number">{row.detail_count}</td>
- <td><strong className="table-number">{moneyFromCents(row.share_cents)}</strong></td>
- <td>
- {/* 本批无明细 ⇒ 按钮整块不渲染;「查看明细」→ V-P6 按对账单号过滤(14.3 筛选行)。 */}
- {row.detail_count > 0 && (
- <button type="button" className="ops-table-action" onClick={() => exportBatch(row.batch_no)}>
- <Download size={13} /> 导出本批账单明细
- </button>
- )}{" "}
- <Link className="workspace-link" to={`/bos/ov/bill-detail?batch=${encodeURIComponent(row.batch_no)}`} state={linkState}>查看明细</Link>
- </td>
- </tr>
- ))
- )}
- {!wiring && !rows.length && (
- <OpsTableEmpty colSpan={7}>
- {VIEW_LIST_EMPTY}{!month && `;${VIEW_ALL_PERIODS_NOTE}`}
- </OpsTableEmpty>
- )}
- </tbody>
- </table>
- </div>
- {!wiring && (
- <ServerListPager total={total} page={page} pageSize={pageSize} onPageChange={setPage} unit="批" />
- )}
- </div>
- )}
- </section>
- );
- }
- /* ── V-P6 运营商「账单明细」(⛔ 导出按钮——导出单位是批次;⛔「涉及分成方」卡) ────── */
- export function OperatorBillDetailPage() {
- const { location, saved, stateFor } = usePartyListReturn();
- const [month, setMonth] = useState(saved?.month ?? lastClosedMonth());
- const [batchKw, setBatchKw] = useState(saved?.batchKw ?? new URLSearchParams(location.search).get("batch") ?? "");
- const [customerKw, setCustomerKw] = useState(saved?.customerKw ?? "");
- const [page, setPage] = useState(saved?.page ?? 1);
- const linkState = stateFor({ month, batchKw, customerKw, page });
- const back = detailBack(location.state, "/bos/ov/bill-detail", "返回账单明细");
- const periodsFetch = useViewFetch(() => reconGetPeriods(), []);
- const periods = periodsFetch.data?.periods ?? null;
- const fetchState = useViewFetch(
- () => billGetList({ page: Math.max(0, page - 1), page_size: 20, period: month || undefined, keyword: batchKw.trim() || undefined, customer_kw: customerKw.trim() || undefined }),
- [month, batchKw, customerKw, page],
- );
- const { data, fail } = fetchState;
- const wiring = fail?.kind === "wiring";
- const rows = data?.items ?? [];
- const total = data?.total ?? 0;
- const pageSize = 20;
- useEffect(() => {
- if (!periods?.length || !month) return;
- if (!periods.includes(month)) setMonth(periods[0]);
- }, [periods, month]);
- return (
- <section className="ops-page reconcile-index page-fill">
- {back.to !== "/bos/ov/bill-detail" && <Link className="ops-back-link self-start" to={back.to} state={back.state}>{back.label}</Link>}
- <header className="reconcile-page-heading">
- <div>
- <p className="ops-eyebrow"><span /> READONLY / 只读视图</p>
- <h1>账单明细</h1>
- <PageIntro>沿账单追到具体客户和订阅,核对本方每笔分成。</PageIntro>
- </div>
- </header>
- {wiring && <p className="ops-import-note" role="status">{VIEW_WIRING_NOTE}</p>}
- <div className="reconcile-filters">
- <label className="ops-search">
- <Search size={17} />
- <Input
- aria-label="搜索对账单号"
- placeholder="搜索对账单号"
- value={batchKw}
- onChange={(event) => { setBatchKw(event.target.value); setPage(1); }}
- />
- {batchKw && <button type="button" aria-label="清空搜索" onClick={() => { setBatchKw(""); setPage(1); }}><X size={15} /></button>}
- </label>
- <label className="ops-search">
- <Search size={17} />
- <Input
- aria-label="搜索客户"
- placeholder="搜索客户"
- value={customerKw}
- onChange={(event) => { setCustomerKw(event.target.value); setPage(1); }}
- />
- {customerKw && <button type="button" aria-label="清空搜索" onClick={() => { setCustomerKw(""); setPage(1); }}><X size={15} /></button>}
- </label>
- <FilterSelect
- icon="month"
- aria-label="自然月"
- value={month}
- disabled={!periods}
- onChange={(event) => { setMonth(event.target.value); setPage(1); }}
- >
- <option value="">{ALL_PERIODS_LABEL}</option>
- {(periods ?? (month ? [month] : [])).map((p) => <option key={p} value={p}>{p}</option>)}
- </FilterSelect>
- <Button variant="ghost" size="sm" onClick={() => { setBatchKw(""); setCustomerKw(""); setMonth(lastClosedMonth()); setPage(1); }}>重置筛选</Button>
- </div>
- <p className="ops-import-note" role="note">{VIEW_KEYWORD_FILTER_NOTE};{VIEW_DETAIL_ONLY_SETTLED}</p>
- {fail?.kind === "binding" && <FullPageState text={VIEW_BINDING_FAILED} />}
- {fail?.kind === "forbidden" && <FullPageState text={VIEW_ROLE_FORBIDDEN} />}
- {fail?.kind === "fail" && <FullPageState text={fail.message} retry={fetchState.reload} />}
- {(wiring || data) && (
- <div className="reconcile-ledger list-shell-fill">
- <div className="ops-table-wrap">
- <table className="ops-table">
- {/* ⚠️ 应收单号/应结金额两列待 R2 真源(对账§6 明细列表口)补列 ⇒ 暂以分成基数/本方分成呈现,缺口已登记。 */}
- <thead><tr><th>账单明细号</th><th>客户名称</th><th>自然月</th><th>分成基数</th><th>本方分成金额</th><th>对账单号</th><th>操作</th></tr></thead>
- <tbody>
- {wiring ? (
- <tr><td colSpan={7}><Tri tone="missing" text={BACKEND_NOT_WIRED} /></td></tr>
- ) : (
- rows.map((row) => (
- <tr key={row.bill_detail_id}>
- <td className="ops-mono">{row.bill_detail_id}</td>
- <td>{row.customer_name}</td>
- <td>{row.period}</td>
- <td className="table-number">{moneyFromCents(row.share_base_cents)}</td>
- <td><strong className="table-number">{moneyFromCents(row.share_amount_cents)}</strong></td>
- <td className="ops-mono">{row.batch_no}</td>
- <td><Link className="workspace-link" to={`/bos/ov/bill-detail/${encodeURIComponent(row.bill_detail_id)}`} state={linkState}>查看详情</Link></td>
- </tr>
- ))
- )}
- {!wiring && !rows.length && (
- <OpsTableEmpty colSpan={7}>
- {VIEW_LIST_EMPTY}{!month && `;${VIEW_ALL_PERIODS_NOTE}`}
- </OpsTableEmpty>
- )}
- </tbody>
- </table>
- </div>
- {!wiring && (
- <ServerListPager total={total} page={page} pageSize={pageSize} onPageChange={setPage} />
- )}
- </div>
- )}
- </section>
- );
- }
- /* ── V-P2/V-P7 本方客户清单(同组件两路由;形态 D 列待客户§登记) ────────────── */
- export function PartyCustomerListPage({ kind }: { kind: "partner" | "operator" }) {
- const prefix = kindPrefix(kind);
- const { saved, stateFor } = usePartyListReturn();
- const [keyword, setKeyword] = useState(saved?.keyword ?? "");
- const [page, setPage] = useState(saved?.page ?? 1);
- const linkState = stateFor({ keyword, page });
- // ⛔ 前端下传 partner_id/operator_id(总则§16.1:范围在服务端谓词层展开)。
- const fetchState = useViewFetch(
- // 分页器是 1 基、后端 `page` 是 0 基(openapi:页码 0 基索引)⇒ 只在请求边界换算。
- () => customerGetList({ page: Math.max(0, page - 1), page_size: 20, keyword: keyword.trim() || undefined }),
- [keyword, page],
- );
- const { data, fail } = fetchState;
- const rows = data?.items ?? [];
- const total = data?.total ?? 0;
- const pageSize = 20;
- return (
- <section className="ops-page reconcile-index page-fill">
- <header className="reconcile-page-heading">
- <div>
- <p className="ops-eyebrow"><span /> READONLY / 只读视图</p>
- <h1>客户清单</h1>
- <PageIntro>查找与本方业务相关的客户,确认客户归属和服务情况。</PageIntro>
- </div>
- </header>
- <div className="reconcile-filters">
- <label className="ops-search">
- <Search size={17} />
- <Input
- aria-label="搜索客户"
- placeholder="客户名称模糊/识别号精确"
- value={keyword}
- onChange={(event) => { setKeyword(event.target.value); setPage(1); }}
- />
- {keyword && <button type="button" aria-label="清空搜索" onClick={() => { setKeyword(""); setPage(1); }}><X size={15} /></button>}
- </label>
- </div>
- {fail?.kind === "fail" && <FullPageState text={fail.message} retry={fetchState.reload} />}
- {fail && fail.kind !== "fail" && <FullPageState text={fail.kind === "forbidden" ? VIEW_ROLE_FORBIDDEN : fail.kind === "wiring" ? VIEW_WIRING_NOTE : VIEW_LIST_EMPTY} />}
- {!fail && (
- <div className="reconcile-ledger list-shell-fill">
- <div className="ops-table-wrap">
- <table className="ops-table">
- {/* 形态 D 列=客户名称/识别号/服务开通状态/所属区域/生效套餐摘要(视图§5.1);
- 识别号│区域路径│套餐名均随 `/customer/get_list@v1` 下发(D-71 三态:键缺失=未下发,
- `null`/空=未登记│未挂载│无在用订阅)。 */}
- <thead><tr><th>客户名称</th><th>客户识别号</th><th>服务开通状态</th><th>所属区域</th><th>生效套餐摘要</th><th>操作</th></tr></thead>
- <tbody>
- {rows.map((row) => (
- <tr key={row.customer_id}>
- <td>{row.customer_name}</td>
- {/* 识别号:列表口下发 `identity_no_masked`(keybox 解密后脱敏);`null`=未登记,键缺失才标未下发。 */}
- <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>
- {/* 三态原样渲染(客户§2 acct_status,库内英文码 ⇒ 按字典转中文),⛔ 重算/派生第四态。 */}
- <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>
- {/* 所属区域:后端 `region_path` 取层级真源 `bos_region_meta.path_name`(未定级回落节点 ID);
- 键缺失=未下发,空=未挂载(⛔ 把「无挂载」说成「未下发」)。 */}
- <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>
- {/* 生效套餐摘要:后端 `plan_names`(在用订阅的套餐名,status ∈ pending/active)。 */}
- <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>
- <td><Link className="workspace-link" to={`${prefix}/customer/${encodeURIComponent(row.customer_id)}`} state={linkState}>查看</Link></td>
- </tr>
- ))}
- {!rows.length && <OpsTableEmpty colSpan={6}>{VIEW_LIST_EMPTY}</OpsTableEmpty>}
- </tbody>
- </table>
- </div>
- <ServerListPager total={total} page={page} pageSize={pageSize} onPageChange={setPage} unit="家" />
- </div>
- )}
- </section>
- );
- }
- /* ── V-P3/V-P8 本方合同清单(行末只有查看) ─────────────────────────────── */
- /**
- * 「合同名称」列取值:合同数据模型**不存名称列**(第 3 册订阅§5「合同条目不存名」)
- * ⇒ 按本合同服务条目的套餐现名/派生档名汇总(真值派生,⛔ 造名)。
- * 条目存在但两枚名字都取不到(档位被删)=「未配置」,无条目也=「未配置」。
- */
- function contractNameOf(row: ContractRow) {
- const items = row.service_items ?? [];
- const names = items
- .map((item) => item.plan_name)
- .filter((name): name is string => Boolean(name && name.trim()));
- if (!names.length) return <Tri tone="missing" text={WORD_UNCONFIGURED} title="本合同未登记服务条目,无法从条目汇总名称(合同数据模型不存名称列)" />;
- return (
- <span title="合同数据模型不存名称列(第 3 册:合同条目不存名);此处按本合同服务条目的套餐名汇总">
- {[...new Set(names)].join("、")}
- </span>
- );
- }
- export function PartyContractListPage({ kind }: { kind: "partner" | "operator" }) {
- const prefix = kindPrefix(kind);
- const { saved, stateFor } = usePartyListReturn();
- const [keyword, setKeyword] = useState(saved?.keyword ?? "");
- const [page, setPage] = useState(saved?.page ?? 1);
- const linkState = stateFor({ keyword, page });
- // 行集=本方客户集合传导(SQL-2 第二段);⛔ 前端下传范围入参。
- const fetchState = useViewFetch(
- // 分页器是 1 基、后端 `page` 是 0 基(openapi:页码 0 基索引)⇒ 只在请求边界换算。
- () => contractGetList({ page: Math.max(0, page - 1), page_size: 20, keyword: keyword.trim() || undefined }),
- [keyword, page],
- );
- const { data, fail } = fetchState;
- const rows = data?.items ?? [];
- const total = data?.total ?? rows.length;
- const pageSize = 20;
- return (
- <section className="ops-page reconcile-index page-fill">
- <header className="reconcile-page-heading">
- <div>
- <p className="ops-eyebrow"><span /> READONLY / 只读视图</p>
- <h1>合同清单</h1>
- <PageIntro>按客户查找与本方业务相关的合同,核对服务期限和开通情况。</PageIntro>
- </div>
- </header>
- <div className="reconcile-filters">
- <label className="ops-search">
- <Search size={17} />
- <Input
- aria-label="搜索合同"
- placeholder="搜索合同编号"
- value={keyword}
- onChange={(event) => { setKeyword(event.target.value); setPage(1); }}
- />
- {keyword && <button type="button" aria-label="清空搜索" onClick={() => { setKeyword(""); setPage(1); }}><X size={15} /></button>}
- </label>
- </div>
- {fail?.kind === "fail" && <FullPageState text={fail.message} retry={fetchState.reload} />}
- {fail && fail.kind !== "fail" && <FullPageState text={fail.kind === "forbidden" ? VIEW_ROLE_FORBIDDEN : fail.kind === "wiring" ? VIEW_WIRING_NOTE : VIEW_LIST_EMPTY} />}
- {!fail && (
- <div className="reconcile-ledger list-shell-fill">
- <div className="ops-table-wrap">
- <table className="ops-table">
- {/*
- 合同名称列:合同数据模型**不存名称列**(第 3 册「合同条目不存名」)⇒ 按本合同
- 服务条目的套餐现名汇总显示(真值派生,⛔ 造名)。无条目时标「未配置」,⛔ 标「后端未下发」。
- */}
- <thead><tr><th>合同编号</th><th>合同名称</th><th>客户名称</th><th>合同期间</th><th>状态</th><th>操作</th></tr></thead>
- <tbody>
- {rows.map((row) => (
- <tr key={row.contract_id}>
- <td className="ops-mono">{row.contract_no}</td>
- <td>{contractNameOf(row)}</td>
- <td>{row.customer_name ?? <Tri tone="missing" text={WORD_NOT_PROVIDED} />}</td>
- <td>{row.start_date ?? <span className="table-placeholder">—</span>} ~ {row.end_date ?? <span className="table-placeholder">—</span>}</td>
- <td><OpsTag tone="neutral">{row.status}</OpsTag></td>
- <td><Link className="workspace-link" to={`${prefix}/contract/${encodeURIComponent(row.contract_id)}`} state={linkState}>查看</Link></td>
- </tr>
- ))}
- {!rows.length && <OpsTableEmpty colSpan={6}>{VIEW_LIST_EMPTY}</OpsTableEmpty>}
- </tbody>
- </table>
- </div>
- <ServerListPager total={total} page={page} pageSize={pageSize} onPageChange={setPage} unit="份" />
- </div>
- )}
- </section>
- );
- }
- /* ── V-D1 详情宿主层(返回链路固定文案+显式路由,⛔ history.back()) ────────── */
- /** 11104 ⇒ 空态卡片「数据不存在或归属已变更」+「刷新列表」(⚠️⛔「无权限」字样)。 */
- function DetailNotFound({ back }: { back: ReturnType<typeof detailBack> }) {
- return (
- <div className="ops-detail-callout" role="alert" style={{ textAlign: "center", padding: "48px 24px" }}>
- <strong>{VIEW_NOT_FOUND}</strong>
- <p><Link className="workspace-link" to={back.to} state={back.state}>刷新列表({back.label.replace("← ", "")})</Link></p>
- </div>
- );
- }
- function DetailHeader({ title, back }: { title: string; back: ReturnType<typeof detailBack> }) {
- return (
- <header className="reconcile-page-heading">
- <div>
- <p className="ops-eyebrow"><span /> READONLY / 只读视图</p>
- <h1>{title}</h1>
- <p><Link className="workspace-link" to={back.to} state={back.state}>← {back.label.replace("← ", "")}</Link></p>
- </div>
- </header>
- );
- }
- /** V9 客户详情(⛔「关联工单」卡片,14.5 白名单第 2 项)。 */
- export function PartyCustomerDetailPage({ kind }: { kind: "partner" | "operator" }) {
- const prefix = kindPrefix(kind);
- const { id = "" } = useParams();
- const location = useLocation();
- const back = detailBack(location.state, `${prefix}/customer`, BACK_TO_CUSTOMER_LIST);
- const fetchState = useViewFetch(() => customerGet({ customer_id: id }), [id]);
- const { data, fail } = fetchState;
- return (
- <section className="ops-page reconcile-index">
- <DetailHeader title="客户详情" back={back} />
- {fail?.kind === "notfound" && <DetailNotFound back={back} />}
- {fail && fail.kind !== "notfound" && <FullPageState text={fail.kind === "fail" ? fail.message : VIEW_WIRING_NOTE} retry={fail.kind === "fail" ? fetchState.reload : undefined} />}
- {data && (
- <div className="ops-table-wrap">
- <table className="ops-table">
- <tbody>
- <tr><th>客户名称</th><td>{data.customer.customer_name}</td></tr>
- <tr><th>主体类型</th><td>{label(SUBJECT_TYPE, data.customer.subject_type)}</td></tr>
- <tr><th>服务开通状态</th><td>{label(ACCT_STATUS, data.customer.acct_status)}</td></tr>
- <tr><th>归属运营商</th><td>{data.customer.operator_name ?? <span className="table-placeholder">—</span>}</td></tr>
- <tr><th>归属合伙人</th><td>{data.customer.partner_name ?? <span className="table-placeholder">—</span>}</td></tr>
- <tr><th>下属分账号</th><td className="table-number">{data.sub_account_count}</td></tr>
- <tr><th>建档时间</th><td>{data.customer.created_at ?? <span className="table-placeholder">—</span>}</td></tr>
- </tbody>
- </table>
- </div>
- )}
- </section>
- );
- }
- /** V11 合同详情(⛔「关联工单」卡片;⛔ 编辑入口)。 */
- export function PartyContractDetailPage({ kind }: { kind: "partner" | "operator" }) {
- const prefix = kindPrefix(kind);
- const { id = "" } = useParams();
- const location = useLocation();
- const back = detailBack(location.state, `${prefix}/contract`, BACK_TO_CONTRACT_LIST);
- const fetchState = useViewFetch(() => contractGet({ contract_id: id }), [id]);
- const { data, fail } = fetchState;
- return (
- <section className="ops-page reconcile-index">
- <DetailHeader title="合同详情" back={back} />
- {fail?.kind === "notfound" && <DetailNotFound back={back} />}
- {fail && fail.kind !== "notfound" && <FullPageState text={fail.kind === "fail" ? fail.message : VIEW_WIRING_NOTE} retry={fail.kind === "fail" ? fetchState.reload : undefined} />}
- {data && (
- <div className="ops-table-wrap">
- <table className="ops-table">
- <tbody>
- <tr><th>合同编号</th><td className="ops-mono">{data.contract_no}</td></tr>
- <tr><th>客户名称</th><td>{data.customer_name ?? <span className="table-placeholder">—</span>}</td></tr>
- <tr><th>合同期间</th><td>{data.start_date ?? <span className="table-placeholder">—</span>} ~ {data.end_date ?? <span className="table-placeholder">—</span>}</td></tr>
- <tr><th>状态</th><td>{data.status}</td></tr>
- <tr><th>合同类型</th><td>{data.contract_type ? (CONTRACT_TYPE_LABEL[data.contract_type] ?? data.contract_type) : <span className="table-placeholder">—</span>}</td></tr>
- <tr><th>签署日期</th><td>{data.sign_date ?? <span className="table-placeholder">—</span>}</td></tr>
- <tr><th>服务期(月)</th><td>{data.service_months ?? <span className="table-placeholder">—</span>}</td></tr>
- <tr><th>合同金额</th><td className="table-number">{moneyFromCents(data.contract_amount_cents)}</td></tr>
- </tbody>
- </table>
- </div>
- )}
- </section>
- );
- }
- /**
- * V12 账单明细详情(对账§14.3 七段同源一个接口);
- * ⛔「同一张应收上其他分成方」面板——三身份一律不渲染(14.5 第 3 项,服务端亦不返回)。
- */
- export function PartyBillDetailPage({ kind }: { kind: ViewKind }) {
- const { id = "" } = useParams();
- const location = useLocation();
- const fallback =
- kind === "partner"
- ? { to: "/bos/pv/recon", text: BACK_TO_REGION_RECON }
- : kind === "team"
- ? { to: "/bos/tv/recon", text: BACK_TO_SELF_RECON }
- : { to: "/bos/ov/bill-detail", text: BACK_TO_BILL_DETAIL_LIST };
- const back = detailBack(location.state, fallback.to, fallback.text);
- const fetchState = useViewFetch<BillDetailResult>(() => billGetDetail(id), [id]);
- const { data, fail } = fetchState;
- return (
- <section className="ops-page reconcile-index">
- <DetailHeader title="账单明细详情" back={back} />
- {fail?.kind === "notfound" && <DetailNotFound back={back} />}
- {fail && fail.kind !== "notfound" && (
- <FullPageState
- 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}
- retry={fail.kind === "fail" || fail.kind === "snapshot" ? fetchState.reload : undefined}
- />
- )}
- {data && (
- <div className="ops-table-wrap">
- <table className="ops-table">
- <tbody>
- <tr><th>账单明细号</th><td className="ops-mono">{data.bill_detail_id}</td></tr>
- <tr><th>所属对账单号</th><td className="ops-mono">{data.batch_no}</td></tr>
- <tr><th>自然月</th><td>{data.period}</td></tr>
- <tr><th>客户名称</th><td>{data.customer_name}</td></tr>
- <tr><th>套餐</th><td>{data.subscription_label}</td></tr>
- {/* ① 尾月对齐前后两值同屏 */}
- <tr><th>计费标准单价</th><td className="table-number">{data.settle_std_cents == null ? <span className="table-placeholder">—</span> : moneyFromCents(data.settle_std_cents)}</td></tr>
- <tr><th>订阅份数</th><td className="table-number">{data.quantity == null ? <span className="table-placeholder">—</span> : data.quantity}</td></tr>
- <tr><th>尾月对齐前</th><td className="table-number">{moneyFromCents(data.pre_align_cents)}</td></tr>
- <tr><th>应结金额(对齐后)</th><td><strong className="table-number">{moneyFromCents(data.receivable_cents)}</strong></td></tr>
- {/* ② 计费区间与天数 */}
- <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>
- <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>
- {/* ④ 分成基数 */}
- <tr><th>分成基数</th><td><span className="table-number">{moneyFromCents(data.share_base_cents)}</span>{data.base_floor_protected ? "(已按下限保护取 0)" : ""}</td></tr>
- {/* ⑤ 当时冻结的分成方式与取值(⛔ 读档案现值,I22) */}
- <tr><th>分成方式与取值</th><td className="table-number">{settleTextFromSnapshot(data.share_mode, data.share_value)}</td></tr>
- {/* ⑥ 本方分成金额 */}
- <tr><th>本方分成金额</th><td><strong className="table-number">{moneyFromCents(data.share_amount_cents)}</strong></td></tr>
- {/* ⑦ 逐账号在期天数:failed ⇒ 取数失败(⛔ 回落「无开停记录」) */}
- <tr>
- <th>逐账号在期天数</th>
- <td>
- {data.account_days_failed
- ? WORD_FETCH_FAILED
- : data.account_days == null
- ? WORD_NOT_PROVIDED
- : data.account_days.length
- ? data.account_days.map((a) => `${a.sub_account_label} ${a.in_period_days} 天`).join(";")
- : <span className="table-placeholder">—</span>}
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- )}
- </section>
- );
- }
|