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.
122 lines
7.5 KiB
122 lines
7.5 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 } from "react/jsx-runtime"; |
|
import { PlusOutlined, PlusCircleOutlined } from '@ant-design/icons'; |
|
import { ModalForm, ProCard, ProFormSelect, ProFormList, ProFormItem, ProFormText, ProFormTextArea, } from '@ant-design/pro-components'; |
|
import { FormUpload } from '@component/ui'; |
|
import { Form, message, Divider } from 'antd'; |
|
import { useCallback } from 'react'; |
|
import { useRequest } from 'ahooks'; |
|
import { getDictValList } from 'actions/base.action'; |
|
import { map, pick } from 'lodash'; |
|
import { severityData, frequencyData, getGrade } from '../../CONST'; |
|
import { getToken, getUploadList, getUploadValueFromEvent, jsonString, themeMessage, } from '@component/utils'; |
|
import { useServiceContext } from '../../context'; |
|
export default ({ title, init, item, service, params, onCancel, serviceid, }) => { |
|
var _a, _b; |
|
const [form] = Form.useForm(); |
|
// 专家端使用serviceId 使用props中的 |
|
const serviceId = (_b = (_a = useServiceContext()) === null || _a === void 0 ? void 0 : _a.serviceId) !== null && _b !== void 0 ? _b : serviceid; |
|
const { runAsync, loading } = useRequest(service, { |
|
manual: true, |
|
onSuccess(result) { |
|
themeMessage(result); |
|
if (result.type === 'success') { |
|
init && init(); |
|
onCancel(); |
|
} |
|
}, |
|
onError(result) { |
|
message.error(result.message); |
|
}, |
|
}); |
|
function onFinish(values) { |
|
return __awaiter(this, void 0, void 0, function* () { |
|
return runAsync(Object.assign({}, params, Object.assign(Object.assign({}, values), { serviceId, attachmentIds: JSON.stringify(getUploadList(values.attachmentIds)), riskAccidents: JSON.stringify(map(values.riskAccidents, (item) => { |
|
return { |
|
accidentTypeId: item.accidentType.value, |
|
accidentTypeName: item.accidentType.label, |
|
severity: item.severity, |
|
frequency: item.frequency, |
|
riskAccidentRelationId: item.riskAccidentRelationId, |
|
conventionMeasures: item.conventionMeasures, |
|
emergencyMeasures: item.emergencyMeasures, |
|
riskGrade: getGrade(item.severity, item.frequency), |
|
}; |
|
})) }))); |
|
}); |
|
} |
|
const request = useCallback(() => __awaiter(void 0, void 0, void 0, function* () { |
|
var _c; |
|
if (item) { |
|
return Object.assign(Object.assign({}, pick(item, [ |
|
'riskId', |
|
'riskName', |
|
'riskContent', |
|
'discoveredAddress', |
|
])), { attachmentIds: yield jsonString(item.attachmentIds), riskAccidents: (_c = item.list) === null || _c === void 0 ? void 0 : _c.map((sub) => ({ |
|
accidentType: { |
|
value: sub.accidentTypeId, |
|
label: sub.accidentTypeName, |
|
}, |
|
severity: sub.severity, |
|
frequency: sub.frequency, |
|
conventionMeasures: sub.conventionMeasures, |
|
emergencyMeasures: sub.emergencyMeasures, |
|
riskAccidentRelationId: sub.riskAccidentRelationId, |
|
})) }); |
|
} |
|
return {}; |
|
}), [item]); |
|
return (_jsxs(ModalForm, Object.assign({ request: request, title: title, visible: true, form: form, autoFocusFirstInput: true, modalProps: { |
|
destroyOnClose: true, |
|
maskClosable: false, |
|
confirmLoading: loading, |
|
onCancel: onCancel, |
|
bodyStyle: { |
|
height: 600, |
|
overflow: 'auto', |
|
}, |
|
}, submitTimeout: 2000, onFinish: onFinish }, { children: [_jsx(ProFormItem, { name: "riskId", hidden: true }), _jsx(ProFormText, { rules: [{ required: true }], name: "riskName", label: "\u98CE\u9669\u540D\u79F0", fieldProps: { |
|
showCount: true, |
|
maxLength: 40, |
|
} }), _jsx(ProFormTextArea, { rules: [{ required: true }], label: "\u98CE\u9669\u63CF\u8FF0", name: "riskContent", fieldProps: { |
|
showCount: true, |
|
maxLength: 4000, |
|
} }), _jsx(ProFormText, { rules: [{ required: true }], name: "discoveredAddress", label: "\u98CE\u9669\u6240\u5728\u573A\u6240/\u90E8\u4F4D", fieldProps: { |
|
showCount: true, |
|
maxLength: 40, |
|
} }), _jsx(FormUpload, { name: "attachmentIds", label: "\u73B0\u573A\u7167\u7247", max: 20, params: { |
|
bizNo: (item === null || item === void 0 ? void 0 : item.riskId) || '', |
|
type: '10', |
|
}, fieldProps: { |
|
accept: 'image/*', |
|
} }), _jsxs(ProFormList, Object.assign({ name: "riskAccidents", rules: [ |
|
{ |
|
validator: (_, names) => __awaiter(void 0, void 0, void 0, function* () { |
|
if (!names || names.length < 1) { |
|
return Promise.reject(new Error('请添加风险评估及管控')); |
|
} |
|
}), |
|
}, |
|
], required: true, label: "\u98CE\u9669\u8BC4\u4F30\u53CA\u7BA1\u63A7", style: { marginBottom: 0 }, min: 1, copyIconProps: false, creatorButtonProps: { |
|
creatorButtonText: '添加风险评估及管控', |
|
}, itemRender: ({ listDom, action }, { index }) => (_jsxs(ProCard, Object.assign({ size: "small", style: { marginBottom: 8 }, title: `评估${index + 1}`, extra: action, bodyStyle: { paddingBottom: 0 } }, { children: [listDom, _jsx(Divider, { className: "self-pro-divider" })] }))) }, { children: [_jsx(ProFormItem, { name: "riskAccidentRelationId", hidden: true }), _jsx(ProFormSelect, { rules: [{ required: true }], label: "\u4E8B\u6545\u7C7B\u578B", name: "accidentType", request: getDictValList, params: { |
|
dictId: 19, |
|
}, options: severityData, fieldProps: { |
|
labelInValue: true, |
|
} }), _jsx(ProFormSelect, { rules: [{ required: true }], label: "\u540E\u679C\u4E25\u91CD\u6027", name: "severity", options: severityData }), _jsx(ProFormSelect, { rules: [{ required: true }], label: "\u4E8B\u6545\u53D1\u751F\u9891\u7387", options: frequencyData, name: "frequency" }), _jsx(ProFormTextArea, { label: "\u65E5\u5E38\u9632\u8303\u63AA\u65BD", name: "conventionMeasures", fieldProps: { |
|
showCount: true, |
|
maxLength: 2000, |
|
} }), _jsx(ProFormTextArea, { label: "\u5E94\u6025\u63AA\u65BD", name: "emergencyMeasures", fieldProps: { |
|
showCount: true, |
|
maxLength: 2000, |
|
} })] }))] }))); |
|
};
|
|
|