import React, { useState, useEffect } from 'react' import { useParams, useNavigate } from 'react-router-dom' import { Card, Descriptions, Tag, Spin, Empty, Row, Col, Button, Divider, Typography, Tabs } from 'antd' import { ArrowLeftOutlined, ShopOutlined, UserOutlined, PhoneOutlined, BankOutlined, DollarOutlined } from '@ant-design/icons' import BusinessLedgerTab from '../components/BusinessLedgerTab' const { Title, Text } = Typography interface Contact { name: string position: string phone: string is_primary?: boolean } interface PaymentInfo { id: number account_name: string bank_account: string bank_name: string qr_code?: string is_primary: boolean } interface LedgerSummary { item_count: number total_order_amount: number total_paid_amount: number total_unpaid_amount: number } interface LedgerItem { id: number type: string code: string name: string order_amount: number paid_amount: number unpaid_amount: number status: string } interface Supplier { id: number code: string name: string supply_category: string country: string contacts: Contact[] payment_infos: PaymentInfo[] remark: string total_purchase_amount: number total_paid: number total_payable: number ledger?: { summary: LedgerSummary items: LedgerItem[] } created_at: string } const SupplierDetail: React.FC = () => { const { id } = useParams<{ id: string }>() const navigate = useNavigate() const [supplier, setSupplier] = useState(null) const [loading, setLoading] = useState(true) const [activeTab, setActiveTab] = useState('basic') useEffect(() => { fetchSupplierDetail() }, [id]) const fetchSupplierDetail = async () => { try { const res = await fetch(`/api/suppliers/${id}`) const data = await res.json() if (data.success) setSupplier(data.data) } catch (error) { console.error('获取供应商详情失败:', error) } finally { setLoading(false) } } if (loading) return if (!supplier) return const tabItems = [ { key: 'basic', label: 基本信息, children: ( <> {supplier.code} {supplier.supply_category || '-'} {supplier.country || '-'} {supplier.remark && (
备注:
{supplier.remark}
)} ) }, { key: 'contacts', label: 联系人, children: ( <> {(supplier.contacts || []).map((contact, i) => (
{contact.name || '未命名'} {contact.is_primary && 主联系人}
{contact.position &&
职位:{contact.position}
} {contact.phone &&
电话:{contact.phone}
}
))}
{(supplier.contacts || []).length === 0 && } ) }, { key: 'payment', label: 收款信息, children: ( <> {(supplier.payment_infos || []).map((payment, i) => (
{payment.bank_name || '未命名'} {payment.is_primary && 主要收款账户}
{payment.account_name &&
户名:{payment.account_name}
} {payment.bank_account &&
账号:{payment.bank_account}
} {payment.qr_code && (
收款码:
收款码
)}
))}
{(supplier.payment_infos || []).length === 0 && } ) }, { key: 'ledger', label: 业务台账, children: ( ) } ] return (
<ShopOutlined style={{ marginRight: 8, color: '#1890ff' }} /> {supplier.name}
) } export default SupplierDetail