zcloud-gbs-accident-react/src/pages/Container/SuperviseAccident/List/index.js

87 lines
2.5 KiB
JavaScript

import { Connect } from "@cqsjjb/jjb-dva-runtime";
import { Button, Form } from "antd";
import { useState } from "react";
import Page from "zy-react-library/components/Page";
import Search from "zy-react-library/components/Search";
import Table from "zy-react-library/components/Table";
import useTable from "zy-react-library/hooks/useTable";
import { NS_ACCIDENT } from "~/enumerate/namespace";
function SuperviseAccident(props) {
const [form] = Form.useForm();
const [accidentCountByCorpinfoAndType, setAccidentCountByCorpinfoAndType] = useState([]);
const getAccidentCountByCorpinfoAndType = async (corpinfoIds, type) => {
const { data } = await props["accidentCountByCorpinfoAndType"]({ corpinfoIds, eqAccidentType: type });
setAccidentCountByCorpinfoAndType(data);
};
const { tableProps, getData } = useTable(props["getCorpInfoList"], {
form,
params: {
inType: [0, 1, 6],
},
onSuccess: ({ data }) => {
getAccidentCountByCorpinfoAndType(data.map(item => item.id), form.getFieldValue("eqAccidentType"));
},
});
const getAccidentTotal = (id, key) => {
return accidentCountByCorpinfoAndType.find(item => item.corpinfoId === id)?.[key] || 0;
};
return (
<Page isShowAllAction={false}>
<Search
form={form}
onFinish={getData}
options={[
{ name: "likecorpName", label: `公司名称` },
]}
/>
<Table
columns={[
{ dataIndex: "corpName", title: `公司名称` },
{
dataIndex: "eventCount",
title: "事件总数",
width: 180,
render: (_, record) => (
<Button
type="link"
onClick={() => {
props.history.push(`./info?corpinfoId=${record.id}&eqAccidentType=1`);
}}
>
{getAccidentTotal(record.id, "eventCount")}
</Button>
),
},
{
dataIndex: "accidentCount",
title: "事故总数",
width: 180,
render: (_, record) => (
<Button
type="link"
onClick={() => {
props.history.push(`./info?corpinfoId=${record.id}&eqAccidentType=2`);
}}
>
{ getAccidentTotal(record.id, "accidentCount")}
</Button>
),
},
]}
{...tableProps}
/>
</Page>
);
}
export default Connect([NS_ACCIDENT], true)(SuperviseAccident);