import React, { useState, useEffect } from 'react'; import { Layout, Card, Row, Col, Button, Table, Tag, Select, Input, Typography, Space, Statistic, Modal, message, Empty, Drawer, Descriptions, Timeline, Divider, Form, Tabs, Progress, Badge, DatePicker, Pagination } from 'antd'; import { CheckOutlined, ClockCircleOutlined, ControlOutlined, BarChartOutlined, RiseOutlined, ArrowUpOutlined, SearchOutlined, PlusOutlined, EditOutlined, DeleteOutlined, EyeOutlined, CommentOutlined, PauseOutlined, FormOutlined, ReloadOutlined, FilterOutlined, MoreOutlined, CheckCircleFilled, PlayCircleFilled, InfoCircleFilled, RobotOutlined, ThunderboltOutlined, AlertOutlined, CheckCircleOutlined } from '@ant-design/icons'; import dayjs from 'dayjs'; import { Pie, Line } from '@ant-design/charts'; import { ClipboardList, Clock, Play, CheckCircle, Timer, Cpu, Calendar as CalendarIcon, ChevronRight, History, ExternalLink } from 'lucide-react'; // 导入工单接口 import { getWorkOrderApi, getWorkOrderDetailApi, updateWorkOrder, dispatchWorkOrder, completeWorkOrder } from '../api/workOrder'; import { UniversalLineChart } from '../components/recharts'; const { Option } = Select; const { Search } = Input; const { Text, Title } = Typography; const { RangePicker } = DatePicker; const FormItem = Form.Item; // 优先级数字映射 1高 2中 3低 const priorityConfig = { 1: { label: '高', color: '#ff4d4f', bg: '#fff1f0', border: '#ff4d4f' }, 2: { label: '中', color: '#faad14', bg: '#fff7e6', border: '#faad14' }, 3: { label: '低', color: '#52c41a', bg: '#f6ffed', border: '#52c41a' } }; // 工单状态数字映射 const orderStatusConfig = { 1: { label: '待处理', textColor: '#1890ff' }, 2: { label: '执行中', textColor: '#1890ff' }, 3: { label: '挂起', textColor: '#faad14' }, 4: { label: '已完成', textColor: '#52c41a' }, 5: { label: '处理中', textColor: '#722ed1' } }; // 工单类型映射 const orderTypeConfig = { 1: '巡检', 2: '检修', 3: '清洗', 4: '维修', 5: '运维' }; const WorkOrderPage = () => { const [activeTab, setActiveTab] = useState('1'); const [selectedRowKey, setSelectedRowKey] = useState(''); // 接口相关状态 const [loading, setLoading] = useState(false); const [workOrderList, setWorkOrderList] = useState([]); const [workOrderTotal, setWorkOrderTotal] = useState(0); const [currentDetail, setCurrentDetail] = useState(null); // 弹窗表单 const [form] = Form.useForm(); const [editModalVisible, setEditModalVisible] = useState(false); const [dispatchModalVisible, setDispatchModalVisible] = useState(false); const [completeModalVisible, setCompleteModalVisible] = useState(false); const [completeForm] = Form.useForm(); // 完成工单表单 // 统计数据(保留原模拟不变) const stats = [ { title: '今日新增工单', value: 18, subValue: '+3', subText: '较昨日', icon: , bg: '#e6f7ff' }, { title: '待处理工单', value: 12, subValue: '5', subText: '高优先级', icon: , bg: '#fff1f0' }, { title: '执行中工单', value: 9, subValue: '92%', subText: '按时率', icon: , bg: '#f6ffed' }, { title: '已完成工单', value: 126, subValue: '', subText: '本月累计', icon: , bg: '#f6ffed' }, { title: '平均处理时长', value: 4.3, unit: '小时', subValue: '-12%', subText: '较上周', icon: , bg: '#e6f7ff' }, { title: 'AI建议生成', value: 7, unit: '单', subValue: '', subText: '今日自动生成', icon: , bg: '#f9f0ff' }, ]; // 图表模拟数据保留不变 const pieData = [ { type: '待处理', value: 12 }, { type: '执行中', value: 9 }, { type: '已完成', value: 126 }, { type: '已挂起', value: 4 }, ]; const alarmTrendData = [ { date: '05-18', value: 5 }, { date: '05-19', value: 10 }, { date: '05-20', value: 7 }, { date: '05-21', value: 12 }, { date: '05-22', value: 8 }, { date: '05-23', value: 15 }, { date: '05-24', value: 11 }, ]; // ========== 接口请求方法 ========== // 获取工单列表 const getWorkOrderList = async () => { setLoading(true); try { const res = await getWorkOrderApi(); if (res.code == 0) { setWorkOrderList(res.rows || []); setWorkOrderTotal(res.total || 0); if (res.rows && res.rows.length > 0) { setSelectedRowKey(res.rows[0].id); getWorkOrderDetail(res.rows[0].id); } } } catch (error) { message.error('获取工单列表失败'); } finally { setLoading(false); } }; // 打开完成工单弹窗 const openCompleteModal = () => { if (!selectedRowKey) return message.warning('请先选择工单'); completeForm.setFieldsValue({ id: currentDetail?.id, orderNo: currentDetail?.orderNo, handleResult: '已处理完成', handleRemark: '', }); setCompleteModalVisible(true); }; // 提交完成工单 const submitComplete = async (values) => { try { // 构造后端需要的参数(只需要传 id + 处理信息) const params = { id: values.id, handleResult: values.handleResult, handleRemark: values.handleRemark, }; await completeWorkOrder(params); message.success('工单已完成'); setCompleteModalVisible(false); // 刷新列表 + 详情 getWorkOrderList(); getWorkOrderDetail(selectedRowKey); } catch (err) { message.error('工单完成失败'); console.error(err); } }; // 获取工单详情 const getWorkOrderDetail = async (id) => { try { const res = await getWorkOrderDetailApi(id); if (res.code == 200) { setCurrentDetail(res.data); } } catch (error) { message.error('获取工单详情失败'); } }; // 选中表格行 const handleRowSelect = (keys) => { if (keys.length > 0) { setSelectedRowKey(keys[0]); getWorkOrderDetail(keys[0]); } }; // 打开修改工单弹窗 const openEditModal = () => { if (!selectedRowKey) return message.warning('请先选择一条工单'); form.setFieldsValue({ title: currentDetail?.orderTitle, content: currentDetail?.taskDescription, priority: currentDetail?.priorityLevel, type: currentDetail?.orderType, remark: currentDetail?.remark }); setEditModalVisible(true); }; // 打开派发工单弹窗 // 打开派发工单弹窗 const openDispatchModal = () => { if (!selectedRowKey) return message.warning('请先选择一条工单'); form.setFieldsValue({ orderId: selectedRowKey, // 自动回填工单ID assigneeName: currentDetail?.assigneeName || '', planStartTime: currentDetail?.planStartTime ? dayjs(currentDetail.planStartTime) : null, planEndTime: currentDetail?.planEndTime ? dayjs(currentDetail.planEndTime) : null, deadlineTime: currentDetail?.deadlineTime ? dayjs(currentDetail.deadlineTime) : null, }); setDispatchModalVisible(true); }; // 提交修改工单 const submitEdit = async (values) => { try { // 适配后端传参:id、title、content、priority、type、remark await updateWorkOrder({ id: selectedRowKey, orderTitle: values.title, taskDescription: values.content, priorityLevel: values.priority, orderType: values.type, remark: values.remark }); message.success('修改工单成功'); setEditModalVisible(false); getWorkOrderList(); } catch (error) { message.error('修改工单失败'); } }; // 提交派发工单 // 提交派发工单 const submitDispatch = async (values) => { try { // 拼接接口需要的参数(完全按你给的格式) const params = { orderId: values.orderId, assigneeId: values.assigneeName === '王工' ? 1003 : '', // 你可以自己映射ID assigneeName: values.assigneeName, collaboratorIds: '', collaboratorNames: values.collaboratorNames?.join(',') || '', planStartTime: values.planStartTime ? values.planStartTime.format('YYYY-MM-DDTHH:mm:ss') : '', planEndTime: values.planEndTime ? values.planEndTime.format('YYYY-MM-DDTHH:mm:ss') : '', deadlineTime: values.deadlineTime ? values.deadlineTime.format('YYYY-MM-DDTHH:mm:ss') : '', }; await dispatchWorkOrder(params); message.success('工单派发成功'); setDispatchModalVisible(false); getWorkOrderList(); // 刷新列表 } catch (error) { message.error('工单派发失败'); console.error(error); } }; useEffect(() => { getWorkOrderList(); }, []); const cardStyle = { borderRadius: 12, border: '1px solid #f0f0f0', boxShadow: '0 4px 12px rgba(0,0,0,0.05)', overflow: 'hidden' }; // 表格列【已适配后端真实字段】 const columns = [ { title: '工单编号', dataIndex: 'orderNo', key: 'orderNo', width: 130 }, { title: '工单标题', dataIndex: 'orderTitle', key: 'orderTitle', width: 180, ellipsis: true }, { title: '来源', dataIndex: 'sourceType', key: 'sourceType', width: 100 }, { title: '类型', dataIndex: 'orderType', key: 'orderType', width: 80, render: (val) => orderTypeConfig[val] || '未知' }, { title: '优先级', dataIndex: 'priorityLevel', key: 'priorityLevel', width: 80, render: (p) => ( {priorityConfig[p]?.label} ) }, { title: '负责人', dataIndex: 'assigneeName', key: 'assigneeName', width: 80 }, { title: '截止时间', dataIndex: 'deadlineTime', key: 'deadlineTime', width: 150 }, { title: '状态', dataIndex: 'orderStatus', key: 'orderStatus', width: 90, render: (s) => (
{orderStatusConfig[s]?.label}
) }, { title: '操作', key: 'action', width: 60, fixed: "right", render: (_, record) => ( ) }, ]; return (
{/* 顶部标题和页签 */}
工单任务管理
{/* 统计卡片 */} {stats.map((item, index) => (
{item.title}
{item.value}
{item.unit && {item.unit}}
{item.subText} {item.subValue}
{item.icon}
))}
{/* 筛选栏 */}
工单类型
优先级
负责人
时间范围
状态
关键词 } size="small" />
{/* 左侧:列表 + 底部图表 */} 工单列表(共 {workOrderTotal} 条)} bodyStyle={{ padding: 0 }} style={{ ...cardStyle, marginBottom: 16 }} >
工单状态分布} style={{ ...cardStyle, height: 380 }}>
{ const total = pieData.reduce((a, b) => a + b.value, 0); const percent = ((item.value / total) * 100).toFixed(1); return `${item.value} (${percent}%)`; } } }} height={260} />
总数
{workOrderTotal}
任务排班 / 日历视图} extra={} style={{ ...cardStyle, height: 380 }} bodyStyle={{ padding: '16px' }} >
{['08:00', '10:00', '12:00', '14:00', '16:00', '18:00'].map(t => (
{t}
))}
{['李工', '王工', '赵工', '陈工'].map((name, idx) => (
{name}
{idx === 0 &&
INV-05 告警排查
08:30 - 12:00
} {idx === 1 &&
B-12 热斑复检
13:30 - 15:00
} {idx === 1 &&
无人机巡检
16:00-18:00
} {idx === 2 &&
组件清洗 C-05
09:00 - 12:00
} {idx === 2 &&
清洗效果复检
15:00 - 17:00
} {idx === 3 &&
周界摄像头修复
10:00 - 12:30
} {idx === 3 &&
设备巡检
15:30 - 17:30
}
))}
{/* 右侧:详情 + AI + 告警 */}
工单详情 工单编号: {currentDetail?.orderNo || '--'}
{currentDetail?.orderTitle || '暂无标题'} {currentDetail?.priorityLevel && ( {priorityConfig[currentDetail.priorityLevel].label}优先级 )}
来源:{currentDetail?.sourceType || '--'}工单类型:{orderTypeConfig[currentDetail?.orderType] || '--'}负责人:{currentDetail?.assigneeName || '--'}协同人员:{currentDetail?.collaboratorNames || '无'}计划时间:{currentDetail?.planStartTime ? `${currentDetail.planStartTime} ~ ${currentDetail.planEndTime}` : '--'}关联设备:{currentDetail?.deviceName || '无'}关联区域:{currentDetail?.siteName || '无'}当前状态:{orderStatusConfig[currentDetail?.orderStatus]?.label || '--'}任务描述:
{currentDetail?.taskDescription || '暂无描述'}
{/* 连线 */}
= 3 ? '100%' : (currentDetail?.orderStatus === 2 ? '66%' : '33%'), height: '100%', background: '#00B42A' }}>
{[ { label: '已创建', step: 1, active: currentDetail?.orderStatus >= 1 }, { label: '已派发', step: 2, active: currentDetail?.orderStatus >= 2 }, { label: '执行中', step: 3, active: currentDetail?.orderStatus >= 2 }, { label: '已完成', step: 4, active: currentDetail?.orderStatus >= 4 }, ].map(item => (
{item.active ? : item.step}
{item.label}
))}
AI 建议与关联信息} style={{ ...cardStyle, marginTop: 16 }} bodyStyle={{ padding: '16px' }} >
建议携带
红外热像设备
优先复检组件
B-12-03 / B-12-05
预计影响发电
2.1%
关联告警趋势 (近 7 天)
关联告警列表 (近 3 条)
{[ { title: 'INV-05 逆变器告警', time: '05-24 10:24', status: 'error' }, { title: 'B-12 区块热斑告警', time: '05-24 09:56', status: 'warning' }, { title: 'B-12 组件温度异常', time: '05-24 09:32', status: 'warning' }, ].map((item, idx) => (
{item.title} {item.time}
))}
{/* 修改工单弹窗 */} setEditModalVisible(false)} footer={null} width={520}>
{/* 派发工单弹窗 */} setDispatchModalVisible(false)} footer={null} width={550}>
); }; export default WorkOrderPage;