/** * 客户档案(工作台)—— 真源=klt-bos 接口,⛔ localStorage 与演示行。 * * 读:`POST /customer/get@v1`(主体资料与归属)+ `POST /account/get_list@v1`(客户主账号与激活码 *  生命周期)+ `POST /sub_account/get_list@v1`(分账号)+ `POST /customer/history@v1`(变更记录); *  区域名经 `/region/tree@v1`(`lib/organization-demo`)解析。 * 写:`POST /customer/attribution_update@v1`(运营商/合伙人)+ `POST /customer/move_region@v1`(挂载区域, *  可带 `ops_team_ids`)+ `POST /customer/update@v1`(仅改运维团队时)+ `POST /sub_account/update@v1`。 * * 后端边界(页面如实呈现,⛔ 造数填补): * * 激活码明文⛔ 读路由(仅开通/重置当次回执一次性下发)⇒ 主账号面板只回显激活码生命周期, *   明文只在「重置激活码」当次回显一次(手册 P2:激活码过期或遗失由运营在本页重置); * * `/sub_account/*` ⛔ 新增与删除路由 ⇒ 分账号只可改名与网络侧账号名; * * ⛔ `/customer/acct_status/update@v1` 封装 ⇒ 停用/恢复入口置灰; * * 登记材料(营业执照影像):读口一次给全 `license{file_name, status, view_url, view_url_expires_at}`; *  补传/替换由浏览器直传平台 `unified-oss` 后调 `POST /customer/update@v1` 回报对象键(⛔ 经本系统传字节); * * ⛔ 合同文档上传路由 ⇒ 合同文档区只给应备项说明。 */ import { useEffect, useMemo, useRef, useState, type FormEvent, type KeyboardEvent as ReactKeyboardEvent, type ReactNode } from "react"; import { ArrowLeft, Building2, CalendarPlus, Check, FileSignature, FileText, Gauge, LoaderCircle, MapPin, PencilLine, RefreshCcw, RefreshCw, ScrollText, Upload, UsersRound, Wrench, X } from "lucide-react"; import { Link, useLocation, useParams } from "react-router"; import { Button } from "../components/ui/button"; import { Input } from "../components/ui/input"; import { OpsMore, OpsNotice, OpsStatus, OpsTableColumns, OpsTableEmpty, OpsTag, type OpsMoreItem } from "../components/OperationsKit"; import { OrderEditor } from "../components/OrderChangeDialogs"; import { CustomerServiceStopAction } from "../components/CustomerServiceStopAction"; import { DeliveryStatusTable } from "../components/DeliveryStatusTable"; import { RecordTabs } from "../components/RecordTabs"; import { orderView, type OrderView } from "../lib/order-demo"; import { FetchError } from "../components/fetchError"; import { Tri } from "../components/triState"; import { TreeSelect } from "../components/ui/tree-select"; import { CustomerTeamSelect } from "../components/CustomerTeamSelect"; import { ACCT_STATUS, ACTIVATION_STATUS, PLAN_KIND, SUBJECT_TYPE, label } from "../lib/api/labels"; import { typeLabel } from "../lib/api/ticket"; import type { ApiError } from "../lib/api/http"; import { accountGetList, accountResetCode, customerAttributionUpdate, customerGet, customerHistory, customerMoveRegion, customerUpdate, subAccountGetList, subAccountUpdate, orderGetList, contractGetList } from "../lib/api/bos"; import { uploadCustomerLicense } from "../lib/api/oss-upload"; import { contractAttachmentLabel } from "../lib/contract-attachments"; import { invalidateCustomerList } from "../lib/customer-list-store"; import type { SubAccountRow } from "../lib/api/types"; import { isSeatPlaceholder, seatDisplayName } from "../lib/customer-subaccounts"; import { useLoad } from "../lib/useLoad"; import { regionComparablePath, regionMountPath, useOrganizationData } from "../lib/organization-demo"; import { lockIfCandidate, operationsTeamDisplay, regionAncestorChain, teamsCoveringRegion } from "../lib/region-ownership"; import { regionTreeNodes } from "../lib/region-tree"; import { isImeComposing } from "../lib/ime"; import { customerMaterials } from "../lib/customer-records"; import { detailBack, detailLinkState } from "../lib/detail-navigation"; import { useBusinessView } from "../lib/use-business-view"; import "../styles/operations.css"; import "../styles/customer-onboarding.css"; const MISSING = "后端未下发"; /** * 客户工作台的页签(讨论稿 §7.7:01–07 七个区块全部改为页签,并新增「交付现状」)。 * `#workspace-service` 锚点落在「全部订阅」页签上(保留旧链接的落点)。 */ type WorkspaceTab = "profile" | "attribution" | "primary" | "subscriptions" | "subaccounts" | "materials" | "history" | "delivery"; const WORKSPACE_TABS: { id: WorkspaceTab; label: string }[] = [ { id: "profile", label: "主体资料" }, { id: "attribution", label: "归属关系" }, { id: "primary", label: "客户主账号" }, { id: "subscriptions", label: "全部订阅" }, { id: "subaccounts", label: "分账号" }, { id: "materials", label: "登记材料与合同文档" }, { id: "history", label: "历史记录" }, { id: "delivery", label: "交付现状" }, ]; /** 客户建档/更正只收这三个主体码(后端 `60004` 会拦下主体类型字典里的其余历史码)。 */ const CUSTOMER_SUBJECT_CODES = ["enterprise", "individual", "sole_proprietor"] as const; const NO_ACCOUNT_FOUND = "未查到该客户的主账号记录:可能尚未开通,或该账号不在当前登录账号的可见范围(/account/get_list@v1 按 subject_id 查询为空)"; const CONTRACT_DOC_NOTE = "合同文档随合同登记上传(合同详情 → 附件),本页只读汇总"; const NO_ACTIVATION_CODE_READ = "激活码仅在后端开通/重置写口回执中一次性下发,读完即失效 ⇒ 无读路由,不回显明文"; const CODE_RESET_ONCE_NOTE = "新激活码明文只随本次应答回显一次,请立即分发或安全保存;关闭后无法再查。"; const CODE_RESET_ACTIVATED_NOTE = "该账号已激活:不可重置激活码(手册 P2「要知道的」)⇒ 换人接手请走客户自助改密或运营换绑手机号"; /** 订阅表仍按中文状态上色(订阅域由 `lib/order-store` 下发,⛔ 在本页改写状态文案)。 */ const statusTone = (status: string) => status === "在用" || status === "生效中" ? "success" : status === "停用" || status === "提前停机" ? "danger" : "neutral"; const money = (value: string) => `¥${Number(value).toLocaleString("zh-CN", { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`; /** 账号状态色调只看后端原值,中文一律取自 `labels.ACCT_STATUS`。 */ const acctTone = (raw: string) => raw === "stopped" || raw === "disabled" ? "danger" : raw === "active" || raw === "normal" || raw === "in_use" ? "success" : "neutral"; /** 激活态色调:已激活绿、待激活/发放中黄、未发放灰。 */ const activationTone = (raw: string) => raw === "activated" ? "success" : raw === "issued" || raw === "issuing" ? "warning" : "neutral"; /** 缺列单元格:⛔ 用「—」「未知」或 0 冒充后端没给的列。 */ function TextCell({ value, note }: { value: string | number | null | undefined; note?: string }) { const text = value === null || value === undefined ? "" : String(value).trim(); return text ? <>{text} : ; } /** 可空资料单元格:读口已回该字段但值为空 ⇒「未登记」,⛔ 与「后端未下发」混为一谈。 */ function OptionalCell({ value, note = "该字段未登记" }: { value: string | number | null | undefined; note?: string }) { const text = value === null || value === undefined ? "" : String(value).trim(); return text ? <>{text} : 未登记; } /** 账号状态单元格:后端未回状态 ≠ 「未开通」,两者分列。 */ function AcctCell({ raw }: { raw: string | null | undefined }) { const text = raw ? label(ACCT_STATUS, raw) : ""; return text ? {text} : ; } function metricCount(value: number | undefined, loading: boolean, error: ApiError | null) { if (error) return ; if (loading) return 读取中; return ; } function CustomerMaterialCard({ children }: { children: ReactNode }) { return
{children}
; } /** * 详情里的单个可编辑项(与合同详情同一交互):非编辑态只渲染值,鼠标移入才显出铅笔;点铅笔切到输入态。 * 改完点对号(或按 Enter)即提交**该项**:客户写口按字段可选,⛔ 攒到底部统一保存。 */ type InlineFieldProps = { id: string; label: string; value: string; editing: boolean; writable: boolean; /** 该项正在提交:锁住对号/取消,避免重复提交。 */ busy?: boolean; onStart: () => void; onChange: (value: string) => void; onDone: () => void; onCancel: () => void; type?: "text" | "date" | "number"; inputMode?: "decimal" | "numeric" | "text"; placeholder?: string; display?: ReactNode; emptyText?: string; invalid?: boolean; error?: ReactNode; selectOptions?: readonly { value: string; label: string }[]; /** 自定义编辑控件(区域树、运维团队下拉):给定时替代默认输入/下拉。 */ editor?: ReactNode; }; function InlineField({ id, label, value, editing, writable, busy = false, onStart, onChange, onDone, onCancel, type = "text", inputMode, placeholder, display, emptyText = MISSING, invalid, error, selectOptions, editor }: InlineFieldProps) { const shown = display ?? (value ? value : emptyText); if (!writable) return {shown}; if (!editing) return {shown} ; const onKeyDown = (event: ReactKeyboardEvent) => { // 输入法上屏用的 Enter/Esc ⛔ 当成「保存/取消」,否则拼音选字就被提交了。 if (isImeComposing(event)) return; if (event.key === "Enter") { event.preventDefault(); onDone(); } if (event.key === "Escape") { event.preventDefault(); onCancel(); } }; return {editor ?? (selectOptions ? ( ) : ( onChange(event.target.value)} onKeyDown={onKeyDown} /> ))} {error} ; } /** 客户档案的草稿:身份号只存「本次新填」的明文(读口只下脱敏值)。 */ type ProfileDraft = { name: string; subject: string; idNo: string; contact: string; phone: string; address: string; regionId: string; operatorId: string; partnerId: string; teamId: string; }; export function CustomerWorkspacePage() { const { no } = useParams(); const location = useLocation(); const outgoingState = detailLinkState(location.pathname, location.state); const organization = useOrganizationData(["regions", "operators", "partners", "operationsTeams", "maintenanceTeams"]); /** 页签=本页唯一的浏览轴(讨论稿 §7.7);`#workspace-service` 仍落在「全部订阅」。 */ const [tab, setTab] = useState(() => (location.hash === "#workspace-service" ? "subscriptions" : "profile")); useEffect(() => { if (location.hash === "#workspace-service") setTab("subscriptions"); }, [location.hash]); const detail = useLoad(() => (no ? customerGet({ customer_id: no }) : Promise.resolve(null)), [no]); // 主账号读口:按绑定主体直取(`subject_id`=客户号),一次取回启停态与激活码生命周期。 const primaryAccountLoad = useLoad(() => (no ? accountGetList({ subject_id: no, page: 0, page_size: 20 }) : Promise.resolve(null)), [no]); const accounts = useLoad(() => (no ? subAccountGetList({ customer_id: no, page: 0, page_size: 200 }) : Promise.resolve(null)), [no]); const changes = useLoad(() => (no ? customerHistory({ customer_id: no, page: 0, page_size: 50 }) : Promise.resolve(null)), [no]); const ordersLoad = useLoad(() => (no ? orderGetList({ customer_id: no, page: 0, page_size: 200 }) : Promise.resolve(null)), [no]); const contractsLoad = useLoad(() => (no ? contractGetList({ customer_id: no, page: 0, page_size: 200 }) : Promise.resolve(null)), [no]); const customer = detail.data?.customer ?? null; const primaryAccount = useMemo(() => { const rows = primaryAccountLoad.data?.items ?? []; // 客户主账号=role_code=enterprise 且绑定客户主体;兼容历史绑定口径时退回首行。 return rows.find((row) => row.role_code === "enterprise" || row.subject_type === "customer") ?? rows[0] ?? null; }, [primaryAccountLoad.data]); /** 主账号读取失败/未查到时的统一说明(⛔ 把「无账号」当「后端未下发」)。 */ const primaryAccountMissing = primaryAccountLoad.error ? MISSING + ":/account/get_list@v1 取数失败(" + primaryAccountLoad.error.message + ")" : primaryAccountLoad.loading ? "主账号信息读取中…" : NO_ACCOUNT_FOUND; const mount = detail.data?.region_mounts?.[0]; const teamIds = detail.data?.team_ids ?? []; const accountRows = accounts.data?.items ?? []; const changeRows = changes.data?.items ?? []; const orders = ordersLoad.data?.items ?? []; const contracts = contractsLoad.data?.items ?? []; const contractFiles = contracts.flatMap((contract) => (contract.attachment_url ? [{ // 单值附件两形态(外部链接/平台桶对象键):对象键末段是随机串 ⇒ 按后缀显示, // ⛔ 把随机串当文件名糊给用户;下载地址只在合同详情读口现签。 name: contractAttachmentLabel(contract.attachment_url), contractNo: contract.contract_id, kind: contract.attachment_kind ?? "other", }] : [])); /** * 登记材料摘要(客户§3.5)——`status ∈ none/viewable/expired` **由后端一次给全**: * 页面⛔ 为影像另发请求、⛔ 拿对象键自拼地址(对象键不在响应体里)。 * 只看主体类型决定面板形态:个人/个体工商户恒「不适用」(⛔ 渲染控件)。 */ const license = detail.data?.license ?? null; const licenseApplicable = customer?.subject_type === "enterprise"; const customerListTitle = "客户管理"; const back = detailBack(location.state, "/customers", `返回${customerListTitle}`); const view = useBusinessView([]); /** 详情即编辑:可写角色才挂铅笔;只读身份(团队长/运维等)看到的是同一页的只读态。 */ const writable = !view.readOnly; /** * 草稿基线=`/customer/get@v1` 的实际值。 * 识别号读口只下发脱敏值 ⇒ 草稿的 `idNo` 恒从空串起,只有用户主动填入完整新号才提交(⛔ 回填脱敏串)。 */ const serverBaseline = useMemo(() => { if (!detail.data?.customer) return null; const c = detail.data.customer; const mounted = detail.data.region_mounts?.[0]?.parent_node_id ?? ""; const teams = detail.data.team_ids ?? []; return { name: c.customer_name ?? "", subject: c.subject_type ?? "", idNo: "", contact: c.contact_name ?? "", phone: c.contact_mobile ?? "", address: c.address ?? "", regionId: mounted, operatorId: c.operator_id ?? "", partnerId: c.partner_id ?? "", teamId: teams.length === 1 ? teams[0] : "", }; }, [detail.data]); const [draft, setDraft] = useState(null); const [editingField, setEditingField] = useState(null); /** * 提交成功后的乐观基线:在 `/customer/get@v1` 重读落定前先用它, * 否则「提交已完成、基线还是旧值」会把刚保存的值再判成未提交,甚至被后台重读回退。 */ const [baselineOverride, setBaselineOverride] = useState(null); /** 读口重读落定 ⇒ 丢弃乐观基线,回到服务端真源。 */ useEffect(() => { setBaselineOverride(null); }, [serverBaseline]); const baseline = baselineOverride ?? serverBaseline; useEffect(() => { // 正在编辑时不覆盖草稿:后台重读落定可能发生在输入过程中;退出编辑后由提交/取消各自对齐。 if (!editingField) setDraft(baseline); }, [baseline]); /** 显示用草稿:数据刚到、state 还没跟上时直接用基线,⛔ 先闪一帧空值。 */ const form = draft ?? baseline; const [fieldError, setFieldError] = useState<{ key: keyof ProfileDraft; message: string } | null>(null); const [notice, setNotice] = useState(""); /** 识别号更正依据(写口 `change_basis`,选填):只在改识别号时随该项提交,由后端留存。 */ const [idBasis, setIdBasis] = useState(""); const [busy, setBusy] = useState(false); /** 登记材料补传/替换:直传状态与错误(⛔ 与建档页共用 state——两页生命周期独立)。 */ const [licenseBusy, setLicenseBusy] = useState(false); const [licenseError, setLicenseError] = useState(""); const [editingSub, setEditingSub] = useState(null); const [orderDraft, setSubDraft] = useState({ displayName: "", netAccount: "" }); const [orderError, setSubError] = useState(""); const orderDialogRef = useRef(null); /** 升降配/叠加:本页「04 全部订阅」行内「更多」直接办理,⛔ 逼用户先跳菜单「全部订阅」页再点一次。 */ const [changeTarget, setChangeTarget] = useState(null); /** D-03:叠加=打开新建订阅弹窗(create@v1),⛔ 就地改结束日。 */ const [createOpen, setCreateOpen] = useState(false); /* ── 主账号激活码重置(手册 P2:激活码过期或遗失 ⇒ 运营在本页重置,新明文只回显一次) ── */ const [resetBusy, setResetBusy] = useState(false); const [resetError, setResetError] = useState(""); const [freshCode, setFreshCode] = useState<{ code: string; expireDate: string } | null>(null); const primaryActivated = primaryAccount?.activation_status === "activated"; async function resetPrimaryCode() { const userId = primaryAccount?.user_id; if (!userId) { setResetError("后端未下发 user_id,无法调用 /account/reset_code@v1。"); return; } setResetBusy(true); setResetError(""); setFreshCode(null); try { const res = await accountResetCode({ user_id: userId }); const code = String(res?.plaintext_once ?? "").trim(); // 平台「作废+发新码」三跳未接通时后端如实回 `capability_pending`+`reason`(本地只复位状态) // ⇒ 如实将原因呈现给运营,⛔ 把「已重置」说成「已发新码」、⛔ 前端造码。 if (code) setFreshCode({ code, expireDate: String((res as { expire_date?: string | null })?.expire_date ?? "").trim() }); else setResetError(res?.reason ? `本地状态已复位(旧码失效、可重新走导出交付),但本次未发新码:${res.reason}` : "应答未回激活码明文(plaintext_once 为空)⇒ 本次没有可分发的新码。"); primaryAccountLoad.reload(); } catch (e) { setResetError((e as ApiError)?.message || "重置激活码失败"); } finally { setResetBusy(false); } } useEffect(() => { const dialog = orderDialogRef.current; if (!dialog) return; if (editingSub && !dialog.open) dialog.showModal(); if (!editingSub && dialog.open) dialog.close(); }, [editingSub]); const regionTree = useMemo(() => regionTreeNodes(organization.regions, organization.regions.map((item) => item.id)), [organization]); const mountedRegionPath = regionMountPath(organization, mount); const teamNames = teamIds.map((id) => organization.maintenanceTeams.find((item) => item.id === id)?.name ?? id); /** 后端当期回显 2 支以上=历史脏数据(运维团队单支定案)⇒ 按实呈现并提示改派,⛔ 前端截断成一支假装正常。 */ const staleTeamHint = teamIds.length > 1 ? `历史脏数据:后端当期回显 ${teamIds.length} 支运维团队,按单支定案需改派为 1 支` : ""; const subjectText = customer?.subject_type ? label(SUBJECT_TYPE, customer.subject_type) : ""; const customerName = customer?.customer_name ?? ""; const subjectOptions = CUSTOMER_SUBJECT_CODES.map((code) => ({ value: code, label: SUBJECT_TYPE[code] ?? code })); /** 草稿态展示名:改过的归属按草稿现算,没改过沿用读口原值(⛔ 用旧名字冒充新选择)。 */ const draftRegionDisplay = form && baseline && form.regionId !== baseline.regionId ? regionComparablePath(organization, form.regionId) || form.regionId : mountedRegionPath; const draftOperatorName = form ? organization.operators.find((item) => item.id === form.operatorId)?.name ?? (form.operatorId === baseline?.operatorId ? customer?.operator_name ?? "" : "") : ""; const draftPartnerName = form ? organization.partners.find((item) => item.id === form.partnerId)?.name ?? (form.partnerId === baseline?.partnerId ? customer?.partner_name ?? "" : "") : ""; const draftTeamName = form ? organization.maintenanceTeams.find((item) => item.id === form.teamId)?.name ?? (form.teamId === baseline?.teamId ? teamNames.join("、") : "") : ""; /** 运营团队=按挂载区域实时反查(⛔ 档案快照);身份命中候选时优先展示本队。 */ const operationsTeamView = useMemo(() => { const regionId = form?.regionId || mount?.parent_node_id || ""; if (!regionId) return { text: "请先挂载所属区域", note: "运营团队按所挂区域实时反查,客户档案不存快照" as string | undefined }; const candidates = teamsCoveringRegion(organization.operationsTeams, regionAncestorChain(organization.regions, regionId)); const lockedId = lockIfCandidate(view.identity?.operationsTeamId, candidates); return operationsTeamDisplay(candidates, lockedId); }, [form?.regionId, mount?.parent_node_id, organization.operationsTeams, organization.regions, view.identity?.operationsTeamId]); /** 主体类型由企业改为其他:后端会同时撤销已留存的营业执照影像(非企业不采集证件影像)。 */ const subjectRevokesLicense = Boolean(baseline && baseline.subject === "enterprise" && form && form.subject !== "enterprise"); if (detail.error) { return
{back.label}

取数失败

; } const invalidOf = (key: keyof ProfileDraft) => (fieldError?.key === key ? true : undefined); const errorOf = (key: keyof ProfileDraft) => (fieldError?.key === key ? {fieldError.message} : null); const patch = (key: K, value: ProfileDraft[K]) => { setDraft((current) => (current ? { ...current, [key]: value } : current)); setFieldError((current) => (current?.key === key ? null : current)); }; /** 点铅笔进入该项编辑:切走时把上一项未提交的草稿退回基线,⛔ 留下看不见的脏值。 */ const startField = (key: keyof ProfileDraft) => { if (busy) return; if (editingField && editingField !== key && baseline) { setDraft((current) => (current ? { ...current, [editingField]: baseline[editingField] } : current)); } setEditingField(key); setFieldError(null); setIdBasis(""); }; const cancelField = (key: keyof ProfileDraft) => { if (busy) return; if (baseline) setDraft((current) => (current ? { ...current, [key]: baseline[key] } : current)); setEditingField(null); setFieldError(null); setIdBasis(""); }; /** 该字段的草稿值是否与基线一致(文本按去首尾空白比较;识别号读口只有脱敏值 ⇒ 从空串起算)。 */ const sameAsBaseline = (key: keyof ProfileDraft, current: ProfileDraft) => { if (!baseline) return true; if (key === "name" || key === "contact" || key === "phone" || key === "address") { return String(current[key]).trim() === String(baseline[key]).trim(); } return current[key] === baseline[key]; }; /** * 提交**单个**可编辑项(点对号/Enter 触发):改一项就写一项,⛔ 攒到底部统一保存。 * * - 只送该项对应的写口:档案字段走 `customer/update@v1`,归属走 `attribution/update`, * 挂载区域走 `move_region`,运维团队走 `customer/update` 的 `ops_team_ids`; * - 失败保留输入态与草稿,错误行内呈现,可改后重试或取消; * - 成功后退出编辑并重读详情与变更历史。 */ async function commitField(key: keyof ProfileDraft) { if (!no || !draft || !baseline || busy) return; const current = draft; if (key === "name" && !current.name.trim()) { setFieldError({ key, message: "请填写客户名称" }); return; } if (key === "subject" && !current.subject) { setFieldError({ key, message: "请选择主体类型" }); return; } if (key === "regionId" && !current.regionId) { setFieldError({ key, message: "请选择挂载区域" }); return; } if (key === "operatorId" && !current.operatorId) { setFieldError({ key, message: "请选择运营商" }); return; } // 运维团队单支定案:客户固定挂 1 支,⛔ 提交空数组清空归属。 if (key === "teamId" && !current.teamId) { setFieldError({ key, message: "请选择 1 支运维团队(客户固定挂 1 支,不可清空)" }); return; } const idNo = key === "idNo" ? current.idNo.trim().replace(/[\s-]/g, "").toUpperCase() : ""; // 识别号读口只下发脱敏值:留空=该项未改,直接退出编辑,⛔ 提交脱敏串。 if (key === "idNo" && !idNo) { setEditingField(null); setFieldError(null); setIdBasis(""); return; } if (key === "idNo" && !/^[A-Z0-9]{18}$|^\d{15}$/.test(idNo)) { setFieldError({ key, message: "识别号格式不符:应为 18 位统一社会信用代码/组织代码,或 15 位旧营业执照号" }); return; } // 值没变:不写接口、不留痕,直接退出编辑。 if (sameAsBaseline(key, current)) { setEditingField(null); setFieldError(null); setIdBasis(""); return; } setBusy(true); setFieldError(null); try { switch (key) { case "name": await customerUpdate({ customer_id: no, customer_name: current.name.trim() }); break; case "subject": await customerUpdate({ customer_id: no, subject_type: current.subject }); break; case "idNo": await customerUpdate({ customer_id: no, id_code: idNo, ...(idBasis.trim() ? { change_basis: idBasis.trim() } : {}) }); break; case "contact": await customerUpdate({ customer_id: no, contact_name: current.contact.trim() }); break; case "phone": await customerUpdate({ customer_id: no, contact_mobile: current.phone.trim() }); break; case "address": await customerUpdate({ customer_id: no, address: current.address.trim() }); break; case "operatorId": case "partnerId": // `partner_id` 传空串=清空合伙人(后端约定),⛔ 用 undefined 冒充「不改」。 await customerAttributionUpdate({ customer_id: no, operator_id: current.operatorId, partner_id: current.partnerId }); break; case "regionId": await customerMoveRegion({ customer_id: no, new_region_node_id: current.regionId }); break; case "teamId": await customerUpdate({ customer_id: no, ops_team_ids: [current.teamId] }); break; } invalidateCustomerList(); // 乐观基线:重读落定前,本次提交的值已视为基线,⛔ 让「刚保存」又被判成未提交。 const committed = { ...current, name: current.name.trim(), contact: current.contact.trim(), phone: current.phone.trim(), address: current.address.trim() }; setDraft(committed); setBaselineOverride(committed); setEditingField(null); setIdBasis(""); setNotice("该项修改已保存,变更记录已写入历史。"); detail.reload(); changes.reload(); } catch (e) { setFieldError({ key, message: (e as ApiError)?.message || "保存失败,请稍后重试。" }); } finally { setBusy(false); } } function openSub(row: SubAccountRow) { if (false) return; setSubDraft({ displayName: row.display_name ?? "", netAccount: row.net_account ?? "" }); setSubError(""); setEditingSub(row); } async function saveSub(event: FormEvent) { event.preventDefault(); if (false || !editingSub || busy) return; if (!orderDraft.displayName.trim()) { setSubError("请填写账号姓名。"); return; } setBusy(true); setSubError(""); try { await subAccountUpdate({ sub_account_id: editingSub.sub_account_id, display_name: orderDraft.displayName.trim(), network_account_name: orderDraft.netAccount.trim() || undefined, }); setEditingSub(null); // 列表口的 `sub_account_count` 随分账号变化 ⇒ 共享快照一并作废(缺口清单 C-8)。 invalidateCustomerList(); accounts.reload(); } catch (e) { setSubError((e as ApiError)?.message || "分账号修改失败。"); } finally { setBusy(false); } } /** * 营业执照影像补传/替换(设计写入口只在本分区):选中即直传平台对象存储, * 成功后调 `POST /customer/update@v1` 写回对象键,再重读详情(拿新签名)。 */ async function replaceLicense(file: File | null) { if (!file || !no) return; setLicenseError(""); setLicenseBusy(true); try { const uploaded = await uploadCustomerLicense(file); await customerUpdate({ customer_id: no, license: uploaded }); invalidateCustomerList(); detail.reload(); } catch (e) { setLicenseError((e as ApiError)?.message || "影像上传失败。"); } finally { setLicenseBusy(false); } } const displayName = customerName || no || ""; /** 页头停用入口:取第一条生效中订阅;多条时行内仍可分别发起。 */ const heroStopSub = orders.find((sub) => { const labelText = sub.status_display?.label ?? orderView(sub).statusLabel; return labelText === "生效中"; }); return
{back.label}

CUSTOMER {no}

{displayName}

{subjectText && {subjectText}}
{/* D-11:手册「客户/订阅详情页」均可发起服务停用;停用挂具体订阅(工单§3.2.1)。 */} {writable && heroStopSub ? : null}
{metricCount(accounts.data?.total, accounts.loading, accounts.error)} 在用分账号{(accounts.data?.total ?? 0) > accountRows.length ? "(已加载)" : ""}{" "} {metricCount(accounts.data ? accountRows.filter((row) => row.status === "in_use").length : undefined, accounts.loading, accounts.error)}
汇总在用订阅席位,生效或终止时自动更新。明细见订阅详情。
{metricCount(ordersLoad.data?.total ?? ordersLoad.data?.items.length, ordersLoad.loading, ordersLoad.error)}含历史订阅
{metricCount(contractsLoad.data?.total ?? contractsLoad.data?.items.length, contractsLoad.loading, contractsLoad.error)}当前客户名下
item.id === "subscriptions" ? { ...item, count: orders.length, panelId: "workspace-service" } : item.id === "subaccounts" ? { ...item, count: accounts.error ? "—" : accountRows.length } : item)} /> {/* 交付现状(讨论稿 §7.7):按需挂载——不进该页签就不发 `/delivery/list@v1`。 */}
{notice && setNotice("")} />} {editingSub && setEditingSub(null)} className="ops-dialog" aria-labelledby="sub-account-edit-title">

编辑分账号

当前状态
{orderError &&

{orderError}

}
} {changeTarget && setChangeTarget(null)} onSaved={(message) => { setChangeTarget(null); setNotice(message); ordersLoad.reload(); detail.reload(); }} />} {createOpen && setCreateOpen(false)} onSaved={(message) => { setCreateOpen(false); setNotice(message); ordersLoad.reload(); detail.reload(); }} />}
; } /** 表头(列宽比例由 OpsTableColumns 组件下发,⛔ 在本页硬编码像素宽)。 */ function OpsTableHead({ columns }: { columns: string[] }) { return {columns.map((title, index) => {title})}; }