'use client' import { useState } from 'react' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/Card' import { Button } from '@/components/ui/Button' import { Modal } from '@/components/ui/Modal' import { SuccessTag, PendingTag, WarningTag } from '@/components/ui/Tag' import { useToast } from '@/components/ui/Toast' import { Search, Plus, Users, TrendingUp, TrendingDown, Copy, CheckCircle, Clock, MoreVertical, Building2, AlertCircle, UserPlus, MessageSquareText, Trash2, FolderPlus } from 'lucide-react' // 代理商类型 interface Agency { id: string agencyId: string // 代理商ID(AG开头) name: string companyName: string email: string status: 'active' | 'pending' | 'paused' creatorCount: number projectCount: number passRate: number trend: 'up' | 'down' | 'stable' joinedAt: string remark?: string } // 模拟项目列表(用于分配代理商) const mockProjects = [ { id: 'proj-001', name: 'XX品牌618推广' }, { id: 'proj-002', name: '口红系列推广' }, { id: 'proj-003', name: 'XX运动品牌' }, { id: 'proj-004', name: '护肤品秋季活动' }, ] // 模拟代理商列表 const initialAgencies: Agency[] = [ { id: 'a-001', agencyId: 'AG789012', name: '星耀传媒', companyName: '上海星耀文化传媒有限公司', email: 'contact@xingyao.com', status: 'active', creatorCount: 50, projectCount: 8, passRate: 92, trend: 'up', joinedAt: '2025-06-15', }, { id: 'a-002', agencyId: 'AG456789', name: '创意无限', companyName: '深圳创意无限广告有限公司', email: 'hello@chuangyi.com', status: 'active', creatorCount: 35, projectCount: 5, passRate: 88, trend: 'up', joinedAt: '2025-08-20', }, { id: 'a-003', agencyId: 'AG123456', name: '美妆达人MCN', companyName: '杭州美妆达人网络科技有限公司', email: 'biz@meizhuang.com', status: 'active', creatorCount: 28, projectCount: 4, passRate: 75, trend: 'down', joinedAt: '2025-10-10', }, { id: 'a-004', agencyId: 'AG111111', name: '蓝海科技', companyName: '北京蓝海数字科技有限公司', email: 'info@lanhai.com', status: 'pending', creatorCount: 0, projectCount: 0, passRate: 0, trend: 'stable', joinedAt: '2026-02-01', }, ] function StatusTag({ status }: { status: string }) { if (status === 'active') return 已激活 if (status === 'pending') return 待接受 return 已暂停 } export default function AgenciesManagePage() { const toast = useToast() const [searchQuery, setSearchQuery] = useState('') const [agencies, setAgencies] = useState(initialAgencies) const [copiedId, setCopiedId] = useState(null) // 邀请代理商弹窗 const [showInviteModal, setShowInviteModal] = useState(false) const [inviteAgencyId, setInviteAgencyId] = useState('') const [inviteResult, setInviteResult] = useState<{ success: boolean; message: string } | null>(null) // 操作菜单状态 const [openMenuId, setOpenMenuId] = useState(null) // 备注弹窗状态 const [remarkModal, setRemarkModal] = useState<{ open: boolean; agency: Agency | null }>({ open: false, agency: null }) const [remarkText, setRemarkText] = useState('') // 删除确认弹窗状态 const [deleteModal, setDeleteModal] = useState<{ open: boolean; agency: Agency | null }>({ open: false, agency: null }) // 分配项目弹窗状态 const [assignModal, setAssignModal] = useState<{ open: boolean; agency: Agency | null }>({ open: false, agency: null }) const [selectedProjects, setSelectedProjects] = useState([]) const filteredAgencies = agencies.filter(agency => agency.name.toLowerCase().includes(searchQuery.toLowerCase()) || agency.agencyId.toLowerCase().includes(searchQuery.toLowerCase()) || agency.companyName.toLowerCase().includes(searchQuery.toLowerCase()) ) // 复制代理商ID const handleCopyAgencyId = async (agencyId: string) => { await navigator.clipboard.writeText(agencyId) setCopiedId(agencyId) setTimeout(() => setCopiedId(null), 2000) } // 邀请代理商 const handleInvite = () => { if (!inviteAgencyId.trim()) { setInviteResult({ success: false, message: '请输入代理商ID' }) return } // 检查代理商ID格式 const idPattern = /^AG\d{6}$/ if (!idPattern.test(inviteAgencyId.toUpperCase())) { setInviteResult({ success: false, message: '代理商ID格式错误,应为AG+6位数字' }) return } // 检查是否已邀请 if (agencies.some(a => a.agencyId === inviteAgencyId.toUpperCase())) { setInviteResult({ success: false, message: '该代理商已在您的列表中' }) return } // 模拟发送邀请成功 setInviteResult({ success: true, message: `已向代理商 ${inviteAgencyId.toUpperCase()} 发送邀请` }) } const handleCloseInviteModal = () => { setShowInviteModal(false) setInviteAgencyId('') setInviteResult(null) } // 打开备注弹窗 const handleOpenRemark = (agency: Agency) => { setRemarkText(agency.remark || '') setRemarkModal({ open: true, agency }) setOpenMenuId(null) } // 保存备注 const handleSaveRemark = () => { if (remarkModal.agency) { setAgencies(prev => prev.map(a => a.id === remarkModal.agency!.id ? { ...a, remark: remarkText } : a )) } setRemarkModal({ open: false, agency: null }) setRemarkText('') } // 打开删除确认 const handleOpenDelete = (agency: Agency) => { setDeleteModal({ open: true, agency }) setOpenMenuId(null) } // 确认删除 const handleConfirmDelete = () => { if (deleteModal.agency) { setAgencies(prev => prev.filter(a => a.id !== deleteModal.agency!.id)) } setDeleteModal({ open: false, agency: null }) } // 打开分配项目弹窗 const handleOpenAssign = (agency: Agency) => { setSelectedProjects([]) setAssignModal({ open: true, agency }) setOpenMenuId(null) } // 切换项目选择 const toggleProjectSelection = (projectId: string) => { setSelectedProjects(prev => prev.includes(projectId) ? prev.filter(id => id !== projectId) : [...prev, projectId] ) } // 确认分配项目 const handleConfirmAssign = () => { if (assignModal.agency && selectedProjects.length > 0) { const projectNames = mockProjects .filter(p => selectedProjects.includes(p.id)) .map(p => p.name) .join('、') toast.success(`已将代理商「${assignModal.agency.name}」分配到项目「${projectNames}」`) } setAssignModal({ open: false, agency: null }) setSelectedProjects([]) } return (
{/* 页面标题 */}

