import React, { useState, useEffect } from 'react' import { useNavigate } from 'react-router-dom' import { Table, Button, Modal, Form, Input, Select, message, Space, Tag, Card, Row, Col, Statistic } from 'antd' import { PlusOutlined, EditOutlined, DeleteOutlined, SearchOutlined, ShopOutlined } from '@ant-design/icons' import type { ColumnsType } from 'antd/es/table' interface Contact { name: string position: string phone: string is_primary?: boolean } interface Supplier { id: number code: string name: string supply_category: string country: string contacts: Contact[] remark: string total_purchase_amount: number total_paid: number total_payable: number created_at: string } const SupplierPage: React.FC = () => { const navigate = useNavigate() const [suppliers, setSuppliers] = useState([]) const [loading, setLoading] = useState(false) const [modalVisible, setModalVisible] = useState(false) const [editingSupplier, setEditingSupplier] = useState(null) const [searchText, setSearchText] = useState('') const [form] = Form.useForm() const fetchSuppliers = async () => { setLoading(true) try { const response = await fetch('/api/suppliers') const data = await response.json() if (data.success) setSuppliers(data.data || []) } catch (error) { message.error('获取供应商列表失败') } finally { setLoading(false) } } useEffect(() => { fetchSuppliers() }, []) const stats = { total: suppliers.length, totalPurchase: suppliers.reduce((sum, s) => sum + (s.total_purchase_amount || 0), 0), totalPayable: suppliers.reduce((sum, s) => sum + (s.total_payable || 0), 0) } const getPrimaryContact = (contacts: Contact[]) => { const primary = contacts?.find(c => c.is_primary) return primary?.name || '-' } const columns: ColumnsType = [ { title: '编号', dataIndex: 'code', key: 'code', width: 120 }, { title: '名称', dataIndex: 'name', key: 'name', render: (text, record) => ( ) }, { title: '供应类别', dataIndex: 'supply_category', key: 'supply_category', width: 120 }, { title: '主联系人', key: 'primary_contact', width: 100, render: (_, record) => getPrimaryContact(record.contacts || []) }, { title: '国家', dataIndex: 'country', key: 'country', width: 80, render: (country) => {country || '-'} }, { title: '采购金额', dataIndex: 'total_purchase_amount', key: 'total_purchase_amount', width: 100, render: (amount) => `¥${(amount || 0).toLocaleString()}` }, { title: '应付金额', dataIndex: 'total_payable', key: 'total_payable', width: 100, render: (amount) => 0 ? '#ff4d4f' : '#52c41a' }}>¥{(amount || 0).toLocaleString()} }, { title: '操作', key: 'actions', width: 100, render: (_, record) => ( `共 ${total} 条` }} scroll={{ x: 900 }} /> { setModalVisible(false); form.resetFields(); setEditingSupplier(null) }} onOk={() => form.submit()} width={700}>

联系人

{(fields, { add, remove }) => (
{fields.map(({ key, name, ...restField }) => (
handleContactChange(name, 'is_primary', e.target.checked)} /> 主联系人 {fields.length > 1 && }
))}
)}
) } export default SupplierPage