Browse Source

feat(web): 对齐客户台账和新增客户表单布局

sy 1 hour ago
parent
commit
f3f76ed872

+ 160 - 35
web-scaffold/src/pages/CustomerEditorPage.tsx

@@ -238,41 +238,166 @@ export function CustomerEditorPage() {
 
   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>;
   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>;
-  const loginPreview = `${MISSING}(后端按客户号生成,可留空由后端分配)`;
-  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>
-    {(saveError || Object.keys(errors).length > 0) && <div className="ops-form-error" role="alert">{saveError || `有 ${Object.keys(errors).length} 项未通过校验,请修正标记的字段,已填内容全部保留。`}</div>}
-    <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">
-      <label><span className="ops-field-title">客户号<FieldHint label="客户号说明">建档后不可修改,由 <code>/customer/create@v1</code> 生成。</FieldHint></span><Input disabled value={no ?? "由后端生成"} /></label>
-      {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} 字`)}
-      {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>)}
-      {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>}
-      {field("idNo", "客户识别号", input("idNo", "统一社会信用代码 / 身份证号"), !no, false,
-        no ? (original?.identity_no_masked
-          ? "当前为后端脱敏识别号(明文不出后端);更正请清空后填入完整号码,不改动=不提交。"
-          : "该客户尚未登记识别号;填入完整号码即视为登记(后端查重+加密落库)。")
-          : "统一社会信用代码 / 身份证号;是查重键,建案时按它判重。")}
-      {no && field("basisNote", "变更依据(选填)", input("basisNote", "例如:客户补充证件,原识别号录入有误"), false, true)}
-      {field("contact", "联系人", input("contact", "客户方联系人,个人客户填本人"))}
-      {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 位手机号,或含区号的固话(数字/空格/-/括号)")}
-      {field("address", "客户地址", input("address", "请输入完整地址,包括楼栋与房间号"), false, true)}
-    </div></section>
-    <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">
-      {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)}
-      {field("operatorId", "运营商", select("operatorId", data.operators.map((item) => ({ id: item.id, name: item.name })), "请选择运营商"), true)}
-      {field("partnerId", "合伙人", select("partnerId", data.partners.map((item) => ({ id: item.id, name: `${item.name} · ${item.title}` })), "不绑定"))}
-      {field("operationsTeamId", "运营团队",
-        <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)}>
-          <option value="">{!draft.regionId ? "请先选取所属区域" : operationsTeamCandidates.length ? "请选择运营团队" : "所挂区域未匹配运营团队"}</option>
-          {operationsTeamCandidates.map((item) => <option key={item.id} value={item.id}>{item.name}</option>)}
-        </select>,
-        false, false,
-        "按所挂区域实时反查,仅用于展示、不写入客户档案;总运营可选手选,其它运营按账号带入只读;唯一候选自动选中。")}
-      <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>
-    </div></section>
-    <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>
-    {!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>}
-    <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>
-  </form>;
+  const fieldGrid = no ? "ops-form-grid" : "ops-form-grid ops-form-grid--business";
+  const formError = saveError || (Object.keys(errors).length > 0
+    ? `有 ${Object.keys(errors).length} 项未通过校验,请修正标记的字段。`
+    : "");
+  const submitLabel = busy ? "正在保存…" : no ? "保存档案" : "新建客户";
+  const formActions = (
+    <div className="ops-form-actions">
+      <Button type="button" variant="outline" disabled={busy} onClick={() => navigate(back.to, { state: back.state })}>取消</Button>
+      <Button type="submit" disabled={busy}>{submitLabel}</Button>
+    </div>
+  );
+
+  const sections = (
+    <>
+      <section className="ops-record-card">
+        <div className="customer-form-section-title"><span>01</span><div><h2>主体资料</h2><p>客户允许重名,以识别号查重、以客户号关联业务。</p></div></div>
+        <div className={fieldGrid}>
+          {no && (
+            <label>
+              <span className="ops-field-title">客户号</span>
+              <Input disabled value={no} />
+            </label>
+          )}
+          {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} 字`)}
+          {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>)}
+          {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>}
+          {field("idNo", "客户识别号", input("idNo", "统一社会信用代码 / 身份证号"), !no, false,
+            no ? (original?.identity_no_masked
+              ? "当前为后端脱敏识别号(明文不出后端);更正请清空后填入完整号码,不改动=不提交。"
+              : "该客户尚未登记识别号;填入完整号码即视为登记(后端查重+加密落库)。")
+              : "统一社会信用代码 / 身份证号;是查重键,建案时按它判重。")}
+          {no && field("basisNote", "变更依据(选填)", input("basisNote", "例如:客户补充证件,原识别号录入有误"), false, true)}
+          {field("contact", "联系人", input("contact", "客户方联系人,个人客户填本人"))}
+          {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 位手机号,或含区号的固话(数字/空格/-/括号)")}
+          {field("address", "客户地址", input("address", "请输入完整地址,包括楼栋与房间号"), false, Boolean(no))}
+        </div>
+      </section>
+      <section className="ops-record-card">
+        <div className="customer-form-section-title"><span>02</span><div><h2>归属与挂载</h2><p>选择所属区域、运营商和服务团队。</p></div></div>
+        <div className={fieldGrid}>
+          {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)}
+          {field("operatorId", "运营商", select("operatorId", data.operators.map((item) => ({ id: item.id, name: item.name })), "请选择运营商"), true)}
+          {field("partnerId", "合伙人", select("partnerId", data.partners.map((item) => ({ id: item.id, name: `${item.name} · ${item.title}` })), "不绑定"))}
+          {field("operationsTeamId", "运营团队",
+            <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)}>
+              <option value="">{!draft.regionId ? "请先选取所属区域" : operationsTeamCandidates.length ? "请选择运营团队" : "所挂区域未匹配运营团队"}</option>
+              {operationsTeamCandidates.map((item) => <option key={item.id} value={item.id}>{item.name}</option>)}
+            </select>,
+            false, false,
+            "按所挂区域实时反查,仅用于展示、不写入客户档案;总运营可选手选,其它运营按账号带入只读;唯一候选自动选中。")}
+          <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>
+        </div>
+      </section>
+      <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={fieldGrid}>
+            {field("login", "主账号登录名", (
+              <Input name="login" value={draft.login} placeholder="留空将自动生成" 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, "用于主账号登录验证与找回。")}
+          </div>
+        )}
+      </section>
+
+      {!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>
+      )}
+    </>
+  );
+
+  return (
+    <form ref={form} noValidate onSubmit={save} className="ops-page ops-record-page customer-editor">
+      {no ? (
+        <>
+          <Link to={back.to} state={back.state} className="ops-back-link"><ArrowLeft size={16} />{back.label}</Link>
+          <header className="ops-record-header">
+            <div>
+              <p>客户管理 / 编辑档案</p>
+              <h1>编辑 {original?.customer_name ?? no}</h1>
+              <p>识别号可更正,留空或保持原值时不提交变更。</p>
+            </div>
+            <Button type="submit" disabled={busy}>{submitLabel}</Button>
+          </header>
+          {formError && <div className="ops-form-error" role="alert">{formError}</div>}
+          {sections}
+          {formActions}
+        </>
+      ) : (
+        <>
+          <header className="ops-page-head">
+            <div>
+              <p className="ops-eyebrow"><span />客户管理</p>
+              <h1>新增客户</h1>
+              <p>登记客户资料和业务归属,并开通客户主账号。</p>
+            </div>
+            <Link to={back.to} state={back.state} className="ops-back-link"><ArrowLeft size={16} />{back.label}</Link>
+          </header>
+          <div className="ops-record-layout">
+            <div className="ops-record-stack">{sections}</div>
+            <aside className="ops-record-side" aria-label="建档操作">
+              <section className="ops-record-card">
+                <h2>提交建档</h2>
+                {formError && <div className="ops-form-error" role="alert">{formError}</div>}
+                {formActions}
+              </section>
+            </aside>
+          </div>
+        </>
+      )}
+    </form>
+  );
 }
 
 /** 主体类型原文 → 中文(走 `labels.ts` 的 `SUBJECT_TYPE` 字典)。 */

