|
|
@@ -1,51 +1,29 @@
|
|
|
import { FilterSelect } from "../components/ui/filter-select";
|
|
|
-import { FetchError } from "../components/fetchError";
|
|
|
-import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState, Fragment, type FormEvent } from "react";
|
|
|
+import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState, Fragment } from "react";
|
|
|
import { createPortal } from "react-dom";
|
|
|
-import { CircleHelp, Info, LockKeyhole, PencilLine, Plus, Search, Trash2, X } from "lucide-react";
|
|
|
+import { CircleHelp, LockKeyhole, PencilLine, Plus, Search, Trash2, X } from "lucide-react";
|
|
|
import { Button } from "../components/ui/button";
|
|
|
import { Input } from "../components/ui/input";
|
|
|
import { Tri } from "../components/triState";
|
|
|
import { NOTICE_DISMISS_MS, OpsTableColumns, OpsTableEmpty } from "../components/OperationsKit";
|
|
|
import { ListPager } from "../components/ListPager";
|
|
|
-import { COST_BY_COMBINATION, DERIVED_PLAN_EDITABLE, FIXED_PLAN_LOCKED_FIELDS, OPERATOR_ONLY_CONFIG, PLAN_COST_ITEM_SAVE_NOTE, WORD_FETCH_FAILED, WORD_NOT_PROVIDED, WORD_UNCONFIGURED } from "../lib/api/lockedCopy";
|
|
|
-import { catalogCreate, catalogCustomerOptions, catalogDelete, catalogUpdate, ipBandwidthTierSave, lineExitSave, planCostItemList, planCostItemSave, rowsOf } from "../lib/api/bos";
|
|
|
-import type { CatalogPlanRow, IpBandwidthTierListResult, LineExitListResult, PlanCostItemRow } from "../lib/api/types";
|
|
|
+import { COST_BY_COMBINATION, OPERATOR_ONLY_CONFIG, WORD_FETCH_FAILED, WORD_NOT_PROVIDED, WORD_UNCONFIGURED } from "../lib/api/lockedCopy";
|
|
|
+import { catalogDelete, ipBandwidthTierSave, lineExitSave } from "../lib/api/bos";
|
|
|
+import type { CatalogPlanRow, IpBandwidthTierListResult, LineExitListResult } from "../lib/api/types";
|
|
|
import { ApiError } from "../lib/api/http";
|
|
|
import { useDemoIdentity } from "../lib/demo-session";
|
|
|
-import { bandwidthTextOfRow, categoryCode, categoryLabel, packageCategories, useCatalogPlans, useIpBandwidthTiers, useLineExits } from "../lib/package-catalog";
|
|
|
+import { bandwidthTextOfRow, familyLabel, planFamilies, useCatalogPlans, useIpBandwidthTiers, useLineExits } from "../lib/package-catalog";
|
|
|
import { exitKey, IP_TIER_UNCOMMITTED, splitExitInput } from "../domain/contract-items";
|
|
|
-import { useLoad, type Load } from "../lib/useLoad";
|
|
|
+import type { Load } from "../lib/useLoad";
|
|
|
import { slicePage, useLocalPage } from "../lib/list-paging";
|
|
|
import { useHorizontalOverflow } from "../lib/use-horizontal-overflow";
|
|
|
+import { PackagePlanEditor, type EditorState } from "../components/PackagePlanEditor";
|
|
|
import "../styles/operations.css";
|
|
|
import "../styles/packages.css";
|
|
|
|
|
|
/** 目录三视图:固定套餐与自定义套餐各一张台账,线路出口是目录级清单。 */
|
|
|
type CatalogTab = "fixed" | "custom" | "exits";
|
|
|
-/** `owner` 为归属客户 ID:`null` 表示公共固定档,空串表示「客户专属档但尚未选择归属」。 */
|
|
|
-type EditorState = { plan?: CatalogPlanRow; owner: string | null };
|
|
|
-type EditorValues = {
|
|
|
- name: string; category: string; owner: string; annualPrice: string; quota: string;
|
|
|
- bandwidthMode: "committed" | "uncommitted" | ""; upload: string; download: string; description: string;
|
|
|
-};
|
|
|
-/** 成本项行=`plan_cost_item` 真实字段面(⛔ 本地「份数」口径,后端无该列)。 */
|
|
|
-type CostDraft = { item_name: string; amount: string; billing_unit: string; remark: string };
|
|
|
|
|
|
-const costDraftOf = (row: PlanCostItemRow): CostDraft => ({
|
|
|
- item_name: row.item_name ?? "",
|
|
|
- amount: row.amount_cents === null || row.amount_cents === undefined ? "" : String(row.amount_cents / 100),
|
|
|
- billing_unit: row.billing_unit ?? "",
|
|
|
- remark: row.remark ?? "",
|
|
|
-});
|
|
|
-
|
|
|
-const costRowOf = (draft: CostDraft): PlanCostItemRow => ({
|
|
|
- item_name: draft.item_name.trim(),
|
|
|
- amount_cents: draft.amount.trim() === "" ? null : Math.round(Number(draft.amount) * 100),
|
|
|
- billing_unit: draft.billing_unit.trim() || null,
|
|
|
- category: null,
|
|
|
- remark: draft.remark.trim() || null,
|
|
|
-});
|
|
|
|
|
|
/** 整数格三态:字段缺失=取数失败,null=未配置,⛔ 显示 0;不给单位时与原型一样只出数字。 */
|
|
|
function intCell(value: number | null | undefined, unit?: string) {
|
|
|
@@ -78,29 +56,6 @@ function ledgerCostCell(plan: CatalogPlanRow) {
|
|
|
return <Tri tone="val" text={COST_BY_COMBINATION} title="金额随各客户的「省份 × 运营商」组合不同,不折中成一个数" />;
|
|
|
}
|
|
|
|
|
|
-function formOf(plan: CatalogPlanRow | undefined, owner: string | null): EditorValues {
|
|
|
- const committed = plan?.bandwidth_committed;
|
|
|
- return {
|
|
|
- name: plan?.plan_name ?? "",
|
|
|
- category: plan ? categoryLabel(plan.use_category) ?? "" : (owner !== null ? "定制化" : "通用办公"),
|
|
|
- owner: plan?.customer_id ?? owner ?? "",
|
|
|
- annualPrice: plan?.annual_price_cents === undefined || plan.annual_price_cents === null ? "" : String(plan.annual_price_cents / 100),
|
|
|
- quota: plan?.sub_account_quota === undefined || plan.sub_account_quota === null ? "" : String(plan.sub_account_quota),
|
|
|
- bandwidthMode: committed === undefined ? "" : committed ? "committed" : "uncommitted",
|
|
|
- upload: plan?.bandwidth_up_mbps === null || plan?.bandwidth_up_mbps === undefined ? "" : String(plan.bandwidth_up_mbps),
|
|
|
- download: plan?.bandwidth_down_mbps === null || plan?.bandwidth_down_mbps === undefined ? "" : String(plan.bandwidth_down_mbps),
|
|
|
- description: plan?.plan_desc ?? "",
|
|
|
- };
|
|
|
-}
|
|
|
-
|
|
|
-function CatalogInfo({ label, children }: { label: string; children: string }) {
|
|
|
- const id = useId();
|
|
|
- return <>
|
|
|
- <button type="button" className="catalog-info" aria-label={label} aria-describedby={id}><Info size={15} aria-hidden="true" /></button>
|
|
|
- <span id={id} className="catalog-info-tip" role="tooltip">{children}</span>
|
|
|
- </>;
|
|
|
-}
|
|
|
-
|
|
|
/**
|
|
|
* 套餐说明:挂在名称右侧的问号图标上,不占一列。图标随行悬停/键盘聚焦显形,点击展开浮层显示说明。
|
|
|
* 浮层走 body 传送门+fixed,避免被台账滚动容器裁掉;**落在图标的左/右侧而非正下方**,
|
|
|
@@ -160,210 +115,11 @@ function PlanDescNote({ name, desc }: { name: string; desc: string }) {
|
|
|
</>;
|
|
|
}
|
|
|
|
|
|
-function PackageEditor({ state, tiers, onClose, onSaved }: {
|
|
|
- state: EditorState; tiers: Load<IpBandwidthTierListResult>; onClose: () => void; onSaved: (message: string, savedPlan: CatalogPlanRow | null) => void;
|
|
|
-}) {
|
|
|
- const original = state.plan;
|
|
|
- /** 锁定:被引用冻结(K204)或合同条目派生档;页面放开名称/说明/成本项,服务端裁决后原样回显拒绝原因。 */
|
|
|
- const derived = Boolean(original?.derived_from_contract_item_id);
|
|
|
- const locked = Boolean(original && (original.frozen === true || derived));
|
|
|
- const settlementId = useId();
|
|
|
- const [values, setValues] = useState(() => formOf(original, state.owner));
|
|
|
- const [costs, setCosts] = useState<CostDraft[]>([]);
|
|
|
- const [costsDirty, setCostsDirty] = useState(false);
|
|
|
- const [error, setError] = useState("");
|
|
|
- const costLoad = useLoad(
|
|
|
- () => (original ? planCostItemList({ plan_id: original.plan_id }).then(rowsOf) : Promise.resolve([] as PlanCostItemRow[])),
|
|
|
- [original?.plan_id],
|
|
|
- );
|
|
|
- useEffect(() => {
|
|
|
- if (original && costLoad.data && !costsDirty) setCosts(costLoad.data.map(costDraftOf));
|
|
|
- }, [costLoad.data, original, costsDirty]);
|
|
|
- useEffect(() => {
|
|
|
- const dialog = document.getElementById("catalog-editor") as HTMLDialogElement | null;
|
|
|
- const previous = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
|
- if (!dialog) return;
|
|
|
- const previousOverflow = document.body.style.overflow;
|
|
|
- document.body.style.overflow = "hidden";
|
|
|
- dialog.showModal();
|
|
|
- return () => { dialog.close(); document.body.style.overflow = previousOverflow; previous?.focus(); };
|
|
|
- }, []);
|
|
|
- /** 归属客户可选项:后端下发的操作人可见客户集合,⛔ 前端拼权限。 */
|
|
|
- const customerOptions = useLoad(() => catalogCustomerOptions().then(rowsOf), []);
|
|
|
- const field = <K extends keyof EditorValues>(key: K, value: EditorValues[K]) => {
|
|
|
- setValues((current) => ({ ...current, [key]: value }));
|
|
|
- setError("");
|
|
|
- };
|
|
|
- /** 带宽档位快捷(2026-11-17 业主裁定):套餐配置里维护的档位即带宽权益的预设备选。
|
|
|
- * 点一条=上下行同值填入;「不承诺带宽」档只切口径、⛔ 清空两格(同 CU-D5 的置灰不清空纪律)。 */
|
|
|
- const tierPresets = useMemo(() => {
|
|
|
- const seen = new Set<string>();
|
|
|
- const rows: { key: string; label: string; mbps: number | null }[] = [];
|
|
|
- for (const item of tiers.data?.items ?? []) {
|
|
|
- const key = tierKeyOf(item.bandwidth_tier_mbps ?? null);
|
|
|
- if (seen.has(key)) continue;
|
|
|
- seen.add(key);
|
|
|
- rows.push({ key, label: item.bandwidth_tier_mbps === null ? "不承诺带宽" : item.tier_name || `${item.bandwidth_tier_mbps} 兆`, mbps: item.bandwidth_tier_mbps ?? null });
|
|
|
- }
|
|
|
- return rows;
|
|
|
- }, [tiers.data]);
|
|
|
- const applyTier = (mbps: number | null) => {
|
|
|
- setValues((current) => mbps === null
|
|
|
- ? { ...current, bandwidthMode: "uncommitted" }
|
|
|
- : { ...current, bandwidthMode: "committed", upload: String(mbps), download: String(mbps) });
|
|
|
- setError("");
|
|
|
- };
|
|
|
- async function submit(event: FormEvent<HTMLFormElement>) {
|
|
|
- event.preventDefault();
|
|
|
- const name = values.name.trim();
|
|
|
- const owner = state.owner === null ? null : values.owner;
|
|
|
- if (!name) { setError("请填写套餐名称。"); return; }
|
|
|
- if (owner !== null && !owner) { setError("请选择归属客户。"); return; }
|
|
|
- if (costLoad.error && costsDirty) { setError("成本项取数失败,整段保存会覆盖后端构成,请重试或放弃本次改动。"); return; }
|
|
|
- let annualPrice = 0;
|
|
|
- let quota = 0;
|
|
|
- let upload: number | null = null;
|
|
|
- let download: number | null = null;
|
|
|
- if (!locked) {
|
|
|
- if (!/^\d+(?:\.\d{1,2})?$/.test(values.annualPrice) || !Number.isFinite(Number(values.annualPrice)) || Number(values.annualPrice) < 0 || Number(values.annualPrice) > 10_000_000) {
|
|
|
- setError("年订阅价格需为非负金额。"); return;
|
|
|
- }
|
|
|
- if (!/^\d+$/.test(values.quota)) { setError("分账号额度需为非负整数。"); return; }
|
|
|
- annualPrice = Number(values.annualPrice);
|
|
|
- quota = Number(values.quota);
|
|
|
- if (values.bandwidthMode === "") { setError("请选择带宽口径(承诺或不承诺)。"); return; }
|
|
|
- if (values.bandwidthMode === "committed") {
|
|
|
- // 文案分档(18 册 R-3):缺格 ⇒ 指名填哪一向;越界 ⇒ 1–1000。两种情形⛔ 共用一句。
|
|
|
- if (!values.upload.trim()) { setError("请填写上行带宽。"); return; }
|
|
|
- if (!values.download.trim()) { setError("请填写下行带宽。"); return; }
|
|
|
- upload = Number(values.upload);
|
|
|
- download = Number(values.download);
|
|
|
- if (!/^\d+$/.test(values.upload) || !/^\d+$/.test(values.download) || upload < 1 || upload > 1000 || download < 1 || download > 1000) {
|
|
|
- setError("上行和下行带宽须分别为 1–1000 Mbps 的整数。"); return;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (costs.some((cost) => !cost.item_name.trim() || (cost.amount.trim() !== "" && !/^\d+(?:\.\d{1,2})?$/.test(cost.amount.trim())))) {
|
|
|
- setError("成本项需填写名称,金额留空表示未配置、否则为非负金额。"); return;
|
|
|
- }
|
|
|
- const costRows = costs.map(costRowOf);
|
|
|
- /** 契约:开关关闭⇒上行/下行两格⛔ 提交(服务端记 FALSE +两列 NULL)。 */
|
|
|
- const bandwidth = values.bandwidthMode === "committed" && upload !== null && download !== null
|
|
|
- ? { bandwidth_committed: true, bandwidth_up_mbps: upload, bandwidth_down_mbps: download }
|
|
|
- : { bandwidth_committed: false };
|
|
|
- try {
|
|
|
- if (!original) {
|
|
|
- /** 自定义档恒为「定制化」(2026-11-15):弹窗不再让选,载荷固定送 customized。 */
|
|
|
- const categoryOf = owner === null ? categoryCode(values.category) : "customized";
|
|
|
- await catalogCreate({
|
|
|
- plan_kind: owner === null ? "fixed" : "custom",
|
|
|
- plan_name: name,
|
|
|
- ...(categoryOf ? { use_category: categoryOf } : {}),
|
|
|
- annual_price_cents: Math.round(annualPrice * 100),
|
|
|
- sub_account_quota: quota,
|
|
|
- ...bandwidth,
|
|
|
- ...(owner ? { customer_id: owner } : {}),
|
|
|
- ...(values.description.trim() ? { plan_desc: values.description.trim() } : {}),
|
|
|
- ...(costRows.length ? { cost_items: costRows } : {}),
|
|
|
- });
|
|
|
- onSaved(`${name}已新建。`, null);
|
|
|
- return;
|
|
|
- }
|
|
|
- await catalogUpdate({
|
|
|
- plan_id: original.plan_id,
|
|
|
- plan_name: name,
|
|
|
- plan_desc: values.description.trim(),
|
|
|
- ...(locked ? {} : {
|
|
|
- annual_price_cents: Math.round(annualPrice * 100),
|
|
|
- sub_account_quota: quota,
|
|
|
- ...bandwidth,
|
|
|
- }),
|
|
|
- ...(original.row_version === undefined || original.row_version === null || original.row_version === "" ? {} : { row_version: Number(original.row_version) }),
|
|
|
- });
|
|
|
- if (costsDirty) await planCostItemSave({ plan_id: original.plan_id, items: costRows });
|
|
|
- onSaved(`${name}已保存。`, original);
|
|
|
- } catch (e) {
|
|
|
- setError(e instanceof ApiError ? e.message : "保存失败,请稍后重试。");
|
|
|
- }
|
|
|
- }
|
|
|
- const settlement = locked
|
|
|
- ? (original?.monthly_settle_cents === null || original?.monthly_settle_cents === undefined ? "" : String(original.monthly_settle_cents / 100))
|
|
|
- : values.annualPrice && /^\d+(?:\.\d{1,2})?$/.test(values.annualPrice)
|
|
|
- ? (Math.floor(Math.round(Number(values.annualPrice) * 100) / 12) / 100).toFixed(2)
|
|
|
- : "";
|
|
|
- return <dialog id="catalog-editor" className="catalog-editor" aria-labelledby="catalog-editor-title" onCancel={onClose} onClick={(event) => { if (event.target === event.currentTarget) onClose(); }}>
|
|
|
- <header className="catalog-editor-head"><div><span>{state.owner === null ? "公共固定套餐" : "客户专属套餐"}</span><h2 id="catalog-editor-title">{original ? "编辑套餐档位" : "新增套餐档位"}</h2></div><button type="button" aria-label="关闭" className="catalog-icon-button" onClick={onClose}><X size={19} /></button></header>
|
|
|
- <form onSubmit={submit} className="catalog-editor-body">
|
|
|
- {locked && <div className="catalog-locked-note"><LockKeyhole size={18} /><p>{derived ? DERIVED_PLAN_EDITABLE : <>已被 {original?.referred_count ?? "—"} 处引用,字段「{FIXED_PLAN_LOCKED_FIELDS.join("、")}」已锁定;调整价格或额度请新建档位,再升级订阅。</>}</p></div>}
|
|
|
- <section><h3><span>01</span> 基本信息</h3><label>套餐名称 <em>*</em><input autoFocus required maxLength={60} value={values.name} onChange={(event) => field("name", event.target.value)} placeholder="输入套餐名称" /></label>
|
|
|
- <div className="catalog-editor-grid">{state.owner === null
|
|
|
- ? <label>用途分类<select disabled={Boolean(original) || locked} value={values.category} onChange={(event) => field("category", event.target.value)}>{!values.category && <option value="">未配置</option>}{packageCategories.filter((item) => item.name !== "定制化" || item.name === values.category).map((item) => <option key={item.name}>{item.name}</option>)}</select></label>
|
|
|
- : <label>用途分类<input disabled value="定制化" /></label>}<label>订阅周期<input disabled value="按年" /></label></div>
|
|
|
- {state.owner !== null && <label>归属客户 <em>*</em>
|
|
|
- <select disabled={locked || Boolean(original)} required value={values.owner} onChange={(event) => field("owner", event.target.value)}>
|
|
|
- <option value="">{customerOptions.loading ? "载入中…" : customerOptions.error ? WORD_FETCH_FAILED : "选择客户"}</option>
|
|
|
- {(customerOptions.data ?? []).map((item) => <option key={item.customer_id} value={item.customer_id}>{item.customer_name}</option>)}
|
|
|
- </select>
|
|
|
- {customerOptions.error && <FetchError message={customerOptions.error.message} onRetry={customerOptions.reload} className="catalog-editor-error" />}
|
|
|
- </label>}
|
|
|
- </section>
|
|
|
- <section>
|
|
|
- <h3><span>02</span> 价格与额度</h3>
|
|
|
- <div className="catalog-editor-grid">
|
|
|
- <label>
|
|
|
- 年订阅价格<span className="sr-only">(元)</span> <em>*</em>
|
|
|
- <span className="catalog-price-input">
|
|
|
- <input disabled={locked} inputMode="decimal" value={values.annualPrice} onChange={(event) => field("annualPrice", event.target.value)} placeholder="0.00" />
|
|
|
- <span className="catalog-price-unit" aria-hidden="true">元</span>
|
|
|
- </span>
|
|
|
- </label>
|
|
|
- <div>
|
|
|
- <div className="catalog-heading-with-info">
|
|
|
- <label htmlFor={settlementId}>月结算标准<span className="sr-only">(元)</span></label>
|
|
|
- <CatalogInfo label="月结算标准说明">年订阅价格除以 12 后向下取整到分。订阅签约时可按合同冻结价格。</CatalogInfo>
|
|
|
- </div>
|
|
|
- <span className="catalog-price-input">
|
|
|
- <input id={settlementId} disabled value={settlement} placeholder="由年价自动计算" />
|
|
|
- <span className="catalog-price-unit" aria-hidden="true">元</span>
|
|
|
- </span>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- <label>分账号额度(个) <em>*</em><input disabled={locked} inputMode="numeric" value={values.quota} onChange={(event) => field("quota", event.target.value)} placeholder="0" /></label>
|
|
|
- </section>
|
|
|
- <section><h3><span>03</span> 带宽与权益</h3><label className="catalog-bandwidth-field">带宽口径<select disabled={locked} value={values.bandwidthMode} onChange={(event) => field("bandwidthMode", event.target.value as EditorValues["bandwidthMode"])}>{values.bandwidthMode === "" && <option value="">未配置</option>}<option value="committed">承诺上下行带宽</option><option value="uncommitted">不承诺带宽</option></select></label>
|
|
|
- {/* 两格**常驻**、非承诺时置灰但⛔ 清空:卸载再挂载会让回切后输入框回读空串
|
|
|
- (18 册 CU-D5),且 DOM 与 state 脱节。 */}
|
|
|
- <div className="catalog-editor-grid"><label>上行带宽(Mbps)<input disabled={locked || values.bandwidthMode !== "committed"} inputMode="numeric" value={values.upload} onChange={(event) => field("upload", event.target.value)} placeholder="1–1000" /></label><label>下行带宽(Mbps)<input disabled={locked || values.bandwidthMode !== "committed"} inputMode="numeric" value={values.download} onChange={(event) => field("download", event.target.value)} placeholder="1–1000" /></label></div>
|
|
|
- {!locked && tierPresets.length > 0 && <div className="catalog-bandwidth-presets">
|
|
|
- <span className="catalog-bandwidth-presets-label">档位快捷<small>(取自「线路出口」Tab 的带宽档位)</small></span>
|
|
|
- <div className="catalog-bandwidth-presets-list">
|
|
|
- {tierPresets.map((preset) => {
|
|
|
- const on = preset.mbps === null
|
|
|
- ? values.bandwidthMode === "uncommitted"
|
|
|
- : values.bandwidthMode === "committed" && values.upload.trim() === String(preset.mbps) && values.download.trim() === String(preset.mbps);
|
|
|
- return <button key={preset.key} type="button" aria-pressed={on} className={`catalog-bandwidth-preset${on ? " is-on" : ""}`} title={preset.mbps === null ? "口径设为不承诺带宽(两格仅置灰,⛔ 不清空)" : `上下行各 ${preset.mbps} Mbps`} onClick={() => applyTier(preset.mbps)}>{preset.label}</button>;
|
|
|
- })}
|
|
|
- </div>
|
|
|
- </div>}
|
|
|
- <p>带宽作为套餐属性保存,首期不按带宽拆分计价。</p><label>套餐说明<textarea rows={4} value={values.description} onChange={(event) => field("description", event.target.value)} placeholder="说明适用场景、服务权益和报价口径" /></label></section>
|
|
|
- <section className="catalog-cost-editor">
|
|
|
- <div className="catalog-heading-with-info">
|
|
|
- <h3><span>04</span> 月成本项</h3>
|
|
|
- <CatalogInfo label="月成本项说明">{`${PLAN_COST_ITEM_SAVE_NOTE}(整段全量替换,逐行增删不单独提交)`}</CatalogInfo>
|
|
|
- </div>
|
|
|
- {costLoad.error && <FetchError message={costLoad.error.message} onRetry={costLoad.reload} className="catalog-editor-error" />}
|
|
|
- {costs.map((cost, index) => <div className="catalog-cost-editor-row" key={index}><input aria-label={`成本项 ${index + 1} 名称`} maxLength={60} value={cost.item_name} onChange={(event) => { setCostsDirty(true); setCosts((current) => current.map((item, i) => i === index ? { ...item, item_name: event.target.value } : item)); }} placeholder="成本项名称" /><span className="catalog-price-input"><input aria-label={`成本项 ${index + 1} 金额`} inputMode="decimal" value={cost.amount} onChange={(event) => { setCostsDirty(true); setCosts((current) => current.map((item, i) => i === index ? { ...item, amount: event.target.value } : item)); }} placeholder="金额" /></span><button aria-label={`移除成本项 ${index + 1}`} onClick={() => { setCostsDirty(true); setCosts((current) => current.filter((_, i) => i !== index)); }} type="button"><X size={16} /></button></div>)}
|
|
|
- <button className="catalog-cost-add" onClick={() => { setCostsDirty(true); setCosts((current) => [...current, { item_name: "", amount: "", billing_unit: "", remark: "" }]); }} type="button"><Plus size={15} /> 添加成本项</button>
|
|
|
- </section>
|
|
|
- {error && <p className="catalog-editor-error" role="alert">{error}</p>}
|
|
|
- <footer><button type="button" className="catalog-button catalog-button-secondary" onClick={onClose}>取消</button><button type="submit" className="catalog-button catalog-button-primary">{original ? "保存修改" : "新建套餐"}</button></footer>
|
|
|
- </form>
|
|
|
- </dialog>;
|
|
|
-}
|
|
|
-
|
|
|
/** 台账列宽:序号/操作列固定,其余按阅读需求分配(同合同台账口径)。
|
|
|
* 套餐说明已收进名称旁问号图标,不再单列;用途分类改由表体内分组行承载,两 Tab 同列(2026-11-15)。 */
|
|
|
const PLAN_COLUMNS = [58, 250, 122, 122, 108, 96, 168, 84, 118] as const;
|
|
|
+/** 自定义档台账多两列:建档人/建档团队(固定档不加)。 */
|
|
|
+const CUSTOM_PLAN_COLUMNS = [...PLAN_COLUMNS, 132, 132] as const;
|
|
|
|
|
|
/**
|
|
|
* 自定义档台账行:与固定档同形的精简行(⛔ 档位编号/类型标签/单位后缀/货币符号)。
|
|
|
@@ -380,7 +136,7 @@ function CustomPlanRow({ plan, index, writable, readOnlyNote, onEdit, onDelete }
|
|
|
<span className="catalog-plan-name">
|
|
|
<strong title={plan.plan_name || undefined}>{plan.plan_name || <Tri tone="missing" text={WORD_UNCONFIGURED} />}</strong>
|
|
|
{plan.plan_desc ? <PlanDescNote name={plan.plan_name || plan.plan_id} desc={plan.plan_desc} /> : null}
|
|
|
- {plan.derived_from_contract_item_id ? <span className="catalog-plan-tag">合同条目派生</span> : null}
|
|
|
+ {plan.plan_family ? <span className="catalog-plan-tag">{familyLabel(plan.plan_family)}</span> : null}
|
|
|
</span>
|
|
|
<small className="catalog-plan-owner" title={plan.customer_name ?? undefined}>归属客户 · {plan.customer_name || WORD_UNCONFIGURED}</small>
|
|
|
</td>
|
|
|
@@ -390,27 +146,23 @@ function CustomPlanRow({ plan, index, writable, readOnlyNote, onEdit, onDelete }
|
|
|
<td>{intCell(plan.sub_account_quota)}</td>
|
|
|
<td>{ledgerBandwidth(plan)}</td>
|
|
|
<td title="后端 referred_count:被合同条目/订阅引用数">{intCell(plan.referred_count)}</td>
|
|
|
- <td>{plan.derived_from_contract_item_id
|
|
|
- ? (writable
|
|
|
- ? <div className="catalog-row-actions"><button type="button" className="is-danger" aria-label="删除套餐" onClick={onDelete} title="派生自定义档是合同条目的只读投影:目录侧无编辑/改名入口,改数回合同条目改;未被订阅引用时可删除"><Trash2 size={15} /></button></div>
|
|
|
- : <small className="catalog-readonly-note">合同条目派生 · 只读</small>)
|
|
|
- : writable
|
|
|
- ? <div className="catalog-row-actions"><button type="button" aria-label="编辑套餐" onClick={onEdit} title="编辑套餐"><PencilLine size={15} /></button><button type="button" className="is-danger" aria-label="删除套餐" onClick={onDelete} title="删除套餐(引用拦截由服务端判定)"><Trash2 size={15} /></button></div>
|
|
|
- : <small className="catalog-readonly-note">{readOnlyNote}</small>}</td>
|
|
|
+ <td title={plan.created_by ?? undefined}>{plan.created_by_name || <Tri tone="missing" text={WORD_UNCONFIGURED} />}</td>
|
|
|
+ <td title={plan.created_team_id ?? undefined}>{plan.created_team_name || <Tri tone="missing" text={WORD_UNCONFIGURED} />}</td>
|
|
|
+ <td>{writable
|
|
|
+ ? <div className="catalog-row-actions"><button type="button" aria-label="编辑套餐" onClick={onEdit} title="编辑套餐"><PencilLine size={15} /></button><button type="button" className="is-danger" aria-label="删除套餐" onClick={onDelete} title="删除套餐(引用拦截由服务端判定)"><Trash2 size={15} /></button></div>
|
|
|
+ : <small className="catalog-readonly-note">{readOnlyNote}</small>}</td>
|
|
|
</tr>;
|
|
|
}
|
|
|
|
|
|
/** 固定档按用途分类分组的一行表头(分组落在表体内,与原型同形):分类名+「X · 口径说明」(X 为订阅方式值,不再冠「订阅方式:」)。
|
|
|
* 用途分类由本行承载,档位行不再单列该字段(2026-11-15)。 */
|
|
|
-function PlanGroupRow({ title, hint }: { title: string; hint?: string }) {
|
|
|
- return <tr className="catalog-group-row"><td colSpan={9}><strong>{title}</strong>{hint && <span>{hint}</span>}</td></tr>;
|
|
|
+function PlanGroupRow({ title, hint, colSpan }: { title: string; hint?: string; colSpan: number }) {
|
|
|
+ return <tr className="catalog-group-row"><td colSpan={colSpan}><strong>{title}</strong>{hint && <span>{hint}</span>}</td></tr>;
|
|
|
}
|
|
|
|
|
|
-/** 原型 `pkgSubMode`:用途分类决定订阅方式(叠加增值可叠加、定制化单独约定、其余可升降配)。 */
|
|
|
-function orderModeOf(category: string) {
|
|
|
- if (category === "叠加增值") return "可叠加";
|
|
|
- if (category === "定制化") return "单独约定";
|
|
|
- return "可升降配";
|
|
|
+/** 交付形态对应的订阅方式提示(`link` 可升降配、`addon` 可叠加)。 */
|
|
|
+function orderModeOf(family: string) {
|
|
|
+ return family === "addon" ? "可叠加" : "可升降配";
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -427,7 +179,7 @@ function FixedPlanRow({ plan, index, writable, readOnlyNote, onEdit, onDelete }:
|
|
|
<span className="catalog-plan-name">
|
|
|
<strong>{plan.plan_name || <Tri tone="missing" text={WORD_UNCONFIGURED} />}</strong>
|
|
|
{plan.plan_desc ? <PlanDescNote name={plan.plan_name || plan.plan_id} desc={plan.plan_desc} /> : null}
|
|
|
- {plan.derived_from_contract_item_id ? <span className="catalog-plan-tag">合同条目派生</span> : null}
|
|
|
+ {plan.plan_family ? <span className="catalog-plan-tag">{familyLabel(plan.plan_family)}</span> : null}
|
|
|
</span>
|
|
|
</td>
|
|
|
<td className="catalog-ledger-price">{ledgerMoney(plan.annual_price_cents)}</td>
|
|
|
@@ -436,13 +188,9 @@ function FixedPlanRow({ plan, index, writable, readOnlyNote, onEdit, onDelete }:
|
|
|
<td>{intCell(plan.sub_account_quota)}</td>
|
|
|
<td>{ledgerBandwidth(plan)}</td>
|
|
|
<td title="后端 referred_count:被合同条目/订阅引用数">{intCell(plan.referred_count)}</td>
|
|
|
- <td>{plan.derived_from_contract_item_id
|
|
|
- ? (writable
|
|
|
- ? <div className="catalog-row-actions"><button type="button" className="is-danger" aria-label="删除套餐" onClick={onDelete} title="派生自定义档是合同条目的只读投影:目录侧无编辑/改名入口,改数回合同条目改;未被订阅引用时可删除"><Trash2 size={15} /></button></div>
|
|
|
- : <small className="catalog-readonly-note">合同条目派生 · 只读</small>)
|
|
|
- : writable
|
|
|
- ? <div className="catalog-row-actions"><button type="button" aria-label="编辑套餐" onClick={onEdit} title="编辑套餐"><PencilLine size={15} /></button><button type="button" className="is-danger" aria-label="删除套餐" onClick={onDelete} title="删除套餐(引用拦截由服务端判定)"><Trash2 size={15} /></button></div>
|
|
|
- : <small className="catalog-readonly-note">{readOnlyNote}</small>}</td>
|
|
|
+ <td>{writable
|
|
|
+ ? <div className="catalog-row-actions"><button type="button" aria-label="编辑套餐" onClick={onEdit} title="编辑套餐"><PencilLine size={15} /></button><button type="button" className="is-danger" aria-label="删除套餐" onClick={onDelete} title="删除套餐(引用拦截由服务端判定)"><Trash2 size={15} /></button></div>
|
|
|
+ : <small className="catalog-readonly-note">{readOnlyNote}</small>}</td>
|
|
|
</tr>;
|
|
|
}
|
|
|
|
|
|
@@ -730,15 +478,14 @@ export function PackageManagementPage() {
|
|
|
const timer = window.setTimeout(() => setNotice(""), NOTICE_DISMISS_MS);
|
|
|
return () => window.clearTimeout(timer);
|
|
|
}, [notice]);
|
|
|
- /** 自定义档恒为「定制化」用途分类;用途分类筛选只在固定档 Tab 出现(2026-11-15)。 */
|
|
|
const isCustomTab = tab === "custom";
|
|
|
- /** 用途分类改为表体内分组行承载,两个 Tab 同为 9 列(2026-11-15)。 */
|
|
|
- const ledgerColSpan = 9;
|
|
|
+ /** 自定义档多「建档人/建档团队」两列;固定档仍 9 列。 */
|
|
|
+ const ledgerColSpan = isCustomTab ? 11 : 9;
|
|
|
/** 检索一次算清,两个 tab 各取自己那一半;计数同源(总则§6.3),⛔ 各算一次。
|
|
|
* 自定义档没有可选分类,进自定义 Tab 时分类筛选不参与过滤(否则会筛成空表)。 */
|
|
|
const activeCategory = isCustomTab ? "all" : category;
|
|
|
- const filtered = useMemo(() => rows.filter((plan) => (activeCategory === "all" || categoryLabel(plan.use_category) === activeCategory)
|
|
|
- && `${plan.plan_name} ${categoryLabel(plan.use_category) ?? ""} ${bandwidthTextOfRow(plan).text} ${plan.plan_desc ?? ""} ${plan.customer_name ?? ""}`.toLowerCase().includes(search.trim().toLowerCase())), [rows, activeCategory, search]);
|
|
|
+ const filtered = useMemo(() => rows.filter((plan) => (activeCategory === "all" || plan.plan_family === activeCategory)
|
|
|
+ && `${plan.plan_name} ${familyLabel(plan.plan_family) ?? ""} ${bandwidthTextOfRow(plan).text} ${plan.plan_desc ?? ""} ${plan.customer_name ?? ""} ${plan.created_by_name ?? ""} ${plan.created_team_name ?? ""}`.toLowerCase().includes(search.trim().toLowerCase())), [rows, activeCategory, search]);
|
|
|
const fixed = filtered.filter((plan) => plan.plan_kind !== "custom");
|
|
|
const custom = filtered.filter((plan) => plan.plan_kind === "custom");
|
|
|
const fixedCount = rows.filter((plan) => plan.plan_kind !== "custom").length;
|
|
|
@@ -749,12 +496,12 @@ export function PackageManagementPage() {
|
|
|
/** 固定套餐按用途分类分组,分组行落在表体内;后端不下发 use_category 的档位单列一组,⛔ 静默丢行。
|
|
|
* 序号取「表内显示顺序」(分组后位置),⛔ 用后端数组下标——否则分组一排序就出现 7 在 6 前面。 */
|
|
|
const fixedGroups = useMemo(() => {
|
|
|
- const nameOf = (plan: CatalogPlanRow) => categoryLabel(plan.use_category);
|
|
|
- const known = packageCategories
|
|
|
- .map((item) => ({ name: item.name as string, hint: `${orderModeOf(item.name)} · ${item.hint}`, plans: pageRows.filter((plan) => nameOf(plan) === item.name) }))
|
|
|
+ const familyOf = (plan: CatalogPlanRow) => plan.plan_family;
|
|
|
+ const known = planFamilies
|
|
|
+ .map((item) => ({ name: item.name as string, hint: `${orderModeOf(item.code)} · ${item.hint}`, plans: pageRows.filter((plan) => familyOf(plan) === item.code) }))
|
|
|
.filter((group) => group.plans.length > 0);
|
|
|
- const uncategorized = pageRows.filter((plan) => !packageCategories.some((item) => item.name === nameOf(plan)));
|
|
|
- const groups = uncategorized.length ? [...known, { name: WORD_UNCONFIGURED, hint: `用途分类:${WORD_NOT_PROVIDED}`, plans: uncategorized }] : known;
|
|
|
+ const uncategorized = pageRows.filter((plan) => !planFamilies.some((item) => item.code === familyOf(plan)));
|
|
|
+ const groups = uncategorized.length ? [...known, { name: WORD_UNCONFIGURED, hint: `交付形态:${WORD_NOT_PROVIDED}`, plans: uncategorized }] : known;
|
|
|
let position = 0;
|
|
|
return groups.map((group) => ({ name: group.name, hint: group.hint, entries: group.plans.map((plan) => ({ plan, position: position++ })) }));
|
|
|
}, [pageRows]);
|
|
|
@@ -857,7 +604,7 @@ export function PackageManagementPage() {
|
|
|
<div className="ops-toolbar">
|
|
|
<label className="ops-search"><Search size={17} /><Input aria-label="搜索套餐" placeholder={isCustomTab ? "搜索名称、带宽、说明或归属客户" : "搜索名称、分类、带宽、说明或归属客户"} value={search} onChange={(event) => { setSearch(event.target.value); paging.resetPage(); }} />{search && <button type="button" aria-label="清空搜索" onClick={() => { setSearch(""); paging.resetPage(); }}><X size={15} /></button>}</label>
|
|
|
{/* 自定义档恒为「定制化」,没有可选项 ⇒ 该 Tab 不出分类筛选(⛔ 给一个筛完必空的控件)。 */}
|
|
|
- {!isCustomTab && <FilterSelect icon="type" aria-label="用途分类筛选" value={category} onChange={(event) => { setCategory(event.target.value); paging.resetPage(); }}><option value="all">全部用途分类</option>{packageCategories.map((item) => <option key={item.name}>{item.name}</option>)}</FilterSelect>}
|
|
|
+ {!isCustomTab && <FilterSelect icon="type" aria-label="交付形态筛选" value={category} onChange={(event) => { setCategory(event.target.value); paging.resetPage(); }}><option value="all">全部交付形态</option>{planFamilies.map((item) => <option key={item.code} value={item.code}>{item.name}</option>)}</FilterSelect>}
|
|
|
{(search || (!isCustomTab && category !== "all")) && <Button variant="ghost" size="sm" onClick={resetFilters}>重置筛选</Button>}
|
|
|
<span className="catalog-ledger-note">{tab === "custom" ? "自定义套餐只属于一个客户,不进公共目录" : "固定套餐为公共档,所有客户可选"}{truncated ? `;目录共 ${truncated} 条,当前仅载入 ${rows.length} 条` : ""}</span>
|
|
|
{/* 新增入口跟着 Tab 走:固定档只有总运营能新建,自定义套餐由总运营/运营主账号建。 */}
|
|
|
@@ -866,16 +613,16 @@ export function PackageManagementPage() {
|
|
|
? <button type="button" className="catalog-button catalog-button-primary catalog-toolbar-action" onClick={() => setEditor({ owner: null })}><Plus size={17} />新增固定套餐</button>
|
|
|
: <span className="catalog-head-note catalog-toolbar-action">区域运营不能配置公共固定档</span>)
|
|
|
: (canWrite
|
|
|
- ? <button type="button" className="catalog-button catalog-button-primary catalog-toolbar-action" onClick={() => setEditor({ owner: "" })}><Plus size={17} />新增自定义套餐</button>
|
|
|
+ ? <button type="button" className="catalog-button catalog-button-primary catalog-toolbar-action" onClick={() => setEditor({ owner: "", planKind: "custom" })}><Plus size={17} />新增自定义套餐</button>
|
|
|
: <span className="catalog-head-note catalog-toolbar-action">本角色只读,不能新增自定义套餐</span>)}
|
|
|
</div>
|
|
|
<div ref={tableOverflow.ref} tabIndex={0} role="region" aria-label="套餐档位台账,可横向滚动查看字段" className={`measured-table-scroll ops-table-wrap catalog-table-wrap${tableOverflow.overflow ? " has-horizontal-overflow" : ""}${tableOverflow.canScrollLeft ? " can-scroll-left" : ""}${tableOverflow.canScrollRight ? " can-scroll-right" : ""}`}>
|
|
|
<table className="ops-table catalog-ledger">
|
|
|
- <OpsTableColumns widths={PLAN_COLUMNS} />
|
|
|
- <thead><tr><th>序号</th><th>套餐</th><th>年订阅价格</th><th>月结算标准</th><th>月成本</th><th>分账号额度</th><th>总带宽</th><th>订阅量</th><th>操作</th></tr></thead>
|
|
|
+ <OpsTableColumns widths={isCustomTab ? CUSTOM_PLAN_COLUMNS : PLAN_COLUMNS} />
|
|
|
+ <thead><tr><th>序号</th><th>套餐</th><th>年订阅价格</th><th>月结算标准</th><th>月成本</th><th>分账号额度</th><th>总带宽</th><th>订阅量</th>{isCustomTab && <><th>建档人</th><th>建档团队</th></>}<th>操作</th></tr></thead>
|
|
|
<tbody>
|
|
|
{tab === "fixed"
|
|
|
- ? fixedGroups.map((group) => <Fragment key={group.name}><PlanGroupRow title={group.name} hint={group.hint} />{group.entries.map(({ plan, position }) => fixedRow(plan, position))}</Fragment>)
|
|
|
+ ? fixedGroups.map((group) => <Fragment key={group.name}><PlanGroupRow title={group.name} hint={group.hint} colSpan={ledgerColSpan} />{group.entries.map(({ plan, position }) => fixedRow(plan, position))}</Fragment>)
|
|
|
: pageRows.map((plan, index) => planRow(plan, index))}
|
|
|
{(!catalog.error && visible.length === 0) && <OpsTableEmpty colSpan={ledgerColSpan}>{emptyMessage}</OpsTableEmpty>}
|
|
|
{catalog.error && <OpsTableEmpty colSpan={ledgerColSpan}>{emptyMessage}</OpsTableEmpty>}
|
|
|
@@ -887,7 +634,7 @@ export function PackageManagementPage() {
|
|
|
</div>
|
|
|
{notice && <div className="catalog-toast" role="status"><span>{notice}</span><button aria-label="关闭提示" onClick={() => setNotice("")}><X size={16} /></button></div>}
|
|
|
{failure && <div className="catalog-toast" role="alert"><span>{failure}</span><button aria-label="关闭提示" onClick={() => setFailure("")}><X size={16} /></button></div>}
|
|
|
- {editor && <PackageEditor key={editor.plan?.plan_id ?? `new-${editor.owner ?? "fixed"}`} state={editor} tiers={tiers} onClose={() => setEditor(null)} onSaved={saved} />}
|
|
|
+ {editor && <PackagePlanEditor key={editor.plan?.plan_id ?? `new-${editor.owner ?? "fixed"}`} state={editor} tiers={tiers} onClose={() => setEditor(null)} onSaved={saved} />}
|
|
|
{deleteTarget && <div className="catalog-confirm-backdrop"><div className="catalog-confirm" role="alertdialog" aria-modal="true" aria-labelledby="catalog-confirm-title">
|
|
|
{deleteError
|
|
|
? <><span className="catalog-confirm-icon"><Trash2 size={20} /></span><h2 id="catalog-confirm-title">无法删除该套餐档位</h2><p>{deleteError}</p>
|