|
@@ -12,6 +12,12 @@ import { useDetailLinkState, type detailBack } from "../lib/detail-navigation";
|
|
|
type RecordBack = ReturnType<typeof detailBack>;
|
|
type RecordBack = ReturnType<typeof detailBack>;
|
|
|
type RecordSection = { id: string; label: string; count?: number; content: ReactNode };
|
|
type RecordSection = { id: string; label: string; count?: number; content: ReactNode };
|
|
|
type RecordMetric = { label: string; icon: ReactNode; value: ReactNode };
|
|
type RecordMetric = { label: string; icon: ReactNode; value: ReactNode };
|
|
|
|
|
+type PartnerRecordState = { back: RecordBack; recordId: string; loading: boolean; fallback?: ReactNode };
|
|
|
|
|
+
|
|
|
|
|
+const recordTypes = {
|
|
|
|
|
+ CUSTOMER: { title: "客户详情", icon: Building2 },
|
|
|
|
|
+ CONTRACT: { title: "合同详情", icon: FileSignature },
|
|
|
|
|
+} as const;
|
|
|
|
|
|
|
|
const empty = <span className="table-placeholder">—</span>;
|
|
const empty = <span className="table-placeholder">—</span>;
|
|
|
const money = (cents: number) => `¥${(cents / 100).toLocaleString("zh-CN", { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
|
|
const money = (cents: number) => `¥${(cents / 100).toLocaleString("zh-CN", { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
|
|
@@ -22,44 +28,52 @@ function RecordFacts({ fields }: { fields: readonly (readonly [string, ReactNode
|
|
|
</dl>;
|
|
</dl>;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function PartnerRecordLayout({ back, type, number, title, icon, context, metrics, sections }: {
|
|
|
|
|
- back: RecordBack;
|
|
|
|
|
- type: string;
|
|
|
|
|
- number: string;
|
|
|
|
|
- title: string;
|
|
|
|
|
- icon: ReactNode;
|
|
|
|
|
- context: ReactNode;
|
|
|
|
|
- metrics: readonly RecordMetric[];
|
|
|
|
|
- sections: readonly [RecordSection, ...RecordSection[]];
|
|
|
|
|
|
|
+function PartnerRecordLayout({ back, recordId, loading, fallback, type, number = recordId, title, context, metrics, sections }: PartnerRecordState & {
|
|
|
|
|
+ type: keyof typeof recordTypes;
|
|
|
|
|
+ number?: string;
|
|
|
|
|
+ title?: string;
|
|
|
|
|
+ context?: ReactNode;
|
|
|
|
|
+ metrics?: readonly RecordMetric[];
|
|
|
|
|
+ sections?: readonly [RecordSection, ...RecordSection[]];
|
|
|
}) {
|
|
}) {
|
|
|
- const [active, setActive] = useState(sections[0].id);
|
|
|
|
|
|
|
+ const [selected, setSelected] = useState<string>();
|
|
|
|
|
+ const active = selected ?? sections?.[0].id ?? "";
|
|
|
|
|
+ const recordType = recordTypes[type];
|
|
|
|
|
+ const Icon = recordType.icon;
|
|
|
|
|
+ const pending = loading && !sections;
|
|
|
const prefix = `partner-${type.toLowerCase()}`;
|
|
const prefix = `partner-${type.toLowerCase()}`;
|
|
|
return <article className="ops-page ops-record-page record-detail">
|
|
return <article className="ops-page ops-record-page record-detail">
|
|
|
<Link className="ops-back-link" to={back.to} state={back.state}><ArrowLeft size={16} aria-hidden="true" />{back.label.replace(/^←\s*/, "")}</Link>
|
|
<Link className="ops-back-link" to={back.to} state={back.state}><ArrowLeft size={16} aria-hidden="true" />{back.label.replace(/^←\s*/, "")}</Link>
|
|
|
<header className="customer-record-masthead">
|
|
<header className="customer-record-masthead">
|
|
|
- <div className="customer-hero-symbol" aria-hidden="true">{icon}</div>
|
|
|
|
|
|
|
+ <div className="customer-hero-symbol" aria-hidden="true"><Icon size={26} /></div>
|
|
|
<div className="customer-hero-copy">
|
|
<div className="customer-hero-copy">
|
|
|
<p className="customer-record-id">{type} <span aria-hidden="true">·</span> <span>{number}</span></p>
|
|
<p className="customer-record-id">{type} <span aria-hidden="true">·</span> <span>{number}</span></p>
|
|
|
- <h1 className="customer-record-title">{title}</h1>
|
|
|
|
|
- <div className="customer-record-tags">{context}</div>
|
|
|
|
|
|
|
+ <h1 className="customer-record-title">{pending ? <>
|
|
|
|
|
+ <span className="sr-only">{recordType.title}</span>
|
|
|
|
|
+ <span className="partner-record-title-placeholder" aria-hidden="true" />
|
|
|
|
|
+ </> : title || recordType.title}</h1>
|
|
|
|
|
+ <div className="customer-record-tags">{pending
|
|
|
|
|
+ ? <span className="partner-record-tags-placeholder" aria-hidden="true" />
|
|
|
|
|
+ : context}</div>
|
|
|
</div>
|
|
</div>
|
|
|
</header>
|
|
</header>
|
|
|
- <dl className="customer-record-metrics partner-record-metrics" aria-label="业务摘要">
|
|
|
|
|
|
|
+ {metrics && <dl className="customer-record-metrics partner-record-metrics" aria-label="业务摘要">
|
|
|
{metrics.map((metric) => <div key={metric.label}>
|
|
{metrics.map((metric) => <div key={metric.label}>
|
|
|
<dt>{metric.icon}{metric.label}</dt><dd><strong>{metric.value}</strong></dd>
|
|
<dt>{metric.icon}{metric.label}</dt><dd><strong>{metric.value}</strong></dd>
|
|
|
</div>)}
|
|
</div>)}
|
|
|
- </dl>
|
|
|
|
|
- <div className="record-tabs-frame">
|
|
|
|
|
- <RecordTabs prefix={prefix} label="详情视图" tabs={sections} active={active} onChange={setActive} />
|
|
|
|
|
|
|
+ </dl>}
|
|
|
|
|
+ {sections ? <div className="record-tabs-frame">
|
|
|
|
|
+ <RecordTabs prefix={prefix} label="详情视图" tabs={sections} active={active} onChange={setSelected} />
|
|
|
{sections.map((section) => <section key={section.id} className="ops-record-card record-summary-panel record-tab-panel"
|
|
{sections.map((section) => <section key={section.id} className="ops-record-card record-summary-panel record-tab-panel"
|
|
|
id={`${prefix}-panel-${section.id}`} role="tabpanel" aria-labelledby={`${prefix}-tab-${section.id}`} hidden={active !== section.id} tabIndex={0}>
|
|
id={`${prefix}-panel-${section.id}`} role="tabpanel" aria-labelledby={`${prefix}-tab-${section.id}`} hidden={active !== section.id} tabIndex={0}>
|
|
|
{section.content}
|
|
{section.content}
|
|
|
</section>)}
|
|
</section>)}
|
|
|
- </div>
|
|
|
|
|
|
|
+ </div> : pending ? <div className="record-tabs-frame"><p className="partner-record-loading" role="status">正在读取{recordType.title}…</p></div> : fallback}
|
|
|
</article>;
|
|
</article>;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export function PartnerCustomerRecord({ data, back }: { data: CustomerDetail; back: RecordBack }) {
|
|
|
|
|
|
|
+export function PartnerCustomerRecord({ data, ...state }: PartnerRecordState & { data: CustomerDetail | null }) {
|
|
|
|
|
+ if (!data) return <PartnerRecordLayout {...state} type="CUSTOMER" />;
|
|
|
const customer = data.customer;
|
|
const customer = data.customer;
|
|
|
const region = data.region_mounts?.[0]?.path_name;
|
|
const region = data.region_mounts?.[0]?.path_name;
|
|
|
const subject = customer.subject_type ? label(SUBJECT_TYPE, customer.subject_type) : null;
|
|
const subject = customer.subject_type ? label(SUBJECT_TYPE, customer.subject_type) : null;
|
|
@@ -67,8 +81,7 @@ export function PartnerCustomerRecord({ data, back }: { data: CustomerDetail; ba
|
|
|
const tone = status === "stopped" || status === "disabled" ? "danger"
|
|
const tone = status === "stopped" || status === "disabled" ? "danger"
|
|
|
: ["active", "normal", "in_use"].includes(status) ? "success" : "neutral";
|
|
: ["active", "normal", "in_use"].includes(status) ? "success" : "neutral";
|
|
|
|
|
|
|
|
- return <PartnerRecordLayout back={back} type="CUSTOMER" number={customer.customer_id} title={customer.customer_name}
|
|
|
|
|
- icon={<Building2 size={26} />}
|
|
|
|
|
|
|
+ return <PartnerRecordLayout {...state} type="CUSTOMER" number={customer.customer_id} title={customer.customer_name}
|
|
|
context={<>
|
|
context={<>
|
|
|
{subject && <OpsTag tone="brand">{subject}</OpsTag>}
|
|
{subject && <OpsTag tone="brand">{subject}</OpsTag>}
|
|
|
{status && <OpsStatus tone={tone}>{label(ACCT_STATUS, status)}</OpsStatus>}
|
|
{status && <OpsStatus tone={tone}>{label(ACCT_STATUS, status)}</OpsStatus>}
|
|
@@ -99,8 +112,9 @@ function PartnerRecordTable({ caption, columns, children }: { caption: string; c
|
|
|
</div>;
|
|
</div>;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export function PartnerContractRecord({ data, back }: { data: ContractGetResult; back: RecordBack }) {
|
|
|
|
|
|
|
+export function PartnerContractRecord({ data, ...state }: PartnerRecordState & { data: ContractGetResult | null }) {
|
|
|
const linkState = useDetailLinkState();
|
|
const linkState = useDetailLinkState();
|
|
|
|
|
+ if (!data) return <PartnerRecordLayout {...state} type="CONTRACT" />;
|
|
|
const profile = data.customer_profile;
|
|
const profile = data.customer_profile;
|
|
|
const items = data.service_items;
|
|
const items = data.service_items;
|
|
|
const subscriptions = data.subscriptions;
|
|
const subscriptions = data.subscriptions;
|
|
@@ -111,8 +125,7 @@ export function PartnerContractRecord({ data, back }: { data: ContractGetResult;
|
|
|
const customerLink = profile && data.customer_id && customerName
|
|
const customerLink = profile && data.customer_id && customerName
|
|
|
? <Link className="contract-ref-link" to={`/bos/pv/customer/${encodeURIComponent(data.customer_id)}`} state={linkState}>{customerName}</Link>
|
|
? <Link className="contract-ref-link" to={`/bos/pv/customer/${encodeURIComponent(data.customer_id)}`} state={linkState}>{customerName}</Link>
|
|
|
: customerName;
|
|
: customerName;
|
|
|
- return <PartnerRecordLayout back={back} type="CONTRACT" number={data.contract_id} title={data.contract_no}
|
|
|
|
|
- icon={<FileSignature size={26} />}
|
|
|
|
|
|
|
+ return <PartnerRecordLayout {...state} type="CONTRACT" number={data.contract_id} title={data.contract_no}
|
|
|
context={<>
|
|
context={<>
|
|
|
{status && <OpsStatus tone={contractStatusTone[status]}>{status}</OpsStatus>}
|
|
{status && <OpsStatus tone={contractStatusTone[status]}>{status}</OpsStatus>}
|
|
|
{data.opened != null && <OpsStatus tone={data.opened ? "success" : "warning"}>{data.opened ? "已开通" : "未开通"}</OpsStatus>}
|
|
{data.opened != null && <OpsStatus tone={data.opened ? "success" : "warning"}>{data.opened ? "已开通" : "未开通"}</OpsStatus>}
|