CustomerEditorPage.tsx 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /**
  2. * 客户建档 / 编辑档案 —— 提交走 klt-bos 写口,⛔ localStorage。
  3. *
  4. * 新建:`POST /customer/create@v1`(必填 customer_name / subject_type / operator_id,运维团队必填 1 支)
  5. *    → 回执若未落运维团队,再 `POST /customer/update@v1` 回填 `ops_team_ids`(单支定案:最多 1 支)。
  6. * 编辑:`POST /customer/update@v1`(资料)+ `POST /customer/attribution_update@v1`(运营商/合伙人)
  7. *    + 区域变更时 `POST /customer/move_region@v1`(必填变更依据)。
  8. * 边界:登记材料(营业执照影像)由浏览器直传平台 `unified-oss`(凭证自取、⛔ 经后端),
  9. * 建档载荷只回报 `{object_key, file_name}`;合同文档区本期仍无路由(保持禁用并说明)。
  10. * 错误一律显示后端/平台 `message` 原文。
  11. */
  12. import { useEffect, useMemo, useRef, useState, type FormEvent, type ReactNode } from "react";
  13. import { ArrowLeft, Upload } from "lucide-react";
  14. import { Link, useLocation, useNavigate, useParams } from "react-router";
  15. import { FetchError } from "../components/fetchError";
  16. import { Button } from "../components/ui/button";
  17. import { Input } from "../components/ui/input";
  18. import { TreeSelect } from "../components/ui/tree-select";
  19. import { FieldHint } from "../components/ui/field-hint";
  20. import { CustomerTeamSelect } from "../components/CustomerTeamSelect";
  21. import { regionTreeNodes } from "../lib/region-tree";
  22. import { lockIfCandidate, pickOwnedId, regionAncestorChain, teamsCoveringRegion } from "../lib/region-ownership";
  23. import { Tri } from "../components/triState";
  24. import { useLoad } from "../lib/useLoad";
  25. import { detailLinkState, formBack } from "../lib/detail-navigation";
  26. import { ApiError } from "../lib/api/http";
  27. import { SUBJECT_TYPE, label } from "../lib/api/labels";
  28. import { typeLabel } from "../lib/api/ticket";
  29. import { customerAttributionUpdate, customerCreate, customerGet, customerMoveRegion, customerUpdate } from "../lib/api/bos";
  30. import { uploadCustomerLicense, type UploadedObject } from "../lib/api/oss-upload";
  31. import { invalidateCustomerList } from "../lib/customer-list-store";
  32. import { useDemoIdentity } from "../lib/demo-session";
  33. import { useOrganizationData } from "../lib/organization-demo";
  34. import "../styles/customer-onboarding.css";
  35. import "../styles/operations.css";
  36. const MISSING = "后端未下发";
  37. /** 客户名称上限(与后端 `customer.customer_name`/建档守卫同口径)。 */
  38. const CUSTOMER_NAME_MAX = 64;
  39. /** 联系电话:11 位手机号,或含区号的固话(数字/空格/-/(),7–20 字符)。 */
  40. const PHONE_OK = /^(1\d{10}|[\d\s\-()]{7,20})$/;
  41. /**
  42. * 客户建档允许提交的主体类型:后端 `POST /customer/create@v1` 只收
  43. * `enterprise/individual/sole_proprietor`(实测其余值回 `60004`,原文:
  44. * 「主体类型只能是 enterprise/individual/sole_proprietor」)。
  45. * ⛔ 直接摊开 `SUBJECT_TYPE` 全字典——那是"组织主体"字典,含 `hq/region/ops_team` 等
  46. * 仅用于展示的历史码,选到就会被后端拒。
  47. */
  48. const CUSTOMER_SUBJECT_CODES = ["enterprise", "individual", "sole_proprietor"] as const;
  49. const SUBJECT_OPTIONS = CUSTOMER_SUBJECT_CODES.map((code) => ({ code, name: SUBJECT_TYPE[code] ?? code }));
  50. type Draft = {
  51. name: string; subject: string; idNo: string; contact: string; phone: string; address: string;
  52. regionId: string; operatorId: string; partnerId: string; /** 仅 UI:按区域反查,⛔ 不入写口 */ operationsTeamId: string; teamIds: string[];
  53. login: string; masterPhone: string; basisNote: string;
  54. };
  55. export function CustomerEditorPage() {
  56. const { no } = useParams(), location = useLocation(), navigate = useNavigate();
  57. const identity = useDemoIdentity();
  58. const data = useOrganizationData(["regions", "operators", "partners", "operationsTeams", "maintenanceTeams"]);
  59. /**
  60. * 返回目标=入口页(客户编辑页有「客户清单」与「客户档案」两个入口):
  61. * 清单进 ⇒ 回清单并保留搜索/筛选/分页;档案进 ⇒ 回档案,且把档案自己的返回链一起带回。
  62. * 直接敲 URL(无 `from`)才兜底回客户档案。
  63. */
  64. const back = formBack({ state: location.state, detail: no ? `/customers/${encodeURIComponent(no)}` : "/customers", detailLabel: no ? "返回客户档案" : "返回客户管理", list: "/customers", listLabel: "返回客户管理" });
  65. const form = useRef<HTMLFormElement>(null);
  66. const detail = useLoad(() => (no ? customerGet({ customer_id: no }) : Promise.resolve(null)), [no]);
  67. const original = detail.data?.customer ?? null;
  68. const originalTeams = detail.data?.team_ids ?? [];
  69. const originalRegion = detail.data?.region_mounts?.[0]?.parent_node_id ?? "";
  70. const regionTree = useMemo(() => regionTreeNodes(data.regions, data.regions.map((item) => item.id)), [data]);
  71. const [manualLogin, setManualLogin] = useState(false);
  72. const [draft, setDraft] = useState<Draft>({ name: "", subject: SUBJECT_OPTIONS[0]?.code ?? "", idNo: "", contact: "", phone: "", address: "", regionId: "", operatorId: "", partnerId: "", operationsTeamId: "", teamIds: [], login: "", masterPhone: "", basisNote: "" });
  73. const [seeded, setSeeded] = useState(false);
  74. if (original && !seeded) {
  75. setSeeded(true);
  76. setDraft((current) => ({ ...current, name: original.customer_name ?? "", subject: original.subject_type ?? current.subject, idNo: original.identity_no_masked ?? "", regionId: originalRegion, operatorId: original.operator_id ?? "", partnerId: original.partner_id ?? "", teamIds: originalTeams, contact: original.contact_name ?? "", phone: original.contact_mobile ?? "", address: original.address ?? "" }));
  77. }
  78. /** 运营团队=按挂载区域实时反查(⛔ 档案快照);身份命中候选时只读带入。 */
  79. const operationsTeamCandidates = useMemo(() => {
  80. if (!draft.regionId) return [];
  81. return teamsCoveringRegion(data.operationsTeams, regionAncestorChain(data.regions, draft.regionId));
  82. }, [data.operationsTeams, data.regions, draft.regionId]);
  83. const lockedOperationsTeamId = lockIfCandidate(identity?.operationsTeamId, operationsTeamCandidates);
  84. useEffect(() => {
  85. setDraft((current) => {
  86. if (!current.regionId) {
  87. return current.operationsTeamId ? { ...current, operationsTeamId: "" } : current;
  88. }
  89. const next = pickOwnedId(current.operationsTeamId, operationsTeamCandidates, lockedOperationsTeamId);
  90. return next === current.operationsTeamId ? current : { ...current, operationsTeamId: next };
  91. });
  92. }, [draft.regionId, operationsTeamCandidates, lockedOperationsTeamId]);
  93. const [errors, setErrors] = useState<Record<string, string>>({}), [saveError, setSaveError] = useState(""), [busy, setBusy] = useState(false);
  94. const [created, setCreated] = useState<{ id: string; userId: string | null; code: string | null } | null>(null);
  95. /** 登记材料:`licenseObj`=已直传成功的对象(建案载荷据此回报);⛔ 存签名 URL/⛔ 存文件本体。 */
  96. const [licenseObj, setLicenseObj] = useState<UploadedObject | null>(null);
  97. const [licenseBusy, setLicenseBusy] = useState(false);
  98. const [licenseError, setLicenseError] = useState("");
  99. function set<K extends keyof Draft>(key: K, value: Draft[K]) { setDraft((current) => ({ ...current, [key]: value })); setErrors((current) => { const next = { ...current }; delete next[key]; return next; }); }
  100. function field(key: keyof Draft, label: string, control: ReactNode, required = false, wide = false, hint?: ReactNode) {
  101. return <label className={`${wide ? "customer-form-wide " : ""}${errors[key] ? "has-error" : ""}`}><span className="ops-field-title">{label}{required && <b>*</b>}{hint && <FieldHint label={`${label}说明`}>{hint}</FieldHint>}</span>{control}{errors[key] && <small className="customer-field-error" id={`error-${key}`}>{errors[key]}</small>}</label>;
  102. }
  103. const input = (key: keyof Draft, placeholder = "") => <Input name={key} value={draft[key]} placeholder={placeholder} aria-invalid={Boolean(errors[key])} aria-describedby={errors[key] ? `error-${key}` : undefined} onChange={(event) => set(key, event.target.value)} />;
  104. const select = (key: keyof Draft, options: { id: string; name: string }[], placeholder: string) => <select name={key} value={draft[key]} aria-invalid={Boolean(errors[key])} aria-describedby={errors[key] ? `error-${key}` : undefined} onChange={(event) => set(key, event.target.value)}><option value="">{placeholder}</option>{options.map((item) => <option key={item.id} value={item.id}>{item.name}</option>)}</select>;
  105. // 编辑态识别号=后端下发的脱敏值;与当前输入不同才算「改过」⇒ 才作为 id_code 提交
  106. // (⛔ 把 `91AB****XYZ0` 这样的脱敏串原样提交,后端归一化会直接拒)。
  107. const seedMasked = (original?.identity_no_masked ?? "").replace(/[\s-]/g, "").toUpperCase();
  108. const typedIdNo = draft.idNo.trim().replace(/[\s-]/g, "").toUpperCase();
  109. const identityPatch = typedIdNo && typedIdNo !== seedMasked ? typedIdNo : undefined;
  110. // 运维团队=单支定案:`ops_team_ids` 最多 1 个元素(后端「本次只受理 1 支」守卫)。
  111. // 没改动 ⇒ ⛔ 随单提交:未改动时提交=把一个现状当成"要写入的归属",语义不对(不提交=不改动);
  112. // 挂了 2 支的历史脏数据一并提交还会被后端拒,导致改任何字段都整体保存失败。
  113. const teamsKey = (ids: string[]) => [...ids].sort().join("|");
  114. const teamsTouched = teamsKey(draft.teamIds) !== teamsKey(originalTeams);
  115. const teamsPatch = teamsTouched ? draft.teamIds : undefined;
  116. const teamName = (id: string) => data.maintenanceTeams.find((item) => item.id === id)?.name ?? id;
  117. // 后端当期回了 2 支以上=历史脏数据 ⇒ 按实呈现并提示改派,⛔ 前端截断成一支假装正常。
  118. const staleTeamIds = originalTeams.length > 1 ? originalTeams : [];
  119. function validate(): Record<string, string> {
  120. const next: Record<string, string> = {};
  121. const name = draft.name.trim();
  122. if (!name) next.name = "请填写客户名称";
  123. else if ([...name].length > CUSTOMER_NAME_MAX) next.name = `客户名称最多 ${CUSTOMER_NAME_MAX} 字`;
  124. if (!draft.subject) next.subject = "请选择主体类型";
  125. if (!draft.regionId) next.regionId = "请选择挂载区域";
  126. if (!draft.operatorId) next.operatorId = "请选择运营商";
  127. if (!no && !draft.idNo.trim()) next.idNo = "请填写客户识别号";
  128. // 运维团队单支定案:建档必须恰好 1 支;编辑态被改动过 ⇒ 同样必须恰好 1 支(⛔ 清空成 0 支)。
  129. // 原本就挂着多支的历史脏数据且未改派 ⇒ 只提示不拦(本次不提交运维团队,其它字段照常可存)。
  130. if (draft.teamIds.length !== 1 && (teamsTouched || !no)) next.teamIds = "请选择 1 支运维团队";
  131. const phone = draft.phone.trim();
  132. if (phone && !PHONE_OK.test(phone)) next.phone = "联系电话格式不符:应为 11 位手机号或含区号的固话";
  133. const masterPhone = draft.masterPhone.trim();
  134. if (masterPhone && !/^\d{11}$/.test(masterPhone)) next.masterPhone = "主账号绑定手机号须为 11 位纯数字";
  135. // 登记材料(客户§2.1):营业执照影像**选填**(业主 2026-11-19 定案,⛔ 强制登记);
  136. // 个人/个体工商户不适用、⛔ 拦(控件也不渲染)。
  137. // 变更依据**选填**(业主 2026-11-12 裁定);改了识别号才校验其格式。
  138. if (identityPatch && !/^[A-Z0-9]{18}$|^\d{15}$/.test(identityPatch)) {
  139. next.idNo = "识别号格式不符:应为 18 位统一社会信用代码/组织代码,或 15 位旧营业执照号";
  140. }
  141. return next;
  142. }
  143. /**
  144. * 营业执照影像:选中即直传(两段式:平台取凭证 → 直传桶),成功后才把对象键挂进建案载荷。
  145. * ⛔ 存文件本体进 state 后等提交再传:一次建档要等两段网络,且失败点被推迟到"保存"按钮上,
  146. * 用户会以为是建档失败。
  147. */
  148. async function pickLicense(file: File | null) {
  149. if (!file) return;
  150. setLicenseError("");
  151. setLicenseBusy(true);
  152. try {
  153. setLicenseObj(await uploadCustomerLicense(file));
  154. setErrors((current) => {
  155. const next = { ...current };
  156. delete next.license;
  157. return next;
  158. });
  159. } catch (e) {
  160. // 上传失败=本次没有可信对象键 ⇒ 清掉旧值,⛔ 让"上一次成功"的文件冒充本次选择。
  161. setLicenseObj(null);
  162. setLicenseError((e as Error)?.message || "影像上传失败。");
  163. } finally {
  164. setLicenseBusy(false);
  165. }
  166. }
  167. async function save(event: FormEvent) { event.preventDefault();
  168. if (busy) return;
  169. const next = validate();
  170. setErrors(next);
  171. setSaveError("");
  172. if (Object.keys(next).length) { window.setTimeout(() => form.current?.querySelector<HTMLElement>('[aria-invalid="true"]')?.focus(), 0); return; }
  173. setBusy(true);
  174. try {
  175. if (!no) {
  176. const res = await customerCreate({
  177. customer_name: draft.name.trim(),
  178. subject_type: draft.subject,
  179. operator_id: draft.operatorId,
  180. parent_node_id: draft.regionId || undefined,
  181. id_code: draft.idNo.trim() || undefined,
  182. contact_name: draft.contact.trim() || undefined,
  183. contact_mobile: draft.phone.trim() || undefined,
  184. address: draft.address.trim() || undefined,
  185. partner_id: draft.partnerId || undefined,
  186. ops_team_ids: draft.teamIds.length === 1 ? draft.teamIds : undefined,
  187. license: licenseObj ?? undefined,
  188. primary_username: manualLogin ? draft.login.trim() || undefined : undefined,
  189. primary_mobile: draft.masterPhone.trim() || undefined,
  190. });
  191. const customerId = res?.customer_id;
  192. if (!customerId) throw new ApiError(null, `${MISSING}:/customer/create@v1 未回 customer_id`);
  193. // 运维团队随建档同批落库(2026-11-15 起 `customer/create@v1` 在原子批里写
  194. // `customer_team_belong`)⇒ 不再补发一次 update 回填,避免同一次建档产生两条归属留痕。
  195. invalidateCustomerList();
  196. setCreated({ id: customerId, userId: res.user_id ?? null, code: res.activation_code ?? null });
  197. return;
  198. }
  199. const rowVersion = original?.row_version;
  200. if (typeof rowVersion !== "number" || !Number.isSafeInteger(rowVersion) || rowVersion < 1) {
  201. throw new ApiError(null, "未取得客户档案版本,请刷新后重试。");
  202. }
  203. await customerUpdate({
  204. customer_id: no,
  205. customer_name: draft.name.trim(),
  206. subject_type: draft.subject,
  207. id_code: identityPatch,
  208. change_basis: draft.basisNote.trim() || undefined,
  209. contact_name: draft.contact.trim() || undefined,
  210. contact_mobile: draft.phone.trim() || undefined,
  211. address: draft.address.trim() || undefined,
  212. ops_team_ids: teamsPatch,
  213. row_version: rowVersion,
  214. });
  215. if (draft.operatorId !== (original?.operator_id ?? "") || draft.partnerId !== (original?.partner_id ?? "")) {
  216. await customerAttributionUpdate({ customer_id: no, operator_id: draft.operatorId || undefined, partner_id: draft.partnerId || undefined });
  217. }
  218. if (draft.regionId && draft.regionId !== originalRegion) {
  219. await customerMoveRegion({ customer_id: no, new_region_node_id: draft.regionId, ops_team_ids: teamsPatch });
  220. }
  221. invalidateCustomerList();
  222. // 保存后回入口页:清单进回清单(筛选还在),档案进回档案。
  223. navigate(back.to, { state: back.state });
  224. } catch (e) {
  225. setSaveError((e as ApiError)?.message || "保存失败。");
  226. } finally {
  227. setBusy(false);
  228. }
  229. }
  230. if (no && detail.error) return <section className="ops-page"><Link to={back.to} state={back.state} className="ops-back-link"><ArrowLeft size={16} />{back.label}</Link><FetchError message={detail.error.message} onRetry={detail.reload} /></section>;
  231. if (created) return <section className="ops-page ops-record-page"><div className="ops-record-card customer-created-result"><h1>客户已建档</h1><p>以下为 <code>POST /customer/create@v1</code> 的回执内容,仅本次展示。</p><dl><dt>客户号</dt><dd>{created.id}</dd><dt>主账号 user_id</dt><dd>{created.userId ?? <Tri tone="missing" text={MISSING} title={`${MISSING}:create 回执未带 user_id`} />}</dd><dt>激活码</dt><dd className="customer-created-secret">{created.code ?? <Tri tone="missing" text={MISSING} title={`${MISSING}:create 回执未带 activation_code`} />}</dd></dl><Button onClick={() => navigate(`/customers/${encodeURIComponent(created.id)}`, { replace: true, state: detailLinkState(back.to, back.state) })}>查看客户档案</Button></div></section>;
  232. const loginPreview = `${MISSING}(后端按客户号生成,可留空由后端分配)`;
  233. return <form ref={form} noValidate onSubmit={save} className="ops-page ops-record-page customer-editor"><Link to={back.to} state={back.state} className="ops-back-link"><ArrowLeft size={16} />{back.label}</Link><header className="ops-record-header"><div><p>客户管理 / {no ? "编辑档案" : "新增客户"}</p><h1>{no ? `编辑 ${original?.customer_name ?? no}` : "新增客户"}</h1><p>{no ? "识别号可更正(留空或不改动=不提交);变更依据选填,填写后由后端留存。" : "建立客户档案与主账号,套餐订阅在建档后办理。"}</p></div><Button type="submit" disabled={busy}>{busy ? "正在保存…" : no ? "保存档案" : "新建客户"}</Button></header>
  234. {(saveError || Object.keys(errors).length > 0) && <div className="ops-form-error" role="alert">{saveError || `有 ${Object.keys(errors).length} 项未通过校验,请修正标记的字段,已填内容全部保留。`}</div>}
  235. <section className="ops-record-card"><div className="customer-form-section-title"><span>01</span><div><h2>主体资料</h2><p>客户允许重名,以识别号查重、以客户号关联业务。</p></div></div><div className="ops-form-grid">
  236. <label><span className="ops-field-title">客户号<FieldHint label="客户号说明">建档后不可修改,由 <code>/customer/create@v1</code> 生成。</FieldHint></span><Input disabled value={no ?? "由后端生成"} /></label>
  237. {field("name", "客户名称", <Input name="name" value={draft.name} maxLength={CUSTOMER_NAME_MAX} placeholder="请输入营业执照名称或个人姓名" aria-invalid={Boolean(errors.name)} aria-describedby={errors.name ? "error-name" : undefined} onChange={(event) => set("name", event.target.value)} />, true, false, `最多 ${CUSTOMER_NAME_MAX} 字`)}
  238. {field("subject", "主体类型", <select value={draft.subject} onChange={(event) => set("subject", event.target.value)}>{SUBJECT_OPTIONS.map((item) => <option key={item.code} value={item.code}>{item.name}</option>)}</select>)}
  239. {no && original?.subject_type === "enterprise" && draft.subject !== "enterprise" && <div className="customer-form-wide"><small className="customer-form-note">保存后主体类型改为「{SUBJECT_OPTIONS.find((item) => item.code === draft.subject)?.name ?? draft.subject}」,系统将<b>同时撤销</b>该客户已留存的营业执照影像(非企业不采集证件影像);本次撤销写入客户档案变更留痕,之后如需恢复只能按企业主体重新上传。</small></div>}
  240. {field("idNo", "客户识别号", input("idNo", "统一社会信用代码 / 身份证号"), !no, false,
  241. no ? (original?.identity_no_masked
  242. ? "当前为后端脱敏识别号(明文不出后端);更正请清空后填入完整号码,不改动=不提交。"
  243. : "该客户尚未登记识别号;填入完整号码即视为登记(后端查重+加密落库)。")
  244. : "统一社会信用代码 / 身份证号;是查重键,建案时按它判重。")}
  245. {no && field("basisNote", "变更依据(选填)", input("basisNote", "例如:客户补充证件,原识别号录入有误"), false, true)}
  246. {field("contact", "联系人", input("contact", "客户方联系人,个人客户填本人"))}
  247. {field("phone", "联系电话", <Input name="phone" value={draft.phone} maxLength={20} placeholder="11 位手机号或含区号固话" aria-invalid={Boolean(errors.phone)} aria-describedby={errors.phone ? "error-phone" : undefined} onChange={(event) => set("phone", event.target.value)} />, false, false, "11 位手机号,或含区号的固话(数字/空格/-/括号)")}
  248. {field("address", "客户地址", input("address", "请输入完整地址,包括楼栋与房间号"), false, true)}
  249. </div></section>
  250. <section className="ops-record-card"><div className="customer-form-section-title"><span>02</span><div><h2>归属与挂载</h2><p>客户挂载一个区域节点,唯一归属一个运营商,运维团队固定一支;运营团队按区域反查、不写入档案。</p></div></div><div className="ops-form-grid">
  251. {field("regionId", "挂载区域", <TreeSelect treeData={regionTree} value={draft.regionId} onChange={(value) => set("regionId", value)} ariaLabel="挂载区域" placeholder="请选择区域节点" name="regionId" required invalid={Boolean(errors.regionId)} describedBy={errors.regionId ? "error-regionId" : undefined} />, true)}
  252. {field("operatorId", "运营商", select("operatorId", data.operators.map((item) => ({ id: item.id, name: item.name })), "请选择运营商"), true)}
  253. {field("partnerId", "合伙人", select("partnerId", data.partners.map((item) => ({ id: item.id, name: `${item.name} · ${item.title}` })), "不绑定"))}
  254. {field("operationsTeamId", "运营团队",
  255. <select name="operationsTeamId" disabled={!draft.regionId || Boolean(lockedOperationsTeamId)} value={draft.operationsTeamId} aria-invalid={Boolean(errors.operationsTeamId)} aria-describedby={errors.operationsTeamId ? "error-operationsTeamId" : undefined} onChange={(event) => set("operationsTeamId", event.target.value)}>
  256. <option value="">{!draft.regionId ? "请先选取所属区域" : operationsTeamCandidates.length ? "请选择运营团队" : "所挂区域未匹配运营团队"}</option>
  257. {operationsTeamCandidates.map((item) => <option key={item.id} value={item.id}>{item.name}</option>)}
  258. </select>,
  259. false, false,
  260. "按所挂区域实时反查,仅用于展示、不写入客户档案;总运营可选手选,其它运营按账号带入只读;唯一候选自动选中。")}
  261. <div className="customer-team-field"><span className="ops-field-title">运维团队{!no && <b>*</b>}</span><CustomerTeamSelect options={data.maintenanceTeams.map((item) => ({ id: item.id, name: item.name, hint: (item.ticketTypes ?? []).map(typeLabel).join("、") }))} value={draft.teamIds[0] ?? ""} onChange={(id) => set("teamIds", [id])} />{errors.teamIds && <small className="customer-field-error">{errors.teamIds}</small>}{staleTeamIds.length > 1 && <small className="customer-form-note">后端当期回显该客户挂了 {staleTeamIds.length} 支运维团队({staleTeamIds.map(teamName).join("、")})——历史脏数据,需改派为单支;改派前本次不提交运维团队。</small>}</div>
  262. </div></section>
  263. <section className="ops-record-card"><div className="customer-form-section-title"><span>03</span><div><h2>客户主账号</h2><p>一个客户一个主账号,不占套餐席位。</p></div></div>{no ? <p className="customer-form-note">主账号登录名与激活状态:{MISSING}(<code>/account/*</code> 无读接口);激活码重置请到客户档案办理。</p> : <><div className="ops-form-grid">{field("login", "主账号登录名(选填)", <Input name="login" value={draft.login} placeholder={loginPreview} autoComplete="off" onChange={(event) => { setManualLogin(true); set("login", event.target.value); }} />, false, false, "留空登录名由后端分配;建档回执若下发激活码,将在结果页一次性展示。")}{field("masterPhone", "主账号绑定手机号", <Input name="masterPhone" value={draft.masterPhone} inputMode="numeric" maxLength={11} autoComplete="off" placeholder="选填,11 位手机号" onChange={(event) => set("masterPhone", event.target.value)} />, false, false, "选填,11 位手机号;用于主账号登录验证与找回,不占套餐席位。")}</div></>}</section>
  264. {!no && <section className="ops-record-card"><div className="customer-form-section-title"><span>04</span><div><h2>登记材料与合同文档</h2><p>企业客户营业执照影像选填,可在客户档案「登记材料」补传/替换;个人与个体工商户不适用。</p></div></div><div className="customer-document-grid">{draft.subject === "enterprise" ? <div className="customer-document-picker"><div><strong>登记材料 · 营业执照影像</strong><label className="customer-upload-button" title="选择后立即直传平台对象存储(字节流不经过本系统)"><Upload size={15} />{licenseBusy ? "正在上传…" : licenseObj ? "重新选择" : "选择文件"}<input aria-label="上传登记材料" type="file" disabled={licenseBusy || busy} onChange={(event) => { const file = event.target.files?.[0] ?? null; event.target.value = ""; void pickLicense(file); }} /></label></div><p>{licenseObj ? `已上传:${licenseObj.file_name}` : licenseBusy ? "正在上传影像…" : "尚未选择文件"}</p>{licenseError && <small className="customer-field-error">{licenseError}</small>}</div>: <div className="customer-document-picker"><div><strong>登记材料</strong></div><p>不适用(个人与个体工商户不采集证件影像)</p></div>}<div className="customer-document-picker"><div><strong>合同文档</strong><label className="customer-upload-button" title="合同文档随合同登记上传(合同详情 → 附件),建档页不采集"><Upload size={15} />选择文件<input aria-label="上传合同文档" type="file" multiple disabled /></label></div><p>合同文档由合同模块登记,本页不采集</p></div></div></section>}
  265. <footer className="ops-form-actions"><Button type="button" variant="outline" disabled={busy} onClick={() => navigate(back.to, { state: back.state })}>取消</Button><Button type="submit" disabled={busy}>{busy ? "正在保存…" : no ? "保存档案" : "新建客户"}</Button></footer>
  266. </form>;
  267. }
  268. /** 主体类型原文 → 中文(走 `labels.ts` 的 `SUBJECT_TYPE` 字典)。 */
  269. export function subjectTypeLabel(raw: string | null | undefined): string | null {
  270. if (!raw) return null;
  271. const text = label(SUBJECT_TYPE, raw);
  272. return text || null;
  273. }