Forráskód Böngészése

fix(web): 对齐工单关联资料与合同客户资料布局

sy 3 napja
szülő
commit
dd7722d4d6

+ 65 - 38
web-scaffold/src/pages/WorkOrderRecordPage.tsx

@@ -1243,6 +1243,8 @@ export function WorkOrderRecordPage() {
   /** 参考卡的弹窗入参(在 JSX 回调里仍要能拿到主键,先固化一次,⛔ 靠闭包里的可选链猜)。 */
   const refCustomer = d.customer;
   const refOrder = d.order;
+  const refSubscriptionId = refOrder?.subscription_id ?? t.subscription_id;
+  const memberSubscriptions = d.subscriptions ?? [];
 
   /**
    * 「下一步」=详情页唯一的主动作。
@@ -1643,45 +1645,70 @@ export function WorkOrderRecordPage() {
       </WorkOrderPanel>}
 
       <WorkOrderPanel tab="references" active={activeTab} className="work-order-refs">
-        <section className="work-order-reference-group">
-          <h2 className="work-order-panel-title">客户与订阅</h2>
-          {refCustomer ? <>
-            <div className="work-order-trace"><span>客户名称</span><strong>{refCustomer.customer_name
-              ? <button type="button" className="work-order-trace-link" onClick={() => openRef({ kind: "customer", id: refCustomer.customer_id, name: refCustomer.customer_name })}>{refCustomer.customer_name}</button>
-              : recordValue(null)}</strong></div>
-            <div className="work-order-trace"><span>客户编号</span><strong>{refCustomer.customer_code || refCustomer.customer_id
-              ? <button type="button" className="work-order-trace-link" onClick={() => openRef({ kind: "customer", id: refCustomer.customer_id, name: refCustomer.customer_name })}>{refCustomer.customer_code ?? refCustomer.customer_id}</button>
-              : recordValue(null)}</strong></div>
-            <div className="work-order-trace"><span>联系人 / 电话</span><strong>{
-              refCustomer.contact_name_missing && refCustomer.contact_mobile_missing
-                ? "资料缺失"
-                : recordValue([
-                    refCustomer.contact_name_missing ? "联系人资料缺失" : refCustomer.contact_name,
-                    refCustomer.contact_mobile_missing
-                      ? "电话资料缺失"
-                      : (refCustomer.contact_mobile_full || refCustomer.contact_mobile),
-                  ].filter(Boolean).join(" / "))
-            }</strong></div>
-            <div className="work-order-trace"><span>通信地址</span><strong>{refCustomer.address_missing
-              ? <button type="button" className="work-order-trace-link work-order-trace-missing" onClick={() => openRef({ kind: "customer", id: refCustomer.customer_id, name: refCustomer.customer_name })}>资料缺失,需补充</button>
-              : recordValue(refCustomer.address)}</strong></div>
-          </> : <p className="work-order-reference-empty">该单未关联客户档案。</p>}
-          {refOrder && <div className="work-order-trace"><span>关联订阅</span><strong><button type="button" className="work-order-trace-link" onClick={() => openRef({ kind: "order", id: refOrder.subscription_id, name: refOrder.plan_name })}>{refOrder.plan_name ?? refOrder.subscription_id}</button></strong><small>{[refOrder.subscription_id, label(PLAN_KIND, refOrder.plan_kind), label(PLAN_FAMILY, refOrder.plan_family), label(ORDER_STATUS, refOrder.status), refOrder.actual_opened_at ? `实际开通 ${fmtDate(refOrder.actual_opened_at)}` : null].filter(Boolean).join(" · ")}</small>{refOrder.parent_subscription_id && <small className="order-parent-mark">叠加于 {refOrder.parent_subscription_id}</small>}</div>}
-          {/* P1(D-2/D-7):并单成员订阅**平铺**列出,附加成员只标「叠加于 SUB-xxx」,⛔ 折叠成树。 */}
-          {(d.subscriptions ?? []).length > 0 && <div className="work-order-trace"><span>并单成员订阅({(d.subscriptions ?? []).length})</span><div className="work-order-member-list">{(d.subscriptions ?? []).map((member) => <div key={member.subscription_id} className="work-order-member-row"><button type="button" className="work-order-trace-link" onClick={() => openRef({ kind: "order", id: member.subscription_id, name: member.plan_name ?? null })}>{member.plan_name ?? member.subscription_id}</button><small>{member.subscription_id}{member.plan_family ? ` · ${label(PLAN_FAMILY, member.plan_family)}` : ""}{member.status ? ` · ${label(ORDER_STATUS, member.status)}` : ""}</small>{member.parent_subscription_id && <small className="order-parent-mark">叠加于 {member.parent_subscription_id}</small>}</div>)}</div></div>}
-        </section>
-        <section className="work-order-reference-group">
-          <h2 className="work-order-panel-title">追溯与关联</h2>
-          {t.ticket_type === "renewal" && (t.renew_from_contract_id || t.renew_from_contract_no) && (
-            <div className="work-order-trace"><span>续签来源合同</span><strong>{t.renew_from_contract_no ?? t.renew_from_contract_id}</strong>
-              {t.renew_from_end_date ? <small>原到期 {fmtDate(t.renew_from_end_date)}</small> : null}
-              {t.renew_contract_no || t.renew_contract_id ? <small> · 新合同 {t.renew_contract_no ?? t.renew_contract_id}</small> : null}
+        <section className="record-summary-panel">
+          <header className="work-order-content-heading">
+            <h2 className="work-order-panel-title">客户资料</h2>
+            {refCustomer?.customer_id && <button type="button" className="ops-card-link contract-ref-link" onClick={() => openRef({ kind: "customer", id: refCustomer.customer_id, name: refCustomer.customer_name })}>查看客户档案<ArrowRight size={15} /></button>}
+          </header>
+          {refCustomer ? <dl className="ops-record-summary">
+            <div>
+              <dt>客户名称</dt>
+              <dd>{refCustomer.customer_name && refCustomer.customer_id
+                ? <button type="button" className="work-order-trace-link" onClick={() => openRef({ kind: "customer", id: refCustomer.customer_id, name: refCustomer.customer_name })}>{refCustomer.customer_name}</button>
+                : recordValue(refCustomer.customer_name)}</dd>
+            </div>
+            <div><dt>客户编号</dt><dd>{recordValue(refCustomer.customer_code || refCustomer.customer_id)}</dd></div>
+            <div><dt>联系人</dt><dd>{refCustomer.contact_name_missing ? <span className="table-placeholder">资料缺失</span> : recordValue(refCustomer.contact_name)}</dd></div>
+            <div><dt>联系电话</dt><dd>{refCustomer.contact_mobile_missing ? <span className="table-placeholder">资料缺失</span> : recordValue(refCustomer.contact_mobile_full || refCustomer.contact_mobile)}</dd></div>
+            <div className="work-order-reference-wide">
+              <dt>客户地址</dt>
+              <dd>{refCustomer.address_missing && refCustomer.customer_id
+                ? <button type="button" className="work-order-trace-link work-order-trace-missing" onClick={() => openRef({ kind: "customer", id: refCustomer.customer_id, name: refCustomer.customer_name })}>资料缺失,需补充</button>
+                : recordValue(refCustomer.address)}</dd>
             </div>
-          )}
-          <div className="work-order-trace"><span>本单来源</span><strong>{t.source_message_id ? "运营商报文触发" : t.submitter_type === "customer" ? "客户侧提交" : "运营侧代报"}</strong></div>
-          {d.messages.length > 0 && <div className="work-order-trace"><span>关联报文</span><strong>{d.messages.map((m) => m.carrier_order_no ?? m.message_id).join("、")}</strong></div>}
-          {t.source_message_id && <div className="work-order-trace"><span>来源报文</span><strong>{t.source_message_id}</strong></div>}
-          {t.subscription_id && <div className="work-order-trace"><span>关联订单号</span><strong><button type="button" className="work-order-trace-link" onClick={() => openRef({ kind: "order", id: t.subscription_id!, name: refOrder?.plan_name })}>{t.subscription_id}</button></strong></div>}
+          </dl> : <p className="work-order-reference-empty">该单未关联客户档案。</p>}
+        </section>
+
+        {(refSubscriptionId || memberSubscriptions.length > 0) && <section className="record-summary-panel">
+          <h2 className="work-order-panel-title">关联订阅</h2>
+          <dl className="ops-record-summary">
+            {refSubscriptionId && <div>
+              <dt>订阅编号</dt>
+              <dd><button type="button" className="work-order-trace-link" onClick={() => openRef({ kind: "order", id: refSubscriptionId, name: refOrder?.plan_name })}>{refSubscriptionId}</button></dd>
+            </div>}
+            {refOrder && <>
+              <div><dt>套餐名称</dt><dd>{refOrder.plan_name
+                ? <button type="button" className="work-order-trace-link" onClick={() => openRef({ kind: "order", id: refOrder.subscription_id, name: refOrder.plan_name })}>{refOrder.plan_name}</button>
+                : recordValue(null)}</dd></div>
+              <div><dt>套餐类型</dt><dd>{recordValue(label(PLAN_KIND, refOrder.plan_kind))}</dd></div>
+              <div><dt>交付形态</dt><dd>{recordValue(label(PLAN_FAMILY, refOrder.plan_family))}</dd></div>
+              <div><dt>订阅状态</dt><dd>{recordValue(label(ORDER_STATUS, refOrder.status))}</dd></div>
+              {refOrder.actual_opened_at && <div><dt>实际开通日</dt><dd>{fmtDate(refOrder.actual_opened_at)}</dd></div>}
+              {refOrder.parent_subscription_id && <div><dt>叠加于</dt><dd>{refOrder.parent_subscription_id}</dd></div>}
+            </>}
+            {memberSubscriptions.length > 0 && <div className="work-order-reference-wide">
+              <dt>并单成员订阅({memberSubscriptions.length})</dt>
+              <dd className="work-order-member-list">{memberSubscriptions.map((member) => <div key={member.subscription_id} className="work-order-member-row">
+                <button type="button" className="work-order-trace-link" onClick={() => openRef({ kind: "order", id: member.subscription_id, name: member.plan_name ?? null })}>{member.plan_name ?? member.subscription_id}</button>
+                <small>{[member.subscription_id, label(PLAN_FAMILY, member.plan_family), label(ORDER_STATUS, member.status)].filter(Boolean).join(" · ")}</small>
+                {member.parent_subscription_id && <small className="order-parent-mark">叠加于 {member.parent_subscription_id}</small>}
+              </div>)}</dd>
+            </div>}
+          </dl>
+        </section>}
+
+        <section className="record-summary-panel">
+          <h2 className="work-order-panel-title">来源与追溯</h2>
+          <dl className="ops-record-summary">
+            <div><dt>本单来源</dt><dd>{t.source_message_id ? "运营商报文触发" : t.submitter_type === "customer" ? "客户侧提交" : "运营侧代报"}</dd></div>
+            {t.source_message_id && <div><dt>来源报文</dt><dd>{t.source_message_id}</dd></div>}
+            {t.ticket_type === "renewal" && (t.renew_from_contract_id || t.renew_from_contract_no) && <>
+              <div><dt>续签来源合同</dt><dd>{t.renew_from_contract_no ?? t.renew_from_contract_id}</dd></div>
+              {t.renew_from_end_date && <div><dt>原合同到期日</dt><dd>{fmtDate(t.renew_from_end_date)}</dd></div>}
+              {(t.renew_contract_no || t.renew_contract_id) && <div><dt>新合同</dt><dd>{t.renew_contract_no ?? t.renew_contract_id}</dd></div>}
+            </>}
+            {d.messages.length > 0 && <div className="work-order-reference-wide"><dt>关联报文</dt><dd>{d.messages.map((m) => m.carrier_order_no ?? m.message_id).join("、")}</dd></div>}
+          </dl>
         </section>
       </WorkOrderPanel>
     </div>

