import PageContent from '@/components/PageContent';
import PageTitle from '@/components/PageTitle';
import { GetTokenFromUrl, UnityAction } from '@/utils/utils';
import { DiffFilled, FundFilled } from '@ant-design/icons';
import { connect, history, useLocation, useParams } from '@umijs/max';
import { Button, Form, Modal, Select, Spin, message } from 'antd';
import dayjs from 'dayjs';
import { useEffect, useState } from 'react';
import styles from './index.less';
const EqSelfInspection = (props) => {
const { dispatch, autoReport, patrolList, loading } = props;
const { projectId } = useParams();
const { routeId } = useLocation();
const [form] = Form.useForm();
const [visible, setVisible] = useState(false);
// 0 正常 1 异常 2 loading
const [patrolStatus, setPatrolStatus] = useState(0);
const [faultAnalysisStatus, setFaultAnalysisStatus] = useState(0);
const [secureStatus, setSecureStatus] = useState(0);
const [secureChildren, setSecureChildren] = useState([]);
const getDate = () => {
dispatch({
type: 'eqSelfInspection/getAutoPatrol',
payload: {
projectId,
},
});
};
const HandleInspection = () => {
if (patrolList?.length === 0) {
message.error('请配置巡检路线!');
} else {
UnityAction.sendMsg('StartInspection', '');
dispatch({
type: 'eqSelfInspection/getAutoPatrol',
payload: { projectId },
callback: (data) => {
setPatrolStatus(data?.patrolStatus);
setFaultAnalysisStatus(data?.faultAnalysisStatus);
setSecureStatus(data?.secureStatus);
setSecureChildren(data?.secureChild);
history.replace(`/self-inspection/${projectId}?routeId=${data.Id}`);
},
});
}
};
const handleOk = () => {
UnityAction.sendMsg('StartInspection', '');
form.validateFields((err, values) => {
if (err) return;
dispatch({
type: 'eqSelfInspection/inspectionRoute',
payload: { projectId, routeId: values.routeId },
callback: (data) => {
setPatrolStatus(data?.patrolStatus);
setFaultAnalysisStatus(data?.faultAnalysisStatus);
setSecureStatus(data?.secureStatus);
setSecureChildren(data?.secureChild);
history.replace(`/self-inspection/${projectId}?routeId=${data.Id}`);
},
});
});
handleCancel();
setPatrolStatus(2);
setSecureStatus(2);
setFaultAnalysisStatus(2);
};
const handleCancel = () => {
setVisible(false);
form.resetFields();
};
useEffect(() => {
if (routeId) {
dispatch({
type: 'eqSelfInspection/getPatrolDataById',
payload: {
routeId: routeId,
},
});
} else if (autoReport.Id) {
dispatch({
type: 'eqSelfInspection/getPatrolDataById',
payload: {
routeId: autoReport.Id,
},
});
} else {
getDate();
}
dispatch({
type: 'eqSelfInspection/getList',
payload: {
ProjectId: projectId * 1,
},
});
}, []);
useEffect(() => {
setPatrolStatus(autoReport?.patrolStatus);
setFaultAnalysisStatus(autoReport?.faultAnalysisStatus);
setSecureStatus(autoReport?.secureStatus);
setSecureChildren(autoReport?.secureChild);
}, [autoReport]);
return (