import React, { useState, useEffect } from 'react' import axios from 'axios' function CustomerManagement() { const [customers, setCustomers] = useState([]) const [loading, setLoading] = useState(true) const [showAddModal, setShowAddModal] = useState(false) const [formData, setFormData] = useState({ company: '', country: '', industry: '', website: '', email: '', phone: '', notes: '' }) useEffect(() => { fetchCustomers() }, []) const fetchCustomers = async () => { try { const response = await axios.get('/api/customers') setCustomers(response.data) } catch (error) { console.error('获取客户列表失败:', error) } finally { setLoading(false) } } const handleSubmit = async (e) => { e.preventDefault() try { await axios.post('/api/customers', formData) setShowAddModal(false) setFormData({ company: '', country: '', industry: '', website: '', email: '', phone: '', notes: '' }) fetchCustomers() } catch (error) { console.error('创建客户失败:', error) alert('创建失败: ' + error.message) } } if (loading) { return
| 公司名称 | 国家 | 行业 | 网站 | 联系方式 | 负责人 | 状态 | 操作 |
|---|---|---|---|---|---|---|---|
| 暂无客户数据 | |||||||
| {customer.company} | {customer.country || '-'} | {customer.industry || '-'} | {customer.website ? ( {customer.website} ) : '-'} |
{customer.email && {customer.email} }
{customer.phone && {customer.phone} }
|
{customer.owner_name || '-'} | {customer.status === 'active' ? '活跃' : '非活跃'} | |