+ 7 - 2
web-scaffold/src/pages/CustomerRecordsPages.tsx

@@ -18,7 +18,7 @@ import { Button } from "../components/ui/button";
 import { Input } from "../components/ui/input";
 import { SearchInput } from "../components/ui/search-input";
 import { OpsNotice, OpsStatus, OpsTableColumns, OpsTableEmpty } from "../components/OperationsKit";
-import { Tri } from "../components/triState";
+import { TableValueText, Tri } from "../components/triState";
 import { useHorizontalOverflow } from "../lib/use-horizontal-overflow";
 import { useBusinessView } from "../lib/use-business-view";
 import { useSession } from "../auth/session";
@@ -257,7 +257,12 @@ export function CustomerListPage() {
       <div ref={tableOverflow.ref} tabIndex={0} role="region" aria-label="客户档案列表,可横向滚动查看字段" className={`measured-table-scroll ops-table-wrap customer-table-scroll${tableOverflow.overflow ? " has-horizontal-overflow" : ""}${tableOverflow.width >= 900 ? " can-pin-identity" : ""}${tableOverflow.canScrollLeft ? " can-scroll-left" : ""}${tableOverflow.canScrollRight ? " can-scroll-right" : ""}`}><table className="ops-table customer-ledger"><OpsTableColumns widths={columnWidths} /><thead><tr><th>客户名称</th><th>主体 / 识别号</th><th>所属区域</th><th>运营商</th><th>合伙人</th><th>运维团队</th><th>服务开通状态</th><th aria-label="操作" /></tr></thead><tbody>{pageRows.map((item) => {
         const tone = item.status === "已停用" ? "danger" : item.status === "正常" || item.status === "使用中" ? "success" : "neutral";
         return <tr key={item.id}>
-          <td><strong className="table-cell-title" title={item.name ?? item.id}>{item.name ?? <Tri tone="missing" text={MISSING} />}</strong><small title={item.id}>{item.id}</small></td>
+          <td>
+            <strong className="table-cell-title" title={item.name ?? item.id}>
+              {item.name ? <TableValueText>{item.name}</TableValueText> : <Tri tone="missing" text={MISSING} />}
+            </strong>
+            <small title={item.id}>{item.id}</small>
+          </td>
           <td><span title={item.subject ?? undefined}>{item.subject ?? <Tri tone="missing" text={MISSING} />}</span>{item.identityNo ? <small title={IDENTITY_NOTE}>{item.identityNo}</small> : <small title={IDENTITY_NOTE}>未登记识别号</small>}</td>
           <td>{item.regionPath ? <span title={item.regionPath}>{item.regionPath}</span> : <Tri tone="missing" text={MISSING} title={REGION_NOTE} />}</td>
           <td>{item.operator ? <span title={item.operator}>{item.operator}</span> : <Tri tone="missing" text={MISSING} />}</td>

+ 1 - 1
web-scaffold/src/styles/operations.css

@@ -805,7 +805,7 @@ body:has(:is(.ops-content-dialog, .header-logout-dialog)[open]) { overflow: hidd
 .ops-page--customers .ops-overview { min-height: 94px; background: var(--primary-soft); border-color: var(--primary-border); }
 .ops-page--customers .ops-overview-lead { padding-top: 12px; padding-bottom: 12px; }
 .ops-page--customers .ops-overview-stats { margin-top: 12px; margin-bottom: 12px; }
-.ops-page--customers .ops-table td:first-child strong { color: var(--primary); }
+.ops-page--customers .ops-table:not(:where(.customer-ledger)) td:first-child strong { color: var(--primary); }
 .ops-page--customers .ops-table td:nth-child(4) strong { font-weight: 650; }
 
 .ops-page--imports .ops-overview { min-height: 96px; }