Explorar o código

新增纯前端原型 prototype/

基于 docs/ 下需求规格与各设计说明实现,含模拟数据。
- 9 身份角色(管理员/团队长/运维/施工/录入/企业用户/分账号/合伙人)共 108 个视图
- 三级区域树、企业增删改留审计、挂载唯一性约束
- 工单分派(手工/自动平均/委托)、开停回填、到期尾月按天折算
- 结算批次出账/补跑、分成规则、对账收款、运营商反馈回填
- 侧栏分组折叠导航、斑马纹/hover/focus 过渡、入场动画、toast 滑入
cg hai 1 mes
pai
achega
9fffde44f5
Modificáronse 4 ficheiros con 2433 adicións e 0 borrados
  1. 1585 0
      prototype/app.js
  2. 446 0
      prototype/data.js
  3. 14 0
      prototype/index.html
  4. 388 0
      prototype/styles.css

+ 1585 - 0
prototype/app.js

@@ -0,0 +1,1585 @@
+let db = cloneSeed();
+let session = null;
+let route = "home";
+let focus = null;
+let selRegion = "pd";
+let toast = "";
+const NOW = TODAY + " 10:30";
+
+const NAV = {
+  admin: [
+    ["home", "概览"],
+    ["g-basic", "基础数据", [
+      ["regions", "区域管理"],
+      ["enterprises", "企业"],
+      ["catalog", "套餐目录"],
+      ["subs", "全部订阅"],
+    ]],
+    ["g-org", "组织与分成", [
+      ["partners", "合伙人"],
+      ["teams", "运维团队"],
+      ["rules", "分成与成本"],
+    ]],
+    ["g-settle", "结算", [
+      ["scopes", "结算范围"],
+      ["batches", "结算批次"],
+      ["bills", "结算明细"],
+      ["settings", "对账设置"],
+    ]],
+    ["g-ops", "运维与反馈", [
+      ["notes", "维护说明"],
+      ["feedback", "运营商反馈"],
+    ]],
+    ["audit", "审计日志"],
+  ],
+  teamLead: [
+    ["queue", "待分派工单"],
+    ["g-team", "团队管理", [
+      ["enterprises", "团队企业"],
+      ["members", "成员与负责范围"],
+      ["mode", "分派方式"],
+    ]],
+    ["g-fin", "财务与审计", [
+      ["rules", "团队分成"],
+      ["logs", "变更记录"],
+    ]],
+  ],
+  ops: [
+    ["mine", "我的工单"],
+    ["backfill", "开停回填"],
+  ],
+  worker: [["mine", "我的施工工单"], ["awards", "奖惩记录"]],
+  entry: [["entry", "代录企业"]],
+  enterprise: [
+    ["g-self", "本企业", [
+      ["plan", "当前套餐"],
+      ["accounts", "下属分账号"],
+      ["logs", "归属变更"],
+    ]],
+    ["g-ticket", "工单", [
+      ["submit", "提交故障或售后"],
+      ["progress", "工单进度"],
+    ]],
+  ],
+  sub: [
+    ["g-self", "个人", [
+      ["self", "我的账号"],
+    ]],
+    ["g-ticket", "工单", [
+      ["submit", "提交故障或售后"],
+      ["progress", "我的工单"],
+    ]],
+  ],
+  partner: [
+    ["g-account", "对账", [
+      ["region", "本区域对账"],
+      ["rules", "名下企业分成"],
+      ["collect", "收款信息"],
+    ]],
+    ["g-log", "变更与范围", [
+      ["logs", "范围变更"],
+    ]],
+  ],
+};
+
+function firstRoute(role) {
+  const items = NAV[role] || [];
+  for (const e of items) {
+    if (e.length === 2) return e[0];
+    if (e.length >= 3) {
+      for (const c of e[2]) return c[0];
+    }
+  }
+  return null;
+}
+
+function navRender(items, depth) {
+  return items.map((e) => {
+    if (e.length === 2) {
+      const [id, label] = e;
+      return `<button class="nav-leaf ${route === id ? "active" : ""}" data-go="${id}">${esc(label)}</button>`;
+    }
+    const [key, label, children] = e;
+    const open = openGroups.has(key) || (openGroups.size === 0 && children.some((c) => c[0] === route));
+    return `
+      <button class="nav-group ${open ? "open" : ""}" data-group-toggle="${key}">${esc(label)}<span class="caret">▾</span></button>
+      <div class="nav-sub ${open ? "" : "closed"}">${navRender(children, depth + 1)}</div>`;
+  }).join("");
+}
+
+const openGroups = new Set();
+
+function user() {
+  return db.users[session];
+}
+
+function entName(i) {
+  return db.enterprises[i] ? db.enterprises[i].name : "";
+}
+function teamName(i) {
+  return db.teams[i] ? db.teams[i].name : "未指定";
+}
+function memberName(i) {
+  return i === null || i === undefined ? "尚未分派" : db.members[i].name;
+}
+function opName(i) {
+  return db.operators[i].name;
+}
+function partnerName(i) {
+  return i === null || i === undefined ? "无" : db.partners[i].name;
+}
+function reconcileDayOf(opIndex) {
+  const d = db.operators[opIndex].reconcileDay;
+  return d === null || d === undefined ? db.setting.defaultReconcileDay : d;
+}
+
+function pill(text) {
+  const kind = text === "在用" || text === "已完成" || text === "生效中" || text === "已执行" || text === "奖励" || text === "启用" ? "ok"
+    : text === "未开通" || text === "待处理" || text === "待生效" || text === "待执行" ? "wait"
+    : text === "停用" || text === "执行失败" || text === "已到期" || text === "已打回" || text === "扣罚" ? "bad"
+    : text === "处理中" || text === "执行成功" ? "run" : "";
+  return `<span class="pill ${kind}">${esc(text)}</span>`;
+}
+
+function esc(s) {
+  return String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }[c]));
+}
+function seq(i) {
+  return i + 1;
+}
+function logNow() {
+  return NOW;
+}
+function addAudit(type, object, before, after) {
+  db.auditLogs.push({ at: NOW, by: user().name, type, object, before: before || "", after: after || "" });
+}
+function entHistory(i, field, before, after) {
+  db.enterprises[i].history.unshift({ at: NOW, field, before, after, by: user().name });
+}
+
+/* ---- 可见范围 ---- */
+
+function teamCovered(teamIndex) {
+  const t = db.teams[teamIndex];
+  return scopeEnterprises(db, t.scope).filter((i) => db.enterprises[i].teams[t.type] === teamIndex);
+}
+
+function visibleEnterprises() {
+  const u = user();
+  if (u.role === "admin") return db.enterprises.map((e, i) => i);
+  if (u.role === "teamLead") return teamCovered(u.team);
+  if (u.role === "ops" || u.role === "worker" || u.role === "entry") return db.members[u.member].scope.slice();
+  if (u.role === "enterprise" || u.role === "sub") return [u.enterprise];
+  if (u.role === "partner") {
+    return scopeEnterprises(db, db.partners[u.partner].scope).filter((i) => db.enterprises[i].partner === u.partner);
+  }
+  return [];
+}
+
+function visibleTickets() {
+  const u = user();
+  return db.tickets.map((t, i) => ({ ...t, i })).filter((t) => {
+    if (u.role === "admin") return true;
+    if (u.role === "teamLead") return t.team === u.team;
+    if (u.role === "ops" || u.role === "worker") return t.assignee === u.member;
+    if (u.role === "enterprise") return t.enterprise === u.enterprise;
+    if (u.role === "sub") return t.enterprise === u.enterprise && t.account === u.account;
+    return false;
+  });
+}
+
+function currentSubs(enterpriseIndex) {
+  return db.subs.map((s, i) => ({ ...s, i })).filter((s) => s.enterprise === enterpriseIndex && s.status === "生效中");
+}
+
+function go(next, id) {
+  route = next;
+  focus = id === undefined ? null : id;
+  render();
+}
+
+function say(text) {
+  toast = text;
+  render();
+  setTimeout(() => {
+    toast = "";
+    const node = document.querySelector(".toast");
+    if (node) node.remove();
+  }, 2600);
+}
+
+function val(id) {
+  const el = document.getElementById(id);
+  return el ? el.value.trim() : "";
+}
+
+/* ---- 工单与开停动作 ---- */
+
+function assignTo(ticketIndex, memberIndex) {
+  const ticket = db.tickets[ticketIndex];
+  const name = db.members[memberIndex].name;
+  ticket.assignee = memberIndex;
+  if (ticket.status === "待处理") ticket.status = "处理中";
+  ticket.logs.push(`${TODAY} ${user().name}分派给${name}`);
+  say(`已分派给${name}`);
+}
+
+function autoAssignTeam(teamIndex) {
+  const pending = db.tickets.map((t, i) => ({ t, i })).filter((x) => x.t.team === teamIndex && x.t.assignee === null && x.t.status !== "已完成" && x.t.status !== "已关闭");
+  if (!pending.length) {
+    say("没有待分派工单");
+    return;
+  }
+  let n = 0;
+  pending.forEach(({ i }) => {
+    const pick = pickEven(db, db.tickets[i]);
+    if (pick === null) return;
+    db.tickets[i].assignee = pick;
+    db.tickets[i].status = "处理中";
+    db.tickets[i].logs.push(`${TODAY} 自动平均分派给${db.members[pick].name}`);
+    n += 1;
+  });
+  say(n ? `已按未完成工单数量平均分派 ${n} 张,其余留在团队` : "工单留在团队:没有可接单成员");
+}
+
+function backfill(ticketIndex, date, ok) {
+  const ticket = db.tickets[ticketIndex];
+  const ent = db.enterprises[ticket.enterprise];
+  const action = db.actions.find((a) => a.ticket === ticketIndex);
+  if (!ok) {
+    if (action) action.status = "执行失败";
+    ticket.status = "处理中";
+    ticket.logs.push(`${TODAY} ${user().name}回填失败,账户状态不变,开停记录置为执行失败`);
+    say("回填失败,账户仍为" + ent.status);
+    return;
+  }
+  if (date > TODAY) {
+    say("实际日期不能晚于回填当天");
+    return;
+  }
+  if (ticket.type === "开户") {
+    const sub = db.subs.find((s) => s.enterprise === ticket.enterprise && s.status === "生效中" && (s.kind === "正式" || s.kind === "叠加"));
+    if (sub && date < sub.start) {
+      ticket.logs.push(`${TODAY} 开通日早于合同生效日 ${sub.start},计费仍从合同生效日起`);
+    }
+    ticket.status = "已完成";
+    ent.status = "在用";
+    entHistory(ticket.enterprise, "账户状态", ent.status, "在用(实际开通日 " + date + ")");
+    if (sub && !sub.openedOn) sub.openedOn = date;
+    db.accounts.filter((a) => a.enterprise === ticket.enterprise && a.status === "未开通" && a.usage === "正式").forEach((a) => {
+      a.status = "在用";
+      a.openedOn = date;
+    });
+    if (action) { action.status = "执行成功"; action.doneOn = date; action.by = user().name; }
+    ticket.logs.push(`${TODAY} ${user().name}回填成功,实际开通日 ${date},未开通的日子不计应收`);
+    say("已开通,企业与合同选定分账号变为在用");
+    return;
+  }
+  if (ticket.type === "到期停机") {
+    ticket.status = "已完成";
+    ent.status = "停用";
+    entHistory(ticket.enterprise, "账户状态", "在用", "停用(到期停机完成日 " + date + ")");
+    db.accounts.filter((a) => a.enterprise === ticket.enterprise && a.status === "在用").forEach((a) => { a.status = "停用"; });
+    if (action) { action.status = "执行成功"; action.doneOn = date; action.by = user().name; }
+    ticket.logs.push(`${TODAY} ${user().name}回填到期停机成功,企业及在用分账号改为停用;计费不延长过订阅结束日`);
+    say("到期停机完成,企业与分账号已停用,历史仍可登录查看");
+  }
+}
+
+function closeTicket(ticketIndex, reason) {
+  const t = db.tickets[ticketIndex];
+  t.status = "已关闭";
+  t.closeReason = reason;
+  t.logs.push(`${TODAY} ${user().name}关闭工单:${reason}`);
+  const action = db.actions.find((a) => a.ticket === ticketIndex);
+  if (action) action.status = "执行失败";
+  say("工单已关闭,开停记录置为执行失败");
+}
+
+function submitTicket(enterpriseIndex, accountIndex, type, text) {
+  const ent = db.enterprises[enterpriseIndex];
+  const team = ent.teams.常规;
+  const ticket = {
+    type, enterprise: enterpriseIndex, account: accountIndex, team, assignee: null,
+    status: "待处理", created: TODAY, text, logs: [`${TODAY} ${accountIndex === null ? "企业用户" : "下属分账号"}在系统内提交(文字)`],
+    closeReason: null, materials: [],
+  };
+  db.tickets.push(ticket);
+  const idx = db.tickets.length - 1;
+  if (db.teams[team].mode === "自动平均") {
+    const pick = pickEven(db, ticket);
+    if (pick !== null) {
+      ticket.assignee = pick;
+      ticket.status = "处理中";
+      ticket.logs.push(`${TODAY} 自动平均分派给${db.members[pick].name}`);
+    }
+  }
+  say(db.teams[team].mode === "手工" ? "工单已到常规团队,等待主账号分派" : "工单已自动分派");
+}
+
+/* ---- 登录与布局 ---- */
+
+function renderLogin() {
+  const cards = db.users.map((u, i) => `
+    <button class="persona" data-login="${i}">
+      <strong>${esc(u.name)}</strong>
+      <span>${esc(u.title)}</span>
+    </button>`).join("");
+  return `
+    <div class="login">
+      <aside class="login-side">
+        <h1>恪澜通<br>运营支撑</h1>
+        <p>纯前端原型。数据全部模拟,刷新或点重置后恢复。运营商不登录。页面序号从 1 起,数据下标从 0 起。</p>
+        <p>演示建议:先用林管查看区域树、结算范围与批次;再由吴队把临港开户工单分派给周宁,周宁回填;然后用孙队体验施工自动平均与委托;邹合可看对账与收款。</p>
+      </aside>
+      <main class="login-main">
+        <h2>选择一个身份进入</h2>
+        <div class="persona-grid">${cards}</div>
+      </main>
+    </div>`;
+}
+
+function layout(title, hint, body) {
+  const u = user();
+  const navHtml = navRender(NAV[u.role] || [], 0);
+  return `
+    <div class="shell">
+      <aside class="nav">
+        <div class="brand">运营支撑</div>
+        ${navHtml}
+        <div class="who">${esc(u.name)}<br>${esc(u.title)}
+          <button data-logout>换身份</button>
+          <button data-reset>重置数据</button>
+        </div>
+      </aside>
+      <section class="main">
+        <div class="top"><div><h1>${title}</h1><p>${hint}</p></div></div>
+        ${body}
+      </section>
+    </div>`;
+}
+
+/* ---- 通用表格 ---- */
+
+function enterpriseTable(indexes, opts = {}) {
+  const rows = indexes.map((i) => {
+    const e = db.enterprises[i];
+    const teams = Object.entries(e.teams).map(([type, ti]) => `${type}·${db.teams[ti].name}`).join("、");
+    return `<tr class="clickable" role="button" tabindex="0" data-go="enterprise" data-id="${i}">
+      <td>${seq(i)}</td>
+      <td>${esc(e.no)}<br><span class="note">${esc(e.name)}</span></td>
+      <td>${esc(e.subject)}</td>
+      <td>${esc(regionPath(db, e.region))}</td>
+      <td>${esc(opName(e.operator))}</td>
+      <td>${partnerName(e.partner)}</td>
+      <td>${esc(teams)}</td>
+      <td>${pill(e.status)}${e.trial ? " " + pill("试用") : ""}</td>
+    </tr>`;
+  }).join("");
+  return `<table><thead><tr><th>序号</th><th>企业</th><th>主体</th><th>所属区域</th><th>运营商</th><th>合伙人</th><th>运维团队</th><th>状态</th></tr></thead><tbody>${rows || `<tr><td colspan="8">范围内没有企业</td></tr>`}</tbody></table>`;
+}
+
+function ticketTable(list, assignable) {
+  const rows = list.map((t) => {
+    const action = db.actions.find((a) => a.ticket === t.i);
+    const late = (t.type === "开户" || t.type === "到期停机") && t.status !== "已完成" && t.status !== "已关闭" && overdueAction(action);
+    return `<tr>
+      <td>${seq(t.i)}</td>
+      <td>${esc(t.type)}${t.account !== undefined && t.account !== null ? " · " + esc(db.accounts[t.account].name) : ""}</td>
+      <td>${esc(entName(t.enterprise))}</td>
+      <td>${esc(teamName(t.team))}</td>
+      <td>${esc(memberName(t.assignee))}</td>
+      <td>${pill(t.status)}${late ? " " + pill("超 7 日") : ""}</td>
+      <td>${assignable && t.assignee === null && t.status !== "已关闭" ? assignSelect(t.i) : `<button class="btn ghost" data-go="ticket" data-id="${t.i}">查看</button>`}</td>
+    </tr>`;
+  }).join("");
+  return `<table><thead><tr><th>序号</th><th>类型</th><th>企业</th><th>团队</th><th>责任人</th><th>状态</th><th></th></tr></thead><tbody>${rows || `<tr><td colspan="7">没有工单</td></tr>`}</tbody></table>`;
+}
+
+function assignSelect(ticketIndex) {
+  const options = eligible(db, db.tickets[ticketIndex]).map((m) =>
+    `<option value="${m.index}">${esc(m.name)}(未完成 ${unfinished(db, m.index)})</option>`).join("");
+  if (!options) return `<span class="note">没有可接单成员,工单留在团队</span>`;
+  return `<span class="row"><select data-pick="${ticketIndex}">${options}</select><button class="btn" data-assign="${ticketIndex}">分派</button></span>`;
+}
+
+/* ================= 系统管理员页面 ================= */
+
+function pageHome() {
+  const lateActions = db.actions.filter(overdueAction);
+  const alerts = lateActions.map((a) => {
+    const t = db.tickets[a.ticket];
+    return `<div class="alert">${esc(entName(a.enterprise))} 的${esc(a.type)}记录 ${esc(a.id)} 自 ${esc(a.created)} 起超过 7 个自然日仍未回填。${t.assignee === null ? "尚未分派,连续提醒团队主账号。" : "连续提醒责任人 " + esc(memberName(t.assignee)) + "。"}只提醒不拦截,授权人员可临时延期。</div>`;
+  }).join("");
+  const failed = db.batches.filter((b) => b.status === "执行失败");
+  return layout("概览", "今天 " + TODAY + "。系统只生成对账依据与工单留痕,不向客户收款,不执行真实开停。", `
+    ${alerts}
+    ${failed.length ? failed.map((b) => `<div class="alert">批次 ${esc(b.no)}(${esc(b.scope)} / ${esc(b.month)})执行失败,需人工补跑。</div>`).join("") : ""}
+    <div class="cards">
+      <div class="card"><span>企业</span><b>${db.enterprises.length}</b></div>
+      <div class="card"><span>未开通</span><b>${db.enterprises.filter((e) => e.status === "未开通").length}</b></div>
+      <div class="card"><span>待分派工单</span><b>${db.tickets.filter((t) => t.assignee === null && t.status !== "已完成" && t.status !== "已关闭").length}</b></div>
+      <div class="card"><span>结算批次</span><b>${db.batches.length}</b></div>
+      <div class="card"><span>未启用范围</span><b>${db.scopes.filter((s) => !s.enabled).length}</b></div>
+    </div>
+    <div class="panel"><h2>每日日任务(每天一轮,数据库租约保证只执行一次)</h2>
+      <table><thead><tr><th>时点</th><th>动作</th><th>当前模拟结果</th></tr></thead><tbody>
+        <tr><td>到达合同生效日</td><td>订阅改为生效中</td><td>海岚续订订阅 2026-11-01 到期自动转生效</td></tr>
+        <tr><td>正式订阅建立且企业未开通</td><td>生成开户记录与工单</td><td>临港开户工单待分派(A-20261007-08)</td></tr>
+        <tr><td>新订阅生效且企业停用</td><td>再按开户处理</td><td>停机后续订开通仍走开户</td></tr>
+        <tr><td>订阅结束日次日仍在用</td><td>生成到期停机记录与工单</td><td>海岚 2026-10-09 已生成(A-20261009-23)</td></tr>
+        <tr><td>运营商对账日</td><td>对已启用范围出上一自然月批次</td><td>联通/移动 2026-09 批次已执行</td></tr>
+        <tr><td>待执行满 7 个自然日</td><td>连续提醒,可单条延期</td><td>临港开户记录已超期</td></tr>
+      </tbody></table>
+    </div>
+    <div class="panel"><h2>演示路径</h2><p class="note">吴队把临港开户工单分给周宁,周宁回填实际开通日(也可由运营商反馈一键回填),临港变为在用;孙队对施工工单做自动平均;澄澜 2026 年 3 月应收 = 1000 × 12 / 31 = 387.10 元;何南合伙人范围与沪东施工范围尚未启用,可在结算范围页补配后只补该渠道分成。</p></div>`);
+}
+
+function pageEnterprises() {
+  return layout("企业", "企业必须挂在区域树的一个节点下;唯一运营商、至多一个合伙人、每种类型至多一个运维团队。", `<div class="panel">${enterpriseTable(visibleEnterprises())}</div>`);
+}
+
+function pageEnterprise() {
+  const e = db.enterprises[focus];
+  if (!e) return layout("企业", "", `<div class="panel">没有该企业。</div>`);
+  const u = user();
+  const subs = db.subs.map((s, i) => ({ ...s, i })).filter((s) => s.enterprise === focus);
+  const accounts = db.accounts.map((a, i) => ({ ...a, i })).filter((a) => a.enterprise === focus);
+  const showAll = u.role === "admin";
+  const subRows = (showAll ? subs : subs.filter((s) => s.status === "生效中")).map((s) => `
+    <tr><td>${seq(s.i)}</td><td>${esc(s.name)}<br><span class="note">合同 ${esc(s.contractNo)}</span></td><td>${esc(s.kind)}</td><td>${pill(s.status)}</td><td>${esc(s.start)} 至 ${esc(s.end)}</td><td>${s.openedOn ? esc(s.openedOn) : "尚未开通"}</td><td>${s.monthPrice === null ? "未填优惠,不套用正式月费" : money(s.monthPrice)}</td></tr>`).join("");
+  const accRows = accounts.map((a) => `<tr><td>${seq(a.i)}</td><td>${esc(a.name)}</td><td>${esc(a.usage)}</td><td>${pill(a.status)}</td><td>${a.openedOn ? esc(a.openedOn) : "—"}</td><td>${a.usage === "测试" ? "不产生正式应收" : a.status === "在用" ? "计入外包运维费" : "未开通不计"}</td></tr>`).join("");
+  const usedFormal = accounts.filter((a) => a.usage === "正式").length;
+
+  const adminAttrs = u.role === "admin" ? `
+    <div class="panel"><h2>归属与挂载(系统管理员)</h2>
+      <p class="note">变更保留历史与审计日志;已生成的结算明细仍指向变更前对象,新结算才用新对象。分成随团队变化,不随工单责任人变化。</p>
+      <div class="form-grid">
+        <div><label>所属区域(只挂一个节点,可挂任一层)</label><select id="attrRegion">${db.regions.map((r) => `<option value="${r.id}" ${r.id === e.region ? "selected" : ""}>${esc(regionPath(db, r.id))}</option>`).join("")}</select></div>
+        <div><label>运营商(唯一)</label><select id="attrOperator">${db.operators.map((o, i) => `<option value="${i}" ${i === e.operator ? "selected" : ""}>${esc(o.name)}</option>`).join("")}</select></div>
+        <div><label>合伙人(可空)</label><select id="attrPartner"><option value="">无</option>${db.partners.map((p, i) => `<option value="${i}" ${i === e.partner ? "selected" : ""}>${esc(p.name)}(${esc(p.title)})</option>`).join("")}</select></div>
+        <div><label>常规类型运维团队(必填)</label><select id="attrTeam0">${db.teams.filter((t) => t.type === "常规").map((t, k) => `<option value="${db.teams.indexOf(t)}" ${db.teams.indexOf(t) === (e.teams.常规 ?? -1) ? "selected" : ""}>${esc(t.name)}</option>`).join("")}</select></div>
+        <div><label>施工类型运维团队(可空,至多一个)</label><select id="attrTeam1"><option value="">无</option>${db.teams.filter((t) => t.type === "施工").map((t) => `<option value="${db.teams.indexOf(t)}" ${db.teams.indexOf(t) === (e.teams.施工 ?? -1) ? "selected" : ""}>${esc(t.name)}</option>`).join("")}</select></div>
+      </div>
+      <div class="form-actions"><button class="btn" data-attr-save="${focus}">保存归属变更</button></div>
+    </div>` : "";
+
+  const filesPanel = `
+    <div class="panel"><h2>登记材料与合同(对象存储只存键,浏览器直传)</h2>
+      <p class="note">应备材料:${esc(e.materials)}。材料只接受运营商提供。</p>
+      <ul class="files">${e.files.map((f) => `<li>${esc(f)}</li>`).join("")}</ul>
+      <p class="note">合同文件挂在订阅上,只存合同编号和文件,不解析正文:</p>
+      <ul class="files">${subs.flatMap((s) => s.files.map((f) => `<li>${esc(f)} <span class="note">(${esc(s.name)})</span></li>`)).join("")}</ul>
+    </div>`;
+
+  const adminAccounts = u.role === "admin" ? `
+    <div class="panel"><h2>创建下属分账号(技术管理中心按合同选定,可不开满额度)</h2>
+      <div class="row">
+        <input id="newAcctName" placeholder="分账号姓名" style="max-width:200px">
+        <select id="newAcctUsage" style="max-width:140px"><option value="正式">正式</option><option value="测试">临时测试</option></select>
+        <button class="btn" data-acct-add="${focus}" ${usedFormal >= e.quota ? "disabled" : ""}>新增</button>
+      </div>
+      <p class="note">正式分账号 ${usedFormal} / 额度 ${e.quota}。测试账号无合同也可挂在企业主体下,不产生正式应收。</p>
+    </div>` : "";
+
+  const histRows = e.history.map((h) => `<tr><td>${esc(h.at)}</td><td>${esc(h.field)}</td><td>${esc(h.before)}</td><td>${esc(h.after)}</td><td>${esc(h.by)}</td></tr>`).join("");
+
+  return layout(e.name, `${e.no} · ${e.subject} · 电话 ${esc(e.phone)} · 材料只接受运营商提供`, `
+    <div class="cards">
+      <div class="card"><span>状态</span><b>${esc(e.status)}</b></div>
+      <div class="card"><span>所属区域</span><b style="font-size:15px">${esc(regionPath(db, e.region))}</b></div>
+      <div class="card"><span>运营商 / 合伙人</span><b style="font-size:15px">${esc(opName(e.operator))} / ${esc(partnerName(e.partner))}</b></div>
+      <div class="card"><span>分账号</span><b>${accounts.filter((a) => a.status === "在用").length} 在用 / 额度 ${e.quota}</b></div>
+    </div>
+    ${adminAttrs}
+    <div class="panel"><h2>${showAll ? "全部订阅(后台保留升级/叠加全部记录)" : "当前生效套餐(前端只展示生效中)"}</h2>
+      <table><thead><tr><th>序号</th><th>套餐 / 合同</th><th>方式</th><th>状态</th><th>合同期间</th><th>实际开通日</th><th>月结算标准</th></tr></thead><tbody>${subRows}</tbody></table>
+    </div>
+    <div class="panel"><h2>下属分账号</h2>
+      <table><thead><tr><th>序号</th><th>姓名</th><th>用途</th><th>状态</th><th>开通日</th><th>计费</th></tr></thead><tbody>${accRows}</tbody></table>
+    </div>
+    ${adminAccounts}
+    ${filesPanel}
+    <div class="panel"><h2>归属与状态变更历史</h2>
+      <table><thead><tr><th>时间</th><th>字段</th><th>变更前</th><th>变更后</th><th>操作人</th></tr></thead><tbody>${histRows || `<tr><td colspan="5">暂无</td></tr>`}</tbody></table>
+    </div>`);
+}
+
+function pageCatalog() {
+  const fixed = db.packages.filter((p) => p.custom === null);
+  const custom = db.packages.filter((p) => p.custom !== null);
+  const row = (p) => `<tr><td>${esc(p.name)}</td><td>${money(p.yearPrice)}</td><td>${money(p.monthPrice)}</td><td>${p.quota}</td><td>${esc(p.bw)}</td><td>${p.custom === null ? "公共固定套餐" : "自定义 · " + esc(entName(p.custom))}</td></tr>`;
+  return layout("套餐目录", "档位与价格由运营确定后写入,不做套餐规则引擎;总带宽只保存,首期不按带宽拆价。", `
+    <div class="panel"><h2>固定套餐(公共档)</h2>
+      <table><thead><tr><th>套餐</th><th>年订阅价格</th><th>月结算标准</th><th>分账号额度</th><th>总带宽</th><th>归属</th></tr></thead><tbody>${fixed.map(row).join("")}</tbody></table>
+    </div>
+    <div class="panel"><h2>自定义套餐(只属于一个企业,不进公共目录)</h2>
+      <table><thead><tr><th>套餐</th><th>年订阅价格</th><th>月结算标准</th><th>分账号额度</th><th>总带宽</th><th>归属</th></tr></thead><tbody>${custom.map(row).join("") || `<tr><td colspan="6">暂无</td></tr>`}</tbody></table>
+    </div>
+    <div class="panel"><h2>新增固定套餐档</h2>
+      <div class="form-grid">
+        <div><label>套餐名称</label><input id="pkgName" placeholder="例如 跨境带宽旗舰版"></div>
+        <div><label>年订阅价格(元)</label><input id="pkgYear" type="number" min="0" step="0.01" value="36000"></div>
+        <div><label>分账号额度</label><input id="pkgQuota" type="number" min="0" step="1" value="20"></div>
+        <div><label>总带宽</label><input id="pkgBw" placeholder="例如 500Mbps" value="500Mbps"></div>
+      </div>
+      <div class="form-actions"><button class="btn" data-pkg-add>写入套餐目录</button></div>
+      <p class="note">月结算标准默认 = 年订阅价格 / 12;合同另定月单价时以后续订阅上的数值为准。</p>
+    </div>`);
+}
+
+function pageSubs() {
+  const rows = db.subs.map((s, i) => `<tr class="clickable" data-go="enterprise" data-id="${s.enterprise}"><td>${seq(i)}</td><td>${esc(entName(s.enterprise))}</td><td>${esc(s.name)}<br><span class="note">${esc(s.contractNo)}</span></td><td>${esc(s.kind)}</td><td>${pill(s.status)}</td><td>${esc(s.start)} 至 ${esc(s.end)}</td><td>${money(s.yearPrice)}</td><td>${s.monthPrice === null ? "—" : money(s.monthPrice)}</td><td>${s.openedOn ? esc(s.openedOn) : "—"}</td></tr>`).join("");
+  return layout("全部订阅", "升级新增订阅、原订阅保留;叠加的多份订阅各自生效各自计费。前端企业页只展示生效中。", `<div class="panel"><table><thead><tr><th>序号</th><th>企业</th><th>套餐 / 合同</th><th>方式</th><th>状态</th><th>期间</th><th>年价</th><th>月标准</th><th>实际开通日</th></tr></thead><tbody>${rows}</tbody></table></div>`);
+}
+
+/* ---- 区域树 ---- */
+
+function treeHtml(parentId, depth) {
+  const nodes = db.regions.filter((r) => r.parent === parentId);
+  if (!nodes.length) return "";
+  return `<ul class="tree">${nodes.map((n) => {
+    const direct = db.enterprises.filter((e) => e.region === n.id).length;
+    const total = enterprisesUnderRegion(db, n.id).length;
+    const childHtml = treeHtml(n.id, depth + 1);
+    return `<li>
+      <div class="tree-node ${selRegion === n.id ? "on" : ""}">
+        <button class="tree-select" data-region-node="${n.id}">${esc(n.name)}</button>
+        <span class="lv">${LEVEL_NAMES[n.level]}</span>
+        <span class="cnt">直属 ${direct} · 含下级 ${total}</span>
+      </div>${childHtml}</li>`;
+  }).join("")}</ul>`;
+}
+
+function pageRegions() {
+  const isNewRoot = selRegion === "__newRoot";
+  const node = isNewRoot ? { id: "__newRoot", name: "", level: 0 } : (regionNode(db, selRegion) || db.regions[0]);
+  selRegion = node.id;
+  const children = db.regions.filter((r) => r.parent === node.id);
+  const direct = db.enterprises.map((e, i) => ({ ...e, i })).filter((e) => e.region === node.id);
+  const refs = regionReferenced(db, node.id);
+  const canAdd = node.level < 2;
+  const mountOptions = db.enterprises.map((e, i) => `<option value="${i}">${esc(e.name)}(现挂:${esc(regionPath(db, e.region))})</option>`).join("");
+  return layout("区域管理", "三级:大区 / 市 / 区县。企业必须挂一个节点。删除前要先移走直属企业、删除下级节点;被合伙人或团队范围引用的节点不能删除。", `
+    <div class="split" style="grid-template-columns: 0.9fr 1.1fr">
+      <div class="panel"><h2>区域树</h2>${treeHtml(null, 0)}
+        <div class="row" style="margin-top:10px"><button class="btn ghost" data-region-node="__newRoot">新建大区</button></div>
+      </div>
+      <div>
+        ${node.id === "__newRoot" ? "" : `
+        <div class="panel"><h2>${esc(regionPath(db, node.id))}</h2>
+          <p class="note">层级:${LEVEL_NAMES[node.level]};直属企业 ${direct.length} 家,含下级共 ${enterprisesUnderRegion(db, node.id).length} 家。</p>
+          ${direct.length ? `<ul class="files">${direct.map((e) => `<li>${esc(e.name)}(当前直属本节点)</li>`).join("")}</ul>` : `<p class="note">本节点没有直属企业。</p>`}
+          ${children.length ? `<p class="note">下级节点:${children.map((c) => c.name).join("、")}。删除前需先删除下级。</p>` : ""}
+          ${refs.length ? `<div class="alert">本节点被引用,不能删除:${refs.map(esc).join(";")}</div>` : ""}
+        </div>
+        <div class="panel"><h2>新建下级节点${canAdd ? `(在「${esc(node.name)}」下新建${LEVEL_NAMES[node.level + 1]})` : "(区县下不能再建节点)"}</h2>
+          ${canAdd ? `<div class="row"><input id="newRegionName" placeholder="新节点名称" style="max-width:220px"><button class="btn" data-region-add="${node.id}">新建</button></div>` : `<p class="note">已经是区县层级。</p>`}
+        </div>
+        <div class="panel"><h2>重命名</h2>
+          <div class="row"><input id="renameRegion" value="${esc(node.name)}" style="max-width:220px"><button class="btn ghost" data-region-rename="${node.id}">保存新名称</button></div>
+        </div>
+        <div class="panel"><h2>删除节点</h2>
+          <button class="btn warn" data-region-delete="${node.id}">删除「${esc(node.name)}」</button>
+        </div>
+        <div class="panel"><h2>把企业挂载 / 改挂到本节点</h2>
+          <p class="note">首次挂载与改挂都写审计日志;改挂不改写已生成的结算明细。</p>
+          <div class="row"><select id="mountEnt" style="max-width:320px">${mountOptions}</select><button class="btn" data-region-mount="${node.id}">挂载到本节点</button></div>
+        </div>`}
+        ${node.id === "__newRoot" ? `
+        <div class="panel"><h2>新建大区</h2>
+          <div class="row"><input id="newRootName" placeholder="例如 华北大区" style="max-width:220px"><button class="btn" data-region-add="">新建大区</button></div></div>` : ""}
+      </div>
+    </div>`);
+}
+
+/* ---- 合伙人 ---- */
+
+function pagePartners() {
+  const cards = db.partners.map((p, i) => {
+    const covered = scopeEnterprises(db, p.scope).filter((ei) => db.enterprises[ei].partner === i);
+    return `<div class="panel">
+      <h2>${esc(p.name)} <span class="note">${esc(p.title)}</span></h2>
+      <p class="note">通知地址:${esc(p.notify)} · 登录账号已建为项目最终用户</p>
+      <p><b>负责范围:</b>${esc(scopeSummary(db, p.scope))}</p>
+      <p class="note">名下企业(${covered.length}):${covered.map((ei) => esc(entName(ei))).join("、") || "无"}。未绑定合伙人的企业不进入合伙人结算范围。</p>
+      <div class="form-actions"><button class="btn" data-go="pscope" data-id="${i}">配置负责范围</button></div>
+    </div>`;
+  }).join("");
+  return layout("合伙人", "即原代理合作商。按区域建账号,负责范围可多选区域或直接多选企业,取并集。合伙人不处理工单、不执行开停。", `
+    ${cards}
+    <div class="panel"><h2>新建合伙人账号</h2>
+      <div class="form-grid">
+        <div><label>名称</label><input id="newPName" placeholder="例如 华北渠道"></div>
+        <div><label>渠道说明</label><input id="newPTitle" placeholder="例如 华北大区渠道"></div>
+      </div>
+      <div class="form-actions"><button class="btn" data-partner-add>开通登录账号</button></div>
+    </div>`);
+}
+
+function scopeEditor(target, kind) {
+  const obj = kind === "partner" ? db.partners[target] : db.teams[target];
+  const name = kind === "partner" ? obj.name : `${obj.name}(${obj.type}类型)`;
+  const checks = (nodes) => `<ul class="tree check">${nodes.map((n) => {
+    const total = enterprisesUnderRegion(db, n.id).length;
+    return `<li><label class="ck"><input type="checkbox" data-rg="${n.id}" ${(obj.scope.regions || []).includes(n.id) ? "checked" : ""}> ${esc(n.name)} <span class="note">[${LEVEL_NAMES[n.level]},含下级 ${total} 家]</span></label>${treeChecks(n.id)}</li>`;
+  }).join("")}</ul>`;
+  const treeChecks = (pid) => {
+    const kids = db.regions.filter((r) => r.parent === pid);
+    return kids.length ? checks(kids) : "";
+  };
+  const entRows = db.enterprises.map((e, i) => `<label class="ck"><input type="checkbox" data-en="${i}" ${(obj.scope.enterprises || []).includes(i) ? "checked" : ""}> ${seq(i)}. ${esc(e.name)} <span class="note">(${esc(regionPath(db, e.region))})</span></label>`).join("");
+  const back = kind === "partner" ? "partners" : "teams";
+  return layout(`配置负责范围 · ${name}`, "可选区域(含其下级全部企业),也可直接多选企业,两者取并集。范围保存后写审计日志,记覆盖企业的变更前后值。", `
+    <div class="panel"><div class="row"><button class="btn ghost" data-go="${back}">返回</button><button class="btn" data-scope-save="${kind}-${target}">保存范围</button></div></div>
+    <div class="split" style="grid-template-columns: 1fr 1fr">
+      <div class="panel"><h2>多选区域</h2>${checks(db.regions.filter((r) => r.level === 0))}</div>
+      <div class="panel"><h2>直接多选企业(与区域取并集)</h2><div class="checklist">${entRows}</div></div>
+    </div>`);
+}
+
+/* ---- 运维团队(管理员) ---- */
+
+function pageTeams() {
+  const body = db.teams.map((team, ti) => {
+    const people = db.members.map((m, i) => ({ ...m, i })).filter((m) => m.team === ti);
+    const rows = people.map((m) => `<tr><td>${seq(m.i)}</td><td>${esc(m.name)}</td><td>${esc(m.type)}</td><td>${m.type === "录入" ? "代录,不接单" : m.scope.map((n) => esc(db.enterprises[n].name)).join("、")}</td><td>${m.type === "录入" ? "—" : unfinished(db, m.i)}</td></tr>`).join("");
+    return `<div class="panel"><h2>${esc(team.name)} · ${esc(team.type)}类型 · ${esc(team.mode)}分派</h2>
+      <p><b>团队负责范围(系统管理员配置):</b>${esc(scopeSummary(db, team.scope))}</p>
+      <p class="note">范围内归属本团队的企业(${teamCovered(ti).length}):${teamCovered(ti).map((i) => esc(entName(i))).join("、") || "无"}。主账号只能在此范围内给成员划范围,不能自行扩大。</p>
+      <div class="form-actions"><button class="btn" data-go="tscope" data-id="${ti}">配置团队负责范围</button></div>
+      <table style="margin-top:10px"><thead><tr><th>序号</th><th>成员</th><th>类型</th><th>负责范围</th><th>未完成工单</th></tr></thead><tbody>${rows}</tbody></table>
+    </div>`;
+  }).join("");
+  return layout("运维团队", "固定两层:团队主账号 / 运维子账号。团队类型记在团队上(首期常规、施工);子账号类型为常规、施工或录入。施工必须以单位签约。", `
+    ${body}
+    <div class="panel"><h2>开通运维团队账号</h2>
+      <div class="form-grid">
+        <div><label>团队名称</label><input id="newTeamName" placeholder="例如 苏南常规运维"></div>
+        <div><label>团队类型</label><select id="newTeamType"><option>常规</option><option>施工</option></select></div>
+        <div><label>分派方式</label><select id="newTeamMode"><option>手工</option><option>自动平均</option></select></div>
+      </div>
+      <div class="form-actions"><button class="btn" data-team-add>开通(负责范围建后再配)</button></div>
+    </div>`);
+}
+
+/* ---- 分成与成本(管理员) ---- */
+
+function ruleInput(rule, ch, ref, ent) {
+  const r = rule ? rule.rate : 0;
+  const layer = rule ? rule.layer : "区域常规";
+  return `<span class="row">
+    <input type="number" min="0" max="1" step="0.01" value="${r}" data-rl-rate="${ch}-${ref}-${ent}" style="max-width:90px">
+    <select data-rl-layer="${ch}-${ref}-${ent}" style="max-width:120px"><option ${layer === "区域常规" ? "selected" : ""}>区域常规</option><option ${layer === "合同增补" ? "selected" : ""}>合同增补</option></select>
+  </span>`;
+}
+
+function pageRules() {
+  const entRows = db.enterprises.map((e, i) => {
+    const get = (ch, ref) => db.rules.find((x) => x.ch === ch && x.ref === ref && x.ent === i);
+    return `<tr>
+      <td>${esc(e.name)}</td>
+      <td>${ruleInput(get("operator", e.operator), "operator", e.operator, i)}</td>
+      <td>${e.teams.常规 !== undefined ? ruleInput(get("team", e.teams.常规), "team", e.teams.常规, i) : "—"}</td>
+      <td>${e.teams.施工 !== undefined ? ruleInput(get("team", e.teams.施工), "team", e.teams.施工, i) : "无"}</td>
+      <td>${e.partner !== null ? ruleInput(get("partner", e.partner), "partner", e.partner, i) : "无"}</td>
+    </tr>`;
+  }).join("");
+  const costRows = db.costs.map((c) => `<tr><td>${esc(entName(c.ent))}</td><td>${esc(db.subs[c.sub].name)}</td><td>${esc(c.kind)}</td><td>${esc(c.name)}</td><td>${money(c.amount)} / 月</td><td>${esc(c.repeat)}</td></tr>`).join("");
+  return layout("分成与成本规则", "分成挂在渠道与企业的关系上,不挂子账号;合同增补优先于区域常规,两层都没有计 0。线路投入不从基数扣;设备同一项目只选比例或固定金额之一;项目费用一次记入。", `
+    <div class="panel"><h2>按总金额比例(大于 0 且不超过 1)</h2>
+      <p class="note">分成基数 = 实际结算金额 − 应扣除成本(国际资源摊销等);分成 = 基数 × 比例。分成不加到客户应付,只用于对账。</p>
+      <table><thead><tr><th>企业</th><th>运营商</th><th>常规运维团队</th><th>施工团队</th><th>合伙人</th></tr></thead><tbody>${entRows}</tbody></table>
+      <div class="form-actions"><button class="btn" data-rules-save="admin">保存全部规则</button></div>
+    </div>
+    <div class="panel"><h2>成本项(模拟)</h2>
+      <table><thead><tr><th>企业</th><th>订阅</th><th>成本类别</th><th>项目</th><th>本期摊销</th><th>方式</th></tr></thead><tbody>${costRows || `<tr><td colspan="6">暂无</td></tr>`}</tbody></table>
+      <p class="note">临时成本增补(如园区另提分成)不建数据、不参与计算。</p>
+    </div>
+    <div class="panel"><h2>外包运维费</h2><p class="note">企业主账号不计;只计本月实际在用的正式下属分账号:单账号月费 ${money(db.setting.perAccountFee)} 元 × 实际使用天数 / 自然月天数。测试账号不计,未开通不计。</p></div>`);
+}
+
+/* ---- 结算范围 ---- */
+
+function scopeTargetName(s) {
+  if (s.kind === "运营商") return opName(s.ref) + "(对账日 " + reconcileDayOf(s.ref) + " 日)";
+  if (s.kind === "合伙人") return partnerName(s.ref) + "(" + db.partners[s.ref].title + ")";
+  return db.teams[s.ref].name + "(" + db.teams[s.ref].type + ")";
+}
+function scopeEnterprisesOf(s) {
+  if (s.kind === "运营商") return db.enterprises.map((e, i) => i).filter((i) => db.enterprises[i].operator === s.ref);
+  if (s.kind === "合伙人") return db.enterprises.map((e, i) => i).filter((i) => db.enterprises[i].partner === s.ref);
+  const t = db.teams[s.ref];
+  return db.enterprises.map((e, i) => i).filter((i) => db.enterprises[i].teams[t.type] === s.ref);
+}
+
+function pageScopes() {
+  const rows = db.scopes.map((s, i) => {
+    const list = scopeEnterprisesOf(s);
+    return `<tr>
+      <td>${seq(i)}</td><td>${esc(s.kind)}</td><td>${esc(scopeTargetName(s))}</td>
+      <td>${pill(s.enabled ? "启用" : "未启用")}</td>
+      <td>${list.length} 家:${list.map((ei) => esc(entName(ei))).join("、") || "无"}</td>
+      <td><button class="btn ghost" data-scope-toggle="${i}">${s.enabled ? "停用" : "启用"}</button></td>
+    </tr>`;
+  }).join("");
+  return layout("结算范围", "出账必须落在预先配置并已启用的范围。运营商范围必选且出账前启用;合伙人、运维范围可选,可在首次应收之后补配,只补该渠道分成。", `
+    <div class="panel"><table><thead><tr><th>序号</th><th>类型</th><th>范围条件</th><th>状态</th><th>圈定企业</th><th></th></tr></thead><tbody>${rows}</tbody></table>
+      <p class="note">同一企业可同时处于一个运营商范围、至多一个合伙人范围和多个不同类型运维范围;同一类型不能进入两个运维范围。</p>
+    </div>`);
+}
+
+/* ---- 结算批次 ---- */
+
+function pageBatches() {
+  const rows = db.batches.map((b, i) => `<tr class="clickable" data-go="batch" data-id="${i}">
+    <td>${esc(b.no)}</td><td>${esc(b.scope)}</td><td>${esc(b.month)}</td><td>${esc(b.day)}</td><td>${esc(b.trigger)}</td><td>${esc(b.by)}</td><td>${pill(b.status)}</td><td>${b.rows.length} 条明细</td></tr>`).join("");
+  const options = db.scopes.map((s, i) => `<option value="${i}">${esc(s.kind)} · ${esc(scopeTargetName(s))}${s.enabled ? "" : "(未启用)"}</option>`).join("");
+  return layout("结算批次", "对账日当天对每条已启用范围自动生成批次;人工触发只补已结束且未出账的自然月,不提前出未结束月份。", `
+    <div class="panel"><h2>人工补跑(模拟上一已结束自然月 2026-09)</h2>
+      <div class="row"><select id="runScope" style="max-width:360px">${options}</select><button class="btn" data-batch-run>对所选范围执行补跑</button></div>
+      <p class="note">已有有效应收的月份跳过,不重复写客户应收;合伙人/运维范围补配后只补该渠道分成。当天没有可出账企业时不生成空批次。</p>
+    </div>
+    <div class="panel"><table><thead><tr><th>批次编号</th><th>范围</th><th>自然月</th><th>对账日</th><th>触发</th><th>执行人</th><th>状态</th><th>明细</th></tr></thead><tbody>${rows}</tbody></table></div>`);
+}
+
+function pageBatch() {
+  const b = db.batches[focus];
+  if (!b) return layout("批次", "", `<div class="panel">没有该批次。</div>`);
+  const rows = b.rows.map((si) => {
+    const s = db.settlements[si];
+    return `<tr class="clickable" data-go="bill" data-id="${si}"><td>${seq(si)}</td><td>${esc(entName(s.enterprise))}</td><td>${esc(db.subs[s.sub].name)}</td><td>${esc(s.month)}</td><td>${s.partial ? `${s.days}/${s.monthDays}` : "满月"}</td><td>${money(s.amount)}</td><td>${money(s.opsFee)}</td></tr>`;
+  }).join("");
+  return layout(b.no, `${b.scope} · 自然月 ${b.month} · ${b.trigger}执行 · ${b.by} ${b.at}`, `
+    <div class="cards">
+      <div class="card"><span>状态</span><b style="font-size:16px">${esc(b.status)}</b></div>
+      <div class="card"><span>明细条数</span><b>${b.rows.length}</b></div>
+      <div class="card"><span>应收合计</span><b>${money(b.rows.reduce((n, si) => n + db.settlements[si].amount, 0))}</b></div>
+    </div>
+    ${b.warning ? `<div class="alert">${esc(b.warning)}</div>` : ""}
+    <div class="panel"><h2>批次内结算明细</h2>
+      <table><thead><tr><th>序号</th><th>企业</th><th>订阅</th><th>自然月</th><th>计费天数</th><th>应收</th><th>外包运维费</th></tr></thead><tbody>${rows || `<tr><td colspan="7">该批次模拟未带明细行(详见批次说明)</td></tr>`}</tbody></table>
+    </div>
+    <div class="panel"><p class="note">状态固定为:待执行、已执行、执行失败、已打回、已作废。自动执行执行人记为系统;执行失败由人工补跑。已打回后重做生成新明细,成为该月唯一有效应收。</p></div>`);
+}
+
+/* ---- 结算明细 ---- */
+
+function pageBills() {
+  const rows = db.settlements.map((b, i) => `<tr class="clickable" data-go="bill" data-id="${i}"><td>${seq(i)}</td><td>${esc(entName(b.enterprise))}</td><td>${esc(db.subs[b.sub].name)}</td><td>${esc(b.month)}</td><td>${b.partial ? `${b.days}/${b.monthDays}` : "满月"}${b.tail ? " · 尾月" : ""}</td><td>${money(b.amount)}</td><td>${money(b.opsFee)}</td><td>${b.batch === null ? "—" : pill(db.batches[b.batch].status)}</td></tr>`).join("");
+  return layout("结算明细", "一份生效正式订阅在一个自然月一条;叠加各算各的;测试账号不进入;未开通不计费。", `
+    <div class="panel"><table><thead><tr><th>序号</th><th>企业</th><th>订阅</th><th>自然月</th><th>天数</th><th>应收</th><th>外包运维费</th><th>批次</th></tr></thead><tbody>${rows}</tbody></table></div>
+    <div class="panel"><h2>验收算例(硬编码公式)</h2>
+      <table><thead><tr><th>算例</th><th>过程</th><th>结果</th></tr></thead><tbody>
+        <tr><td>不满月</td><td>年价 12000、月标准 1000,开通日 2026-03-20,3 月共 31 天:1000 × 12 / 31</td><td><b>387.10 元</b>(3 月 18、19 日不计费;4 月 5 日仍未开通则 3 月不出应收)</td></tr>
+        <tr><td>尾月对齐</td><td>年价 10000,月精确 833.333…,前 11 个月各 833.33,合计 9166.63</td><td><b>尾月 833.37 元</b>,12 个月合计恰好 10000 元</td></tr>
+        <tr><td>首/尾均不满</td><td>目标合计 = 各月精确应收之和四舍五入到分;尾月只消化四舍五入差额</td><td>不把少收部分补回整年价格</td></tr>
+      </tbody></table>
+    </div>`);
+}
+
+function pageBill() {
+  const b = db.settlements[focus];
+  if (!b) return layout("明细", "", `<div class="panel">没有该明细。</div>`);
+  const shareRows = b.shares.map((s) => `<tr><td>${esc(s.who)}</td><td>${esc(s.mode)}</td><td>${s.rate ? pct(s.rate) : "—"}</td><td>${money(s.amount)}</td></tr>`).join("");
+  const costRows = b.costs.length ? b.costs.map((c) => `<tr><td>${esc(c.name)}</td><td>${money(c.amount)}</td></tr>`).join("") : `<tr><td>本月无从分成基数扣除的成本(线路投入按比例分成,不扣基数)</td><td>0.00</td></tr>`;
+  const acctRows = b.acctDays.length ? b.acctDays.map((a) => `<tr><td>${esc(a.name)}</td><td>${a.days} / ${b.monthDays}</td><td>${money(db.setting.perAccountFee)} × ${a.days} / ${b.monthDays}</td><td>${money(a.fee)}</td></tr>`).join("") : `<tr><td colspan="4">本月没有计入外包运维费的正式在用分账号(企业主账号不计、测试账号不计)</td></tr>`;
+  const formula = b.partial ? `${money(b.std)} × ${b.days} / ${b.monthDays} = ${money(b.amount)}` : `整月按月结算标准金额 ${money(b.std)} 元`;
+  return layout(`${entName(b.enterprise)} · ${b.month}`, `订阅:${esc(db.subs[b.sub].name)}(${esc(db.subs[b.sub].start)} 至 ${esc(db.subs[b.sub].end)})`, `
+    <div class="cards">
+      <div class="card"><span>应收金额</span><b>${money(b.amount)}</b></div>
+      <div class="card"><span>分成基数</span><b>${money(b.base)}</b></div>
+      <div class="card"><span>外包运维费</span><b>${money(b.opsFee)}</b></div>
+      <div class="card"><span>尾月对齐</span><b style="font-size:16px">${b.tail ? "是" : "否"}</b></div>
+    </div>
+    <div class="panel"><h2>计费区间</h2>
+      <p class="note">${esc(formula)}。计费起点 = max(实际开通日, 合同生效日);结束日当天计入。${b.tail ? `本明细是订阅结束日所在自然月,尾月应收对齐:对齐前精确 ${money(b.exact)},对齐后 ${money(b.amount)}。` : "非尾月四舍五入到分,累计差额留到尾月。"}</p>
+    </div>
+    <div class="split">
+      <div class="panel"><h2>本月成本(从分成基数扣除)</h2><table><thead><tr><th>项目</th><th>金额</th></tr></thead><tbody>${costRows}</tbody></table></div>
+      <div class="panel"><h2>外包运维费分账号天数</h2><table><thead><tr><th>分账号</th><th>使用天数</th><th>折算</th><th>运维费</th></tr></thead><tbody>${acctRows}</tbody></table></div>
+    </div>
+    <div class="panel"><h2>各渠道分成(结果只用于对账,不是付款指令)</h2>
+      <table><thead><tr><th>渠道</th><th>方式</th><th>比例</th><th>分成金额</th></tr></thead><tbody>${shareRows}</tbody></table>
+      <p class="note">结算时点归属快照:${esc(b.attrs)}。工单责任人不写入分成对象;范围未配置的渠道分成计 0。归属事后变更不回本明细。</p>
+    </div>`);
+}
+
+/* ---- 对账设置 ---- */
+
+function pageSettings() {
+  const rows = db.operators.map((o, i) => `<tr>
+    <td>${esc(o.name)}</td>
+    <td><select id="opDay${i}" style="max-width:150px"><option value="">跟随系统默认(${db.setting.defaultReconcileDay} 日)</option>${Array.from({ length: 28 }, (_, k) => k + 1).map((d) => `<option value="${d}" ${o.reconcileDay === d ? "selected" : ""}>每月 ${d} 日</option>`).join("")}</select></td>
+    <td>${esc(o.payCycle)}</td>
+    <td>${esc(o.notify)}</td>
+    <td><button class="btn ghost" data-op-day="${i}">保存</button></td>
+  </tr>`).join("");
+  return layout("对账设置", "对账日只能是每月 1 至 28 日;对账日当天只核算已结束的自然月。付款周期只记录,不触发扣款。", `
+    <div class="panel"><h2>系统默认对账日</h2>
+      <div class="row"><label style="margin:0">默认每月</label><input id="defaultDay" type="number" min="1" max="28" value="${db.setting.defaultReconcileDay}" style="max-width:90px"><label style="margin:0">日</label><button class="btn" data-day-save>保存默认值</button></div>
+    </div>
+    <div class="panel"><h2>运营商覆盖与付款周期</h2>
+      <table><thead><tr><th>运营商</th><th>对账日覆盖</th><th>付款周期(只记录)</th><th>通知地址</th><th></th></tr></thead><tbody>${rows}</tbody></table>
+      <p class="note">移动、联通:合同生效次月起必须付款,与其是否已向客户收妥无关;电信 ICT:按合同年 / 半年 / 季度。对账周期按月或季度,按季度也先按自然月计算再合并核对。</p>
+    </div>`);
+}
+
+/* ---- 维护说明 ---- */
+
+function pageNotes() {
+  const rows = db.notes.map((n, i) => `<tr><td>${seq(i)}</td><td>${pill(n.level)}</td><td>${esc(n.bill)}</td><td class="wrap">${esc(n.text)}</td><td>${esc(n.by)}<br><span class="note">${esc(n.at)}</span></td></tr>`).join("");
+  return layout("维护说明", "已递交运营商的账单保留原明细;必须登记严重级维护说明,修正核验通过后从下一自然月生效;未付款可打回重做,已付款由财务对冲。", `
+    <div class="panel"><table><thead><tr><th>序号</th><th>级别</th><th>关联账单</th><th>错误内容</th><th>登记人 / 时间</th></tr></thead><tbody>${rows}</tbody></table></div>
+    <div class="panel"><h2>登记严重级维护说明</h2>
+      <label>关联账单</label><input id="noteBill" placeholder="例如 临港跨境 2026-09">
+      <label>错误内容</label><textarea id="noteText" placeholder="写明错误公式/比例与影响"></textarea>
+      <div class="form-actions"><button class="btn warn" data-note-add>登记(保留不删除)</button></div>
+    </div>`);
+}
+
+/* ---- 运营商反馈 ---- */
+
+function pageFeedback() {
+  const stateText = { nomatch: "匹配不到", pending: "可回填", conflict: "状态冲突", done: "已处理" };
+  const rows = db.feedback.map((f, i) => {
+    let action = "";
+    if (f.state === "pending" && !f.handled) action = `<button class="btn" data-fb-fill="${i}">按反馈回填(${esc(f.fillDate)})</button>`;
+    else if (!f.handled) action = `<button class="btn ghost" data-fb-done="${i}">登记人工已处理</button>`;
+    else action = pill("已处理");
+    return `<tr><td>${seq(i)}</td><td>${esc(f.no)}</td><td>${esc(f.action)}</td><td>${esc(f.date)}</td><td>${esc(stateText[f.state])}</td><td class="wrap">${esc(f.result)}</td><td>${action}</td></tr>`;
+  }).join("");
+  return layout("运营商反馈", "反馈用服务凭证进入,不发人的登录令牌;用企业主体号匹配待执行记录。匹配不到不自动建企业,冲突不覆盖。", `
+    <div class="panel"><table><thead><tr><th>序号</th><th>企业主体号</th><th>动作</th><th>反馈日期</th><th>匹配</th><th>内容</th><th>处理</th></tr></thead><tbody>${rows}</tbody></table></div>`);
+}
+
+/* ---- 审计日志 ---- */
+
+function visibleAudit() {
+  const u = user();
+  const logs = db.auditLogs.map((l, i) => ({ ...l, i }));
+  if (u.role === "admin") return logs;
+  const entIndex = (l) => db.enterprises.findIndex((e) => e.name === l.object);
+  const isEntLog = (l) => l.type.startsWith("企业");
+  if (u.role === "teamLead") {
+    const covered = new Set(teamCovered(u.team));
+    const teamName = db.teams[u.team].name;
+    return logs.filter((l) =>
+      (l.type.includes("负责范围") && l.object.startsWith(teamName)) ||
+      (isEntLog(l) && covered.has(entIndex(l))));
+  }
+  if (u.role === "partner") {
+    const covered = new Set(visibleEnterprises());
+    const pName = db.partners[u.partner].name;
+    return logs.filter((l) =>
+      (l.type.includes("合伙人负责范围") && l.object.startsWith(pName)) ||
+      (isEntLog(l) && covered.has(entIndex(l))));
+  }
+  if (u.role === "enterprise" || u.role === "sub") {
+    const eName = db.enterprises[u.enterprise].name;
+    return logs.filter((l) => isEntLog(l) && l.object === eName);
+  }
+  return [];
+}
+
+function auditTable(list) {
+  const rows = list.map((l) => `<tr><td>${esc(l.at)}</td><td>${esc(l.by)}</td><td>${esc(l.type)}</td><td>${esc(l.object)}</td><td class="wrap">${esc(l.before) || "—"}</td><td class="wrap">${esc(l.after) || "—"}</td></tr>`).join("");
+  return `<table><thead><tr><th>时间</th><th>操作人</th><th>操作类型</th><th>对象</th><th>变更前</th><th>变更后</th></tr></thead><tbody>${rows || `<tr><td colspan="6">可见范围内暂无记录</td></tr>`}</tbody></table>`;
+}
+
+function pageAudit() {
+  return layout("审计日志", "只追加,不允许修改或删除。区域树维护记录仅系统管理员可见;其他角色只看本企业挂载与自身范围变更。", `<div class="panel">${auditTable(visibleAudit().slice().reverse())}</div>`);
+}
+
+/* ================= 团队主账号页面 ================= */
+
+function pageQueue() {
+  const team = db.teams[user().team];
+  const list = visibleTickets();
+  const waiting = list.filter((t) => t.assignee === null && t.status !== "已完成" && t.status !== "已关闭");
+  const late = waiting.filter((t) => {
+    const a = db.actions.find((x) => x.ticket === t.i);
+    return (t.type === "开户" || t.type === "到期停机") && overdueAction(a);
+  });
+  const banner = late.map((t) => `<div class="alert">${esc(entName(t.enterprise))} 的${esc(t.type)}已超过 7 个自然日仍未回填,当前连续提醒团队主账号。可在工单详情里临时延期。</div>`).join("");
+  const action = team.mode === "自动平均"
+    ? `<button class="btn" data-auto="${user().team}">按未完成数量平均分派</button>`
+    : `<span class="note">本团队是手工分派,在下表指定成员;也可对已分派工单改派。</span>`;
+  return layout("待分派工单", `${team.name} · ${team.type}类型 · 当前方式:${team.mode}`, `
+    ${banner}
+    <div class="panel"><div class="row" style="margin-bottom:10px">${action}</div>${ticketTable(list, team.mode === "手工")}</div>
+    <div class="panel"><h2>可接单成员的未完成数</h2><p class="note">${eligibleHint(user().team)}</p><p class="note">录入类型不接单;没有可接单成员时工单留在团队,不派到团队外。</p></div>`);
+}
+function eligibleHint(teamIndex) {
+  return db.members.map((m, i) => ({ ...m, i })).filter((m) => m.team === teamIndex && m.type !== "录入")
+    .map((m) => `${m.name}(${m.type}) ${unfinished(db, m.i)} 单 · 范围 ${m.scope.length} 家`).join(";");
+}
+
+function pageTeamEnterprises() {
+  return layout("团队企业", "团队负责范围由系统管理员划定;主账号只能在范围内配置成员负责范围,不能自行扩大。", `<div class="panel">${enterpriseTable(visibleEnterprises())}</div>`);
+}
+
+function pageMembers() {
+  const team = user().team;
+  const covered = teamCovered(team);
+  const blocks = db.members.map((m, i) => ({ ...m, i })).filter((m) => m.team === team).map((m) => {
+    const checks = covered.map((ei) => `<label class="ck"><input type="checkbox" data-men="${ei}" ${m.scope.includes(ei) ? "checked" : ""}> ${esc(entName(ei))}</label>`).join("");
+    const awards = m.type === "施工" ? db.awards.filter((a) => a.member === m.i).map((a) => `<li>${esc(a.at)} ${pill(a.kind)} ${esc(a.text)}</li>`).join("") : "";
+    return `<div class="panel">
+      <h2>${esc(m.name)} · ${esc(m.type)}类型 ${m.type === "录入" ? "(代录,不接单)" : ""}</h2>
+      <p class="note">负责范围必须是团队负责范围的子集;同一企业可同时落在多名成员范围内。</p>
+      <div class="checklist" data-mem-checks="${m.i}">${checks || "团队范围暂不含企业"}</div>
+      <div class="form-actions"><button class="btn" data-member-save="${m.i}">保存该成员负责范围</button></div>
+      ${awards ? `<h2 style="margin-top:12px">奖惩记录(只作考核,费用扣减在线下)</h2><ul class="files">${awards}</ul>` : ""}
+    </div>`;
+  }).join("");
+  return layout("成员与负责范围", "主账号在团队范围内为每名子账号配置负责范围,以及手工 / 自动平均分派方式。", blocks);
+}
+
+function pageMode() {
+  const team = db.teams[user().team];
+  return layout("分派方式", "每个团队选一种。自动平均之后仍可在待分派页手工改派。", `
+    <div class="panel">
+      <p>当前:<b>${esc(team.mode)}</b></p>
+      <div class="form-actions">
+        <button class="btn ${team.mode === "手工" ? "" : "ghost"}" data-mode="手工">手工分派</button>
+        <button class="btn ${team.mode === "自动平均" ? "" : "ghost"}" data-mode="自动平均">自动平均分派</button>
+      </div>
+      <p class="note">自动平均:在可接单成员(本团队、类型匹配、企业在其负责范围内)中选未完成工单最少的一名;数量相同按成员账号固定顺序取靠前的。录入不参与。首期不做轮班。</p>
+    </div>`);
+}
+
+/* ================= 常规 / 施工 / 录入 ================= */
+
+function pageMine() {
+  const list = visibleTickets();
+  return layout(user().role === "worker" ? "我的施工工单" : "我的工单", "只显示分派给自己的工单。施工人员不执行网络侧开停,处理不了可委托本团队另一名施工人员。", `<div class="panel">${ticketTable(list, false)}</div>`);
+}
+
+function pageAwards() {
+  const rows = db.awards.filter((a) => a.member === user().member).map((a) => `<tr><td>${esc(a.at)}</td><td>${pill(a.kind)}</td><td class="wrap">${esc(a.text)}</td><td>${a.amount >= 0 ? "+" : ""}${money(Math.abs(a.amount))}</td></tr>`).join("");
+  return layout("奖惩记录", "奖惩记在施工人员账号上作为考核;扣罚不进入客户应收,也不进入渠道分成。", `
+    <div class="panel"><table><thead><tr><th>日期</th><th>类型</th><th>说明</th><th>金额(元)</th></tr></thead><tbody>${rows || `<tr><td colspan="4">暂无记录</td></tr>`}</tbody></table></div>
+    <div class="panel"><h2>我的负责区域与跟进进度</h2>${enterpriseTable(visibleEnterprises())}</div>`);
+}
+
+function pageBackfill() {
+  const list = visibleTickets().filter((t) => t.type === "开户" || t.type === "到期停机");
+  return layout("开停回填", "网络侧由人执行,系统不把“已生成工单”当成“已完成”。回填成功才改账户状态;失败则记录执行失败、工单退回处理中。", `<div class="panel">${ticketTable(list, false)}</div>`);
+}
+
+function pageTicket() {
+  const t = db.tickets[focus];
+  if (!t) return layout("工单", "", `<div class="panel">没有该工单。</div>`);
+  const u = user();
+  const action = db.actions.find((a) => a.ticket === focus);
+  const isOpenType = t.type === "开户" || t.type === "到期停机";
+  const canFill = (u.role === "ops" && t.assignee === u.member || u.role === "admin") && isOpenType && t.status !== "已完成" && t.status !== "已关闭";
+  const canDelegate = u.role === "worker" && t.assignee === u.member && t.status !== "已完成" && t.status !== "已关闭";
+  const canFinish = (u.role === "ops" || u.role === "worker") && t.assignee === u.member && !isOpenType && t.status !== "已完成" && t.status !== "已关闭";
+  const canClose = (u.role === "teamLead" && t.team === u.team || u.role === "admin") && t.status !== "已完成" && t.status !== "已关闭";
+  const canExtend = (u.role === "teamLead" && t.team === u.team || u.role === "admin") && action && action.status === "待执行";
+  const others = canDelegate ? db.members.map((m, i) => ({ ...m, i })).filter((m) => m.team === t.team && m.type === "施工" && m.i !== u.member) : [];
+  const late = action && overdueAction(action);
+  return layout(`${t.type} · ${entName(t.enterprise)}${t.account !== undefined && t.account !== null ? " · " + esc(db.accounts[t.account].name) : ""}`, `${teamName(t.team)} · ${memberName(t.assignee)}`, `
+    <div class="split">
+      <div class="panel">
+        <p>${pill(t.status)} <span class="note">创建于 ${esc(t.created)}${action ? ` · 开停记录 ${esc(action.id)} · ${esc(action.status)}${action.doneOn ? "(" + esc(action.doneOn) + ")" : ""}` : ""}</span>${late ? " " + pill("超 7 日") : ""}</p>
+        <p style="margin-top:10px">${esc(t.text)}</p>
+        ${t.closeReason ? `<div class="alert" style="margin-top:10px">关闭原因:${esc(t.closeReason)}</div>` : ""}
+        <h2 style="margin-top:14px">处理记录</h2>
+        <ol class="log">${t.logs.map((line) => `<li>${esc(line)}</li>`).join("")}</ol>
+        <h2 style="margin-top:14px">过程材料(照片与回填说明,正式系统走对象存储浏览器直传)</h2>
+        ${t.materials.length ? `<ul class="files">${t.materials.map((m) => `<li>${esc(m)}</li>`).join("")}</ul>` : `<p class="note">暂无材料。照片不是完成门槛。</p>`}
+      </div>
+      <div class="panel">
+        <h2>处理</h2>
+        ${canFill ? `<label>${t.type === "开户" ? "实际开通日" : "停机完成日"}(不晚于今天)</label><input id="openedOn" type="date" value="${TODAY}" max="${TODAY}"><div class="form-actions"><button class="btn" data-fill="${focus}">回填成功</button><button class="btn warn" data-fail="${focus}">回填失败</button></div><p class="note">${t.type === "开户" ? "成功后企业与合同选定分账号变为在用;开通日早于合同生效日时计费仍从生效日起。" : "成功后企业及其在用分账号改为停用;计费不延长过订阅结束日。"}</p>` : ""}
+        ${canFinish ? `<label>处理记录(故障/售后有处理记录即可完成,照片非门槛)</label><textarea id="handleNote" placeholder="填写处理说明"></textarea><div class="form-actions"><button class="btn" data-done="${focus}">标记已完成</button></div>` : ""}
+        ${canDelegate ? `<label>委托本团队另一名施工人员(委托记在工单上,不再重算平均分派)</label><select id="delegateTo">${others.map((m) => `<option value="${m.i}">${esc(m.name)}</option>`).join("")}</select><div class="form-actions"><button class="btn ghost" data-delegate="${focus}">委托</button></div><p class="note">施工费用扣减在线下处理,不改结算明细。</p>` : ""}
+        ${canClose ? `<label>关闭原因(必填;开停类关闭后开停记录改为执行失败)</label><textarea id="closeReason" placeholder="例如:重复报修合并处理"></textarea><div class="form-actions"><button class="btn warn" data-close="${focus}">关闭工单</button></div>` : ""}
+        ${canExtend ? `<div class="form-actions" style="margin-top:8px"><button class="btn ghost" data-extend="${action.id}">临时延期 7 个自然日</button></div><p class="note">只对这一条记录生效,只提醒不拦截。</p>` : ""}
+        ${!canFill && !canFinish && !canDelegate && !canClose ? `<p class="note">当前身份只能查看这张工单。企业用户和下属分账号不能改派、不能关闭。</p>` : ""}
+      </div>
+    </div>`);
+}
+
+function pageEntry() {
+  return layout("代录企业、合同和金额", "电信、移动按 ICT 在本系统界面录入,由录入类型子账号用自己的账号代录。不开放结算范围、分成规则和已出账更正。", `
+    <div class="panel">
+      <div class="form-grid">
+        <div><label>企业主体号(手工填写,不自动生成)</label><input id="entNo" placeholder="例如 KL-2026-0030"></div>
+        <div><label>名称</label><input id="entName" placeholder="企业或个人名称"></div>
+        <div><label>主体类型</label><select id="entSubject"><option>企业</option><option>个人</option><option>个体工商户</option></select></div>
+        <div><label>挂载区域(必选)</label><select id="entRegion">${db.regions.map((r) => `<option value="${r.id}">${esc(regionPath(db, r.id))}</option>`).join("")}</select></div>
+        <div><label>运营商</label><select id="entOp">${db.operators.map((o, i) => i > 0 ? `<option value="${i}">${o.name}</option>` : null).filter(Boolean).join("")}</select></div>
+        <div><label>合伙人(可空)</label><select id="entPartner"><option value="">无</option>${db.partners.map((p, i) => `<option value="${i}">${esc(p.name)}</option>`).join("")}</select></div>
+        <div><label>常规运维团队</label><select id="entTeam">${db.teams.map((t, i) => t.type === "常规" ? `<option value="${i}">${esc(t.name)}</option>` : null).filter(Boolean).join("")}</select></div>
+        <div><label>合同编号</label><input id="entContract" placeholder="ICT 合同编号"></div>
+        <div><label>固定套餐</label><select id="entPkg">${db.packages.filter((p) => p.custom === null).map((p, i) => `<option value="${i}">${esc(p.name)}(年价 ${p.yearPrice},额度 ${p.quota})</option>`).join("")}</select></div>
+      </div>
+      <div class="form-actions"><button class="btn" data-entry>写入(不直接改为在用)</button></div>
+      <p class="note">材料只接受运营商提供。同步或代录只写主数据和订阅;正式订阅建立后由系统生成待执行开户记录与工单。</p>
+    </div>`);
+}
+
+/* ================= 企业 / 分账号 ================= */
+
+function pagePlan() {
+  focus = user().enterprise;
+  const e = db.enterprises[focus];
+  const rows = currentSubs(focus).map((s) => `<tr><td>${esc(s.name)}<br><span class="note">${esc(s.contractNo)}</span></td><td>${esc(s.kind)}</td><td>${esc(s.start)} 至 ${esc(s.end)}</td><td>${s.monthPrice === null ? "试用未填优惠金额" : money(s.monthPrice) + " 元/月"}</td><td>${pill(e.status)}</td></tr>`).join("");
+  return layout("当前套餐", `所属区域:${esc(regionPath(db, e.region))}。${e.status === "停用" ? "账号仍可登录查看历史,不能继续使用订阅权益。" : "只展示当前生效套餐,历史变更留在后台。"}`, `
+    <div class="panel"><table><thead><tr><th>套餐 / 合同</th><th>方式</th><th>期间</th><th>月标准</th><th>账户</th></tr></thead><tbody>${rows}</tbody></table>
+    <p class="note">不能在这里发起开户或到期停机;开户和到期停机只由运维侧执行。试用未填优惠金额时不套用正式月费。</p></div>`);
+}
+
+function pageAccounts() {
+  const rows = db.accounts.map((a, i) => ({ ...a, i })).filter((a) => a.enterprise === user().enterprise).map((a) =>
+    `<tr><td>${seq(a.i)}</td><td>${esc(a.name)}</td><td>${esc(a.usage)}</td><td>${pill(a.status)}</td><td>${a.openedOn ? esc(a.openedOn) : "—"}</td></tr>`).join("");
+  return layout("下属分账号", `额度 ${db.enterprises[user().enterprise].quota},本次可只开其中一部分;不能单独停用某个分账号。`, `<div class="panel"><table><thead><tr><th>序号</th><th>账号</th><th>用途</th><th>状态</th><th>开通日</th></tr></thead><tbody>${rows}</tbody></table></div>`);
+}
+
+function pageSelf() {
+  const a = db.accounts[user().account];
+  return layout("我的账号", "只能看到自己,以及本人发起的故障和售后工单。", `<div class="panel"><p><b>${esc(a.name)}</b></p><p class="note" style="margin-top:8px">${esc(entName(a.enterprise))} · ${esc(a.usage)} · ${pill(a.status)}</p></div>`);
+}
+
+function pageSubmit() {
+  return layout("提交故障或售后", "提交文字、图片或语音后生成工单,先到常规团队再分派。不能分派、不能关闭、不能发起开停。", `
+    <div class="panel">
+      <label>类型</label><select id="faultType"><option>故障</option><option>售后</option></select>
+      <label>内容</label><textarea id="faultText" placeholder="文字说明;图片、语音在正式系统一并提交。"></textarea>
+      <div class="form-actions"><button class="btn" data-submit>生成工单</button></div>
+      <p class="note">也可以通过企业微信或运营商客服进入:由我方运维人员在系统内代建工单。</p>
+    </div>`);
+}
+
+function pageProgress() {
+  return layout(user().role === "sub" ? "我的工单" : "工单进度", "只能查看,不能改派或关闭。", `<div class="panel">${ticketTable(visibleTickets(), false)}</div>`);
+}
+
+/* ================= 合伙人 ================= */
+
+function pageRegion() {
+  const indexes = visibleEnterprises();
+  const rows = indexes.map((i) => {
+    const bills = db.settlements.filter((b) => b.enterprise === i);
+    const sum = bills.reduce((n, b) => n + b.amount, 0);
+    const share = bills.reduce((n, b) => n + b.shares.filter((s) => s.who.includes("合伙人")).reduce((m, s) => m + s.amount, 0), 0);
+    return `<tr class="clickable" data-go="enterprise" data-id="${i}"><td>${seq(i)}</td><td>${esc(entName(i))}</td><td>${money(sum)}</td><td>${money(share)}</td></tr>`;
+  }).join("");
+  return layout("本区域对账", `负责范围:${esc(scopeSummary(db, db.partners[user().partner].scope))}。收款信息单独保存,不回写应收与分成,不生成支付指令。`, `<div class="panel"><table><thead><tr><th>序号</th><th>企业</th><th>已出账应收</th><th>合伙人分成</th></tr></thead><tbody>${rows || `<tr><td colspan="4">范围内暂无企业</td></tr>`}</tbody></table></div>`);
+}
+
+function partnerOrTeamRules() {
+  const u = user();
+  let entIndexes, ch, ref, title, hint;
+  if (u.role === "partner") {
+    entIndexes = visibleEnterprises(); ch = "partner"; ref = u.partner;
+    title = "名下企业分成"; hint = "分成挂在合伙人与企业的关系上;合同增补优先于区域常规,两层都没有计 0。合伙人不改派工单、不执行开停。";
+  } else {
+    entIndexes = teamCovered(u.team); ch = "team"; ref = u.team;
+    title = "团队分成"; hint = `分成挂在「${db.teams[ref].name}」与企业的关系上,不挂到子账号,不随工单责任人变化。`;
+  }
+  const rows = entIndexes.map((i) => {
+    const rule = db.rules.find((x) => x.ch === ch && x.ref === ref && x.ent === i);
+    return `<tr><td>${esc(entName(i))}</td><td>${ruleInput(rule, ch, ref, i)}</td></tr>`;
+  }).join("");
+  return layout(title, hint, `
+    <div class="panel"><table><thead><tr><th>企业</th><th>比例(0-1)与规则层</th></tr></thead><tbody>${rows || `<tr><td colspan="2">范围内暂无企业</td></tr>`}</tbody></table>
+      <div class="form-actions"><button class="btn" data-rules-save="${ch}">保存分成比例</button></div>
+      <p class="note">分成 =(实际结算金额 − 应扣除成本)× 比例,只用于对账。线路投入不扣基数,国际资源按摊销扣,设备固定金额与比例同一项目不并用。</p>
+    </div>`);
+}
+
+function pageCollect() {
+  const mine = db.collections.filter((c) => c.partner === user().partner);
+  const rows = mine.map((c, i) => `<tr><td>${i + 1}</td><td>${esc(entName(c.enterprise))}</td><td>${money(c.amount)}</td><td>${esc(c.date)}</td><td>${esc(c.note)}</td></tr>`).join("");
+  const options = visibleEnterprises().map((i) => `<option value="${i}">${esc(db.enterprises[i].name)}</option>`).join("");
+  return layout("收款信息", "只记录本区域收款,用于和运营商核对;不回写应收、不生成支付指令。", `
+    <div class="panel"><table><thead><tr><th>序号</th><th>企业</th><th>金额</th><th>日期</th><th>说明</th></tr></thead><tbody>${rows || `<tr><td colspan="5">还没有收款记录</td></tr>`}</tbody></table></div>
+    <div class="panel"><h2>登记一笔</h2>
+      <label>企业</label><select id="colEnt">${options}</select>
+      <label>金额</label><input id="colAmount" type="number" min="0" step="0.01" value="1000">
+      <label>日期</label><input id="colDate" type="date" value="${TODAY}">
+      <div class="form-actions"><button class="btn" data-collect>保存</button></div>
+    </div>`);
+}
+
+const PAGES = {
+  home: pageHome,
+  regions: pageRegions,
+  enterprises: pageEnterprises,
+  enterprise: pageEnterprise,
+  catalog: pageCatalog,
+  subs: pageSubs,
+  partners: pagePartners,
+  pscope: () => scopeEditor(focus, "partner"),
+  teams: pageTeams,
+  tscope: () => scopeEditor(focus, "team"),
+  rules: () => (user().role === "admin" ? pageRules() : partnerOrTeamRules()),
+  scopes: pageScopes,
+  batches: pageBatches,
+  batch: pageBatch,
+  bills: pageBills,
+  bill: pageBill,
+  settings: pageSettings,
+  notes: pageNotes,
+  feedback: pageFeedback,
+  audit: pageAudit,
+  logs: pageAudit,
+  queue: pageQueue,
+  members: pageMembers,
+  mode: pageMode,
+  mine: pageMine,
+  awards: pageAwards,
+  backfill: pageBackfill,
+  ticket: pageTicket,
+  entry: pageEntry,
+  plan: pagePlan,
+  accounts: pageAccounts,
+  self: pageSelf,
+  submit: pageSubmit,
+  progress: pageProgress,
+  region: pageRegion,
+  collect: pageCollect,
+};
+
+function render() {
+  const root = document.getElementById("app");
+  if (session === null) {
+    root.innerHTML = renderLogin();
+  } else {
+    const fn = PAGES[route] || pageHome;
+    root.innerHTML = fn();
+  }
+  if (toast) root.insertAdjacentHTML("beforeend", `<div class="toast">${esc(toast)}</div>`);
+}
+
+/* ================= 事件处理 ================= */
+
+document.body.addEventListener("click", (event) => {
+  const node = event.target.closest("[data-login],[data-go],[data-logout],[data-reset],[data-group-toggle],[data-assign],[data-auto],[data-mode],[data-fill],[data-fail],[data-done],[data-close],[data-delegate],[data-extend],[data-submit],[data-entry],[data-collect],[data-region-node],[data-region-add],[data-region-rename],[data-region-delete],[data-region-mount],[data-scope-save],[data-scope-toggle],[data-member-save],[data-attr-save],[data-acct-add],[data-pkg-add],[data-partner-add],[data-team-add],[data-rules-save],[data-day-save],[data-op-day],[data-note-add],[data-fb-fill],[data-fb-done],[data-batch-run]");
+  if (!node) return;
+  const d = node.dataset;
+
+  if (d.login !== undefined) {
+    session = Number(d.login);
+    route = firstRoute(user().role);
+    render();
+    return;
+  }
+  if (d.logout !== undefined) {
+    session = null;
+    render();
+    return;
+  }
+  if (d.reset !== undefined) {
+    db = cloneSeed();
+    selRegion = "pd";
+    route = firstRoute(user().role);
+    say("已恢复模拟数据");
+    return;
+  }
+  if (d.groupToggle !== undefined) {
+    const k = d.groupToggle;
+    if (openGroups.has(k)) openGroups.delete(k); else openGroups.add(k);
+    render();
+    return;
+  }
+  if (d.go) {
+    go(d.go, d.id === undefined ? undefined : Number(d.id));
+    return;
+  }
+  if (d.assign !== undefined) {
+    const id = Number(d.assign);
+    assignTo(id, Number(document.querySelector(`[data-pick="${id}"]`).value));
+    return;
+  }
+  if (d.auto !== undefined) {
+    autoAssignTeam(Number(d.auto));
+    return;
+  }
+  if (d.mode) {
+    db.teams[user().team].mode = d.mode;
+    say("分派方式已改为" + d.mode);
+    return;
+  }
+  if (d.fill !== undefined) {
+    backfill(Number(d.fill), document.getElementById("openedOn").value, true);
+    return;
+  }
+  if (d.fail !== undefined) {
+    backfill(Number(d.fail), TODAY, false);
+    return;
+  }
+  if (d.done !== undefined) {
+    const id = Number(d.done);
+    const text = document.getElementById("handleNote").value.trim();
+    if (!text) { say("请填写处理记录"); return; }
+    db.tickets[id].status = "已完成";
+    db.tickets[id].logs.push(`${TODAY} ${user().name}:${text}`);
+    say("工单已完成");
+    return;
+  }
+  if (d.close !== undefined) {
+    const id = Number(d.close);
+    const reason = document.getElementById("closeReason").value.trim();
+    if (!reason) { say("关闭必须填写原因"); return; }
+    closeTicket(id, reason);
+    return;
+  }
+  if (d.delegate !== undefined) {
+    const id = Number(d.delegate);
+    const to = Number(document.getElementById("delegateTo").value);
+    db.tickets[id].assignee = to;
+    db.tickets[id].logs.push(`${TODAY} 委托给${db.members[to].name}(委托人:${user().name})`);
+    say("已委托,不重新平均分派");
+    return;
+  }
+  if (d.extend !== undefined) {
+    const a = db.actions.find((x) => x.id === d.extend);
+    a.extendUntil = addDays(TODAY, 7);
+    const t = db.tickets[a.ticket];
+    t.logs.push(`${TODAY} ${user().name}将该记录提醒期限临时延至 ${a.extendUntil}`);
+    say("已临时延期至 " + a.extendUntil);
+    return;
+  }
+  if (d.submit !== undefined) {
+    const text = document.getElementById("faultText").value.trim();
+    if (!text) { say("请填写内容"); return; }
+    const u = user();
+    submitTicket(u.enterprise, u.role === "sub" ? u.account : null, document.getElementById("faultType").value, text);
+    document.getElementById("faultText").value = "";
+    return;
+  }
+  if (d.entry !== undefined) {
+    handleEntry();
+    return;
+  }
+  if (d.collect !== undefined) {
+    db.collections.push({
+      partner: user().partner,
+      enterprise: Number(document.getElementById("colEnt").value),
+      amount: Number(document.getElementById("colAmount").value),
+      date: document.getElementById("colDate").value,
+      note: "手工登记,不回写应收",
+    });
+    say("收款已登记,应收未改");
+    return;
+  }
+  if (d.regionNode !== undefined) {
+    selRegion = d.regionNode;
+    render();
+    return;
+  }
+  if (d.regionAdd !== undefined) {
+    const parent = d.regionAdd || null;
+    const input = parent ? "newRegionName" : "newRootName";
+    const name = val(input);
+    if (!name) { say("请填写节点名称"); return; }
+    const pNode = parent ? regionNode(db, parent) : null;
+    const id = "r" + Date.now();
+    db.regions.push({ id, name, level: parent ? pNode.level + 1 : 0, parent });
+    addAudit("新建区域", parent ? regionPath(db, parent) + " / " + name : name, "", `新建${LEVEL_NAMES[parent ? pNode.level + 1 : 0]}节点`);
+    selRegion = id;
+    say("区域节点已新建");
+    return;
+  }
+  if (d.regionRename !== undefined) {
+    const id = d.regionRename;
+    const n = regionNode(db, id);
+    const name = val("renameRegion");
+    if (!name || name === n.name) { say("名称未变化"); return; }
+    addAudit("重命名区域", regionPath(db, id), n.name, name);
+    n.name = name;
+    say("已重命名");
+    return;
+  }
+  if (d.regionDelete !== undefined) {
+    const id = d.regionDelete;
+    const n = regionNode(db, id);
+    if (db.regions.some((r) => r.parent === id)) { say("请先删除下级节点"); return; }
+    if (db.enterprises.some((e) => e.region === id)) { say("请先移走直属企业"); return; }
+    const refs = regionReferenced(db, id);
+    if (refs.length) { say("该节点被负责范围引用,不能删除:" + refs.join(";")); return; }
+    addAudit("删除区域", regionPath(db, id), n.name, "(节点已删除)");
+    db.regions = db.regions.filter((r) => r.id !== id);
+    selRegion = db.regions[0].id;
+    say("节点已删除");
+    return;
+  }
+  if (d.regionMount !== undefined) {
+    const rid = d.regionMount;
+    const ei = Number(document.getElementById("mountEnt").value);
+    const before = regionPath(db, db.enterprises[ei].region);
+    const after = regionPath(db, rid);
+    if (before === after) { say("企业已经挂在该节点"); return; }
+    db.enterprises[ei].region = rid;
+    addAudit(before === "" ? "企业挂载" : "企业改挂区域", entName(ei), before, after);
+    entHistory(ei, "挂载区域", before, after);
+    say("已挂载到 " + after);
+    return;
+  }
+  if (d.scopeSave !== undefined) {
+    const [kind, targetStr] = d.scopeSave.split("-");
+    const target = Number(targetStr);
+    const obj = kind === "partner" ? db.partners[target] : db.teams[target];
+    const before = scopeEnterprises(db, obj.scope).map((i) => entName(i)).join("、") || "(空)";
+    const regions = Array.from(document.querySelectorAll("[data-rg]:checked")).map((el) => el.dataset.rg);
+    const enterprises = Array.from(document.querySelectorAll("[data-en]:checked")).map((el) => Number(el.dataset.en));
+    obj.scope = { regions, enterprises };
+    const after = scopeEnterprises(db, obj.scope).map((i) => entName(i)).join("、") || "(空)";
+    addAudit(kind === "partner" ? (before === "(空)" ? "合伙人负责范围首次配置" : "合伙人负责范围调整") : "运维团队负责范围调整", kind === "partner" ? `${obj.name}(${obj.title})` : obj.name, before, after);
+    say("负责范围已保存,审计日志已追加");
+    go(kind === "partner" ? "partners" : "teams");
+    return;
+  }
+  if (d.scopeToggle !== undefined) {
+    const i = Number(d.scopeToggle);
+    const s = db.scopes[i];
+    s.enabled = !s.enabled;
+    addAudit("结算范围" + (s.enabled ? "启用" : "停用"), `${s.kind}范围 · ${scopeTargetName(s)}`, s.enabled ? "未启用" : "启用", s.enabled ? "启用" : "未启用");
+    say((s.enabled ? "已启用" : "已停用") + ":" + scopeTargetName(s));
+    return;
+  }
+  if (d.memberSave !== undefined) {
+    const mi = Number(d.memberSave);
+    const m = db.members[mi];
+    const covered = new Set(teamCovered(user().team));
+    m.scope = Array.from(document.querySelectorAll(`[data-mem-checks="${mi}"] [data-men]:checked`)).map((el) => Number(el.dataset.men)).filter((i) => covered.has(i));
+    addAudit("团队成员负责范围调整", `${db.teams[user().team].name} / ${m.name}`, "", m.scope.map((i) => entName(i)).join("、") || "(空)");
+    say(`${m.name} 的负责范围已保存(${m.scope.length} 家)`);
+    return;
+  }
+  if (d.attrSave !== undefined) {
+    handleAttrSave(Number(d.attrSave));
+    return;
+  }
+  if (d.acctAdd !== undefined) {
+    const ei = Number(d.acctAdd);
+    const name = val("newAcctName");
+    if (!name) { say("请填写分账号姓名"); return; }
+    const usage = document.getElementById("newAcctUsage").value;
+    const formalCount = db.accounts.filter((a) => a.enterprise === ei && a.usage === "正式").length;
+    if (usage === "正式" && formalCount >= db.enterprises[ei].quota) { say("正式分账号数量不能超过套餐额度"); return; }
+    db.accounts.push({ enterprise: ei, name, status: "未开通", usage, openedOn: null });
+    addAudit("企业新增分账号", db.enterprises[ei].name, "—", `${name}(${usage})`);
+    say("分账号已创建,状态未开通");
+    return;
+  }
+  if (d.pkgAdd !== undefined) {
+    const name = val("pkgName");
+    if (!name) { say("请填写套餐名称"); return; }
+    const year = Number(document.getElementById("pkgYear").value);
+    db.packages.push({ name, yearPrice: year, monthPrice: Math.round(year / 12 * 100) / 100, quota: Number(document.getElementById("pkgQuota").value), bw: document.getElementById("pkgBw").value, custom: null });
+    say("套餐档已写入目录");
+    return;
+  }
+  if (d.partnerAdd !== undefined) {
+    const name = val("newPName");
+    if (!name) { say("请填写名称"); return; }
+    db.partners.push({ name, title: val("newPTitle") || "区域渠道", notify: "", scope: { regions: [], enterprises: [] } });
+    addAudit("合伙人负责范围首次配置", `${name}(新账号)`, "(空)", "(空,账号已开通待配置)");
+    say("合伙人账号已开通,请继续配置负责范围");
+    return;
+  }
+  if (d.teamAdd !== undefined) {
+    const name = val("newTeamName");
+    if (!name) { say("请填写团队名称"); return; }
+    db.teams.push({ name, type: document.getElementById("newTeamType").value, mode: document.getElementById("newTeamMode").value, scope: { regions: [], enterprises: [] } });
+    addAudit("运维团队负责范围首次配置", name, "(空)", "(空,团队账号已开通待配置)");
+    say("运维团队已开通,请继续配置负责范围");
+    return;
+  }
+  if (d.rulesSave !== undefined) {
+    saveRules(d.rulesSave);
+    return;
+  }
+  if (d.daySave !== undefined) {
+    const day = Number(document.getElementById("defaultDay").value);
+    if (day < 1 || day > 28) { say("对账日只能是 1 至 28 日"); return; }
+    db.setting.defaultReconcileDay = day;
+    say("系统默认对账日已改为每月 " + day + " 日");
+    return;
+  }
+  if (d.opDay !== undefined) {
+    const i = Number(d.opDay);
+    const v = document.getElementById("opDay" + i).value;
+    db.operators[i].reconcileDay = v === "" ? null : Number(v);
+    say(`${db.operators[i].name} 对账日覆盖已保存`);
+    return;
+  }
+  if (d.noteAdd !== undefined) {
+    const bill = val("noteBill");
+    const text = val("noteText");
+    if (!bill || !text) { say("请填写关联账单和错误内容"); return; }
+    db.notes.push({ level: "严重", bill, text, by: user().name, at: NOW });
+    say("严重级维护说明已登记,保留不删除");
+    return;
+  }
+  if (d.fbFill !== undefined) {
+    const fi = Number(d.fbFill);
+    const f = db.feedback[fi];
+    const a = db.actions.find((x) => x.id === f.actionId);
+    if (a) backfill(a.ticket, f.fillDate, true);
+    f.handled = true;
+    say("已按运营商反馈回填");
+    return;
+  }
+  if (d.fbDone !== undefined) {
+    db.feedback[Number(d.fbDone)].handled = true;
+    say("已登记为人工处理");
+    return;
+  }
+  if (d.batchRun !== undefined) {
+    runBatch(Number(document.getElementById("runScope").value));
+    return;
+  }
+});
+
+function handleAttrSave(ei) {
+  const e = db.enterprises[ei];
+  const region = document.getElementById("attrRegion").value;
+  const operator = Number(document.getElementById("attrOperator").value);
+  const partnerRaw = document.getElementById("attrPartner").value;
+  const partner = partnerRaw === "" ? null : Number(partnerRaw);
+  const team0 = Number(document.getElementById("attrTeam0").value);
+  const team1Raw = document.getElementById("attrTeam1").value;
+  const teams = { 常规: team0 };
+  if (team1Raw !== "") teams.施工 = Number(team1Raw);
+
+  const before = regionPath(db, e.region);
+  const after = regionPath(db, region);
+  if (region !== e.region) {
+    addAudit("企业改挂区域", e.name, before, after);
+    entHistory(ei, "挂载区域", before, after);
+    e.region = region;
+  }
+  if (operator !== e.operator) {
+    addAudit("企业变更运营商", e.name, opName(e.operator), opName(operator));
+    entHistory(ei, "运营商", opName(e.operator), opName(operator));
+    e.operator = operator;
+  }
+  if (partner !== e.partner) {
+    addAudit("企业变更合伙人", e.name, partnerName(e.partner), partnerName(partner));
+    entHistory(ei, "合伙人", partnerName(e.partner), partnerName(partner));
+    e.partner = partner;
+  }
+  if (team0 !== e.teams.常规) {
+    addAudit("企业变更常规运维团队", e.name, teamName(e.teams.常规), teamName(team0));
+    entHistory(ei, "常规运维团队", teamName(e.teams.常规), teamName(team0));
+  }
+  if (teams.施工 !== e.teams.施工) {
+    const beforeTeam = e.teams.施工 === undefined ? "无" : teamName(e.teams.施工);
+    const afterTeam = team1Raw === "" ? "无" : teamName(teams.施工);
+    addAudit("企业变更施工运维团队", e.name, beforeTeam, afterTeam);
+    entHistory(ei, "施工运维团队", beforeTeam, afterTeam);
+  }
+  e.teams = teams;
+  say("归属已保存,变更历史和审计日志已追加");
+}
+
+function saveRules(scope) {
+  document.querySelectorAll("[data-rl-rate]").forEach((el) => {
+    const [ch, refStr, entStr] = el.dataset.rlRate.split("-");
+    if (scope !== "admin" && ch !== scope) return;
+    const ref = Number(refStr);
+    const ent = Number(entStr);
+    const rate = Number(el.value) || 0;
+    const layerEl = document.querySelector(`[data-rl-layer="${ch}-${ref}-${ent}"]`);
+    const layer = layerEl ? layerEl.value : "区域常规";
+    const idx = db.rules.findIndex((x) => x.ch === ch && x.ref === ref && x.ent === ent);
+    if (rate <= 0) {
+      if (idx >= 0) db.rules.splice(idx, 1);
+      return;
+    }
+    if (rate > 1) { return; }
+    if (idx >= 0) { db.rules[idx].rate = rate; db.rules[idx].layer = layer; }
+    else db.rules.push({ ch, ref, ent, layer, rate });
+  });
+  say("分成规则已保存;修正从下一个自然月开始使用");
+}
+
+function handleEntry() {
+  const no = val("entNo");
+  const name = val("entName");
+  if (!no || !name) { say("请填写主体号和名称"); return; }
+  if (db.enterprises.some((e) => e.no === no)) { say("企业主体号已存在(幂等:联通同步以主体号加外部单号去重)"); return; }
+  const subject = document.getElementById("entSubject").value;
+  const region = document.getElementById("entRegion").value;
+  const operator = Number(document.getElementById("entOp").value);
+  const partnerRaw = document.getElementById("entPartner").value;
+  const team = Number(document.getElementById("entTeam").value);
+  const contract = val("entContract") || "ICT-" + no;
+  const pkgIdx = Number(document.getElementById("entPkg").value);
+  const pkg = db.packages.filter((p) => p.custom === null)[pkgIdx];
+
+  db.enterprises.push({
+    no, name, subject,
+    materials: subject === "企业" ? "营业执照、企业名称、合同、电话" : "身份证、手机号",
+    files: [], phone: "", region, operator,
+    partner: partnerRaw === "" ? null : Number(partnerRaw),
+    teams: { 常规: team }, status: "未开通", quota: pkg.quota,
+    history: [{ at: NOW, field: "挂载区域", before: "未挂载", after: regionPath(db, region), by: user().name }],
+  });
+  const ei = db.enterprises.length - 1;
+  db.subs.push({
+    enterprise: ei, name: pkg.name, kind: "正式", status: "生效中",
+    start: TODAY, end: yearLater(TODAY),
+    yearPrice: pkg.yearPrice, monthPrice: pkg.monthPrice, openedOn: null, contractNo: contract, files: [],
+  });
+  /* 正式订阅建立且企业未开通:生成待执行开户记录与工单 */
+  db.tickets.push({
+    type: "开户", enterprise: ei, account: null, team, assignee: null, status: "待处理",
+    created: TODAY, text: `${contract} 合同套餐已建立,等待网络侧开通。`,
+    logs: [`${TODAY} 录入人员代录,生成待执行开户记录`], closeReason: null, materials: [],
+  });
+  const ti = db.tickets.length - 1;
+  db.actions.push({ id: "A-" + TODAY.replace(/-/g, "") + "-" + String(ei).padStart(2, "0"), enterprise: ei, type: "开户", status: "待执行", ticket: ti, created: TODAY, doneOn: null, extendUntil: null, by: null });
+  /* 录入员代录范围显式加入新企业,方便其看到自己录的企业;团队范围仍由管理员配置 */
+  const entryMember = db.members.find((m) => m.type === "录入" && m.team === team);
+  if (entryMember && !entryMember.scope.includes(ei)) entryMember.scope.push(ei);
+  addAudit("企业挂载", name, "未挂载", regionPath(db, region));
+  if (db.teams[team].mode === "自动平均") {
+    const ticket = db.tickets[ti];
+    const pick = pickEven(db, ticket);
+    if (pick !== null) {
+      ticket.assignee = pick;
+      ticket.status = "处理中";
+      ticket.logs.push(`${TODAY} 自动平均分派给${db.members[pick].name}`);
+    }
+  }
+  say("已代录:主数据与订阅已写入,账户仍未开通,开户工单已生成");
+}
+
+function yearLater(date) {
+  const [y, m, dd] = date.split("-").map(Number);
+  const end = new Date(y + 1, m - 1, dd - 1);
+  const pad = (x) => String(x).padStart(2, "0");
+  return end.getFullYear() + "-" + pad(end.getMonth() + 1) + "-" + pad(end.getDate());
+}
+
+function runBatch(scopeIndex) {
+  const s = db.scopes[scopeIndex];
+  if (!s.enabled) { say("该范围尚未启用,不能出账"); return; }
+  const month = "2026-09";
+  const set = new Set(scopeEnterprisesOf(s));
+  const existing = new Set();
+  db.batches.forEach((b) => {
+    if (b.status !== "已打回") b.rows.forEach((si) => existing.add(si + "@" + b.month));
+  });
+  const rows = db.settlements.map((x, i) => ({ x, i }))
+    .filter(({ x, i }) => x.month === month && set.has(x.enterprise) && !existing.has(i + "@" + month))
+    .map(({ i }) => i);
+  const pendingOpen = db.tickets.filter((t) => t.type === "开户" && set.has(t.enterprise) && t.status !== "已完成" && t.status !== "已关闭");
+  const warning = pendingOpen.length ? `范围内仍有 ${pendingOpen.length} 张未完成开户工单:不阻止按实际开通日计费,只提示运维未完成。` : "";
+  if (!rows.length) { say("没有需要补跑的已结束未出账月份(当月未结束不能提前出账)"); return; }
+  const no = "PC-MANUAL-" + Date.now().toString().slice(-6);
+  db.batches.push({ no, day: TODAY, month, scope: `${scopeTargetName(s)} · ${s.kind}范围`, trigger: "人工", status: "已执行", by: user().name, at: NOW, rows, warning });
+  rows.forEach((si) => { db.settlements[si].batch = db.batches.length - 1; });
+  say(`补跑完成,生成批次 ${no},含 ${rows.length} 条明细` + (warning ? ";有未完成开户工单提示" : ""));
+}
+
+render();

