import Link from "next/link"; import { prisma } from "@/lib/prisma"; import { auth } from "@/lib/auth"; import { isStaff, isSuperAdmin } from "@/lib/acl"; import { fmtDate, maskPhone } from "@/lib/utils"; import { Card } from "@/components/ui/card"; import { Table, THead, TR, TH, TD } from "@/components/ui/table"; import { Button } from "@/components/ui/button"; import { CustomerToolbar } from "./customer-toolbar"; import { DeleteButton } from "./delete-button"; import { CustomerView } from "./customer-view"; import { buildCustomerWhere } from "./query"; const PAGE_SIZE = 15; type SearchParams = { keyword?: string; start?: string; end?: string; page?: string; }; export default async function CustomersPage({ searchParams, }: { searchParams: Promise; }) { const session = await auth(); const superAdmin = isSuperAdmin(session?.user?.roles); // 查看弹窗:业务员角色也展示明文手机号(列表仍脱敏) const viewFullPhone = superAdmin || isStaff(session?.user?.roles); const sp = await searchParams; const keyword = (sp.keyword ?? "").trim(); const page = Math.max(1, Number(sp.page) || 1); const where = buildCustomerWhere(sp); const [rows, total] = await Promise.all([ prisma.customer.findMany({ where, orderBy: { reportDate: "desc" }, skip: (page - 1) * PAGE_SIZE, take: PAGE_SIZE, }), prisma.customer.count({ where }), ]); const totalPages = Math.max(1, Math.ceil(total / PAGE_SIZE)); const exportQs = new URLSearchParams(); if (sp.keyword) exportQs.set("keyword", sp.keyword); if (sp.start) exportQs.set("start", sp.start); if (sp.end) exportQs.set("end", sp.end); return (
{rows.length === 0 && ( )} {rows.map((c) => { // 旧公共 phone 已停用,不随序列化下发到客户端 const { phone: _legacyPhone, ...rest } = c; return ( ); })}
商户注册名称 商户经营名称 商户编号 联系人 结算人 产品明细 押金 买断 生日 业务员 报单日期 备注 操作
暂无数据
{c.customerName} {c.businessName || "—"} {c.customerNo || "—"}
{c.contacts}
{superAdmin ? c.contactsPhone : maskPhone(c.contactsPhone)}
{c.balanceUser}
{superAdmin ? c.balanceUserPhone : maskPhone(c.balanceUserPhone)}
{c.detail} {c.deposit} {c.buy} {fmtDate(c.birthday)} {c.salesman} {fmtDate(c.reportDate)} {c.remark}
{/* 弹窗展示用的手机号在服务端预处理:超管和业务员看明文,其余角色脱敏 */} {superAdmin && }
{rows.length === 0 && ( 暂无数据 )} {rows.map((c) => { const { phone: _legacyPhone, ...rest } = c; return (
{c.customerName}
{c.businessName ? (
经营名称 {c.businessName}
) : null}
编号 {c.customerNo || "—"}
{c.salesman} {c.reportDate ? ` · ${fmtDate(c.reportDate)}` : ""}
{c.birthday ? ( {fmtDate(c.birthday)} ) : null}
联系人
{c.contacts || "—"}
{superAdmin ? c.contactsPhone : maskPhone(c.contactsPhone)}
结算人
{c.balanceUser || "—"}
{superAdmin ? c.balanceUserPhone : maskPhone(c.balanceUserPhone)}
{c.detail && (
产品明细
{c.detail}
)}
{superAdmin && }
); })}
{/* 分页 */}
共 {total.toLocaleString()} 条
{page} / {totalPages} = totalPages} sp={sp} label="下一页" />
); } function PageLink({ page, disabled, sp, label, }: { page: number; disabled: boolean; sp: SearchParams; label: string; }) { if (disabled) { return ( {label} ); } const params = new URLSearchParams(); if (sp.keyword) params.set("keyword", sp.keyword); if (sp.start) params.set("start", sp.start); if (sp.end) params.set("end", sp.end); params.set("page", String(page)); return ( {label} ); }