import React, { useState, useEffect } from 'react'; import { Table, Button, Tag, Space, Typography, message, Modal } from 'antd'; import { CheckOutlined, DeleteOutlined, EyeOutlined, FilterOutlined } from '@ant-design/icons'; import { useAdminStore } from '../store'; import { api } from '../api/client'; interface ContactRequest { id: string; user_id: string; phone: string; company_name: string; industry: string; name: string; message: string | null; is_handled: boolean; created_at: string; } const AdminContactRequests: React.FC = () => { const [data, setData] = useState([]); const [total, setTotal] = useState(0); const [loading, setLoading] = useState(false); const [page, setPage] = useState(1); const [pageSize, setPageSize] = useState(20); const [isHandledFilter, setIsHandledFilter] = useState(null); const [selectedItem, setSelectedItem] = useState(null); const [detailModalOpen, setDetailModalOpen] = useState(false); const { user } = useAdminStore(); const fetchData = async () => { if (!user?.isAdmin) return; setLoading(true); try { const query = new URLSearchParams(); query.set('page', String(page)); query.set('page_size', String(pageSize)); if (isHandledFilter !== null) { query.set('is_handled', String(isHandledFilter)); } const res = await api.get<{ items: ContactRequest[]; total: number }>(`/contact/requests?${query.toString()}`); setData(res.items); setTotal(res.total); } catch (err: any) { message.error(err?.message || '获取失败'); } finally { setLoading(false); } }; useEffect(() => { fetchData(); }, [page, pageSize, isHandledFilter]); const handleMarkHandled = async (id: string) => { try { await api.put(`/contact/requests/${id}/handle`); message.success('已标记为处理'); fetchData(); } catch (err: any) { message.error(err?.message || '操作失败'); } }; const handleDelete = async (id: string) => { Modal.confirm({ title: '确认删除', content: '确定要删除这条联系请求吗?', onOk: async () => { try { await api.delete(`/contact/requests/${id}`); message.success('删除成功'); fetchData(); } catch (err: any) { message.error(err?.message || '删除失败'); } }, }); }; const handleViewDetail = (item: ContactRequest) => { setSelectedItem(item); setDetailModalOpen(true); }; const columns = [ { title: '姓名', dataIndex: 'name', key: 'name', width: 100, }, { title: '手机号', dataIndex: 'phone', key: 'phone', width: 120, }, { title: '公司名称', dataIndex: 'company_name', key: 'company_name', width: 150, ellipsis: true, }, { title: '行业', dataIndex: 'industry', key: 'industry', width: 120, }, { title: '状态', dataIndex: 'is_handled', key: 'is_handled', width: 80, render: (isHandled: boolean) => ( {isHandled ? '已处理' : '待处理'} ), }, { title: '提交时间', dataIndex: 'created_at', key: 'created_at', width: 160, render: (date: string) => { return new Date(date).toLocaleString('zh-CN'); }, }, { title: '操作', key: 'actions', width: 180, render: (_: unknown, record: ContactRequest) => ( {!record.is_handled && ( )} ), }, ]; return (
联系请求管理
共 {total} 条记录
{ setPage(p); setPageSize(s); }, }} rowKey="id" bordered={false} style={{ background: '#ffffff', borderRadius: 12 }} /> setDetailModalOpen(false)} footer={null} width={500} > {selectedItem && (
{selectedItem.name} {selectedItem.is_handled ? '已处理' : '待处理'}
手机号: {selectedItem.phone} 公司名称: {selectedItem.company_name} 行业: {selectedItem.industry} 提交时间: {new Date(selectedItem.created_at).toLocaleString('zh-CN')} {selectedItem.message && ( <> 留言: {selectedItem.message} )}
{!selectedItem.is_handled && ( )}
)}
); }; export default AdminContactRequests;