+ 446 - 0
prototype/data.js

@@ -0,0 +1,446 @@
+/* 模拟数据只存在于页面内存。内部下标从 0 开始,页面上的序号从 1 开始。 */
+const TODAY = "2026-10-15";
+
+/* 区域三级:大区 / 市 / 区县。企业可挂在任一层,只能挂一个节点。 */
+const LEVEL_NAMES = ["大区", "市", "区县"];
+
+const SEED = {
+  setting: { defaultReconcileDay: 5, perAccountFee: 80 },
+  regions: [
+    { id: "east", name: "华东大区", level: 0, parent: null },
+    { id: "south", name: "华南大区", level: 0, parent: null },
+    { id: "sh", name: "上海市", level: 1, parent: "east" },
+    { id: "su", name: "苏州市", level: 1, parent: "east" },
+    { id: "gz", name: "广州市", level: 1, parent: "south" },
+    { id: "pd", name: "浦东新区", level: 2, parent: "sh" },
+    { id: "lg", name: "临港新片区", level: 2, parent: "sh" },
+    { id: "mh", name: "闵行区", level: 2, parent: "sh" },
+    { id: "ks", name: "昆山市", level: 2, parent: "su" },
+    { id: "th", name: "天河区", level: 2, parent: "gz" },
+  ],
+  operators: [
+    { name: "联通", reconcileDay: null, payCycle: "合同生效次月起付款,与是否已向客户收妥无关", notify: "notice@unicorn.example" },
+    { name: "电信", reconcileDay: null, payCycle: "按 ICT 合同,可为年、半年或季度", notify: "notice@ict-telecom.example" },
+    { name: "移动", reconcileDay: 8, payCycle: "合同生效次月起付款,与是否已向客户收妥无关", notify: "notice@mobile.example" },
+  ],
+  partners: [
+    { name: "邹合", title: "华东渠道", notify: "zouhe@example", scope: { regions: ["east"], enterprises: [] } },
+    { name: "何南", title: "华南渠道", notify: "henan@example", scope: { regions: ["th"], enterprises: [2] } },
+  ],
+  teams: [
+    { name: "华东常规运维", type: "常规", mode: "手工", scope: { regions: ["sh", "su"], enterprises: [] } },
+    { name: "沪东施工", type: "施工", mode: "自动平均", scope: { regions: ["pd"], enterprises: [1] } },
+  ],
+  members: [
+    { name: "周宁", team: 0, type: "常规", scope: [0, 1, 2, 4] },
+    { name: "李可", team: 0, type: "常规", scope: [0, 3, 4] },
+    { name: "赵工", team: 1, type: "施工", scope: [0, 1, 3] },
+    { name: "钱工", team: 1, type: "施工", scope: [0, 1, 3] },
+    { name: "陈录", team: 0, type: "录入", scope: [0, 1, 2, 3, 4] },
+  ],
+  awards: [
+    { member: 2, at: "2026-09-20", kind: "奖励", text: "浦东园区割接提前 1 天完成,客户零投诉", amount: 200 },
+    { member: 2, at: "2026-10-11", kind: "扣罚", text: "临港上门未按约定时间到达,扣罚只作考核,费用在线下处理", amount: -100 },
+  ],
+  enterprises: [
+    {
+      no: "KL-2026-0001",
+      name: "澄澜科技有限公司",
+      subject: "企业",
+      materials: "营业执照、企业名称、合同、电话",
+      files: ["oss://materials/KL-2026-0001/营业执照.pdf", "oss://materials/KL-2026-0001/受理单.pdf"],
+      phone: "021-66001001",
+      region: "pd",
+      operator: 0,
+      partner: 0,
+      teams: { 常规: 0, 施工: 1 },
+      status: "在用",
+      quota: 5,
+      history: [
+        { at: "2026-08-10 10:20", field: "挂载区域", before: "未挂载", after: "华东大区 / 上海市 / 浦东新区", by: "林管" },
+        { at: "2026-03-20 16:40", field: "账户状态", before: "未开通", after: "在用(实际开通日 2026-03-20)", by: "周宁回填" },
+      ],
+    },
+    {
+      no: "KL-2026-0008",
+      name: "临港跨境贸易",
+      subject: "企业",
+      materials: "营业执照、企业名称、合同、电话",
+      files: ["oss://materials/KL-2026-0008/营业执照.pdf", "oss://materials/KL-2026-0008/ICT合同.pdf"],
+      phone: "021-66002008",
+      region: "lg",
+      operator: 1,
+      partner: null,
+      teams: { 常规: 0 },
+      status: "未开通",
+      quota: 8,
+      history: [
+        { at: "2026-09-02 09:05", field: "挂载区域", before: "未挂载", after: "华东大区 / 上海市 / 临港新片区", by: "林管" },
+      ],
+    },
+    {
+      no: "KL-2026-0012",
+      name: "陈阿福",
+      subject: "个体工商户",
+      materials: "身份证、手机号",
+      files: ["oss://materials/KL-2026-0012/身份证.jpg"],
+      phone: "13800001112",
+      region: "ks",
+      operator: 2,
+      partner: 1,
+      teams: { 常规: 0 },
+      status: "在用",
+      quota: 1,
+      trial: true,
+      history: [
+        { at: "2026-08-28 14:10", field: "挂载区域", before: "未挂载", after: "华东大区 / 苏州市 / 昆山市", by: "林管" },
+      ],
+    },
+    {
+      no: "KL-2026-0019",
+      name: "王敏",
+      subject: "个人",
+      materials: "身份证、手机号",
+      files: ["oss://materials/KL-2026-0019/身份证.jpg"],
+      phone: "13900001019",
+      region: "pd",
+      operator: 2,
+      partner: 1,
+      teams: { 常规: 0, 施工: 1 },
+      status: "在用",
+      quota: 2,
+      history: [
+        { at: "2026-08-20 11:30", field: "挂载区域", before: "华东大区 / 苏州市 / 昆山市", after: "华东大区 / 上海市 / 浦东新区", by: "林管" },
+        { at: "2026-08-20 11:32", field: "合伙人", before: "无", after: "何南(华南渠道,直接多选企业)", by: "林管" },
+      ],
+    },
+    {
+      no: "KL-2026-0023",
+      name: "海岚跨境电商(上海)",
+      subject: "企业",
+      materials: "营业执照、企业名称、合同、电话",
+      files: ["oss://materials/KL-2026-0023/营业执照.pdf", "oss://materials/KL-2026-0023/续约合同.pdf"],
+      phone: "021-54002023",
+      region: "mh",
+      operator: 0,
+      partner: 0,
+      teams: { 常规: 0 },
+      status: "在用",
+      quota: 2,
+      history: [
+        { at: "2026-09-12 15:00", field: "挂载区域", before: "未挂载", after: "华东大区 / 上海市 / 闵行区", by: "林管" },
+        { at: "2025-10-01 10:00", field: "账户状态", before: "未开通", after: "在用(实际开通日 2025-10-01)", by: "周宁回填" },
+      ],
+    },
+  ],
+  packages: [
+    { name: "跨境带宽基础版", yearPrice: 9600, monthPrice: 800, quota: 3, bw: "50Mbps", custom: null },
+    { name: "跨境带宽标准版", yearPrice: 12000, monthPrice: 1000, quota: 5, bw: "100Mbps", custom: null },
+    { name: "跨境带宽尊享版", yearPrice: 24000, monthPrice: 2000, quota: 10, bw: "200Mbps", custom: null },
+    { name: "国际资源叠加包", yearPrice: 3600, monthPrice: 300, quota: 0, bw: "30Mbps", custom: null },
+    { name: "临港 ICT 定制套餐", yearPrice: 24000, monthPrice: 2000, quota: 8, bw: "150Mbps", custom: 1 },
+  ],
+  subs: [
+    { enterprise: 0, name: "跨境带宽基础版", kind: "升级前", status: "已到期", start: "2025-03-18", end: "2026-03-17", yearPrice: 9600, monthPrice: 800, openedOn: "2025-03-20", contractNo: "HT-CL-20250318", files: ["oss://contracts/HT-CL-20250318.pdf"] },
+    { enterprise: 0, name: "跨境带宽标准版", kind: "正式", status: "生效中", start: "2026-03-18", end: "2027-03-17", yearPrice: 12000, monthPrice: 1000, openedOn: "2026-03-20", contractNo: "HT-CL-20260318", files: ["oss://contracts/HT-CL-20260318.pdf"] },
+    { enterprise: 1, name: "临港 ICT 定制套餐", kind: "正式", status: "生效中", start: "2026-09-02", end: "2027-09-01", yearPrice: 24000, monthPrice: 2000, openedOn: null, contractNo: "ICT-LG-20260902", files: ["oss://contracts/ICT-LG-20260902.pdf"] },
+    { enterprise: 2, name: "试用优惠(1-2 个月)", kind: "试用", status: "生效中", start: "2026-09-01", end: "2026-10-31", yearPrice: 0, monthPrice: null, openedOn: "2026-09-01", contractNo: "XY-SY-20260901", files: ["oss://contracts/XY-SY-20260901.pdf"] },
+    { enterprise: 3, name: "跨境带宽标准版", kind: "正式", status: "生效中", start: "2026-06-01", end: "2027-05-31", yearPrice: 12000, monthPrice: 1000, openedOn: "2026-06-01", contractNo: "HT-WM-20260601", files: ["oss://contracts/HT-WM-20260601.pdf"] },
+    { enterprise: 3, name: "国际资源叠加包", kind: "叠加", status: "生效中", start: "2026-08-01", end: "2027-07-31", yearPrice: 3600, monthPrice: 300, openedOn: "2026-08-01", contractNo: "HT-WM-20260801", files: ["oss://contracts/HT-WM-20260801.pdf"] },
+    { enterprise: 4, name: "跨境带宽标准版", kind: "正式", status: "已到期", start: "2025-10-01", end: "2026-09-30", yearPrice: 12000, monthPrice: 1000, openedOn: "2025-10-01", contractNo: "HT-HL-20251001", files: ["oss://contracts/HT-HL-20251001.pdf"] },
+    { enterprise: 4, name: "跨境带宽标准版(续订)", kind: "正式", status: "待生效", start: "2026-11-01", end: "2027-10-31", yearPrice: 12000, monthPrice: 1000, openedOn: null, contractNo: "HT-HL-20261101", files: ["oss://contracts/HT-HL-20261101.pdf"] },
+  ],
+  accounts: [
+    { enterprise: 0, name: "张敏", status: "在用", usage: "正式", openedOn: "2026-03-20" },
+    { enterprise: 0, name: "李航", status: "在用", usage: "正式", openedOn: "2026-03-20" },
+    { enterprise: 0, name: "联调测试", status: "在用", usage: "测试", openedOn: "2026-04-01" },
+    { enterprise: 0, name: "待开通席位", status: "未开通", usage: "正式", openedOn: null },
+    { enterprise: 1, name: "临港-财务", status: "未开通", usage: "正式", openedOn: null },
+    { enterprise: 1, name: "临港-关务", status: "未开通", usage: "正式", openedOn: null },
+    { enterprise: 3, name: "王敏本人", status: "在用", usage: "正式", openedOn: "2026-06-01" },
+    { enterprise: 4, name: "海岚-小王", status: "在用", usage: "正式", openedOn: "2025-10-01" },
+  ],
+  /* 开停记录与工单一一对应;状态:待执行 / 执行成功 / 执行失败 */
+  actions: [
+    { id: "A-20261007-08", enterprise: 1, type: "开户", status: "待执行", ticket: 0, created: "2026-10-07", doneOn: null, extendUntil: null, by: null },
+    { id: "A-20261009-23", enterprise: 4, type: "到期停机", status: "待执行", ticket: 7, created: "2026-10-09", doneOn: null, extendUntil: null, by: null },
+  ],
+  tickets: [
+    { type: "开户", enterprise: 1, account: null, team: 0, assignee: null, status: "待处理", created: "2026-10-07", text: "ICT 合同套餐已建立,网络侧尚未开通。开通名单以合同选定:临港-财务、临港-关务。", logs: ["2026-10-07 生成待执行开户记录(A-20261007-08)"], closeReason: null, materials: [] },
+    { type: "故障", enterprise: 0, account: null, team: 0, assignee: 0, status: "处理中", created: "2026-10-12", text: "办公网晚高峰丢包,疑似国际出口拥塞。", logs: ["2026-10-12 企业用户在系统内提交(文字)", "2026-10-12 吴队分派给周宁"], closeReason: null, materials: [] },
+    { type: "故障", enterprise: 0, account: null, team: 1, assignee: null, status: "待处理", created: "2026-10-14", text: "机房侧线路需要现场复查(现场施工类)。", logs: ["2026-10-14 常规团队转施工团队,尚未分派"], closeReason: null, materials: [] },
+    { type: "故障", enterprise: 0, account: null, team: 1, assignee: 2, status: "处理中", created: "2026-10-10", text: "园区弱电井跳纤,现场施工。", logs: ["2026-10-10 自动平均分派给赵工"], closeReason: null, materials: ["oss://tickets/T-1010/现场照片-1.jpg"] },
+    { type: "故障", enterprise: 3, account: null, team: 1, assignee: 2, status: "待处理", created: "2026-10-13", text: "上门后用户不在,待再次上门。", logs: ["2026-10-13 分派给赵工"], closeReason: null, materials: [] },
+    { type: "售后", enterprise: 0, account: null, team: 0, assignee: 1, status: "已完成", created: "2026-09-28", text: "补充开通说明并回传配置手册。", logs: ["2026-09-29 李可填写处理记录并完成"], closeReason: null, materials: [] },
+    { type: "故障", enterprise: 0, account: 0, team: 0, assignee: 0, status: "处理中", created: "2026-10-14", text: "我的座位网络登不上。", logs: ["2026-10-14 下属分账号张敏在系统内提交", "2026-10-14 吴队分派给周宁"], closeReason: null, materials: [] },
+    { type: "到期停机", enterprise: 4, account: null, team: 0, assignee: 0, status: "待处理", created: "2026-10-09", text: "订阅于 2026-09-30 到期,次日生成到期停机记录。停机不把计费延长过结束日。", logs: ["2026-10-09 日任务生成待执行到期停机记录(A-20261009-23)", "2026-10-09 吴队分派给周宁"], closeReason: null, materials: [] },
+    { type: "故障", enterprise: 0, account: null, team: 0, assignee: 1, status: "已关闭", created: "2026-10-08", text: "重复报修:办公网丢包。", logs: ["2026-10-08 企业用户在系统内提交", "2026-10-08 分派给李可", "2026-10-09 吴队关闭:与 10-12 晚高峰丢包工单重复,合并处理"], closeReason: "与同期晚高峰丢包工单重复,合并处理。", materials: [] },
+  ],
+  /* 分成规则挂在渠道与企业的关系上。两层都没有时分成计 0。合同增补优先于区域常规。 */
+  rules: [
+    { ch: "operator", ref: 0, ent: 0, layer: "区域常规", rate: 0.2 },
+    { ch: "team", ref: 0, ent: 0, layer: "合同增补", rate: 0.1 },
+    { ch: "team", ref: 1, ent: 0, layer: "区域常规", rate: 0.05 },
+    { ch: "partner", ref: 0, ent: 0, layer: "区域常规", rate: 0.05 },
+    { ch: "operator", ref: 2, ent: 3, layer: "区域常规", rate: 0.15 },
+    { ch: "team", ref: 0, ent: 3, layer: "区域常规", rate: 0.1 },
+    { ch: "team", ref: 1, ent: 3, layer: "区域常规", rate: 0.05 },
+    { ch: "partner", ref: 1, ent: 3, layer: "合同增补", rate: 0.08 },
+    { ch: "operator", ref: 0, ent: 4, layer: "区域常规", rate: 0.2 },
+    { ch: "team", ref: 0, ent: 4, layer: "区域常规", rate: 0.1 },
+    { ch: "partner", ref: 0, ent: 4, layer: "区域常规", rate: 0.05 },
+  ],
+  /* 应扣除成本:线路投入不扣基数;国际资源按摊销扣;项目费用一次性。设备同一项目只选比例或固定金额之一。 */
+  costs: [
+    { ent: 3, sub: 4, kind: "国际资源", name: "国家 IP 地址月摊销", amount: 50, repeat: "每月" },
+    { ent: 3, sub: 5, kind: "国际资源", name: "国际云主机月摊销", amount: 30, repeat: "每月" },
+  ],
+  settlements: [
+    {
+      enterprise: 0, sub: 1, month: "2026-03", days: 12, monthDays: 31, partial: true, std: 1000, amount: 387.1, tail: false, exact: 387.1,
+      costs: [], base: 387.1,
+      shares: [
+        { who: "联通", mode: "按总金额比例", rate: 0.2, amount: 77.42 },
+        { who: "华东常规运维", mode: "按总金额比例", rate: 0.1, amount: 38.71 },
+        { who: "沪东施工", mode: "按总金额比例", rate: 0.05, amount: 19.36 },
+        { who: "华东合伙人", mode: "按总金额比例", rate: 0.05, amount: 19.36 },
+      ],
+      opsFee: 61.94, acctDays: [{ name: "张敏", days: 12, fee: 30.97 }, { name: "李航", days: 12, fee: 30.97 }],
+      attrs: "联通 / 邹合(华东) / 华东常规运维 / 沪东施工", batch: null,
+    },
+    {
+      enterprise: 0, sub: 1, month: "2026-04", days: 30, monthDays: 30, partial: false, std: 1000, amount: 1000, tail: false, exact: 1000,
+      costs: [], base: 1000,
+      shares: [
+        { who: "联通", mode: "按总金额比例", rate: 0.2, amount: 200 },
+        { who: "华东常规运维", mode: "按总金额比例", rate: 0.1, amount: 100 },
+        { who: "沪东施工", mode: "按总金额比例", rate: 0.05, amount: 50 },
+        { who: "华东合伙人", mode: "按总金额比例", rate: 0.05, amount: 50 },
+      ],
+      opsFee: 160, acctDays: [{ name: "张敏", days: 30, fee: 80 }, { name: "李航", days: 30, fee: 80 }],
+      attrs: "联通 / 邹合(华东) / 华东常规运维 / 沪东施工", batch: null,
+    },
+    {
+      enterprise: 0, sub: 1, month: "2026-09", days: 30, monthDays: 30, partial: false, std: 1000, amount: 1000, tail: false, exact: 1000,
+      costs: [], base: 1000,
+      shares: [
+        { who: "联通", mode: "按总金额比例", rate: 0.2, amount: 200 },
+        { who: "华东常规运维", mode: "按总金额比例", rate: 0.1, amount: 100 },
+        { who: "沪东施工", mode: "按总金额比例", rate: 0.05, amount: 50 },
+        { who: "华东合伙人", mode: "按总金额比例", rate: 0.05, amount: 50 },
+      ],
+      opsFee: 160, acctDays: [{ name: "张敏", days: 30, fee: 80 }, { name: "李航", days: 30, fee: 80 }],
+      attrs: "联通 / 邹合(华东) / 华东常规运维 / 沪东施工", batch: 0,
+    },
+    {
+      enterprise: 3, sub: 4, month: "2026-09", days: 30, monthDays: 30, partial: false, std: 1000, amount: 1000, tail: false, exact: 1000,
+      costs: [{ name: "国家 IP 地址月摊销", amount: 50 }], base: 950,
+      shares: [
+        { who: "移动", mode: "按总金额比例", rate: 0.15, amount: 142.5 },
+        { who: "华东常规运维", mode: "按总金额比例", rate: 0.1, amount: 95 },
+        { who: "沪东施工", mode: "按总金额比例", rate: 0.05, amount: 47.5 },
+        { who: "华南合伙人", mode: "合同增补 · 比例", rate: 0.08, amount: 76 },
+      ],
+      opsFee: 80, acctDays: [{ name: "王敏本人", days: 30, fee: 80 }],
+      attrs: "移动 / 何南(华南) / 华东常规运维 / 沪东施工", batch: 1,
+    },
+    {
+      enterprise: 3, sub: 5, month: "2026-09", days: 30, monthDays: 30, partial: false, std: 300, amount: 300, tail: false, exact: 300,
+      costs: [{ name: "国际云主机月摊销", amount: 30 }], base: 270,
+      shares: [
+        { who: "移动", mode: "按总金额比例", rate: 0.15, amount: 40.5 },
+        { who: "华东常规运维", mode: "按总金额比例", rate: 0.1, amount: 27 },
+        { who: "沪东施工", mode: "按总金额比例", rate: 0.05, amount: 13.5 },
+        { who: "华南合伙人", mode: "合同增补 · 比例", rate: 0.08, amount: 21.6 },
+      ],
+      opsFee: 0, acctDays: [],
+      attrs: "移动 / 何南(华南) / 华东常规运维 / 沪东施工(叠加订阅各算各的)", batch: 1,
+    },
+    {
+      enterprise: 4, sub: 6, month: "2026-09", days: 30, monthDays: 30, partial: false, std: 1000, amount: 1000, tail: true, exact: 1000,
+      costs: [], base: 1000,
+      shares: [
+        { who: "联通", mode: "按总金额比例", rate: 0.2, amount: 200 },
+        { who: "华东常规运维", mode: "按总金额比例", rate: 0.1, amount: 100 },
+        { who: "沪东施工(未配置,计 0)", mode: "—", rate: 0, amount: 0 },
+        { who: "华东合伙人", mode: "按总金额比例", rate: 0.05, amount: 50 },
+      ],
+      opsFee: 80, acctDays: [{ name: "海岚-小王", days: 30, fee: 80 }],
+      attrs: "联通 / 邹合(华东) / 华东常规运维 / 无施工团队", batch: 0,
+    },
+  ],
+  scopes: [
+    { kind: "运营商", ref: 0, enabled: true },
+    { kind: "运营商", ref: 1, enabled: true },
+    { kind: "运营商", ref: 2, enabled: true },
+    { kind: "合伙人", ref: 0, enabled: true },
+    { kind: "合伙人", ref: 1, enabled: false },
+    { kind: "运维", ref: 0, enabled: true },
+    { kind: "运维", ref: 1, enabled: false },
+  ],
+  batches: [
+    { no: "PC-20261005-LT", day: "2026-10-05", month: "2026-09", scope: "联通 · 运营商范围", trigger: "自动", status: "已执行", by: "系统", at: "2026-10-05 06:00", rows: [2, 5], warning: "" },
+    { no: "PC-20261008-YD", day: "2026-10-08", month: "2026-09", scope: "移动 · 运营商范围", trigger: "自动", status: "已执行", by: "系统", at: "2026-10-08 06:00", rows: [3, 4], warning: "" },
+    { no: "PC-20260905-DX", day: "2026-09-05", month: "2026-08", scope: "电信 · 运营商范围", trigger: "自动", status: "已打回", by: "系统", at: "2026-09-05 06:00", rows: [], warning: "分成比例误录,运营商尚未付款" },
+    { no: "PC-20260912-DX-R", day: "2026-09-12", month: "2026-08", scope: "电信 · 运营商范围", trigger: "人工", status: "已执行", by: "林管", at: "2026-09-12 10:20", rows: [], warning: "打回后重做,新明细成为 8 月唯一有效应收" },
+    { no: "PC-20260605-LT", day: "2026-06-05", month: "2026-05", scope: "联通 · 运营商范围", trigger: "自动", status: "执行失败", by: "系统", at: "2026-06-05 06:00", rows: [], warning: "出账任务异常中断,等待人工补跑" },
+  ],
+  notes: [
+    { level: "严重", bill: "澄澜科技 2026-03", text: "3 月比例曾按 0.18 录入,核验后从 4 月起改为 0.20。3 月账单已递交运营商,原明细保留不改。", by: "林管", at: "2026-04-06 09:30" },
+    { level: "严重", bill: "电信范围 2026-08(PC-20260905-DX)", text: "批次分成比例误录,运营商尚未付款,批次打回重做;重做批次 PC-20260912-DX-R 核验通过。", by: "林管", at: "2026-09-12 10:15" },
+  ],
+  feedback: [
+    { no: "KL-UNKNOWN-3", action: "开户", date: "2026-10-11", state: "nomatch", result: "主体号匹配不到任何待执行记录,待人工处理。不自动创建企业,不改账户状态。", handled: false },
+    { no: "KL-2026-0008", action: "开户", date: "2026-10-14", state: "pending", result: "匹配到待执行记录 A-20261007-08,反馈实际开通日 2026-10-14,可据此回填(与人工回填等效)。", handled: false, actionId: "A-20261007-08", fillDate: "2026-10-14" },
+    { no: "KL-2026-0019", action: "开户", date: "2026-10-13", state: "conflict", result: "该企业开户记录已于 2026-06-01 回填成功,反馈与现状冲突,不覆盖,待人工确认。", handled: false },
+  ],
+  collections: [
+    { partner: 0, enterprise: 0, amount: 8000, date: "2026-04-18", note: "运营商已收,仅作区域核对,不回写应收" },
+  ],
+  /* 审计日志只追加。区域树维护仅系统管理员可见。 */
+  auditLogs: [
+    { at: "2026-08-01 09:12", by: "林管", type: "新建区域", object: "华东大区 / 上海市 / 浦东新区", before: "", after: "新建三级节点" },
+    { at: "2026-08-01 09:20", by: "林管", type: "新建区域", object: "华东大区 / 上海市 / 临港新片区", before: "", after: "新建区县节点" },
+    { at: "2026-08-02 14:02", by: "林管", type: "新建区域", object: "华东大区 / 苏州市 / 昆山市", before: "", after: "新建区县节点" },
+    { at: "2026-08-05 10:40", by: "林管", type: "重命名区域", object: "华东大区 / 上海市 / 临港新片区", before: "南汇新城区", after: "临港新片区" },
+    { at: "2026-08-10 10:20", by: "林管", type: "企业挂载", object: "澄澜科技有限公司", before: "未挂载", after: "华东大区 / 上海市 / 浦东新区" },
+    { at: "2026-08-20 11:30", by: "林管", type: "企业改挂区域", object: "王敏", before: "华东大区 / 苏州市 / 昆山市", after: "华东大区 / 上海市 / 浦东新区" },
+    { at: "2026-08-21 16:00", by: "林管", type: "合伙人负责范围首次配置", object: "邹合(华东渠道)", before: "(空)", after: "澄澜科技、临港跨境、陈阿福、王敏、海岚跨境(选定华东大区,含其下级全部企业)" },
+    { at: "2026-09-02 09:10", by: "林管", type: "运维团队负责范围调整", object: "沪东施工", before: "澄澜科技、王敏", after: "澄澜科技、临港跨境、王敏(新增直接多选企业:临港跨境)" },
+    { at: "2026-10-05 15:20", by: "林管", type: "合伙人负责范围调整", object: "何南(华南渠道)", before: "(空)", after: "天河区(暂无直属企业);直接多选企业:陈阿福" },
+    { at: "2026-10-05 15:25", by: "林管", type: "结算范围启用", object: "合伙人范围 · 何南(华南渠道)", before: "未启用", after: "未启用(拟首次应收后再启用)" },
+  ],
+  users: [
+    { name: "林管", role: "admin", title: "系统管理员 · 技术管理中心" },
+    { name: "吴队", role: "teamLead", team: 0, title: "华东常规运维 · 团队主账号" },
+    { name: "周宁", role: "ops", member: 0, title: "常规运维 · 开停回填" },
+    { name: "孙队", role: "teamLead", team: 1, title: "沪东施工 · 团队主账号" },
+    { name: "赵工", role: "worker", member: 2, title: "施工人员" },
+    { name: "陈录", role: "entry", member: 4, title: "录入人员 · 电信/移动 ICT 代录" },
+    { name: "澄澜科技", role: "enterprise", enterprise: 0, title: "企业用户" },
+    { name: "张敏", role: "sub", enterprise: 0, account: 0, title: "下属分账号" },
+    { name: "邹合", role: "partner", partner: 0, title: "华东合伙人" },
+  ],
+};
+
+function cloneSeed() {
+  return JSON.parse(JSON.stringify(SEED));
+}
+
+function money(n) {
+  return Number(n || 0).toLocaleString("zh-CN", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
+}
+
+function pct(n) {
+  const v = Math.round(Number(n || 0) * 10000) / 100;
+  return String(v) + "%";
+}
+
+function daysBetween(start, end) {
+  const a = new Date(start + "T00:00:00");
+  const b = new Date(end + "T00:00:00");
+  return Math.round((b - a) / 86400000) + 1;
+}
+
+function addDays(date, n) {
+  const d = new Date(date + "T00:00:00");
+  d.setDate(d.getDate() + n);
+  const pad = (x) => String(x).padStart(2, "0");
+  return d.getFullYear() + "-" + pad(d.getMonth() + 1) + "-" + pad(d.getDate());
+}
+
+function overdueAction(action) {
+  if (!action || action.status !== "待执行") return false;
+  const limit = action.extendUntil || addDays(action.created, 7);
+  return TODAY > limit;
+}
+
+function unfinished(db, memberIndex) {
+  return db.tickets.filter((t) => t.assignee === memberIndex && (t.status === "待处理" || t.status === "处理中")).length;
+}
+
+function ticketTypeOfTeam(team) {
+  return team.type === "施工" ? "施工" : "常规";
+}
+
+function eligible(db, ticket) {
+  const team = db.teams[ticket.team];
+  const need = ticketTypeOfTeam(team);
+  return db.members
+    .map((m, index) => ({ ...m, index }))
+    .filter((m) => m.team === ticket.team && m.type === need && m.scope.includes(ticket.enterprise));
+}
+
+function pickEven(db, ticket) {
+  const list = eligible(db, ticket);
+  if (!list.length) return null;
+  list.sort((a, b) => unfinished(db, a.index) - unfinished(db, b.index) || a.index - b.index);
+  return list[0].index;
+}
+
+/* ---- 区域与范围工具 ---- */
+
+function regionNode(db, id) {
+  return db.regions.find((r) => r.id === id) || null;
+}
+
+function regionPath(db, id) {
+  const names = [];
+  let cur = regionNode(db, id);
+  while (cur) {
+    names.unshift(cur.name);
+    cur = cur.parent ? regionNode(db, cur.parent) : null;
+  }
+  return names.join(" / ");
+}
+
+function descendantIds(db, id) {
+  const out = [id];
+  let added = true;
+  while (added) {
+    added = false;
+    db.regions.forEach((r) => {
+      if (r.parent && out.includes(r.parent) && !out.includes(r.id)) {
+        out.push(r.id);
+        added = true;
+      }
+    });
+  }
+  return out;
+}
+
+function enterprisesUnderRegion(db, id) {
+  const ids = new Set(descendantIds(db, id));
+  return db.enterprises.map((e, i) => i).filter((i) => ids.has(db.enterprises[i].region));
+}
+
+function scopeEnterpriseSet(db, scope) {
+  const set = new Set();
+  (scope.regions || []).forEach((rid) => enterprisesUnderRegion(db, rid).forEach((i) => set.add(i)));
+  (scope.enterprises || []).forEach((i) => set.add(i));
+  return set;
+}
+
+function scopeEnterprises(db, scope) {
+  return Array.from(scopeEnterpriseSet(db, scope)).sort((a, b) => a - b);
+}
+
+function scopeSummary(db, scope) {
+  const parts = [];
+  (scope.regions || []).forEach((rid) => {
+    const n = regionNode(db, rid);
+    if (n) parts.push(`${n.name}(含下级 ${enterprisesUnderRegion(db, rid).length} 家企业)`);
+  });
+  const fromRegion = new Set();
+  (scope.regions || []).forEach((rid) => enterprisesUnderRegion(db, rid).forEach((i) => fromRegion.add(i)));
+  const extra = (scope.enterprises || []).filter((i) => !fromRegion.has(i));
+  if (extra.length) parts.push(`直接多选:${extra.map((i) => db.enterprises[i].name).join("、")}`);
+  return parts.length ? parts.join(";") : "(空)";
+}
+
+function regionReferenced(db, id) {
+  const refs = [];
+  db.teams.forEach((t, i) => { if ((t.scope.regions || []).includes(id)) refs.push(`运维团队「${t.name}」负责范围`); });
+  db.partners.forEach((p, i) => { if ((p.scope.regions || []).includes(id)) refs.push(`合伙人「${p.name}」负责范围`); });
+  return refs;
+}

+ 14 - 0
prototype/index.html

@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html lang="zh-CN">
+<head>
+  <meta charset="UTF-8">
+  <meta name="viewport" content="width=device-width, initial-scale=1">
+  <title>恪澜通运营支撑原型</title>
+  <link rel="stylesheet" href="styles.css">
+</head>
+<body>
+  <div id="app"></div>
+  <script src="data.js"></script>
+  <script src="app.js"></script>
+</body>
+</html>

+ 388 - 0
prototype/styles.css

@@ -0,0 +1,388 @@
+:root {
+  --ink: #1b2430;
+  --muted: #5c6b7a;
+  --line: #e2d9cc;
+  --paper: #f6f1e8;
+  --card: #fffdf8;
+  --teal: #0e6e68;
+  --teal-ink: #084843;
+  --amber: #9a5b12;
+  --red: #8f2d2d;
+  --green: #1d6b45;
+  --shadow: 0 10px 30px rgba(40, 32, 20, 0.06);
+  font-family: "PingFang SC", "Noto Sans SC", "Source Han Sans SC", sans-serif;
+}
+
+* { box-sizing: border-box; }
+body { margin: 0; color: var(--ink); background: var(--paper); }
+button, input, select, textarea { font: inherit; color: inherit; }
+button { cursor: pointer; }
+h1, h2, h3, p { margin: 0; }
+
+.login {
+  min-height: 100vh;
+  display: grid;
+  grid-template-columns: 320px 1fr;
+}
+.login-side {
+  background: var(--teal-ink);
+  color: #f3efe6;
+  padding: 48px 36px;
+}
+.login-side h1 { font-size: 28px; font-weight: 650; letter-spacing: 0.04em; }
+.login-side p { margin-top: 16px; line-height: 1.7; color: #d5ebe8; }
+.login-main { padding: 40px 48px 64px; }
+.login-main h2 { font-size: 20px; font-weight: 640; }
+.persona-grid {
+  margin-top: 20px;
+  display: grid;
+  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
+  gap: 12px;
+}
+.persona {
+  text-align: left;
+  background: var(--card);
+  border: 1px solid var(--line);
+  border-radius: 12px;
+  padding: 14px 16px;
+  box-shadow: var(--shadow);
+}
+.persona strong { display: block; font-size: 16px; }
+.persona span { display: block; margin-top: 6px; color: var(--muted); font-size: 13px; line-height: 1.5; }
+.persona:hover { border-color: var(--teal); }
+
+.shell { min-height: 100vh; display: grid; grid-template-columns: 220px 1fr; }
+.nav {
+  background: #172028;
+  color: #e7e1d6;
+  padding: 22px 14px;
+  display: flex;
+  flex-direction: column;
+  gap: 4px;
+}
+.brand { padding: 0 8px 16px; font-weight: 650; letter-spacing: 0.06em; }
+.nav button {
+  background: transparent;
+  border: 0;
+  color: inherit;
+  text-align: left;
+  border-radius: 8px;
+  padding: 9px 10px;
+  width: 100%;
+  font-size: 14px;
+  cursor: pointer;
+}
+.nav button.active, .nav button:hover { background: rgba(255, 255, 255, 0.08); }
+.nav .nav-group {
+  font-size: 12px;
+  letter-spacing: 0.08em;
+  text-transform: uppercase;
+  color: #8ea0a0;
+  padding: 14px 10px 6px;
+  cursor: pointer;
+  display: flex;
+  justify-content: space-between;
+  align-items: center;
+  user-select: none;
+}
+.nav .nav-group:hover { background: transparent; color: #c2d3d1; }
+.nav .nav-group .caret { font-size: 11px; transition: transform 0.18s ease; }
+.nav .nav-group.open .caret { transform: rotate(0deg); }
+.nav .nav-sub { padding-left: 12px; display: flex; flex-direction: column; gap: 2px; }
+.nav .nav-sub.closed { display: none; }
+.nav .nav-sub .nav-leaf { font-size: 13.5px; color: #d1c8ba; padding: 7px 10px; }
+.nav .nav-sub .nav-leaf.active {
+  background: linear-gradient(90deg, rgba(255,255,255,0.14), rgba(255,255,255,0.04));
+  color: #fff;
+}
+.nav .who { margin-top: auto; padding: 12px 8px 0; font-size: 13px; color: #b7c4c2; line-height: 1.5; }
+.nav .who button { margin-top: 8px; border: 1px solid rgba(255,255,255,0.2); width: 100%; }
+
+.main { padding: 22px 28px 48px; min-width: 0; }
+.top { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; }
+.top h1 { font-size: 22px; font-weight: 650; }
+.top p { color: var(--muted); margin-top: 4px; font-size: 13px; }
+.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
+
+.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
+.card, .panel {
+  background: var(--card);
+  border: 1px solid var(--line);
+  border-radius: 14px;
+  box-shadow: var(--shadow);
+}
+.card { padding: 14px 16px; }
+.card b { display: block; font-size: 22px; margin-top: 4px; word-break: break-word; }
+.card span { color: var(--muted); font-size: 13px; }
+.panel { padding: 16px 18px; margin-bottom: 14px; overflow-x: auto; min-width: 0; }
+.panel h2 { font-size: 16px; margin-bottom: 10px; }
+.panel > .note { margin-top: 8px; }
+
+table { width: 100%; border-collapse: collapse; font-size: 14px; }
+th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
+td.wrap { white-space: normal; min-width: 240px; }
+th { color: var(--muted); font-weight: 550; font-size: 12px; }
+tr.clickable { cursor: pointer; }
+tr.clickable:hover { background: #f3efe6; }
+
+.pill {
+  display: inline-block;
+  border-radius: 999px;
+  padding: 2px 8px;
+  font-size: 12px;
+  background: #efe7da;
+  white-space: nowrap;
+}
+.pill.ok { background: #e5f4ea; color: var(--green); }
+.pill.wait { background: #fff1d6; color: var(--amber); }
+.pill.bad { background: #fde8e4; color: var(--red); }
+.pill.run { background: #e5f3f2; color: var(--teal-ink); }
+
+.btn, .btn.ghost {
+  border-radius: 8px;
+  padding: 7px 12px;
+  border: 1px solid var(--teal);
+  background: var(--teal);
+  color: white;
+  white-space: nowrap;
+}
+.btn.ghost { background: transparent; color: var(--teal-ink); }
+.btn.warn { background: var(--red); border-color: var(--red); }
+.btn:disabled { opacity: 0.45; cursor: not-allowed; }
+
+label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
+input, select, textarea {
+  width: 100%;
+  max-width: 420px;
+  border: 1px solid var(--line);
+  background: white;
+  border-radius: 8px;
+  padding: 8px 10px;
+}
+input[type="checkbox"], input[type="radio"] { width: auto; max-width: none; margin: 0; }
+td select, .row select { width: auto; min-width: 96px; max-width: 200px; }
+.row input { width: auto; }
+textarea { min-height: 88px; max-width: 560px; }
+.form-actions { margin-top: 14px; display: flex; gap: 8px; flex-wrap: wrap; }
+
+/* 多列表单 */
+.form-grid {
+  display: grid;
+  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
+  gap: 0 18px;
+}
+.form-grid label { margin-top: 8px; }
+.form-grid .form-actions { grid-column: 1 / -1; }
+
+/* 对象存储键列表 / 材料列表 */
+ul.files {
+  margin: 8px 0 0;
+  padding: 0;
+  list-style: none;
+}
+ul.files li {
+  padding: 6px 10px;
+  background: #f7f2e8;
+  border: 1px solid var(--line);
+  border-radius: 8px;
+  margin-bottom: 6px;
+  font-size: 13px;
+  word-break: break-all;
+}
+
+/* 复选列表(成员范围、企业直选) */
+.checklist {
+  display: grid;
+  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
+  gap: 2px 18px;
+  margin-top: 6px;
+}
+label.ck {
+  display: flex;
+  align-items: center;
+  gap: 7px;
+  font-size: 14px;
+  font-weight: normal;
+  color: var(--ink);
+  margin: 4px 0;
+  line-height: 1.5;
+}
+label.ck .note { font-weight: normal; }
+
+/* 区域树 */
+ul.tree {
+  list-style: none;
+  margin: 0;
+  padding: 0;
+}
+ul.tree ul.tree { padding-left: 24px; }
+.tree-node {
+  display: flex;
+  align-items: center;
+  gap: 8px;
+  padding: 2px 0;
+}
+.tree-select {
+  background: transparent;
+  border: 1px solid transparent;
+  border-radius: 8px;
+  padding: 5px 10px;
+  color: var(--ink);
+}
+.tree-select:hover { background: #f3efe6; }
+.tree-node.on .tree-select {
+  background: var(--teal);
+  border-color: var(--teal);
+  color: #fff;
+}
+.lv {
+  font-size: 12px;
+  color: var(--teal-ink);
+  background: #e5f3f2;
+  border-radius: 6px;
+  padding: 1px 7px;
+  white-space: nowrap;
+}
+.cnt { font-size: 12px; color: var(--muted); white-space: nowrap; }
+
+/* 范围配置里的勾选树 */
+ul.tree.check label.ck { margin: 5px 0; }
+ul.tree.check ul.tree { margin: 2px 0; }
+
+.note { color: var(--muted); font-size: 13px; line-height: 1.6; }
+.alert {
+  background: #fff4ec;
+  border: 1px solid #f0d2bc;
+  color: #7a3e12;
+  border-radius: 12px;
+  padding: 10px 12px;
+  margin-bottom: 12px;
+  font-size: 14px;
+  line-height: 1.6;
+}
+.toast {
+  position: fixed;
+  right: 20px;
+  bottom: 20px;
+  background: var(--ink);
+  color: white;
+  padding: 12px 14px;
+  border-radius: 10px;
+  max-width: 320px;
+  box-shadow: var(--shadow);
+  font-size: 14px;
+  line-height: 1.5;
+}
+.split { display: grid; grid-template-columns: 1.2fr 0.8fr; gap: 14px; align-items: start; }
+.log { margin: 0; padding-left: 18px; color: var(--muted); }
+.log li { margin: 4px 0; line-height: 1.6; }
+@media (max-width: 900px) {
+  .login, .shell, .split { grid-template-columns: 1fr; }
+  .login-side { padding: 28px 22px; }
+}
+
+/* ================= 交互与视觉增强 ================= */
+
+/* 全局过渡基类,给常见可交互元素 */
+button, .card, .panel, tr.clickable, .tree-select, label.ck {
+  transition: background 180ms ease, border-color 180ms ease, color 180ms ease, transform 120ms ease, box-shadow 180ms ease;
+}
+input, select, textarea { transition: border-color 180ms ease, box-shadow 180ms ease; }
+
+/* 侧栏:折叠子菜单过渡(用 max-height 替代 display:none) */
+.nav .nav-sub { overflow: hidden; transition: max-height 220ms ease, opacity 220ms ease; max-height: 600px; opacity: 1; }
+.nav .nav-sub.closed { max-height: 0; opacity: 0; }
+
+/* 侧栏叶子按钮活跃态:左侧竖条 + 更强对比 */
+.nav .nav-sub .nav-leaf.active {
+  position: relative;
+  background: rgba(14, 110, 104, 0.22);
+  color: #fff;
+  padding-left: 14px;
+}
+.nav .nav-sub .nav-leaf.active::before {
+  content: "";
+  position: absolute; left: -12px; top: 4px; bottom: 4px; width: 3px;
+  background: #19d0c0; border-radius: 2px;
+}
+.nav .nav-sub .nav-leaf:hover { color: #fff; background: rgba(255,255,255,0.06); }
+
+/* 顶层叶子按钮(如"概览""审计日志")活跃态 */
+.nav > button.nav-leaf.active {
+  background: rgba(14, 110, 104, 0.22);
+  color: #fff;
+}
+
+/* 折叠 caret 旋转 */
+.nav .nav-group .caret { transform: rotate(-90deg); }
+.nav .nav-group.open .caret { transform: rotate(0deg); }
+
+/* 按钮:focus-visible + 按下态 */
+.btn:focus-visible, button:focus-visible,
+.persona:focus-visible, .tree-select:focus-visible {
+  outline: 2px solid var(--teal);
+  outline-offset: 2px;
+}
+.btn:active { transform: translateY(1px); }
+
+/* 表格:thead 底线 + hover 高亮 + 斑马纹 */
+table { border-radius: 10px; overflow: hidden; }
+thead th {
+  background: #faf4e8;
+  border-bottom: 2px solid var(--line);
+  padding: 10px 10px;
+  position: sticky; top: 0; z-index: 1;
+}
+tbody tr:nth-child(even) td { background: #fbf7ee; }
+tbody tr.clickable:hover td, tbody tr:hover td {
+  background: #f0e8d6 !important;
+}
+
+/* 表单 focus glow */
+input:focus, select:focus, textarea:focus {
+  border-color: var(--teal);
+  box-shadow: 0 0 0 3px rgba(14, 110, 104, 0.14);
+  outline: none;
+}
+
+/* panel / card 入场动画 */
+@keyframes fadeInUp {
+  from { opacity: 0; transform: translateY(6px); }
+  to   { opacity: 1; transform: none; }
+}
+.panel, .card, .alert, .persona { animation: fadeInUp 300ms ease both; }
+.panel:nth-child(2)  { animation-delay: 40ms; }
+.panel:nth-child(3)  { animation-delay: 80ms; }
+.panel:nth-child(4)  { animation-delay: 120ms; }
+
+/* toast 滑入 */
+.toast {
+  animation: slideInRight 280ms ease both;
+}
+@keyframes slideInRight {
+  from { opacity: 0; transform: translateX(24px); }
+  to   { opacity: 1; transform: none; }
+}
+
+/* 登录 persona 悬停抬升 */
+.persona { transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease; }
+.persona:hover {
+  transform: translateY(-2px);
+  box-shadow: 0 14px 32px rgba(40, 32, 20, 0.12);
+  border-color: var(--teal);
+}
+
+/* webkit 滚动条 */
+::-webkit-scrollbar { width: 10px; height: 10px; }
+::-webkit-scrollbar-track { background: transparent; }
+::-webkit-scrollbar-thumb { background: #d7ccba; border-radius: 5px; }
+::-webkit-scrollbar-thumb:hover { background: #b9ac95; }
+.panel::-webkit-scrollbar-thumb { background: #d7ccba; }
+
+/* pill hover 微动(可交互的情况下) */
+.pill { cursor: default; }
+
+/* 区域树选中节点加 glow */
+.tree-node.on .tree-select {
+  box-shadow: 0 0 0 2px rgba(14,110,104,0.2);
+}