/** * 工单详情右栏「客户与订阅」参考卡的弹窗(右侧抽屉)。 * * 参考卡上只放摘要;客户名称、关联订阅等改为链接,点开本件按主键现取完整档案: * · 客户 → `POST /customer/get@v1`(+ `POST /subscription/get_list@v1` 列名下订阅); * · 订阅 → `POST /subscription/get@v1`(合同编号跳合同详情、客户主体可反查客户档案)。 * * 取数口径遵守总则「查不到 ≠ 查不了」:请求失败走 `FetchError` 并保留重试, * 业务空值只写「未登记」,⛔ 用 0/「正常」冒充。 * * 抽屉内容可以逐层深入(客户 → 名下订阅 → 客户),所以页面持有的是一个**栈**: * 本件始终渲染栈顶,栈深 > 1 时给出「返回上一级」,关闭则整栈清空。 */ import { useState, type ReactNode } from "react"; import { Link, useLocation } from "react-router"; import { ArrowLeft, ArrowRight, Building2, Package, Tag } from "lucide-react"; import { FetchError } from "./fetchError"; import { ListPager } from "./ListPager"; import { OpsDrawer, OpsStatus } from "./OperationsKit"; import { catalogGet, customerGet, orderGet, orderGetList } from "../lib/api/bos"; import type { CatalogPlanRow, OrderGetResult, OrderListResult } from "../lib/api/types"; import { ACCT_STATUS, PLAN_FAMILY, PLAN_KIND, ORDER_MODE, ORDER_STATUS, SUBJECT_TYPE, TERM, label } from "../lib/api/labels"; import { bandwidthTextOfRow, moneyCell } from "../lib/package-catalog"; import { detailLinkState } from "../lib/detail-navigation"; import { LIST_PAGE_SIZE, clampPage } from "../lib/list-paging"; import { fmtDate } from "../lib/ticket"; import { useLoad } from "../lib/useLoad"; import "../styles/work-order-record.css"; /** 抽屉栈里的一层:客户档案或订阅详情,`name` 只作加载期的标题兜底。 */ export type RefTarget = | { kind: "customer"; id: string; name?: string | null } | { kind: "order"; id: string; name?: string | null } | { kind: "plan"; id: string; name?: string | null }; const missing = (value: string | null | undefined) => (value && value.trim() ? value : "未登记"); /** 日期列(`created_at` 等)按全站口径显示到日;缺失回「未登记」,⛔ 原样吐 ISO 串。 */ const dateText = (value: string | null | undefined) => (value && value.trim() ? fmtDate(value) : "未登记"); const statusTone = (status: string | null | undefined) => status === "active" ? "success" : status === "pending" ? "warning" : "neutral"; function Row({ label: name, children }: { label: string; children: ReactNode }) { return
{name}
{children}
; } function period(start: string | null | undefined, end: string | null | undefined) { if (!start && !end) return "未登记"; return `${start || "未登记"} 至 ${end || "未登记"}`; } export function ReferenceDrawer({ stack, onPush, onBack, onClose }: { stack: RefTarget[]; onPush: (target: RefTarget) => void; onBack: () => void; onClose: () => void; }) { const top = stack[stack.length - 1]; if (!top) return null; const title = top.kind === "customer" ? "客户档案" : top.kind === "plan" ? "套餐档位详情" : "订阅详情"; const subtitle = top.name ? `${top.name} · ${top.id}` : top.kind === "customer" ? "客户主体参考信息" : top.kind === "plan" ? "套餐目录参考信息" : "订阅参考信息"; return {stack.length > 1 && } {top.kind === "customer" ? : top.kind === "plan" ? : } ; } function CustomerPanel({ customerId, onOpenOrder }: { customerId: string; onOpenOrder: (target: RefTarget) => void; }) { const location = useLocation(); const linkState = detailLinkState(location.pathname, location.state); const [orderPage, setOrderPage] = useState(0); const [orderPageSize, setOrderPageSize] = useState(LIST_PAGE_SIZE); const detail = useLoad(() => customerGet({ customer_id: customerId }), [customerId]); const orders = useLoad( () => orderGetList({ customer_id: customerId, page: orderPage, page_size: orderPageSize }), [customerId, orderPage, orderPageSize], ); if (detail.loading) return

正在读取客户档案…

; if (detail.error) return ; const c = detail.data?.customer; if (!c) return

未取到该客户档案(可能不在当前负责范围)。

; const mount = detail.data?.region_mounts?.[0]?.path_name ?? null; const teams = detail.data?.team_ids ?? []; const rows = orders.data?.items ?? []; const orderTotal = Number(orders.data?.total ?? 0); const safeOrderPage = clampPage(orderPage, orderTotal, orderPageSize); return
{label(ACCT_STATUS, c.acct_status) || missing(c.acct_status)} {c.subject_type && {label(SUBJECT_TYPE, c.subject_type) || c.subject_type}}

{missing(c.customer_name)}

{c.customer_id} · {missing(mount)}

01 · 主体与归属

{c.customer_id} {missing(c.customer_name)} {label(SUBJECT_TYPE, c.subject_type) || missing(c.subject_type)} {label(ACCT_STATUS, c.acct_status) || missing(c.acct_status)} {missing(c.identity_no_masked)} {missing(mount)} {missing(c.operator_name)} / {missing(c.partner_name)} {teams.length ? `${teams.length} 支` : "未登记"} {detail.data?.sub_account_count ?? "未登记"} {dateText(c.created_at)} {dateText(c.updated_at)}

02 · 联系方式

{missing(c.contact_name)} {missing(c.contact_mobile)} {missing(c.address)}

03 · 名下订阅{orders.loading ? "读取中…" : `共 ${orderTotal} 条`}

{orders.error && } {!orders.loading && !orders.error && !rows.length &&

该客户暂无可读订阅。

} {rows.length > 0 &&
    {rows.map((sub) =>
  • )}
} setOrderPage(page)} onPageSizeChange={(size) => { setOrderPageSize(size); setOrderPage(0); }} unit="条" />

