Bladeren bron

feat(web): 统一客户建档和合同签订操作区

sy 50 minuten geleden
bovenliggende
commit
ddd80aee3f

+ 15 - 0
web-scaffold/src/components/RecordRequiredProgress.tsx

@@ -0,0 +1,15 @@
+export function RecordRequiredProgress({ done, total }: { done: number; total: number }) {
+  const percent = total ? Math.round((done / total) * 100) : 100;
+
+  return (
+    <section className="ops-record-card">
+      <h2>必填完成度</h2>
+      <div className="contract-progress" role="progressbar" aria-label="必填完成度" aria-valuemin={0} aria-valuemax={100} aria-valuenow={percent}>
+        <i style={{ width: `${percent}%` }} />
+      </div>
+      <div className="ops-contract-summary contract-side-kv">
+        <div><span>已填 / 必填</span><strong>{done} / {total}</strong></div>
+      </div>
+    </section>
+  );
+}

+ 9 - 15
web-scaffold/src/pages/ContractDetailPages.tsx

@@ -1,7 +1,8 @@
 import { useEffect, useMemo, useRef, useState, type KeyboardEvent, type ReactNode } from "react";
 import { ArrowLeft, Lock, Plus, Trash2, Upload, X } from "lucide-react";
 import { FetchError } from "../components/fetchError";
-import { useLocation, useNavigate, useParams, useSearchParams } from "react-router";
+import { Link, useLocation, useNavigate, useParams, useSearchParams } from "react-router";
+import { RecordRequiredProgress } from "../components/RecordRequiredProgress";
 import { Button } from "../components/ui/button";
 import { Input } from "../components/ui/input";
 import { TreeSelect } from "../components/ui/tree-select";
