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.
160 lines
7.4 KiB
160 lines
7.4 KiB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { |
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } |
|
return new (P || (P = Promise))(function (resolve, reject) { |
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } |
|
step((generator = generator.apply(thisArg, _arguments || [])).next()); |
|
}); |
|
}; |
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; |
|
import { ProCard, ProTable } from '@ant-design/pro-components'; |
|
import { Link } from 'react-router-dom'; |
|
import { Space, Button, message, Popconfirm } from 'antd'; |
|
import { useRef } from 'react'; |
|
import { getList, onAdd, onEdit, onDelete } from './action'; |
|
import Form from './form'; |
|
import { PlusCircleOutlined } from '@ant-design/icons'; |
|
import { useServiceContext } from '../../context'; |
|
import { useRequest, useToggle } from 'ahooks'; |
|
import { riskGrade, riskStatus } from '../../CONST'; |
|
import { dateFormatter, urlEncodeParams, themeMessage } from '@component/utils'; |
|
import { CardForm, CardDetail } from '@component/ui'; |
|
export default ({ readonly, required, title, serviceid, riskurl, setRiskIds, }) => { |
|
var _a, _b, _c, _d; |
|
const actionRef = useRef(); |
|
/** |
|
* @auth: fengkai |
|
* @description: 专家端使用当前组件serviceId使用props中的 |
|
* @date: 2023/04/14 11:13 |
|
*/ |
|
// const { serviceId, riskUrl } = useServiceContext(); |
|
const serviceId = (_b = (_a = useServiceContext()) === null || _a === void 0 ? void 0 : _a.serviceId) !== null && _b !== void 0 ? _b : serviceid; |
|
const riskUrl = (_d = (_c = useServiceContext()) === null || _c === void 0 ? void 0 : _c.riskUrl) !== null && _d !== void 0 ? _d : riskurl; |
|
const [value, { set }] = useToggle({ |
|
visible: false, |
|
}); |
|
const { runAsync, confirmLoading } = useRequest(onDelete, { |
|
manual: true, |
|
onSuccess(result) { |
|
themeMessage(result); |
|
if (result.type === 'success') { |
|
init && init(); |
|
} |
|
}, |
|
onError(result) { |
|
message.error(result.message); |
|
}, |
|
}); |
|
const columns = [ |
|
{ |
|
title: '风险编号', |
|
dataIndex: 'riskNumber', |
|
ellipsis: true, |
|
}, |
|
{ |
|
title: '风险名称', |
|
dataIndex: 'riskName', |
|
ellipsis: true, |
|
search: false, |
|
}, |
|
{ |
|
title: '风险描述', |
|
dataIndex: 'riskContent', |
|
ellipsis: true, |
|
search: false, |
|
}, |
|
{ |
|
title: '场所/部位', |
|
dataIndex: 'discoveredAddress', |
|
ellipsis: true, |
|
search: false, |
|
}, |
|
{ |
|
title: '风险等级', |
|
dataIndex: 'riskGrade', |
|
ellipsis: true, |
|
search: false, |
|
render(_, item) { |
|
return riskGrade[item.riskGrade]; |
|
}, |
|
}, |
|
{ |
|
title: '风险状态', |
|
dataIndex: 'status', |
|
ellipsis: true, |
|
search: false, |
|
render(_, item) { |
|
return riskStatus[item.status]; |
|
}, |
|
}, |
|
{ |
|
title: '发现时间', |
|
dataIndex: 'discoveredAt', |
|
ellipsis: true, |
|
search: false, |
|
renderText: dateFormatter, |
|
}, |
|
{ |
|
title: '操作', |
|
dataIndex: 'option', |
|
search: false, |
|
render(_, item) { |
|
if (readonly) { |
|
return (_jsx(Button, Object.assign({ type: "link", size: "small" }, { children: _jsx(Link, Object.assign({ to: `${riskUrl}${urlEncodeParams({ riskId: item.riskId })}` }, { children: "\u8BE6\u60C5" })) }))); |
|
} |
|
return (_jsxs(Space, { children: [_jsx(Button, Object.assign({ type: "link", size: "small", onClick: () => set({ |
|
visible: true, |
|
item: item, |
|
title: '风险评估及管控编辑', |
|
service: onEdit, |
|
}) }, { children: "\u7F16\u8F91" })), _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() { |
|
var _a; |
|
(_a = actionRef.current) === null || _a === void 0 ? void 0 : _a.reload(); |
|
} |
|
function handleDelete(item) { |
|
return runAsync({ |
|
riskId: item.riskId, |
|
}); |
|
} |
|
function onCancel() { |
|
set({ |
|
visible: false, |
|
}); |
|
} |
|
if (readonly) { |
|
return (_jsx(CardDetail, Object.assign({ title: title }, { children: _jsx(ProTable, { cardProps: { |
|
bodyStyle: { |
|
padding: 0, |
|
}, |
|
}, rowKey: "riskId", actionRef: actionRef, params: { serviceId }, columns: columns, request: (params) => __awaiter(void 0, void 0, void 0, function* () { |
|
var _e; |
|
const res = yield getList(params); |
|
// 外部使用当前组件,把风险列表传递出去 |
|
setRiskIds && setRiskIds((_e = res === null || res === void 0 ? void 0 : res.data) !== null && _e !== void 0 ? _e : []); |
|
return res; |
|
}), options: false, search: false, pagination: false }) }))); |
|
} |
|
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: "riskId", actionRef: actionRef, params: { serviceId }, columns: columns, request: (params) => __awaiter(void 0, void 0, void 0, function* () { |
|
var _f; |
|
const res = yield getList(params); |
|
// 外部使用当前组件,把风险列表传递出去 |
|
setRiskIds && setRiskIds((_f = res === null || res === void 0 ? void 0 : res.data) !== null && _f !== void 0 ? _f : []); |
|
return res; |
|
}), options: false, search: false, pagination: false })] }))); |
|
};
|
|
|