import ModuleTitle from '@/components/ManagementPage/moduleTitle';
import TabsContent from '@/components/TabsContent';
import ThresholdDetail from '@/components/ThresholdDetail';
import ThresholdModal from '@/components/ThresholdDetail/ThresholdModal';
import { changeRecordStatus, getDumuDetail } from '@/services/eqSelfInspection';
import { UnityAction } from '@/utils/utils';
import { connect, useRequest } from '@umijs/max';
import {
Col,
DatePicker,
Form,
Input,
Modal,
Row,
Select,
Spin,
Table,
message,
} from 'antd';
import dayjs from 'dayjs';
import { useEffect, useMemo, useState } from 'react';
import ReactZmage from 'react-zmage';
import styles from './PatrolReportDetail.less';
function Detail(props) {
const { data, userList, projectId, dispatch, loading = false } = props;
const [select, setSelect] = useState();
const [dumuList, setDumuList] = useState([]);
const sendMessageToUnity = (select, data) => {
setSelect(select);
if (window.HightlightEquipment) {
window.HightlightEquipment(data);
}
};
const { run: detailRun } = useRequest(getDumuDetail, {
manual: true,
fetchKey: (id) => id,
onSuccess: (data) => {
var item = dumuList?.find((child) => child.id === data.id);
if (item) {
item.url = base64ToImageUrl(data.event_bg);
}
setDumuList([...dumuList]);
},
});
const result = useMemo(() => {
var resultArr = [];
var tempResult = data?.PatrolResult;
var tempArr = tempResult?.split(';');
const getTextColor = (status) => {
switch (status) {
case '警告':
return {
color: '#FFE26D',
className: styles.warn,
};
case '异常':
return {
color: '#FE5850',
className: styles.error,
};
default:
return {
color: '#12CEB3',
className: '',
};
}
};
if (tempArr?.length > 0) {
tempArr?.forEach((item, index) => {
var tempItem = item;
var itemSplit = tempItem.split(':');
if (itemSplit?.length > 1) {
var label = '';
var value = itemSplit[1];
if (index === 0) label = '设备自检';
else if (index === 1) label = '工艺自检';
else {
label = '安全隐患';
value = data?.secureStatus === 0 ? '正常' : '异常';
}
resultArr.push({
...getTextColor(value),
label,
value,
});
}
});
}
return resultArr;
}, [data]);
useEffect(() => {
dispatch({
type: 'eqSelfInspection/fetchUserList',
payload: {
projectId,
},
});
}, []);
useEffect(() => {
setDumuList(data?.dumuList);
data?.dumuList?.map((item) => {
detailRun(item.id);
});
}, [data?.dumuList]);
return (
自检时间:{data?.CreatedTime}
自检路线:{data?.RouteInfo?.Name}
工艺段:{data?.RouteInfo?.GroupID}
{result?.map((item) => {
return (
{item.value}
{item?.label}
);
})}
{/* 设备自检报告 */}
{/* 液位异常 */}
{/* 加药流量校验 */}
{/* 工艺自检报告"> */}
异常({data?.FaultAnalysis?.length || 0})
{/* 安全隐患自检报告"> */}
{/* 环境异常 */}
{/* 液位异常 */}
{/* }
/> */}
{/* 安防检测异常 */}
{/* 电器检测异常 */}
{/* 密闭空间检测异常 */}
{/* */}
);
}
export function DeviceTable(props) {
const {
onClickItem,
data = {},
items,
onErrorHandle,
select,
userList,
type,
} = props;
console.log(items);
const { ProjectId, Id } = data;
const [loading, setLoading] = useState(false);
const [visible, setVisible] = useState(false);
const [errVisible, setErrVisible] = useState(false);
const [currentItem, setCurrentItem] = useState({});
const isSensor = type == 'sensor';
const onClickThreshold = (record) => {
setCurrentItem(record);
setVisible(true);
};
const onClickError = (record) => {
setCurrentItem(record);
setErrVisible(true);
};
const handleError = async (values) => {
setLoading(true);
var res = await changeRecordStatus({
...values,
Id: currentItem.Id,
DeviceCode: currentItem.DeviceCode,
DeviceName: currentItem.DeviceName,
RecordId: data.Id,
RepairMan: values.RepairMan * 1,
});
setLoading(false);
if (res) {
message.success('操作成功');
setErrVisible(false);
}
};
const columns = [
{
title: '设备名称',
width: '20%',
dataIndex: 'DeviceName',
},
{
title: '巡检项',
key: 'TemplateItem.Name',
dataIndex: 'TemplateItem',
render: (TemplateItem) =>
{TemplateItem.Name}
,
},
// {
// title: '设备位号',
// width: '16%',
// dataIndex: 'DeviceCode',
// },
{
title: '设定值范围',
render: (record) => (
onClickThreshold(record)}
/>
),
},
{
title: '状态',
dataIndex: 'Status',
width: '1.25rem',
render: (Status) => {
switch (Status) {
case -1:
case 0:
return (
正常
);
case 1:
return (
异常
);
case 2:
return (
警告
);
}
},
},
];
const handleClickItem = (data) => {
if (!isSensor) {
onClickItem(`DeviceTable-${data.Id}`, {
type: data.Status,
deviceCode: data.DeviceCode,
});
} else {
onClickItem(`DeviceTable-${data.Id}`, {
// type: data.Status,
deviceCode: data.DeviceCode,
value: Number(data.Value || 0),
threshold: data.JsonNumThreshold,
});
UnityAction.sendMsg('SinglePowerEnvironFromWeb', JSON.stringify(data));
}
};
// useEffect(() => {
// console.log('温控', items);
// if (isSensor)
// UnityAction.sendMsg('PowerEnvironsFromWeb', JSON.stringify(items));
// }, [items]);
// if (!isSensor) {
// columns.push({
// title: '操作',
// render: (record) =>
// record.Status == 1 && (
// onClickError(record)}>
// 异常处理
//
// ),
// });
// }
return (
,
}}
pagination={false}
/>
setVisible(false)}
/>
setErrVisible(false)}
onOk={handleError}
/>
);
}
function AalysisTable(props) {
const { onClickItem, data = {}, select } = props;
const { FaultAnalysis } = data;
const columns = [
{
title: '异常名称',
width: '18%',
dataIndex: 'device_name',
},
// {
// title: '位号',
// width: '15%',
// dataIndex: 'device_code',
// },
{
title: '可能原因',
width: '30%',
render: (record) => record.reason,
},
{
title: '解决方案',
width: '52%',
render: (record) => {
if (record.fix_plan instanceof Array) {
return (
{record.fix_plan.map((item) => (
{item.content}
))}
);
} else {
return record.fix_plan;
}
},
},
];
return (
,
}}
pagination={false}
/>
);
}
function ErrorHandleModal(props) {
const { visible, onCancel, onOk, userList } = props;
const [form] = Form.useForm();
const status = form.getFieldValue('Status');
const handleOk = () => {
form.validateFields((error, values) => {
if (error) return;
onOk({
...values,
PlanTime: values?.PlanTime?.format('YYYY-MM-DD HH:mm:ss'),
});
});
};
return (
{status == 1 && (
<>
>
)}
);
}
export function WarningTable(props) {
const {
onClickItem,
data = {},
onErrorHandle,
select,
userList,
type,
items,
} = props;
const { ProjectId, Id } = data;
const [loading, setLoading] = useState(false);
const [visible, setVisible] = useState(false);
const [errVisible, setErrVisible] = useState(false);
const [currentItem, setCurrentItem] = useState({});
const isSensor = type == 'sensor';
const onClickThreshold = (record) => {
setCurrentItem(record);
setVisible(true);
};
const onClickError = (record) => {
setCurrentItem(record);
setErrVisible(true);
};
const handleError = async (values) => {
setLoading(true);
var res = await changeRecordStatus({
...values,
Id: currentItem.Id,
DeviceCode: currentItem.DeviceCode,
DeviceName: currentItem.DeviceName,
RecordId: data.Id,
RepairMan: values.RepairMan * 1,
});
setLoading(false);
if (res) {
message.success('操作成功');
setErrVisible(false);
}
};
const columns = [
{
title: '设备名称',
width: '20%',
dataIndex: 'DeviceName',
},
{
title: '巡检项',
dataIndex: 'TemplateItem.Name',
},
// {
// title: '设备位号',
// width: '16%',
// dataIndex: 'DeviceCode',
// },
{
title: '设定值范围',
width: '30%',
render: (record) => (
onClickThreshold(record)}
/>
),
},
{
title: '状态',
dataIndex: 'Status',
width: '1.25rem',
render: (Status) => {
switch (Status) {
case -1:
case 0:
return (
正常
);
case 1:
return (
异常
);
case 2:
return (
警告
);
}
},
},
];
const handleClickItem = (data) => {
if (!isSensor) {
onClickItem(`DeviceTable-${data.Id}`, {
type: data.Status,
deviceCode: data.DeviceCode,
});
} else {
onClickItem(`DeviceTable-${data.Id}`, {
// type: data.Status,
deviceCode: data.DeviceCode,
value: Number(data.Value || 0),
threshold: data.JsonNumThreshold,
});
UnityAction.sendMsg('SinglePowerEnvironFromWeb', JSON.stringify(data));
}
};
// if (!isSensor) {
// columns.push({
// title: '操作',
// render: (record) =>
// record.Status == 1 && (
// onClickError(record)}>
// 异常处理
//
// ),
// });
// }
// useEffect(() => {
// if (isSensor)
// UnityAction.sendMsg('PowerEnvironsFromWeb', JSON.stringify(items));
// }, [items]);
return (
,
}}
pagination={false}
/>
setVisible(false)}
/>
setErrVisible(false)}
onOk={handleError}
/>
);
}
function ReportCom(props) {
const {
sendMessageToUnity,
select,
waringData = [],
allData = [],
userList,
type,
title,
data,
} = props;
const [activeKey, setActiveKey] = useState('1');
const handleTabsChange = (activeKey) => {
setActiveKey(activeKey);
};
return (
{title}
,
},
{
key: '2',
label: `全部(${allData.length || 0})`,
children:
,
},
]}
>
{activeKey == '1' && (
)}
{activeKey == '2' && (
)}
);
}
export function LiquidTable(props) {
const { onClickItem, data = {}, items, select, type } = props;
const { ProjectId, Id } = data;
const [loading, setLoading] = useState(false);
const [currentItem, setCurrentItem] = useState({});
const columns = [
{
title: '设备名称',
width: '20%',
dataIndex: 'device_name',
},
{
title: '类型',
key: 'template_item_name',
dataIndex: 'template_item_name',
},
{
title: '液位数',
dataIndex: 'origin_value',
},
{
title: '差值',
dataIndex: 'value',
},
{
title: '设定值范围',
width: '25%',
render: (record) => (
),
},
{
title: '状态',
dataIndex: 'status',
width: '1.25rem',
render: (status) => {
switch (status) {
case -1:
case 0:
return (
正常
);
case 1:
return (
异常
);
case 2:
return (
警告
);
}
},
},
];
const handleClickItem = (data) => {
onClickItem(`DeviceTable-${data.device_code}`, {
type: data.status,
deviceCode: data.device_code,
});
};
return (
,
}}
pagination={false}
/>
);
}
function LiquidLevelCom(props) {
const { sendMessageToUnity, select, allData = [], type, title } = props;
const [activeKey, setActiveKey] = useState('1');
const errorData = useMemo(() => {
const errorData = allData?.filter((item) => item.status);
return errorData;
}, [allData]);
const handleTabsChange = (activeKey) => {
setActiveKey(activeKey);
};
return (
{title}
,
},
{
key: '2',
label: `全部(${allData?.length || 0})`,
children:
,
},
]}
>
{activeKey == '1' && (
)}
{activeKey == '2' && (
)}
);
}
function DosingFlowTable(props) {
const { onClickItem, data = {}, items } = props;
const columns = [
{
title: '设备名称',
width: '20%',
dataIndex: 'device_name',
},
{
title: '类型',
width: '1rem',
key: 'template_item_name',
dataIndex: 'template_item_name',
},
{
title: '实际流量',
dataIndex: 'origin_value',
},
{
title: '计量流量',
dataIndex: 'value',
},
{
title: '差值/比值',
dataIndex: 'value',
},
{
title: '设定值范围',
width: '20%',
render: (record) => (
),
},
{
title: '状态',
dataIndex: 'status',
width: '1.25rem',
render: (status) => {
switch (status) {
case -1:
case 0:
return (
正常
);
case 1:
return (
异常
);
case 2:
return (
警告
);
default:
return null;
}
},
},
];
const handleClickItem = (data) => {
onClickItem(`DeviceTable-${data.device_code}`, {
type: data.status,
deviceCode: data.device_code,
});
};
return (
,
}}
pagination={false}
/>
);
}
function DosingFlowCom(props) {
const { sendMessageToUnity, select, allData = [], type, title } = props;
const [activeKey, setActiveKey] = useState('1');
const errorData = useMemo(() => {
const errorData = allData?.filter((item) => item.status);
return errorData;
}, [allData]);
const handleTabsChange = (key) => {
setActiveKey(key);
};
return (
{title}
,
},
{
key: '2',
label: `全部(${allData?.length || 0})`,
children:
,
},
]}
>
{activeKey === '1' && (
)}
{activeKey === '2' && (
)}
);
}
function WaterInTable(props) {
const { onClickItem, data = {}, items } = props;
const columns = [
{
title: '设备名称',
width: '20%',
dataIndex: 'item_alias',
},
{
title: '差值',
// width: '15%',
dataIndex: 'current_val',
},
{
title: '时间',
// width: '15%',
dataIndex: 'create_time',
render: (text) => {
if (text) {
return dayjs(text).format('HH:mm:ss');
}
return '-';
},
},
{
title: '设定值范围',
width: '30%',
render: (record) => (
),
},
{
title: '状态',
dataIndex: 'status',
width: '1.25rem',
render: (status) => {
switch (status) {
case -1:
case 0:
return (
正常
);
case 1:
return (
异常
);
case 2:
return (
警告
);
default:
return (
异常
);
}
},
},
];
const handleClickItem = (params) => {
onClickItem(`DeviceTable-${params.device_code}`, {
type: params.status,
deviceCode: params.device_code,
});
};
return (
,
}}
pagination={false}
/>
);
}
function WaterInCom(props) {
const { sendMessageToUnity, select, allData = [], title } = props;
const [activeKey, setActiveKey] = useState('1');
const errorData = useMemo(() => {
const tempData = allData?.filter((item) => item.status);
return tempData;
}, [allData]);
const handleTabsChange = (key) => {
setActiveKey(key);
};
return (
{title}
,
},
{
key: '2',
label: `全部(${allData?.length || 0})`,
children:
,
},
]}
>
{activeKey === '1' && (
)}
{activeKey === '2' && (
)}
);
}
function PressureGaugeTable(props) {
const { onClickItem, data = {}, items } = props;
const columns = [
{
title: '设备名称',
width: '20%',
dataIndex: 'item_alias',
},
{
title: '时间范围',
key: 'dataRange',
width: '1.5rem',
render: (record) => {
if (record.query_start && record.query_end) {
return (
<>
{dayjs(record.query_start).format('HH:mm:ss')}
{dayjs(record.query_end).format('HH:mm:ss')}
>
);
}
return '-';
},
},
{
title: (
<>
仪表
最小数
>
),
width: '1.25rem',
dataIndex: 'data_min',
},
{
title: (
<>
仪表
最大数
>
),
width: '1.25rem',
dataIndex: 'data_max',
},
{
title: '可能原因',
dataIndex: 'content',
},
{
title: '状态',
dataIndex: 'status',
width: '1.25rem',
render: (status) => {
switch (status) {
case -1:
case 0:
return (
正常
);
case 1:
return (
异常
);
case 2:
return (
警告
);
default:
return (
异常
);
}
},
},
];
const handleClickItem = (params) => {
onClickItem(`DeviceTable-${params.device_code}`, {
type: params.status,
deviceCode: params.device_code,
});
};
return (
,
}}
pagination={false}
/>
);
}
function PressureGaugeCom(props) {
const { sendMessageToUnity, select, allData = [], title } = props;
const [activeKey, setActiveKey] = useState('2');
const errorData = useMemo(() => {
const tempData = allData?.filter((item) => item.status);
return tempData;
}, [allData]);
const handleTabsChange = (key) => {
setActiveKey(key);
};
return (
{activeKey === '2' && (
)}
);
}
function WaterQualityTable(props) {
const { onClickItem, data = {}, items } = props;
const columns = [
{
title: '设备名称',
width: '20%',
dataIndex: 'item_alias',
},
{
title: '时间范围',
key: 'dataRange',
width: '1.5rem',
render: (record) => {
if (record.query_start && record.query_end) {
return (
<>
{dayjs(record.query_start).format('HH:mm:ss')}
{dayjs(record.query_end).format('HH:mm:ss')}
>
);
}
return '-';
},
},
{
title: (
<>
仪表
最小数
>
),
width: '1.25rem',
dataIndex: 'data_min',
},
{
title: (
<>
仪表
最大数
>
),
width: '1.25rem',
dataIndex: 'data_max',
},
{
title: '可能原因',
dataIndex: 'content',
},
{
title: '状态',
dataIndex: 'status',
width: '1.25rem',
render: (status) => {
switch (status) {
case -1:
case 0:
return (
正常
);
case 1:
return (
异常
);
case 2:
return (
警告
);
default:
return (
异常
);
}
},
},
];
const handleClickItem = (params) => {
onClickItem(`DeviceTable-${params.device_code}`, {
type: params.status,
deviceCode: params.device_code,
});
};
return (
,
}}
pagination={false}
/>
);
}
function WaterQualityCom(props) {
const { sendMessageToUnity, select, allData = [], title } = props;
const [activeKey, setActiveKey] = useState('2');
const errorData = useMemo(() => {
const tempData = allData?.filter((item) => item.status);
return tempData;
}, [allData]);
const handleTabsChange = (key) => {
setActiveKey(key);
};
return (
{activeKey === '2' && (
)}
);
}
function ReportDumCom(props) {
const { data = [], title } = props;
const columns = [
{
title: '报警时间',
dataIndex: 'event_time',
render: (time) => dayjs(time).format('YYYY-MM-DD HH:mm:ss'),
},
{
title: '设备名称',
dataIndex: 'device_name',
},
{
title: '报警类型',
dataIndex: 'event_type',
// render: type => alarmType[type],
},
{
title: '报警图片',
render: (item) => (
),
},
];
return (
,
}}
pagination={false}
/>
);
}
function base64ToImageUrl(base64String) {
const byteCharacters = atob(base64String);
const byteArrays = [];
for (let i = 0; i < byteCharacters.length; i++) {
byteArrays.push(byteCharacters.charCodeAt(i));
}
const byteArray = new Uint8Array(byteArrays);
const blob = new Blob([byteArray], { type: 'image/png' });
const imageUrl = URL.createObjectURL(blob);
return imageUrl;
}
function Empty() {
return (
自检正常
);
}
export default connect(({ eqSelfInspection }) => ({
userList: eqSelfInspection.userList,
mandateInfo: eqSelfInspection.mandateInfo,
}))(Detail);