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
加载中...
} return (

客户管理

{customers.length === 0 ? ( ) : ( customers.map(customer => ( )) )}
公司名称 国家 行业 网站 联系方式 负责人 状态 操作
暂无客户数据
{customer.company} {customer.country || '-'} {customer.industry || '-'} {customer.website ? ( {customer.website} ) : '-'} {customer.email &&
{customer.email}
} {customer.phone &&
{customer.phone}
}
{customer.owner_name || '-'} {customer.status === 'active' ? '活跃' : '非活跃'}
{/* 新增客户模态框 */} {showAddModal && (
setShowAddModal(false)}>
e.stopPropagation()}>

新增客户

setFormData({...formData, company: e.target.value})} />
setFormData({...formData, country: e.target.value})} />
setFormData({...formData, industry: e.target.value})} />
setFormData({...formData, website: e.target.value})} />
setFormData({...formData, email: e.target.value})} />
setFormData({...formData, phone: e.target.value})} />