+ 23 - 0
web-scaffold/src/pages/__tests__/work-order-record-tabs.test.tsx

@@ -1,6 +1,7 @@
 import { cleanup, fireEvent, render, screen, within } from "@testing-library/react";
 import { MemoryRouter, Route, Routes } from "react-router";
 import { afterEach, expect, it, vi } from "vitest";
+import { ReferenceDrawer } from "../../components/ReferenceDrawer";
 import { WorkOrderRecordPage } from "../WorkOrderRecordPage";
 
 const { useTicketDetail } = vi.hoisted(() => {
@@ -11,6 +12,7 @@ vi.mock("../../lib/ticket", async (load) => ({
   ...await load<typeof import("../../lib/ticket")>(),
   useTicketDetail,
 }));
+vi.mock("../../components/ReferenceDrawer", () => ({ ReferenceDrawer: vi.fn(() => null) }));
 
 const detail = {
   ticket: {
@@ -102,3 +104,24 @@ it("施工回填、竣工回执、材料和报文有各自的页签,终态材
   expect(materials.queryByRole("button", { name: "补充过程材料" })).toBeNull();
   expect(pick(/^运营商报文/).getByText("CARRIER-1")).toBeTruthy();
 });
+
+it("关联资料分组显示客户和订阅字段,并保留对应档案入口", () => {
+  renderRecord({
+    customer: { customer_id: "CUS-1", customer_name: "澄澜科技", customer_code: "KL-01", contact_name: "林女士", contact_mobile: "138****0000", address_missing: true },
+    order: { subscription_id: "SUB-1", plan_name: "跨境办公专线", plan_kind: "fixed", status: "active" },
+    subscriptions: [{ subscription_id: "SUB-2", plan_name: "叠加服务", parent_subscription_id: "SUB-1" }],
+  });
+  fireEvent.click(screen.getByRole("tab", { name: "关联资料" }));
+  const related = within(screen.getByRole("tabpanel", { name: "关联资料" }));
+  const customer = within(related.getByRole("heading", { name: "客户资料" }).closest("section")!);
+  expect(customer.getByText("联系电话").tagName).toBe("DT");
+  expect(customer.getByText("138****0000").tagName).toBe("DD");
+  expect(customer.getByRole("button", { name: "资料缺失,需补充" })).toBeTruthy();
+
+  fireEvent.click(customer.getByRole("button", { name: "查看客户档案" }));
+  expect(vi.mocked(ReferenceDrawer).mock.lastCall?.[0].stack.at(-1)).toMatchObject({ kind: "customer", id: "CUS-1" });
+  const subscription = within(related.getByRole("heading", { name: "关联订阅" }).closest("section")!);
+  expect(subscription.getByText("叠加于 SUB-1")).toBeTruthy();
+  fireEvent.click(subscription.getByRole("button", { name: "跨境办公专线" }));
+  expect(vi.mocked(ReferenceDrawer).mock.lastCall?.[0].stack.at(-1)).toMatchObject({ kind: "order", id: "SUB-1" });
+});

+ 5 - 2
web-scaffold/src/styles/record-detail.css

@@ -198,12 +198,14 @@
   display: none;
 }
 
-.record-detail :is(.customer-workspace-panel, .contract-summary-panel) > .ops-record-summary {
+.record-detail :is(.customer-workspace-panel, .contract-summary-panel) > .ops-record-summary,
+.record-summary-panel > .ops-record-summary {
   grid-template-columns: repeat(2, minmax(0, 1fr));
   gap: 0 24px;
 }
 
-.record-detail :is(.customer-workspace-panel, .contract-summary-panel) > .ops-record-summary > div {
+.record-detail :is(.customer-workspace-panel, .contract-summary-panel) > .ops-record-summary > div,
+.record-summary-panel > .ops-record-summary > div {
   min-width: 0;
   padding: 12px 0;
   border-bottom: 1px solid var(--border-subtle);
@@ -364,6 +366,7 @@
 @media (max-width: 600px) {
   .customer-record-metrics > div { padding-inline: 12px; }
   .record-detail :is(.customer-workspace-panel, .contract-summary-panel) > .ops-record-summary,
+  .record-summary-panel > .ops-record-summary,
   .record-detail .customer-panel-grid { grid-template-columns: minmax(0, 1fr); }
 }
 

+ 12 - 7
web-scaffold/src/styles/work-order-record.css

@@ -141,12 +141,12 @@
 .work-order-detail-text { margin: 0 0 14px; overflow-wrap: anywhere; color: var(--text-secondary); font-size: var(--type-body); line-height: 1.6; }
 .work-order-detail-text:last-child { margin-bottom: 0; }
 
-.work-order-overview-panel, .work-order-refs { display: grid; gap: 18px; align-items: start; }
+.work-order-overview-panel { display: grid; gap: 18px; align-items: start; }
 .work-order-description { min-width: 0; }
 .work-order-ticket-lead { margin: 10px 0 0; color: var(--foreground); font-size: var(--type-comfort); line-height: 1.8; overflow-wrap: anywhere; white-space: pre-wrap; }
 .work-order-ticket-lead[data-empty] { color: var(--muted-foreground); font-size: var(--type-support); }
 .work-order-overview-context { min-width: 0; padding: 15px 16px; border: 1px solid var(--border-subtle); border-radius: var(--radius-control); background: var(--surface-subtle); }
-.work-order-overview-context > h2, .work-order-reference-group > h2 { margin-bottom: 10px; }
+.work-order-overview-context > h2 { margin-bottom: 10px; }
 .work-order-panel-stack { display: grid; gap: 22px; }
 .work-order-content-group { display: grid; gap: 10px; min-width: 0; }
 .work-order-content-group + .work-order-content-group { padding-top: 16px; border-top: 1px solid var(--border-subtle); }
@@ -304,15 +304,18 @@
 .work-order-tl small { display: block; margin-top: 3px; color: var(--muted-foreground); font-size: var(--type-meta); line-height: 1.5; overflow-wrap: anywhere; }
 
 /* ── 关联资料 ────────────────────────────────────────────────── */
-.work-order-reference-group { min-width: 0; padding: 15px 16px; border: 1px solid var(--border-subtle); border-radius: var(--radius-control); }
+.work-order-refs { display: grid; gap: 24px; }
+.work-order-refs .record-summary-panel { min-width: 0; }
+.work-order-refs .work-order-content-heading { margin-bottom: 4px; }
+.work-order-refs .work-order-reference-wide { grid-column: 1 / -1; }
 .work-order-reference-empty { margin: 0; color: var(--muted-foreground); font-size: var(--type-support); }
 .work-order-trace { display: grid; grid-template-columns: minmax(84px, 35%) minmax(0, 1fr); align-items: baseline; gap: 4px 10px; padding: 7px 0; border-bottom: 1px solid var(--border-subtle); }
 .work-order-trace:first-of-type { padding-top: 0; }
 .work-order-trace:last-child { padding-bottom: 0; border-bottom: 0; }
-.work-order-trace > strong, .work-order-trace .work-order-member-row { overflow-wrap: anywhere; }
-.work-order-trace .work-order-member-row { font-size: var(--type-support); }
+.work-order-trace > strong { overflow-wrap: anywhere; }
 .work-order-trace > small { grid-column: 2; overflow-wrap: anywhere; color: var(--muted-foreground); font-size: var(--type-meta); line-height: 1.5; }
-.work-order-trace .work-order-member-row small { font-size: var(--type-meta); font-weight: 400; }
+.work-order-refs .work-order-member-row { font-size: var(--type-support); }
+.work-order-refs .work-order-member-row small { font-size: var(--type-meta); font-weight: 400; }
 /* 参考区的可点字段:外观仍是一行摘要,只把「能点开」显性化 */
 .work-order-trace-link { padding: 0; border: 0; background: none; color: var(--primary); font: inherit; font-weight: 600; text-align: left; overflow-wrap: anywhere; cursor: pointer; }
 .work-order-trace-link:hover { text-decoration: underline; }
@@ -360,7 +363,9 @@
 
 @container (min-width: 610px) {
   .work-order-overview-panel { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
-  .work-order-refs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
+}
+@container (max-width: 520px) {
+  .work-order-refs .record-summary-panel > .ops-record-summary { grid-template-columns: minmax(0, 1fr); }
 }
 
 /* ── 窄屏 ────────────────────────────────────────────────────── */