import React, { useState, useEffect, useRef } from 'react'; import * as echarts from 'echarts'; import styles from './CustomerInfoManagement.less'; const CustomerInfoManagement = () => { const [searchKeyword, setSearchKeyword] = useState(''); const [customerType, setCustomerType] = useState('全部'); const [customerLevel, setCustomerLevel] = useState('全部'); const [cooperationStatus, setCooperationStatus] = useState('全部'); const [selectedRows, setSelectedRows] = useState([]); const [currentPage, setCurrentPage] = useState(1); const [pageSize, setPageSize] = useState(10); // 图表引用 const customerTypeChartRef = useRef(null); const customerValueChartRef = useRef(null); const customerTypeChartInstance = useRef(null); const customerValueChartInstance = useRef(null); // KPI数据 const kpiData = { totalCustomers: 389, highValueCustomers: 180, inCooperation: 360, newThisMonth: 8, }; // 客户类型分布图表配置 const customerTypeChartOption = { title: { text: '客户类型分布', left: 'left', textStyle: { fontSize: 16, fontWeight: 600, }, }, tooltip: { trigger: 'axis', axisPointer: { type: 'shadow', }, }, grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true, }, xAxis: { type: 'category', data: ['客户', '供应商', '第3周', '第4周'], axisLabel: { rotate: 0, }, }, yAxis: { type: 'value', max: 100, }, series: [ { name: '数量', type: 'bar', data: [56, 32, 85, 15], itemStyle: { color: '#1890ff', }, label: { show: true, position: 'top', }, }, ], }; // 客户价值分布环形图配置 const customerValueChartOption = { title: { text: '客户价值分布', left: 'left', textStyle: { fontSize: 16, fontWeight: 600, }, }, tooltip: { trigger: 'item', formatter: '{a}
{b}: {c} ({d}%)', }, legend: { orient: 'vertical', left: 'right', top: 'middle', }, series: [ { name: '客户价值', type: 'pie', radius: ['40%', '70%'], avoidLabelOverlap: false, itemStyle: { borderRadius: 10, borderColor: '#fff', borderWidth: 2, }, label: { show: false, }, emphasis: { label: { show: true, fontSize: 16, fontWeight: 'bold', }, }, data: [ { value: 180, name: '高价值客户', itemStyle: { color: '#5B9BD5' } }, { value: 120, name: '中等客户', itemStyle: { color: '#FFC000' } }, { value: 89, name: '小客户', itemStyle: { color: '#9E7CC1' } }, ], }, ], }; // 初始化图表 useEffect(() => { // 初始化客户类型分布图表 if (customerTypeChartRef.current) { customerTypeChartInstance.current = echarts.init(customerTypeChartRef.current); customerTypeChartInstance.current.setOption(customerTypeChartOption); } // 初始化客户价值分布图表 if (customerValueChartRef.current) { customerValueChartInstance.current = echarts.init(customerValueChartRef.current); customerValueChartInstance.current.setOption(customerValueChartOption); } // 响应式调整 const handleResize = () => { customerTypeChartInstance.current?.resize(); customerValueChartInstance.current?.resize(); }; window.addEventListener('resize', handleResize); // 清理函数 return () => { window.removeEventListener('resize', handleResize); customerTypeChartInstance.current?.dispose(); customerValueChartInstance.current?.dispose(); }; }, []); // 最近活动数据 const recentActivities = [ { id: 1, title: '新合同签署', description: '与中石化华东分公司签署年度供应合同', time: '2小时前', }, { id: 2, title: '订单完成', description: '完成海南石油贸易有限公司的油品配送', time: '昨天', }, { id: 3, title: '客户反馈', description: '收到华南能源集团的满意度调查回复', time: '昨天', }, { id: 4, title: '新客户注册', description: '新客户"浙江能源有限公司"完成注册', time: '3天前', }, ]; // 表格数据 const tableData = [ { id: '1', customerName: '中国石化销售股份有限公司', contact: '钱亚男', phone: '18901563341', classification: '高价值', monthlyAmount: 1250000, cooperationStatus: '合作中', satisfaction: 4.5, }, { id: '2', customerName: '中石化华东分公司', contact: '郑宇雅', phone: '15341731282', classification: '常规客户', monthlyAmount: 1250000, cooperationStatus: '合作中', satisfaction: 4.0, }, { id: '3', customerName: '海南石油贸易有限公司', contact: '孙向明', phone: '13252257033', classification: '高价值', monthlyAmount: 850000, cooperationStatus: '合作中', satisfaction: 4.5, }, { id: '4', customerName: '东莞石化有限公司', contact: '何思颖', phone: '18931788771', classification: '高价值', monthlyAmount: 980000, cooperationStatus: '合作中', satisfaction: 4.5, }, { id: '5', customerName: '中国石油化工集团有限公司', contact: '钱佳仪', phone: '13743378254', classification: '常规客户', monthlyAmount: 980000, cooperationStatus: '暂停合作', satisfaction: 4.0, }, ]; // 处理选择 const handleSelectRow = (id) => { if (selectedRows.includes(id)) { setSelectedRows(selectedRows.filter(rowId => rowId !== id)); } else { setSelectedRows([...selectedRows, id]); } }; // 处理全选 const handleSelectAll = () => { if (selectedRows.length === tableData.length) { setSelectedRows([]); } else { setSelectedRows(tableData.map(item => item.id)); } }; // 渲染星级评分 const renderStars = (rating) => { const stars = []; const fullStars = Math.floor(rating); const hasHalfStar = rating % 1 !== 0; for (let i = 0; i < fullStars; i++) { stars.push(); } if (hasHalfStar) { stars.push(); } const emptyStars = 5 - Math.ceil(rating); for (let i = 0; i < emptyStars; i++) { stars.push(); } return stars; }; // 计算总页数 const totalPages = Math.ceil(85 / pageSize); return (
{/* KPI卡片区域 */}
👥
{kpiData.totalCustomers}
总客户数
👑
{kpiData.highValueCustomers}
高价值客户
🤝
{kpiData.inCooperation}
合作中
{kpiData.newThisMonth}
本月新增
{/* 图表和活动区域 */}
{/* 客户类型分布图表 */}
客户类型分布
{/* 客户价值分布图表 */}
客户价值分布
{/* 最近活动列表 */}
最近活动
{recentActivities.map((activity) => (
{activity.id === 1 && '📄'} {activity.id === 2 && '✅'} {activity.id === 3 && '💬'} {activity.id === 4 && '👤'}
{activity.title}
{activity.description}
🕐 {activity.time}
))}
{/* 客户列表区域 */}
客户列表
{/* 筛选栏 */}
setSearchKeyword(e.target.value)} />
{/* 表格 */}
{tableData.map((row) => ( ))}
客户名称 联系人 联系电话 分类 交易额度(月) 合作状态 满意度 操作
handleSelectRow(row.id)} /> {row.customerName} {row.contact} {row.phone} {row.classification} ¥{row.monthlyAmount.toLocaleString()} {row.cooperationStatus}
{renderStars(row.satisfaction)}
{/* 分页 */}
共85条
{currentPage > 3 && ( <> ... )} {Array.from({ length: Math.min(5, totalPages) }, (_, i) => { let pageNum; if (currentPage <= 3) { pageNum = i + 1; } else if (currentPage >= totalPages - 2) { pageNum = totalPages - 4 + i; } else { pageNum = currentPage - 2 + i; } if (pageNum > totalPages) return null; return ( ); })} {currentPage < totalPages - 2 && ( <> ... )}
); }; export default CustomerInfoManagement;