import { useState, useEffect, Table, Button, Input, Select, message, Card, Modal, Form, InputNumber, Row, Col, Tag, Rate, PlusOutlined, EditOutlined, DeleteOutlined, SearchOutlined, UserOutlined, PhoneOutlined, MailOutlined, HomeOutlined, useNavigate, Option, Search, TextArea, FC, } from '@/imports'; import { suppliersDataSource, Supplier } from '@/services/suppliersDataSource'; const Suppliers: FC = () => { const navigate = useNavigate(); const [suppliers, setSuppliers] = useState([]); const [loading, setLoading] = useState(false); const [modalVisible, setModalVisible] = useState(false); const [editingSupplier, setEditingSupplier] = useState(null); const [form] = Form.useForm(); const [filters, setFilters] = useState({ category: '', status: '', search: '', }); useEffect(() => { fetchSuppliers(); }, [filters]); const fetchSuppliers = async () => { setLoading(true); try { const data = await suppliersDataSource.fetchSuppliers(); setSuppliers(data); } catch (error) { message.error('Failed to load suppliers'); } finally { setLoading(false); } }; const handleAddSupplier = () => { setEditingSupplier(null); form.resetFields(); form.setFieldsValue({ status: 'active', rating: 3, leadTime: 7, minOrder: 100, paymentTerms: 'Net 30', }); setModalVisible(true); }; const handleEditSupplier = (id: string) => { const supplier = suppliers.find(s => s.id === id); if (supplier) { setEditingSupplier(supplier); form.setFieldsValue(supplier); setModalVisible(true); } }; const handleSaveSupplier = async () => { try { const values = await form.validateFields(); if (editingSupplier) { const updatedSuppliers = suppliers.map(s => s.id === editingSupplier.id ? { ...s, ...values } : s ); setSuppliers(updatedSuppliers); message.success('供应商已更新'); } else { const newSupplier: Supplier = { id: `supplier-${Date.now()}`, ...values, createdAt: new Date().toISOString(), }; setSuppliers([...suppliers, newSupplier]); message.success('供应商已添加'); } setModalVisible(false); } catch (error) { message.error('保存失败'); } }; const handleDeleteSupplier = (id: string) => { const updatedSuppliers = suppliers.filter(s => s.id !== id); setSuppliers(updatedSuppliers); message.success('供应商已删除'); }; const columns = [ { title: '供应商名称', dataIndex: 'name', key: 'name', }, { title: '联系人', dataIndex: 'contactName', key: 'contactName', }, { title: '邮箱', dataIndex: 'email', key: 'email', }, { title: '电话', dataIndex: 'phone', key: 'phone', }, { title: '类别', dataIndex: 'category', key: 'category', render: (category: string) => { const colorMap: Record = { Electronics: 'blue', Clothing: 'purple', 'Home Goods': 'green', }; return {category}; }, }, { title: '状态', dataIndex: 'status', key: 'status', render: (status: string) => { const statusMap: Record = { active: { label: '活跃', color: 'success' }, inactive: { label: '非活跃', color: 'default' }, pending: { label: '待审核', color: 'warning' }, }; const config = statusMap[status] || { label: status, color: 'default' }; return {config.label}; }, }, { title: '评分', dataIndex: 'rating', key: 'rating', render: (rating: number) => , }, { title: '交货期(天)', dataIndex: 'leadTime', key: 'leadTime', }, { title: '最小订单量', dataIndex: 'minOrder', key: 'minOrder', }, { title: '操作', key: 'action', render: (_: any, record: Supplier) => (
), }, ]; return (

供应商管理

setFilters({ ...filters, search: e.target.value })} />
setModalVisible(false)} onOk={handleSaveSupplier} width={800} >