@@ -1029,7 +1030,7 @@ export function ContractEditorPage() {
     const missing = items.filter((item) => !item.filled).map((item) => item.label);
     const total = items.length;
     const done = total - missing.length;
-    return { done, total, pct: total ? Math.round((done / total) * 100) : 100, missing };
+    return { done, total, missing };
   }, [customerId, customerTerm, draft.agent, draft.agentPhone, draft.amount, draft.contractType, draft.items, draft.serviceMonths, draft.signDate, draft.start, editing, inline.businessName, inline.businessPhone, inline.financeName, inline.financePhone, inline.idNo, inline.operatorId, inline.regionId, inline.teamId, inline.techName, inline.techPhone, renewFrom]);
 
   async function save() {
@@ -1277,6 +1278,7 @@ export function ContractEditorPage() {
     </section>;
   }
 
+  const backToLedger = <Link to="/contracts" className="ops-back-link"><ArrowLeft size={16} />返回合同台账</Link>;
   return <section className="ops-page ops-record-page contract-editor record-editor-fields">
     <header className="ops-page-head">
       <div>
@@ -1284,13 +1286,11 @@ export function ContractEditorPage() {
         <h1>{editing ? "编辑合同" : "合同签订表单"}</h1>
         <p>{editing ? `合同 ${no}` : "采集客户、商务、订购额度与合规信息,用于生成合同快照、资源额度和后续工单的授权依据。"}</p>
       </div>
-      <div className="ops-head-actions">
-        <Button variant="outline" size="sm" onClick={() => navigate("/contracts")}><ArrowLeft size={15} />返回合同台账</Button>
-      </div>
+      {backToLedger}
     </header>
     {record.loading && <div className="ops-record-layout"><section className="ops-record-card ops-record-card-full"><h2>合同资料</h2><p className="contract-form-summary">正在从合同接口读取…</p></section></div>}
-    {record.error && <div className="ops-record-layout"><section className="ops-record-card ops-record-card-full"><h2>合同资料</h2><p className="ops-form-error" role="alert">{record.error.message}</p><div className="ops-form-actions"><Button variant="outline" size="sm" onClick={() => navigate("/contracts")}>返回合同台账</Button></div></section></div>}
-    {!record.loading && !record.error && editing && !record.data && <div className="ops-record-layout"><section className="ops-record-card ops-record-card-full"><h2>合同资料</h2><p className="contract-form-summary">未找到合同 {no},可能已被删除。请从合同台账重新进入,或返回台账检索。</p><div className="ops-form-actions"><Button variant="outline" size="sm" onClick={() => navigate("/contracts")}>返回合同台账</Button></div></section></div>}
+    {record.error && <div className="ops-record-layout"><section className="ops-record-card ops-record-card-full"><h2>合同资料</h2><p className="ops-form-error" role="alert">{record.error.message}</p><div className="ops-form-actions">{backToLedger}</div></section></div>}
+    {!record.loading && !record.error && editing && !record.data && <div className="ops-record-layout"><section className="ops-record-card ops-record-card-full"><h2>合同资料</h2><p className="contract-form-summary">未找到合同 {no},可能已被删除。请从合同台账重新进入,或返回台账检索。</p><div className="ops-form-actions">{backToLedger}</div></section></div>}
     {(!editing || record.data) && <div className="ops-record-layout">
       <div className="ops-record-stack">
         <section className="ops-record-card">
@@ -1801,19 +1801,13 @@ export function ContractEditorPage() {
           </div>
         </section>
 
-        <section className="ops-record-card">
-          <h2>必填完成度</h2>
-          <div className="contract-progress" role="progressbar" aria-valuemin={0} aria-valuemax={100} aria-valuenow={requiredProgress.pct} aria-label="必填完成度"><i style={{ width: `${requiredProgress.pct}%` }} /></div>
-          <div className="ops-contract-summary contract-side-kv">
-            <div><span>已填 / 必填</span><strong>{requiredProgress.done} / {requiredProgress.total}</strong></div>
-          </div>
-        </section>
+        <RecordRequiredProgress done={requiredProgress.done} total={requiredProgress.total} />
 
         {/* 动作区(2026-11-19):不再列「提交后系统生成」说明,只留提交与取消。 */}
         <section className="ops-record-card">
           {error && <p className="ops-form-error" role="alert">{error}</p>}
           <div className="ops-form-actions">
-            <Button size="sm" disabled={submitting || replacementBusy || (editing && record.loading)} onClick={save}>{submitting ? "正在提交…" : replacementBusy ? "正在比对替换候选…" : editing ? "保存修改" : "校验并提交"}</Button>
+            <Button size="sm" disabled={submitting || replacementBusy || (editing && record.loading)} onClick={save}>{submitting ? "正在提交…" : replacementBusy ? "正在比对替换候选…" : editing ? "保存修改" : "检查并签订"}</Button>
             <Button size="sm" variant="outline" onClick={() => navigate(-1)}>取消</Button>
           </div>
         </section>

+ 25 - 12
web-scaffold/src/pages/CustomerEditorPage.tsx

@@ -13,6 +13,7 @@ import { useEffect, useMemo, useRef, useState, type FormEvent, type ReactNode }
 import { ArrowLeft, FileText, Upload } from "lucide-react";
 import { Link, useLocation, useNavigate, useParams } from "react-router";
 import { FetchError } from "../components/fetchError";
+import { RecordRequiredProgress } from "../components/RecordRequiredProgress";
 import { Button } from "../components/ui/button";
 import { Input } from "../components/ui/input";
 import { TreeSelect } from "../components/ui/tree-select";
@@ -30,7 +31,7 @@ import { customerAttributionUpdate, customerCreate, customerGet, customerMoveReg
 import { uploadCustomerLicense, type UploadedObject } from "../lib/api/oss-upload";
 import { invalidateCustomerList } from "../lib/customer-list-store";
 import { useDemoIdentity } from "../lib/demo-session";
-import { useOrganizationData } from "../lib/organization-demo";
+import { regionPath, useOrganizationData } from "../lib/organization-demo";
 import "../styles/customer-onboarding.css";
 import "../styles/operations.css";
 import "../styles/record-editor-fields.css";
@@ -38,6 +39,7 @@ import "../styles/record-editor-fields.css";
 const MISSING = "后端未下发";
 /** 客户名称上限(与后端 `customer.customer_name`/建档守卫同口径)。 */
 const CUSTOMER_NAME_MAX = 64;
+const REQUIRED_CUSTOMER_FIELDS = ["name", "subject", "idNo", "regionId", "operatorId", "teamIds"] as const;
 /** 联系电话:11 位手机号,或含区号的固话(数字/空格/-/(),7–20 字符)。 */
 const PHONE_OK = /^(1\d{10}|[\d\s\-()]{7,20})$/;
 /**
@@ -256,13 +258,9 @@ export function CustomerEditorPage() {
   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 createErrors: Record<string, string> = no ? {} : validate();
+  const completedFields = REQUIRED_CUSTOMER_FIELDS.filter((key) => !createErrors[key]).length;
+  const cancel = () => navigate(back.to, { state: back.state });
 
   const sections = (
     <>
@@ -405,11 +403,14 @@ export function CustomerEditorPage() {
               <h1>编辑 {original?.customer_name ?? no}</h1>
               <p>识别号可更正,留空或保持原值时不提交变更。</p>
             </div>
-            <Button type="submit" disabled={busy}>{submitLabel}</Button>
+            <Button type="submit" disabled={busy}>{busy ? "正在保存…" : "保存档案"}</Button>
           </header>
           {formError && <div className="ops-form-error" role="alert">{formError}</div>}
           {sections}
-          {formActions}
+          <div className="ops-form-actions">
+            <Button type="button" variant="outline" disabled={busy} onClick={cancel}>取消</Button>
+            <Button type="submit" disabled={busy}>{busy ? "正在保存…" : "保存档案"}</Button>
+          </div>
         </>
       ) : (
         <>
@@ -425,9 +426,21 @@ export function CustomerEditorPage() {
             <div className="ops-record-stack">{sections}</div>
             <aside className="ops-record-side" aria-label="建档操作">
               <section className="ops-record-card">
-                <h2>提交建档</h2>
+                <h2>建档摘要</h2>
+                <div className="ops-contract-summary contract-side-kv">
+                  <div><span>客户名称</span><strong>{draft.name.trim() || "—"}</strong></div>
+                  <div><span>主体类型</span><strong>{SUBJECT_TYPE[draft.subject] ?? "—"}</strong></div>
+                  <div><span>所属区域</span><strong>{regionPath(data, draft.regionId)}</strong></div>
+                  <div><span>运营商</span><strong>{data.operators.find((item) => item.id === draft.operatorId)?.name ?? "—"}</strong></div>
+                </div>
+              </section>
+              <RecordRequiredProgress done={completedFields} total={REQUIRED_CUSTOMER_FIELDS.length} />
+              <section className="ops-record-card" aria-label="建档确认">
                 {formError && <div className="ops-form-error" role="alert">{formError}</div>}
-                {formActions}
+                <div className="ops-form-actions">
+                  <Button type="submit" size="sm" disabled={busy}>{busy ? "正在保存…" : "检查并新建"}</Button>
+                  <Button type="button" size="sm" variant="outline" disabled={busy} onClick={cancel}>取消</Button>
+                </div>
               </section>
             </aside>
           </div>