import PageContent from '@/components/PageContent';
import PageTitle from '@/components/PageTitle';
import { getMandateIDs } from '@/services/eqSelfInspection';
import { GetTokenFromUrl, UnityAction } from '@/utils/utils';
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();
};
const openTaskModal = async () => {
if (!autoReport.Id) {
return;
}
let mandateIDs = await getMandateIDs({
project_id: projectId,
id: autoReport.Id,
}).catch((err) => {
console.log(err);
});
if (mandateIDs?.length) {
mandateIDs = [...new Set(mandateIDs)];
UnityAction.sendMsg('OpenTaskModal', `mandate_id=${mandateIDs.join()}`);
} else {
message.info('未查询到相关任务');
}
};
//消息跳转过来近具体自检报告详情页面
const handleJumpDetail = (id) => {
history.push(
`/self-inspection/detail/${projectId}/${id}?JWT-TOKEN=${GetTokenFromUrl()}`,
);
};
useEffect(() => {
if (routeId) {
dispatch({
type: 'eqSelfInspection/getPatrolDataById',
payload: {
routeId: routeId,
},
});
} else {
getDate();
}
dispatch({
type: 'eqSelfInspection/getList',
payload: {
ProjectId: projectId * 1,
},
});
//自检页面加载完毕
UnityAction.sendMsg('pageInited');
UnityAction.on('notiZiJian', (id) => {
alert('0-00000' + id);
handleJumpDetail(id);
});
return UnityAction.off('notiZiJian');
}, []);
useEffect(() => {
setPatrolStatus(autoReport?.patrolStatus);
setFaultAnalysisStatus(autoReport?.faultAnalysisStatus);
setSecureStatus(autoReport?.secureStatus);
setSecureChildren(autoReport?.secureChild);
}, [autoReport]);
return (