ConstructionGuidePanel.tsx 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /**
  2. * 施工指导只读区:开户见套餐权益;停机见开机施工参数;变更见前后对照+原施工参数。
  3. */
  4. import type { ConstructionGuide, PriorActivation, ConstructionPlanSummary } from "../../lib/api/ticket";
  5. import { PLAN_FAMILY, PLAN_KIND, label } from "../../lib/api/labels";
  6. function exitsText(v: ConstructionPlanSummary["line_exits"]): string {
  7. if (Array.isArray(v)) return v.filter(Boolean).join("、") || "—";
  8. if (typeof v === "string" && v.trim()) {
  9. try {
  10. const parsed = JSON.parse(v) as unknown;
  11. if (Array.isArray(parsed)) return parsed.filter(Boolean).join("、") || "—";
  12. } catch { /* plain csv */ }
  13. return v;
  14. }
  15. return "—";
  16. }
  17. function PlanCard({ title, plan }: { title: string; plan: ConstructionPlanSummary | null | undefined }) {
  18. if (!plan) return null;
  19. return (
  20. <div className="wo-guide-card">
  21. <h4 className="work-order-subhead">{title}</h4>
  22. {plan.summary ? <p className="wo-guide-summary">{plan.summary}</p> : null}
  23. <div className="work-order-summary-grid">
  24. <div><span>套餐</span><strong>{plan.plan_name ?? "—"}</strong></div>
  25. <div><span>交付形态</span><strong>{plan.plan_family ? label(PLAN_FAMILY, plan.plan_family) : "—"}</strong></div>
  26. <div><span>档位类型</span><strong>{plan.plan_kind ? label(PLAN_KIND, plan.plan_kind) : "—"}</strong></div>
  27. <div><span>份数</span><strong>{plan.quantity ?? "—"}</strong></div>
  28. <div><span>分账号额度</span><strong>{plan.quota_slots ?? plan.sub_account_quota ?? "—"}</strong></div>
  29. <div><span>承诺带宽</span><strong>
  30. {[plan.bandwidth_down_mbps != null && `↓${plan.bandwidth_down_mbps}`, plan.bandwidth_up_mbps != null && `↑${plan.bandwidth_up_mbps}`]
  31. .filter(Boolean).join(" / ") || "—"}
  32. {plan.bandwidth_committed === false ? "(不承诺)" : ""}
  33. </strong></div>
  34. <div className="wide"><span>线路出口</span><strong>{exitsText(plan.line_exits)}</strong></div>
  35. </div>
  36. </div>
  37. );
  38. }
  39. function PriorBlock({ prior }: { prior: PriorActivation }) {
  40. return (
  41. <div className="wo-guide-card">
  42. <h4 className="work-order-subhead">开机时施工参数</h4>
  43. <p className="wo-guide-summary">
  44. 来源开户单 {prior.ticket_no ?? prior.ticket_id ?? "—"}
  45. {prior.actual_opened_date ? ` · 实际开通 ${prior.actual_opened_date.slice(0, 10)}` : ""}
  46. (PIN/CPID 仅显示是否已登记)
  47. </p>
  48. {(prior.routes?.length ?? 0) > 0 && (
  49. <div className="work-order-table-wrap compact">
  50. <table>
  51. <thead><tr>
  52. <th>分账号</th><th>网络账户</th><th>内网 IP</th><th>VLAN/VNI</th><th>出口 PoP</th><th>带宽</th>
  53. </tr></thead>
  54. <tbody>
  55. {prior.routes!.map((r) => (
  56. <tr key={r.id}>
  57. <td>{r.sub_account_id ?? "—"}</td>
  58. <td>{r.network_account_name ?? "—"}</td>
  59. <td>{[r.intranet_ip, r.subnet_mask].filter(Boolean).join(" / ") || "—"}</td>
  60. <td>{[r.vlan, r.vni].filter(Boolean).join(" / ") || "—"}</td>
  61. <td>{r.egress_pop ?? "—"}</td>
  62. <td>{[r.down_mbps && `↓${r.down_mbps}`, r.up_mbps && `↑${r.up_mbps}`].filter(Boolean).join(" / ") || "—"}</td>
  63. </tr>
  64. ))}
  65. </tbody>
  66. </table>
  67. </div>
  68. )}
  69. {(prior.ips?.length ?? 0) > 0 && (
  70. <div className="work-order-table-wrap compact">
  71. <table>
  72. <thead><tr><th>出境口岸</th><th>境外 IP</th><th>类型</th><th>带宽档</th><th>凭据</th></tr></thead>
  73. <tbody>
  74. {prior.ips!.map((r) => (
  75. <tr key={r.id}>
  76. <td>{r.egress ?? "—"}</td>
  77. <td>{r.overseas_ip ?? "—"}</td>
  78. <td>{r.ip_type ?? "—"}</td>
  79. <td>{r.bandwidth_mbps ?? "—"}</td>
  80. <td>PIN {r.pin_registered === "true" ? "✓" : "—"} / CPID {r.cpid_registered === "true" ? "✓" : "—"}</td>
  81. </tr>
  82. ))}
  83. </tbody>
  84. </table>
  85. </div>
  86. )}
  87. {!prior.routes?.length && !prior.ips?.length && <p className="work-order-detail-footnote">暂无历史开通明细。</p>}
  88. </div>
  89. );
  90. }
  91. export function ConstructionGuidePanel({ guide }: { guide: ConstructionGuide | null | undefined }) {
  92. if (!guide || typeof guide !== "object") return null;
  93. const t = guide.ticket_type ?? "";
  94. const isStop = t === "expiry_stop" || t === "service_stop";
  95. const isUpdown = t === "updown";
  96. return (
  97. <section className="wo-guide" aria-label="施工指导">
  98. <h3 className="work-order-section-title">施工指导</h3>
  99. {isUpdown ? (
  100. <>
  101. <PlanCard title="变更前" plan={guide.plan_before} />
  102. <PlanCard title="变更后" plan={guide.plan_after ?? guide.plan} />
  103. </>
  104. ) : (
  105. <PlanCard title="相关套餐" plan={guide.plan} />
  106. )}
  107. {(guide.member_plans?.length ?? 0) > 0 && (
  108. <div className="wo-guide-card">
  109. <h4 className="work-order-subhead">并单成员订阅</h4>
  110. <ul className="wo-guide-members">
  111. {guide.member_plans!.map((m) => (
  112. <li key={m.subscription_id ?? m.plan_name ?? Math.random()}>
  113. {m.plan_name ?? m.subscription_id}
  114. {m.plan_family ? ` · ${label(PLAN_FAMILY, m.plan_family)}` : ""}
  115. </li>
  116. ))}
  117. </ul>
  118. </div>
  119. )}
  120. {(isStop || isUpdown) && guide.prior_activation && <PriorBlock prior={guide.prior_activation} />}
  121. {guide.defaults && (guide.defaults.suggest_down_mbps != null || (guide.defaults.line_exits?.length ?? 0) > 0) && (
  122. <p className="work-order-detail-footnote">
  123. 系统建议(可改):出口 {exitsText(guide.defaults.line_exits)}
  124. {guide.defaults.suggest_down_mbps != null ? ` · 下行 ${guide.defaults.suggest_down_mbps} Mbps` : ""}
  125. {guide.defaults.suggest_up_mbps != null ? ` · 上行 ${guide.defaults.suggest_up_mbps} Mbps` : ""}
  126. {guide.defaults.suggest_ip_bandwidth_mbps != null ? ` · IP 档 ${guide.defaults.suggest_ip_bandwidth_mbps}` : ""}
  127. {guide.defaults.suggest_seat_count != null ? ` · 席位约 ${guide.defaults.suggest_seat_count}` : ""}
  128. </p>
  129. )}
  130. </section>
  131. );
  132. }