订阅行来自 /subscription/get_list@v1(默认每页 {LIST_PAGE_SIZE},由本抽屉请求决定),点开按订单号取详情。

打开完整客户档案
; } /** 套餐档位详情:合同条目的「套餐 / 配置」是外部引用,点开按 `plan_id` 现取目录档。 */ function PlanPanel({ planId, onOpenCustomer }: { planId: string; onOpenCustomer: (target: RefTarget) => void; }) { const location = useLocation(); const linkState = detailLinkState(location.pathname, location.state); const detail = useLoad(() => catalogGet({ plan_id: planId }), [planId]); if (detail.loading) return

正在读取套餐档位…

; if (detail.error) return ; const p: CatalogPlanRow | null = detail.data; if (!p) return

未取到该套餐档位(可能已删除或不在当前负责范围)。

; const bandwidth = bandwidthTextOfRow(p); const annual = moneyCell(p.annual_price_cents); const monthly = moneyCell(p.monthly_settle_cents); const cost = moneyCell(p.plan_cost_cents); const costs = detail.data?.cost_items ?? []; return
{label(PLAN_KIND, p.plan_kind) || missing(p.plan_kind)} {p.plan_family && {label(PLAN_FAMILY, p.plan_family) || p.plan_family}}

{missing(p.plan_name)}

{p.plan_id} · {p.customer_name ?? "平台公共档"}

01 · 档位事实

{p.plan_id} {missing(p.plan_name)} {label(PLAN_KIND, p.plan_kind) || missing(p.plan_kind)} {label(PLAN_FAMILY, p.plan_family) || missing(p.plan_family)} {annual.text} {monthly.text} {cost.text} {p.sub_account_quota ?? "未配置"} {bandwidth.text} {p.referred_count ?? "未下发"} {missing(p.status)} {missing(p.plan_desc)} {dateText(p.created_at)}

02 · 随附成本项{costs.length ? `${costs.length} 项` : "暂无"}

{costs.length ?
    {costs.map((item, index) =>
  • {missing(item.item_name)}{[item.category, item.billing_unit, item.remark].filter(Boolean).join(" · ") || "明细未配置"}{item.amount_cents === null ? "未配置" : moneyCell(item.amount_cents).text}
  • )}
:

暂无随附成本项。

}
{p.customer_id &&

03 · 归属客户

}
打开套餐配置
; } function OrderPanel({ orderId, onOpenCustomer }: { orderId: string; onOpenCustomer: (target: RefTarget) => void; }) { const location = useLocation(); const linkState = detailLinkState(location.pathname, location.state); const detail = useLoad(() => orderGet({ subscription_id: orderId }), [orderId]); if (detail.loading) return

正在读取订阅详情…

; if (detail.error) return ; const s: OrderGetResult | null = detail.data; if (!s) return

未取到该订阅详情(可能不在当前负责范围)。

; const contractKey = s.contract_id ?? s.contract_no; const contractHref = contractKey ? `/contracts/${encodeURIComponent(contractKey)}` : null; const exits = Array.isArray(s.line_exits) ? s.line_exits.filter(Boolean) : []; return
{label(ORDER_STATUS, s.status) || missing(s.status)} {s.plan_kind && {label(PLAN_KIND, s.plan_kind) || s.plan_kind}} {s.plan_family && {label(PLAN_FAMILY, s.plan_family) || s.plan_family}}

{missing(s.plan_name ?? s.subscription_id)}

{s.subscription_id} · {period(s.start_date, s.end_date)}

01 · 订阅事实

{s.subscription_id} {missing(s.plan_name)} {label(PLAN_KIND, s.plan_kind) || missing(s.plan_kind)} / {label(PLAN_FAMILY, s.plan_family) || missing(s.plan_family)} {s.sub_mode_label || label(ORDER_MODE, s.sub_mode) || missing(s.sub_mode)} {label(TERM, s.term) || missing(s.term)} {label(ORDER_STATUS, s.status) || missing(s.status)} {period(s.start_date, s.end_date)} {dateText(s.effective_date)} / {dateText(s.expire_date)} {dateText(s.actual_opened_at)} {dateText(s.early_stopped_at)} {s.quota_slots ?? "未登记"}

02 · 商务与关联

{moneyCell(s.annual_price_cents).text} {moneyCell(s.monthly_settle_cents).text} {s.trial_months ? {s.trial_months} 个月{s.discount_monthly_cents ? ` · ${moneyCell(s.discount_monthly_cents).text} / 月` : ""} : null} {contractHref ? {(s.contract_no || s.contract_id) as string} : "未关联合同"} {missing(s.order_no)} {exits.length ? exits.join("、") : "未登记"} {dateText(s.created_at)}

03 · 客户主体

; }