代理商管理

管理合作代理商,查看代理商绩效数据

{/* 统计卡片 */}

总代理商

{agencies.length}

已激活

{agencies.filter(a => a.status === 'active').length}

待接受

{agencies.filter(a => a.status === 'pending').length}

平均通过率

{agencies.filter(a => a.status === 'active').length > 0 ? Math.round(agencies.filter(a => a.status === 'active').reduce((sum, a) => sum + a.passRate, 0) / agencies.filter(a => a.status === 'active').length) : 0}%

{/* 搜索 */}
setSearchQuery(e.target.value)} className="w-full pl-10 pr-4 py-2.5 border border-border-subtle rounded-xl bg-bg-elevated text-text-primary focus:outline-none focus:ring-2 focus:ring-accent-indigo" />
{/* 代理商列表 */} {filteredAgencies.map((agency) => ( ))}
代理商 代理商ID 状态 达人数 项目数 通过率 加入时间 操作
{agency.name} {agency.remark && ( 有备注 )}
{agency.companyName}
{agency.remark && (

{agency.remark}

)}
{agency.agencyId}
{agency.creatorCount} {agency.projectCount} {agency.status === 'active' ? (
= 90 ? 'text-accent-green' : agency.passRate >= 80 ? 'text-accent-indigo' : 'text-orange-400'}`}> {agency.passRate}% {agency.trend === 'up' && } {agency.trend === 'down' && }
) : ( - )}
{agency.joinedAt}
{/* 下拉菜单 */} {openMenuId === agency.id && (
)}
{filteredAgencies.length === 0 && (

没有找到匹配的代理商

)}
{/* 邀请代理商弹窗 */}

输入代理商ID邀请合作。代理商ID可在代理商的个人中心查看。

{ setInviteAgencyId(e.target.value.toUpperCase()) setInviteResult(null) }} placeholder="例如: AG789012" className="flex-1 px-4 py-2.5 border border-border-subtle rounded-xl bg-bg-elevated text-text-primary font-mono focus:outline-none focus:ring-2 focus:ring-accent-indigo" />

代理商ID格式:AG + 6位数字

{inviteResult && (
{inviteResult.success ? ( ) : ( )} {inviteResult.message}
)}
{/* 备注弹窗 */} { setRemarkModal({ open: false, agency: null }); setRemarkText(''); }} title={`${remarkModal.agency?.remark ? '编辑' : '添加'}备注 - ${remarkModal.agency?.name}`} >