import React, { useCallback, useEffect, useState } from 'react';
import './ShYj.less';
import appconsts from '../../../../models/appconsts';
import { useDispatch } from 'react-redux';
import apiurl from '../../../../models/apiurl';
import { httpget } from '../../../../utils/request';
import config from '../../../../config';
import DpAlert from '../../../../layouts/mui/DpAlert';
import { DcpjPromise } from '../../../../models/_/dcpj';
function Item({ data, viewInfo }) {
return (
viewInfo(data)}>{data.adnm || '--'}
{appconsts.warnStatus_TYPE[data.warnstatusid]}
{data.warndesc}
);
}
function ShYj({ data }) {
const [hisdata, sethisdata] = useState();
useEffect(() => {
if (!data) {
return;
}
if (data.length === 0) {
httpget(apiurl.shyj.find, { adcd: config.SHYJ_ADCD, page: 1, size: 10, warnstatusid: 30 })
.then(({ data }) => sethisdata(data.list || []))
}
}, [data?.length]);
const dispatch = useDispatch();
const viewInfo = useCallback((record, type) => {
if (type === 'danad') {
const adcd = record?.adcd?.replace(/([0]{3})*$/, '');
if (adcd) {
Promise.all([
DcpjPromise.danad.get(),
DcpjPromise.transfer.get(),
DcpjPromise.placement.get(),
]).then(([danads, transfers, placements]) => {
const highlights = [
...((danads || []).filter(o => o?.ADCD?.startsWith(adcd)).map(o => ({ ...o, type: 'danad' }))),
...((transfers || []).filter(o => o?.ADCD?.startsWith(adcd)).map(o => ({ ...o, type: 'transfer' }))),
...((placements || []).filter(o => o?.ADCD?.startsWith(adcd)).map(o => ({ ...o, type: 'placement' })))
];
if (highlights.length > 0) {
dispatch.map.openHighlights({
title: `${record.adnm}危险区/转移路线/安置点`,
records: highlights.map(o => ({
id: o.PID,
adcd: o.ADCD,
lgtd: o.lgtd,
lttd: o.lttd,
name: o.NAME,
type: o.type,
}))
})
}
dispatch.map.highlightFeatures(highlights.map(o => ({
type: o.type,
props: o,
fill: 'rgb(239, 164, 114)',
stroke: o.type === 'danad' ? 'rgb(239, 164, 114)' : '#f6f082'
})));
});
}
} else {
dispatch.runtime.setInfoDlg({ layerId: 'ShWarn', properties: record })
}
}, [dispatch]);
const showdata = hisdata?.length > 0 ? hisdata : (data || []);
return (
{
hisdata?.length > 0 && 当前无预警,显示最新10条已关闭预警
}
{
showdata.map(o => (
))
}
)
}
export default React.memo(ShYj);