You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
164 lines
6.2 KiB
164 lines
6.2 KiB
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; |
|
import { ProTable } from '@ant-design/pro-components'; |
|
import { useEffect, useRef, useState } from 'react'; |
|
import { Space, Button, Popconfirm, message } from 'antd'; |
|
import { getHiddenList, getHiddenDetailList, onAdd, onDelete } from './action'; |
|
import Form from './form'; |
|
import { PlusCircleOutlined } from '@ant-design/icons'; |
|
import { hiddenDangerStatus, getHiddenTroubleGrade } from '../CONST'; |
|
import { useRequest, useToggle } from 'ahooks'; |
|
import { dateFormatter, themeMessage } from '@component/utils'; |
|
import { CardForm } from '@component/ui'; |
|
import { isEmpty, map } from 'lodash'; |
|
export default ({ title, required, serviceId, setHiddenIds, readonly, type, }) => { |
|
const actionRef = useRef(); |
|
const [value, { set }] = useToggle({ |
|
visible: false, |
|
}); |
|
const [dataSource, setDataSource] = useState([]); |
|
const [hiddenIds, set_hiddenIds] = useState([]); |
|
const isMount = useRef(!serviceId ? true : false); |
|
const [loading, setLoading] = useState(false); |
|
const { runAsync, confirmLoading } = useRequest(onDelete, { |
|
manual: true, |
|
onSuccess(result, params) { |
|
themeMessage(result); |
|
if (result.type === 'success') { |
|
// 刷新列表 |
|
set_hiddenIds(hiddenIds.filter((i) => i != params[0].hiddenDangerId)); |
|
} |
|
}, |
|
onError(result) { |
|
message.error(result.message); |
|
}, |
|
}); |
|
const { run: get_list } = useRequest(getHiddenList, { |
|
manual: true, |
|
defaultParams: { |
|
serviceId, |
|
}, |
|
onSuccess(result) { |
|
setLoading(false); |
|
setDataSource(result === null || result === void 0 ? void 0 : result.data); |
|
setHiddenIds(result === null || result === void 0 ? void 0 : result.data); |
|
}, |
|
onError(result) { |
|
setLoading(false); |
|
message.error(result.message); |
|
}, |
|
}); |
|
const { runAsync: get_Detail_list } = useRequest(getHiddenDetailList, { |
|
manual: true, |
|
}); |
|
const columns = [ |
|
{ |
|
title: '隐患编号', |
|
dataIndex: 'hiddenNumber', |
|
ellipsis: true, |
|
}, |
|
{ |
|
title: '隐患描述', |
|
dataIndex: 'description', |
|
ellipsis: true, |
|
search: false, |
|
}, |
|
{ |
|
title: '隐患类型', |
|
dataIndex: 'classifyName', |
|
ellipsis: true, |
|
search: false, |
|
}, |
|
{ |
|
title: '隐患分类', |
|
dataIndex: 'dangerTypeName', |
|
ellipsis: true, |
|
search: false, |
|
}, |
|
{ |
|
title: '隐患等级', |
|
dataIndex: 'hiddenTroubleGrade', |
|
ellipsis: true, |
|
search: false, |
|
render: (_, item) => { |
|
return getHiddenTroubleGrade(item.hiddenTroubleGrade); |
|
}, |
|
}, |
|
{ |
|
title: '隐患所在场所/部位', |
|
dataIndex: 'discoveredAddress', |
|
ellipsis: true, |
|
search: false, |
|
}, |
|
{ |
|
title: '整改状态', |
|
dataIndex: 'hiddenDangerStatus', |
|
ellipsis: true, |
|
search: false, |
|
render: (_, item) => { |
|
return hiddenDangerStatus[item.hiddenDangerStatus]; |
|
}, |
|
}, |
|
{ |
|
title: '更新时间', |
|
dataIndex: 'changedAt', |
|
ellipsis: true, |
|
search: false, |
|
renderText: dateFormatter, |
|
}, |
|
{ |
|
title: '操作', |
|
dataIndex: 'policyNumber', |
|
hideInTable: readonly, |
|
ellipsis: true, |
|
search: false, |
|
fixed: 'right', |
|
render(_, item) { |
|
return (_jsx(Space, { children: _jsx(Popconfirm, Object.assign({ placement: "top", title: "\u786E\u8BA4\u5220\u9664\u5417\uFF1F", onConfirm: () => handleDelete(item), okText: "\u786E\u8BA4", cancelText: "\u53D6\u6D88", getPopupContainer: (node) => { |
|
return document.body; |
|
}, okButtonProps: { loading: confirmLoading } }, { children: _jsx(Button, Object.assign({ type: "link", danger: true, size: "small" }, { children: "\u5220\u9664" })) })) })); |
|
}, |
|
}, |
|
]; |
|
function init(ids) { |
|
set_hiddenIds([...hiddenIds, ids]); |
|
} |
|
function handleDelete(item) { |
|
return runAsync({ |
|
hiddenDangerId: item.hiddenDangerId, |
|
}); |
|
} |
|
function onCancel() { |
|
set({ |
|
visible: false, |
|
}); |
|
} |
|
useEffect(() => { |
|
if (!isMount.current && type != 'add') { |
|
get_Detail_list({ serviceId }).then((res) => { |
|
const ids = map(res === null || res === void 0 ? void 0 : res.data, (item) => item.hiddenDangerId); |
|
if (!isEmpty(ids)) { |
|
setLoading(true); |
|
set_hiddenIds(ids); |
|
} |
|
}); |
|
} |
|
}, []); |
|
useEffect(() => { |
|
if (!isMount.current) { |
|
get_list({ ids: hiddenIds.join(',') }); |
|
} |
|
if (isMount.current) { |
|
isMount.current = false; |
|
} |
|
}, [JSON.stringify(hiddenIds)]); |
|
return (_jsxs(CardForm, Object.assign({ gutter: [10, 10], title: _jsxs(_Fragment, { children: [required && _jsx("i", Object.assign({ style: { color: 'red' } }, { children: "*" })), title] }), extra: !readonly && (_jsx(Button, Object.assign({ type: "link", size: "small", icon: _jsx(PlusCircleOutlined, {}), onClick: () => set({ |
|
item: null, |
|
title: '企业现场隐患添加', |
|
service: onAdd, |
|
visible: true, |
|
}) }, { children: "\u6DFB\u52A0" }))) }, { children: [value.visible && (_jsx(Form, { item: value.item, title: value.title, service: value.service, init: init, onCancel: onCancel, serviceid: serviceId })), _jsx(ProTable, { cardProps: { |
|
bodyStyle: { |
|
padding: 0, |
|
}, |
|
}, rowKey: "hiddenDangerId", actionRef: actionRef, options: false, search: false, pagination: { pageSize: 10 }, columns: columns, dataSource: dataSource, loading: loading })] }))); |
|
};
|
|
|