|
@@ -0,0 +1,552 @@
|
|
|
|
|
+/**
|
|
|
|
|
+ * 套餐目录(路由 `catalog`)—— 页面契约 14.1。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 两张表(固定档/自定义档)**一次请求**按 `plan_kind` 分组(`/catalog/get_list@v1`),⛔ 两次请求。
|
|
|
|
|
+ * 写口只走 `catalog/create`/`catalog/update`/`catalog/delete`;随附成本项走整段 `plan_cost_item/save`。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 禁止入口清单(14.1 底部,逐条不渲染):档位列表的状态列按钮与批量操作、导出、规格列、
|
|
|
|
|
+ * 子账号配额列、成本构成列合计、成本构成行删除按钮、批量设置成本构成、成本构成历史、档位复制。
|
|
|
|
|
+ */
|
|
|
|
|
+import { useCallback, useRef, useState } from "react";
|
|
|
|
|
+import { catalogCreate, catalogCustomerOptions, catalogDelete, catalogGet, catalogGetList, catalogUpdate, planCostItemList, planCostItemSave, rowsOf } from "../api/bos";
|
|
|
|
|
+import { label, OPTIONS, PLAN_KIND, SUB_MODE, USE_CATEGORY } from "../api/labels";
|
|
|
|
|
+import {
|
|
|
|
|
+ COST_ITEM_EMPTY,
|
|
|
|
|
+ DERIVED_PLAN_BADGE,
|
|
|
|
|
+ DERIVED_PLAN_EDITABLE,
|
|
|
|
|
+ FIXED_PLAN_LOCKED_FIELDS,
|
|
|
|
|
+ OPERATOR_ONLY_CONFIG,
|
|
|
|
|
+ PLAN_COST_ITEM_SAVE_NOTE,
|
|
|
|
|
+ SUB_MODE_BY_CATEGORY,
|
|
|
|
|
+ WORD_FETCH_FAILED,
|
|
|
|
|
+ WORD_UNCONFIGURED,
|
|
|
|
|
+} from "../api/lockedCopy";
|
|
|
|
|
+import { hasBizCode } from "../api/http";
|
|
|
|
|
+import type { CatalogPlanRow, PlanCostItemRow } from "../api/types";
|
|
|
|
|
+import { Async, Btn, Cell, ErrorBox, Field, Modal, Notice, Pager, Panel, Pill, day, money, seq } from "../components/ui";
|
|
|
|
|
+import { Tri, triTone } from "../components/triState";
|
|
|
|
|
+import { Shell } from "../layout/Shell";
|
|
|
|
|
+import { useSession } from "../auth/session";
|
|
|
|
|
+import { useForm, useLoad, useSubmit } from "../hooks/useLoad";
|
|
|
|
|
+
|
|
|
|
|
+/** 月成本单元格:三态+悬停看构成(`plan_cost_item/get_list`,悬停发起、失败即「取数失败」)。 */
|
|
|
|
|
+function CostCell({ plan }: { plan: CatalogPlanRow }) {
|
|
|
|
|
+ const [pop, setPop] = useState<{ items?: PlanCostItemRow[]; error?: unknown } | null>(null);
|
|
|
|
|
+ const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
|
|
|
+
|
|
|
|
|
+ const open = useCallback(async () => {
|
|
|
|
|
+ setPop({});
|
|
|
|
|
+ try {
|
|
|
|
|
+ const items = await planCostItemList({ plan_id: plan.plan_id });
|
|
|
|
|
+ setPop({ items: rowsOf(items) });
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ setPop({ error: e });
|
|
|
|
|
+ }
|
|
|
|
|
+ }, [plan.plan_id]);
|
|
|
|
|
+
|
|
|
|
|
+ const tone = triTone(plan.plan_cost_state, plan.plan_cost_cents !== null && plan.plan_cost_cents !== undefined);
|
|
|
|
|
+ const text = tone === "val" ? money(plan.plan_cost_cents) : tone === "fail" ? WORD_FETCH_FAILED : WORD_UNCONFIGURED;
|
|
|
|
|
+
|
|
|
|
|
+ return (
|
|
|
|
|
+ <span
|
|
|
|
|
+ style={{ position: "relative" }}
|
|
|
|
|
+ onMouseEnter={() => {
|
|
|
|
|
+ if (timer.current) clearTimeout(timer.current);
|
|
|
|
|
+ timer.current = setTimeout(open, 200);
|
|
|
|
|
+ }}
|
|
|
|
|
+ onMouseLeave={() => {
|
|
|
|
|
+ if (timer.current) clearTimeout(timer.current);
|
|
|
|
|
+ setPop(null);
|
|
|
|
|
+ }}
|
|
|
|
|
+ >
|
|
|
|
|
+ <Tri tone={tone} text={text} title="悬停查看月成本构成" />
|
|
|
|
|
+ {pop ? (
|
|
|
|
|
+ <span className="qtip" style={{ whiteSpace: "nowrap" }}>
|
|
|
|
|
+ {pop.error ? WORD_FETCH_FAILED : pop.items ? (pop.items.length ? pop.items.map((it) => `${it.item_name} ${money(it.amount_cents)}`).join(";") : COST_ITEM_EMPTY) : "读取中…"}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ ) : null}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ );
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/** 带宽三态单元格:未承诺(开关关,无数字)/未填(承诺但某向为空)/未配置(该向取数失败)。 */
|
|
|
|
|
+function BandwidthCell({ plan }: { plan: CatalogPlanRow }) {
|
|
|
|
|
+ if (plan.bandwidth_committed === null || plan.bandwidth_committed === undefined) {
|
|
|
|
|
+ return <Tri tone="missing" text={WORD_UNCONFIGURED} />;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!plan.bandwidth_committed) return <Tri tone="missing" text="未承诺" />;
|
|
|
|
|
+ const up = plan.bandwidth_up_mbps;
|
|
|
|
|
+ const down = plan.bandwidth_down_mbps;
|
|
|
|
|
+ if (up === null || up === undefined || down === null || down === undefined) {
|
|
|
|
|
+ const fail = plan.bandwidth_up_mbps === undefined && plan.bandwidth_down_mbps === undefined;
|
|
|
|
|
+ return <Tri tone={fail ? "fail" : "missing"} text={fail ? WORD_FETCH_FAILED : "未填"} title="已承诺带宽,但上/下行至少一路为空" />;
|
|
|
|
|
+ }
|
|
|
|
|
+ return (
|
|
|
|
|
+ <span>
|
|
|
|
|
+ 上行 {up} / 下行 {down} Mbps
|
|
|
|
|
+ </span>
|
|
|
|
|
+ );
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/** 随附成本项整段编辑器:整段编辑+「添加成本项」+「清空本段」,⛔ 逐行删除按钮、⛔ 合计。 */
|
|
|
|
|
+function CostItemsEditor({ items, onChange }: { items: PlanCostItemRow[]; onChange: (v: PlanCostItemRow[]) => void }) {
|
|
|
|
|
+ const patch = (i: number, k: keyof PlanCostItemRow, v: string) => {
|
|
|
|
|
+ const next = items.map((it, idx) => {
|
|
|
|
|
+ if (idx !== i) return it;
|
|
|
|
|
+ if (k === "amount_cents") return { ...it, amount_cents: v === "" ? null : Math.round(Number(v) * 100) };
|
|
|
|
|
+ return { ...it, [k]: v };
|
|
|
|
|
+ });
|
|
|
|
|
+ onChange(next);
|
|
|
|
|
+ };
|
|
|
|
|
+ return (
|
|
|
|
|
+ <>
|
|
|
|
|
+ <table className="sub">
|
|
|
|
|
+ <thead>
|
|
|
|
|
+ <tr>
|
|
|
|
|
+ <th>名称</th>
|
|
|
|
|
+ <th>金额</th>
|
|
|
|
|
+ <th>计费单位</th>
|
|
|
|
|
+ <th>分类</th>
|
|
|
|
|
+ <th>说明</th>
|
|
|
|
|
+ </tr>
|
|
|
|
|
+ </thead>
|
|
|
|
|
+ <tbody>
|
|
|
|
|
+ {items.length === 0 ? (
|
|
|
|
|
+ <tr>
|
|
|
|
|
+ <td colSpan={5}>
|
|
|
|
|
+ <span className="note">{COST_ITEM_EMPTY}</span>
|
|
|
|
|
+ </td>
|
|
|
|
|
+ </tr>
|
|
|
|
|
+ ) : (
|
|
|
|
|
+ items.map((it, i) => (
|
|
|
|
|
+ <tr key={i}>
|
|
|
|
|
+ <td>
|
|
|
|
|
+ <input value={it.item_name ?? ""} onChange={(e) => patch(i, "item_name", e.target.value)} />
|
|
|
|
|
+ </td>
|
|
|
|
|
+ <td>
|
|
|
|
|
+ <input
|
|
|
|
|
+ type="number"
|
|
|
|
|
+ min={0}
|
|
|
|
|
+ step="0.01"
|
|
|
|
|
+ value={it.amount_cents === null || it.amount_cents === undefined ? "" : String(it.amount_cents / 100)}
|
|
|
|
|
+ onChange={(e) => patch(i, "amount_cents", e.target.value)}
|
|
|
|
|
+ />
|
|
|
|
|
+ </td>
|
|
|
|
|
+ <td>
|
|
|
|
|
+ <input value={it.billing_unit ?? ""} onChange={(e) => patch(i, "billing_unit", e.target.value)} />
|
|
|
|
|
+ </td>
|
|
|
|
|
+ <td>
|
|
|
|
|
+ <input value={it.category ?? ""} onChange={(e) => patch(i, "category", e.target.value)} />
|
|
|
|
|
+ </td>
|
|
|
|
|
+ <td>
|
|
|
|
|
+ <input value={it.remark ?? ""} onChange={(e) => patch(i, "remark", e.target.value)} />
|
|
|
|
|
+ </td>
|
|
|
|
|
+ </tr>
|
|
|
|
|
+ ))
|
|
|
|
|
+ )}
|
|
|
|
|
+ </tbody>
|
|
|
|
|
+ </table>
|
|
|
|
|
+ <div className="row" style={{ marginTop: 8 }}>
|
|
|
|
|
+ <Btn ghost onClick={() => onChange([...items, { item_name: "", amount_cents: null, billing_unit: null, category: null, remark: null }])}>
|
|
|
|
|
+ 添加成本项
|
|
|
|
|
+ </Btn>
|
|
|
|
|
+ <Btn ghost onClick={() => onChange([])}>
|
|
|
|
|
+ 清空本段
|
|
|
|
|
+ </Btn>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <p className="note">{PLAN_COST_ITEM_SAVE_NOTE}</p>
|
|
|
|
|
+ </>
|
|
|
|
|
+ );
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+const EMPTY_COST: PlanCostItemRow[] = [];
|
|
|
|
|
+
|
|
|
|
|
+export default function CatalogPage() {
|
|
|
|
|
+ const { ctx } = useSession();
|
|
|
|
|
+ const isAdmin = ctx?.role_code === "admin";
|
|
|
|
|
+ const [f, setF] = useState({ keyword: "", use_category: "", page: 1, page_size: 20 });
|
|
|
|
|
+ const [draft, setDraft] = useState<{ plan?: CatalogPlanRow; kind: string; customers?: { customer_id: string; customer_name: string }[] } | null>(null);
|
|
|
|
|
+ const [del, setDel] = useState<{ plan: CatalogPlanRow; result?: unknown; error?: unknown } | null>(null);
|
|
|
|
|
+ const [detail, setDetail] = useState<{ plan: CatalogPlanRow; cost_items?: PlanCostItemRow[]; locked?: boolean; referred?: number | null } | null>(null);
|
|
|
|
|
+ const [costItems, setCostItems] = useState<PlanCostItemRow[]>(EMPTY_COST);
|
|
|
|
|
+ const form = useForm({
|
|
|
|
|
+ plan_name: "",
|
|
|
|
|
+ use_category: "office",
|
|
|
|
|
+ customer_id: "",
|
|
|
|
|
+ annual_price_cents: "",
|
|
|
|
|
+ sub_account_quota: "",
|
|
|
|
|
+ bandwidth_committed: "1",
|
|
|
|
|
+ bandwidth_up_mbps: "",
|
|
|
|
|
+ bandwidth_down_mbps: "",
|
|
|
|
|
+ plan_desc: "",
|
|
|
|
|
+ sort_no: "",
|
|
|
|
|
+ });
|
|
|
|
|
+ const sub = useSubmit();
|
|
|
|
|
+
|
|
|
|
|
+ const list = useLoad(
|
|
|
|
|
+ () => catalogGetList({ keyword: f.keyword || undefined, use_category: f.use_category || undefined, page: f.page - 1, page_size: f.page_size }),
|
|
|
|
|
+ [f.keyword, f.use_category, f.page, f.page_size],
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ const rows = list.data?.items ?? [];
|
|
|
|
|
+ /** 一次请求后按 plan_kind 前端分组;后端如回 `fixed`/`custom` 两段则优先使用。 */
|
|
|
|
|
+ const fixed = list.data?.fixed ?? rows.filter((r) => r.plan_kind === "fixed");
|
|
|
|
|
+ const custom = list.data?.custom ?? rows.filter((r) => r.plan_kind !== "fixed");
|
|
|
|
|
+
|
|
|
|
|
+ const openCreate = async (kind: string) => {
|
|
|
|
|
+ form.reset({
|
|
|
|
|
+ plan_name: "",
|
|
|
|
|
+ use_category: kind === "fixed" ? "office" : "customized",
|
|
|
|
|
+ customer_id: "",
|
|
|
|
|
+ annual_price_cents: "",
|
|
|
|
|
+ sub_account_quota: "",
|
|
|
|
|
+ bandwidth_committed: "1",
|
|
|
|
|
+ bandwidth_up_mbps: "",
|
|
|
|
|
+ bandwidth_down_mbps: "",
|
|
|
|
|
+ plan_desc: "",
|
|
|
|
|
+ sort_no: "",
|
|
|
|
|
+ });
|
|
|
|
|
+ setCostItems(EMPTY_COST);
|
|
|
|
|
+ setDetail(null);
|
|
|
|
|
+ const customers = kind === "custom" ? rowsOf(await catalogCustomerOptions().catch(() => [])) : [];
|
|
|
|
|
+ setDraft({ kind, customers });
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const openEdit = async (plan: CatalogPlanRow) => {
|
|
|
|
|
+ const [g, costs] = await Promise.all([
|
|
|
|
|
+ catalogGet({ plan_id: plan.plan_id }).catch(() => null),
|
|
|
|
|
+ planCostItemList({ plan_id: plan.plan_id })
|
|
|
|
|
+ .then(rowsOf)
|
|
|
|
|
+ .catch(() => [] as PlanCostItemRow[]),
|
|
|
|
|
+ ]);
|
|
|
|
|
+ const p = g ?? plan;
|
|
|
|
|
+ const items = g?.cost_items ?? costs ?? EMPTY_COST;
|
|
|
|
|
+ form.reset({
|
|
|
|
|
+ plan_name: p.plan_name ?? "",
|
|
|
|
|
+ use_category: p.use_category ?? "",
|
|
|
|
|
+ customer_id: p.customer_id ?? "",
|
|
|
|
|
+ annual_price_cents: p.annual_price_cents === null || p.annual_price_cents === undefined ? "" : String(p.annual_price_cents / 100),
|
|
|
|
|
+ sub_account_quota: p.sub_account_quota === null || p.sub_account_quota === undefined ? "" : String(p.sub_account_quota),
|
|
|
|
|
+ bandwidth_committed: p.bandwidth_committed === false ? "0" : "1",
|
|
|
|
|
+ bandwidth_up_mbps: p.bandwidth_up_mbps === null || p.bandwidth_up_mbps === undefined ? "" : String(p.bandwidth_up_mbps),
|
|
|
|
|
+ bandwidth_down_mbps: p.bandwidth_down_mbps === null || p.bandwidth_down_mbps === undefined ? "" : String(p.bandwidth_down_mbps),
|
|
|
|
|
+ plan_desc: p.plan_desc ?? "",
|
|
|
|
|
+ sort_no: p.sort_no === null || p.sort_no === undefined ? "" : String(p.sort_no),
|
|
|
|
|
+ });
|
|
|
|
|
+ setCostItems(items);
|
|
|
|
|
+ setDetail({ plan: p, cost_items: items, locked: p.frozen === true, referred: p.referred_count });
|
|
|
|
|
+ setDraft({ plan: p, kind: p.plan_kind, customers: p.customer_id ? [{ customer_id: p.customer_id, customer_name: p.customer_name ?? p.customer_id }] : [] });
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const committed = form.get("bandwidth_committed") !== "0";
|
|
|
|
|
+ const isEdit = !!draft?.plan;
|
|
|
|
|
+ const isFixed = (draft?.plan?.plan_kind ?? draft?.kind) === "fixed";
|
|
|
|
|
+ const derived = draft?.plan?.derived_from_contract_item_id !== null && draft?.plan?.derived_from_contract_item_id !== undefined;
|
|
|
|
|
+ const locked = detail?.locked === true || derived;
|
|
|
|
|
+
|
|
|
|
|
+ const save = async () => {
|
|
|
|
|
+ let frozen = false;
|
|
|
|
|
+ const ok = await sub.run(async () => {
|
|
|
|
|
+ if (!form.get("plan_name")) throw new Error("请填写套餐名称");
|
|
|
|
|
+ if (!isEdit && !form.get("annual_price_cents")) throw new Error("请填写年订阅价格");
|
|
|
|
|
+ const price = Math.round(Number(form.get("annual_price_cents") || 0) * 100);
|
|
|
|
|
+ const items = costItems.filter((it) => (it.item_name ?? "").trim() !== "");
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (draft?.plan) {
|
|
|
|
|
+ const r = await catalogUpdate({
|
|
|
|
|
+ plan_id: draft.plan.plan_id,
|
|
|
|
|
+ plan_name: form.get("plan_name"),
|
|
|
|
|
+ annual_price_cents: locked ? undefined : price,
|
|
|
|
|
+ sub_account_quota: locked || !form.get("sub_account_quota") ? undefined : Number(form.get("sub_account_quota")),
|
|
|
|
|
+ bandwidth_committed: committed,
|
|
|
|
|
+ bandwidth_up_mbps: committed && form.get("bandwidth_up_mbps") ? Number(form.get("bandwidth_up_mbps")) : undefined,
|
|
|
|
|
+ bandwidth_down_mbps: committed && form.get("bandwidth_down_mbps") ? Number(form.get("bandwidth_down_mbps")) : undefined,
|
|
|
|
|
+ plan_desc: form.get("plan_desc") || undefined,
|
|
|
|
|
+ sort_no: form.get("sort_no") ? Number(form.get("sort_no")) : undefined,
|
|
|
|
|
+ });
|
|
|
|
|
+ // 随附成本项=整段全量替换(`plan_cost_item/save`),⛔ 逐行增删改
|
|
|
|
|
+ await planCostItemSave({ plan_id: draft.plan.plan_id, items });
|
|
|
|
|
+ return r;
|
|
|
|
|
+ }
|
|
|
|
|
+ return await catalogCreate({
|
|
|
|
|
+ plan_kind: draft?.kind ?? "fixed",
|
|
|
|
|
+ plan_name: form.get("plan_name"),
|
|
|
|
|
+ use_category: form.get("use_category") || undefined,
|
|
|
|
|
+ annual_price_cents: price,
|
|
|
|
|
+ sub_account_quota: form.get("sub_account_quota") ? Number(form.get("sub_account_quota")) : undefined,
|
|
|
|
|
+ bandwidth_committed: committed,
|
|
|
|
|
+ bandwidth_up_mbps: committed && form.get("bandwidth_up_mbps") ? Number(form.get("bandwidth_up_mbps")) : undefined,
|
|
|
|
|
+ bandwidth_down_mbps: committed && form.get("bandwidth_down_mbps") ? Number(form.get("bandwidth_down_mbps")) : undefined,
|
|
|
|
|
+ customer_id: draft?.kind === "custom" ? form.get("customer_id") || undefined : undefined,
|
|
|
|
|
+ plan_desc: form.get("plan_desc") || undefined,
|
|
|
|
|
+ sort_no: form.get("sort_no") ? Number(form.get("sort_no")) : undefined,
|
|
|
|
|
+ cost_items: items,
|
|
|
|
|
+ });
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ frozen = hasBizCode(e, "K204");
|
|
|
|
|
+ throw e;
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ if (ok) {
|
|
|
|
|
+ setDraft(null);
|
|
|
|
|
+ await list.reload();
|
|
|
|
|
+ return ok;
|
|
|
|
|
+ }
|
|
|
|
|
+ // K204 引用冻结:整表单失败+只读横幅+重取 catalog/get 驱动状态
|
|
|
|
|
+ if (frozen && draft?.plan) {
|
|
|
|
|
+ const g = await catalogGet({ plan_id: draft.plan.plan_id }).catch(() => null);
|
|
|
|
|
+ if (g) setDetail({ plan: g, cost_items: g.cost_items, locked: true, referred: g.referred_count });
|
|
|
|
|
+ }
|
|
|
|
|
+ return ok;
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const doDelete = async () => {
|
|
|
|
|
+ if (!del) return;
|
|
|
|
|
+ let removed = false;
|
|
|
|
|
+ const ok = await sub.run(async () => {
|
|
|
|
|
+ const r = await catalogDelete({ plan_id: del.plan.plan_id });
|
|
|
|
|
+ removed = r.deleted === true;
|
|
|
|
|
+ if (!removed) setDel((d) => (d ? { ...d, result: r } : d));
|
|
|
|
|
+ return r;
|
|
|
|
|
+ });
|
|
|
|
|
+ if (ok && removed) {
|
|
|
|
|
+ setDel(null);
|
|
|
|
|
+ await list.reload();
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const table = (rowsOfKind: CatalogPlanRow[], kind: "fixed" | "custom") => (
|
|
|
|
|
+ <Panel
|
|
|
|
|
+ title={label(PLAN_KIND, kind)}
|
|
|
|
|
+ extra={
|
|
|
|
|
+ <Btn ghost onClick={() => openCreate(kind)}>
|
|
|
|
|
+ 新增{label(PLAN_KIND, kind)}
|
|
|
|
|
+ </Btn>
|
|
|
|
|
+ }
|
|
|
|
|
+ >
|
|
|
|
|
+ <table>
|
|
|
|
|
+ <thead>
|
|
|
|
|
+ <tr>
|
|
|
|
|
+ <th>序号</th>
|
|
|
|
|
+ <th>套餐名称</th>
|
|
|
|
|
+ <th>年订阅价格</th>
|
|
|
|
|
+ <th>月成本</th>
|
|
|
|
|
+ <th>带宽</th>
|
|
|
|
|
+ <th>用途分类</th>
|
|
|
|
|
+ <th>订阅方式</th>
|
|
|
|
|
+ <th>状态</th>
|
|
|
|
|
+ <th>引用数</th>
|
|
|
|
|
+ <th>操作</th>
|
|
|
|
|
+ </tr>
|
|
|
|
|
+ </thead>
|
|
|
|
|
+ <tbody>
|
|
|
|
|
+ <Async error={list.error} loading={list.loading} isEmpty={rowsOfKind.length === 0} emptyText={`暂无${label(PLAN_KIND, kind)}`} cols={10}>
|
|
|
|
|
+ {rowsOfKind.map((p, i) => {
|
|
|
|
|
+ const isDerived = p.derived_from_contract_item_id !== null && p.derived_from_contract_item_id !== undefined;
|
|
|
|
|
+ return (
|
|
|
|
|
+ <tr key={p.plan_id}>
|
|
|
|
|
+ <td>{seq(f.page, f.page_size, i)}</td>
|
|
|
|
|
+ <td>
|
|
|
|
|
+ {p.plan_name}
|
|
|
|
|
+ {isDerived ? (
|
|
|
|
|
+ <>
|
|
|
|
|
+ {" "}
|
|
|
|
|
+ <span className="ref-tag">{DERIVED_PLAN_BADGE}</span>
|
|
|
|
|
+ <div className="note">
|
|
|
|
|
+ {p.source_label ?? ""}
|
|
|
|
|
+ {p.customer_name ? `|${p.customer_name}` : ""}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </>
|
|
|
|
|
+ ) : null}
|
|
|
|
|
+ </td>
|
|
|
|
|
+ <td>{money(p.annual_price_cents)}</td>
|
|
|
|
|
+ <td>
|
|
|
|
|
+ <CostCell plan={p} />
|
|
|
|
|
+ </td>
|
|
|
|
|
+ <td>
|
|
|
|
|
+ <BandwidthCell plan={p} />
|
|
|
|
|
+ </td>
|
|
|
|
|
+ <td>
|
|
|
|
|
+ <Cell v={label(USE_CATEGORY, p.use_category)} />
|
|
|
|
|
+ </td>
|
|
|
|
|
+ <td>
|
|
|
|
|
+ <Cell v={label(SUB_MODE, p.use_category ? subModeOf(p.use_category) : null)} />
|
|
|
|
|
+ <span className="note" style={{ marginLeft: 6 }}>
|
|
|
|
|
+ {SUB_MODE_BY_CATEGORY}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ </td>
|
|
|
|
|
+ <td>
|
|
|
|
|
+ <Pill text={p.frozen ? "已冻结" : p.status === "active" ? "在用" : p.status} />
|
|
|
|
|
+ </td>
|
|
|
|
|
+ <td>{p.referred_count === null || p.referred_count === undefined ? <span className="note">{WORD_UNCONFIGURED}</span> : p.referred_count}</td>
|
|
|
|
|
+ <td>
|
|
|
|
|
+ <div className="row">
|
|
|
|
|
+ <Btn ghost onClick={() => openEdit(p)}>
|
|
|
|
|
+ 编辑
|
|
|
|
|
+ </Btn>
|
|
|
|
|
+ <Btn ghost danger onClick={() => setDel({ plan: p })}>
|
|
|
|
|
+ 删除
|
|
|
|
|
+ </Btn>
|
|
|
|
|
+ {!isAdmin && kind === "fixed" ? <span className="note">{OPERATOR_ONLY_CONFIG}</span> : null}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </td>
|
|
|
|
|
+ </tr>
|
|
|
|
|
+ );
|
|
|
|
|
+ })}
|
|
|
|
|
+ </Async>
|
|
|
|
|
+ </tbody>
|
|
|
|
|
+ </table>
|
|
|
|
|
+ </Panel>
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ return (
|
|
|
|
|
+ <Shell route="catalog" title="套餐目录" hint="固定档仅总部管理员可建;自定义档限负责范围内客户;被引用后相关字段冻结。">
|
|
|
|
|
+ <Panel title="套餐目录" note="月成本为派生只读值(年订阅价 ÷ 12 向下取整),悬停可看随附成本项构成;两张表同一次请求取数。">
|
|
|
|
|
+ <div className="filters">
|
|
|
|
|
+ <label className="f-item">
|
|
|
|
|
+ 关键词
|
|
|
|
|
+ <input
|
|
|
|
|
+ placeholder="套餐名称"
|
|
|
|
|
+ value={f.keyword}
|
|
|
|
|
+ onChange={(e) => setF((s) => ({ ...s, keyword: e.target.value, page: 1 }))}
|
|
|
|
|
+ />
|
|
|
|
|
+ </label>
|
|
|
|
|
+ <label className="f-item">
|
|
|
|
|
+ 用途分类
|
|
|
|
|
+ <select value={f.use_category} onChange={(e) => setF((s) => ({ ...s, use_category: e.target.value, page: 1 }))}>
|
|
|
|
|
+ <option value="">全部</option>
|
|
|
|
|
+ {OPTIONS.use_category.map((o) => (
|
|
|
|
|
+ <option key={o.value} value={o.value}>
|
|
|
|
|
+ {o.label}
|
|
|
|
|
+ </option>
|
|
|
|
|
+ ))}
|
|
|
|
|
+ </select>
|
|
|
|
|
+ </label>
|
|
|
|
|
+ <span className="note">默认全量返回,无省份与日期筛选</span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </Panel>
|
|
|
|
|
+ {table(fixed, "fixed")}
|
|
|
|
|
+ {table(custom, "custom")}
|
|
|
|
|
+ {list.data ? (
|
|
|
|
|
+ <Pager page={f.page} page_size={f.page_size} total={list.data.total ?? rows.length} onChange={(p) => setF((s) => ({ ...s, page: p }))} />
|
|
|
|
|
+ ) : null}
|
|
|
|
|
+
|
|
|
|
|
+ {draft ? (
|
|
|
|
|
+ <Modal wide title={`${isEdit ? "编辑" : "新增"}${label(PLAN_KIND, draft.kind)}`} onClose={() => setDraft(null)}>
|
|
|
|
|
+ {locked ? <Notice tone="warn">{derived ? DERIVED_PLAN_EDITABLE : `${FIXED_PLAN_LOCKED_FIELDS.join("、")}已被引用(${detail?.referred ?? 0} 处),本表单为只读。`}</Notice> : null}
|
|
|
|
|
+ <div className="form-grid">
|
|
|
|
|
+ <Field label="套餐名称" required>
|
|
|
|
|
+ <input {...form.bind("plan_name")} />
|
|
|
|
|
+ </Field>
|
|
|
|
|
+ {isEdit ? (
|
|
|
|
|
+ <Field label="用途分类" hint={locked ? "由用途分类决定,被引用后锁定" : undefined}>
|
|
|
|
|
+ <span>{label(USE_CATEGORY, form.get("use_category")) || "—"}</span>
|
|
|
|
|
+ </Field>
|
|
|
|
|
+ ) : isFixed ? (
|
|
|
|
|
+ <Field label="用途分类" required>
|
|
|
|
|
+ <select {...form.bind("use_category")}>
|
|
|
|
|
+ {OPTIONS.use_category.map((o) => (
|
|
|
|
|
+ <option key={o.value} value={o.value}>
|
|
|
|
|
+ {o.label}
|
|
|
|
|
+ </option>
|
|
|
|
|
+ ))}
|
|
|
|
|
+ </select>
|
|
|
|
|
+ </Field>
|
|
|
|
|
+ ) : (
|
|
|
|
|
+ <Field label="用途分类" hint={SUB_MODE_BY_CATEGORY}>
|
|
|
|
|
+ <select {...form.bind("use_category")}>
|
|
|
|
|
+ {OPTIONS.use_category.map((o) => (
|
|
|
|
|
+ <option key={o.value} value={o.value}>
|
|
|
|
|
+ {o.label}
|
|
|
|
|
+ </option>
|
|
|
|
|
+ ))}
|
|
|
|
|
+ </select>
|
|
|
|
|
+ </Field>
|
|
|
|
|
+ )}
|
|
|
|
|
+ {isFixed ? null : (
|
|
|
|
|
+ <Field label="归属客户" required={!isEdit}>
|
|
|
|
|
+ {isEdit ? (
|
|
|
|
|
+ <span>{draft?.plan?.customer_name ?? "—"}</span>
|
|
|
|
|
+ ) : (
|
|
|
|
|
+ <select {...form.bind("customer_id")}>
|
|
|
|
|
+ <option value="">请选择</option>
|
|
|
|
|
+ {(draft?.customers ?? []).map((c) => (
|
|
|
|
|
+ <option key={c.customer_id} value={c.customer_id}>
|
|
|
|
|
+ {c.customer_name}
|
|
|
|
|
+ </option>
|
|
|
|
|
+ ))}
|
|
|
|
|
+ </select>
|
|
|
|
|
+ )}
|
|
|
|
|
+ </Field>
|
|
|
|
|
+ )}
|
|
|
|
|
+ <Field label="年订阅价格(元)" required hint={locked ? "被引用后锁定,不可编辑" : undefined}>
|
|
|
|
|
+ {locked ? <span>{money(Math.round(Number(form.get("annual_price_cents") || 0) * 100))}</span> : <input type="number" min={0} step="0.01" {...form.bind("annual_price_cents")} />}
|
|
|
|
|
+ </Field>
|
|
|
|
|
+ <Field label="子账号配额" hint={locked ? "被引用后锁定" : "留空=不限"}>
|
|
|
|
|
+ {locked ? <span>{form.get("sub_account_quota") || "不限"}</span> : <input type="number" min={0} {...form.bind("sub_account_quota")} />}
|
|
|
|
|
+ </Field>
|
|
|
|
|
+ <Field label="承诺带宽">
|
|
|
|
|
+ <select {...form.bind("bandwidth_committed")}>
|
|
|
|
|
+ <option value="1">承诺</option>
|
|
|
|
|
+ <option value="0">不承诺</option>
|
|
|
|
|
+ </select>
|
|
|
|
|
+ </Field>
|
|
|
|
|
+ <Field label="上行带宽(Mbps)" hint={committed ? undefined : "开关关闭⇒两格不提交"}>
|
|
|
|
|
+ <input type="number" min={0} disabled={!committed} {...form.bind("bandwidth_up_mbps")} />
|
|
|
|
|
+ </Field>
|
|
|
|
|
+ <Field label="下行带宽(Mbps)">
|
|
|
|
|
+ <input type="number" min={0} disabled={!committed} {...form.bind("bandwidth_down_mbps")} />
|
|
|
|
|
+ </Field>
|
|
|
|
|
+ <Field label="说明">
|
|
|
|
|
+ <input {...form.bind("plan_desc")} />
|
|
|
|
|
+ </Field>
|
|
|
|
|
+ <Field label="排序">
|
|
|
|
|
+ <input type="number" min={0} {...form.bind("sort_no")} />
|
|
|
|
|
+ </Field>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <h3 style={{ marginTop: 14 }}>随附成本项(整段编辑)</h3>
|
|
|
|
|
+ <CostItemsEditor items={costItems} onChange={setCostItems} />
|
|
|
|
|
+ {sub.error ? <ErrorBox error={sub.error} /> : null}
|
|
|
|
|
+ <div className="form-actions" style={{ marginTop: 12 }}>
|
|
|
|
|
+ <Btn onClick={save} disabled={sub.busy}>
|
|
|
|
|
+ {sub.busy ? "提交中…" : "保存"}
|
|
|
|
|
+ </Btn>
|
|
|
|
|
+ <Btn ghost onClick={() => setDraft(null)}>
|
|
|
|
|
+ 取消
|
|
|
|
|
+ </Btn>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </Modal>
|
|
|
|
|
+ ) : null}
|
|
|
|
|
+
|
|
|
|
|
+ {del ? (
|
|
|
|
|
+ <Modal title={`删除${label(PLAN_KIND, del.plan.plan_kind)}「${del.plan.plan_name}」`} onClose={() => setDel(null)}>
|
|
|
|
|
+ <p>
|
|
|
|
|
+ 档位编码:<code>{del.plan.plan_id}</code>,创建日期:{day(del.plan.created_at)}
|
|
|
|
|
+ </p>
|
|
|
|
|
+ <p className="note">月成本 {money(del.plan.plan_cost_cents ?? undefined)} 为派生只读值,此处不提供编辑入口;月结算标准金额由套餐带出,不可录入。</p>
|
|
|
|
|
+ {del.result ? (
|
|
|
|
|
+ <Notice tone="warn">
|
|
|
|
|
+ <strong>该档位已被引用,不能删除。</strong>
|
|
|
|
|
+ <pre style={{ whiteSpace: "pre-wrap", margin: "6px 0 0" }}>{JSON.stringify(del.result, null, 2)}</pre>
|
|
|
|
|
+ </Notice>
|
|
|
|
|
+ ) : null}
|
|
|
|
|
+ {sub.error ? <ErrorBox error={sub.error} /> : null}
|
|
|
|
|
+ <div className="form-actions" style={{ marginTop: 12 }}>
|
|
|
|
|
+ <Btn danger onClick={doDelete} disabled={sub.busy}>
|
|
|
|
|
+ {sub.busy ? "提交中…" : "确认删除"}
|
|
|
|
|
+ </Btn>
|
|
|
|
|
+ <Btn ghost onClick={() => setDel(null)}>
|
|
|
|
|
+ 取消
|
|
|
|
|
+ </Btn>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </Modal>
|
|
|
|
|
+ ) : null}
|
|
|
|
|
+ </Shell>
|
|
|
|
|
+ );
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/** 用途分类→订阅方式(后端 `sub_mode` 由服务端派生并冻结;缺字段时按映射兜底显示)。 */
|
|
|
|
|
+function subModeOf(useCategory: string): string | null {
|
|
|
|
|
+ const map: Record<string, string> = { office: "upgrade", live: "upgrade", ai: "stackable", value_add: "stackable", customized: "customized" };
|
|
|
|
|
+ return map[useCategory] ?? null;
|
|
|
|
|
+}
|