import React, { useState, useEffect } from 'react' import { Table, Button, Modal, Form, Input, Switch, message, Space, Tag, Popconfirm } from 'antd' import { PlusOutlined, EditOutlined, DeleteOutlined, PhoneOutlined, UserOutlined } from '@ant-design/icons' import type { ColumnsType } from 'antd/es/table' import { useTranslation } from 'react-i18next' interface Contact { id: number name: string name_zh?: string position?: string department?: string is_primary: boolean phone?: string mobile?: string wechat?: string whatsapp?: string line_id?: string notes?: string } interface ContactManagerProps { companyType: 'customer' | 'supplier' | 'subcontractor' companyId: number companyName: string onContactsUpdated?: () => void } const ContactManager: React.FC = ({ companyType, companyId, companyName, onContactsUpdated }) => { const { t } = useTranslation() const [contacts, setContacts] = useState([]) const [loading, setLoading] = useState(false) const [modalVisible, setModalVisible] = useState(false) const [editingContact, setEditingContact] = useState(null) const [form] = Form.useForm() const fetchContacts = async () => { setLoading(true) try { const response = await fetch(`/api/${companyType}s/${companyId}/contacts`) const data = await response.json() setContacts(data.contacts || []) } catch (error) { console.error('获取联系人失败:', error) } finally { setLoading(false) } } useEffect(() => { if (companyId) { fetchContacts() } }, [companyId, companyType]) const columns: ColumnsType = [ { title: t('contact.name'), dataIndex: 'name', key: 'name', render: (text, record) => (
{text}
{record.position &&
{record.position}
}
) }, { title: t('contact.contactInfo'), key: 'contact', render: (_, record) => ( {record.mobile &&
{record.mobile}
} {record.phone &&
{t('component.phonePrefix')}{record.phone}
} {record.wechat &&
{t('component.wechatPrefix')}{record.wechat}
}
) }, { title: t('contact.status'), dataIndex: 'is_primary', key: 'is_primary', width: 100, render: (isPrimary) => ( {isPrimary ? t('contact.primary') : t('contact.secondary')} ) }, { title: t('common.actions'), key: 'actions', width: 120, render: (_, record) => ( { setModalVisible(false); form.resetFields(); setEditingContact(null) }} onOk={() => form.submit()} width={600} destroyOnClose >
) } export default ContactManager