485 lines
17 KiB
JavaScript
485 lines
17 KiB
JavaScript
import React,{useEffect,useState,useMemo,useRef} from 'react';
|
||
import { Form, Button, Input, Row,Upload, Col, Table, DatePicker, InputNumber,message,Image,Modal,Typography ,Popconfirm } from 'antd';
|
||
import { DeleteOutlined,FileWordOutlined,FilePdfOutlined,FileZipOutlined,FileExcelOutlined } from '@ant-design/icons';
|
||
import { formItemLayout, btnItemLayout } from '../../../../components/crud/FormLayoutProps';
|
||
|
||
import apiurl from '../../../../service/apiurl';
|
||
|
||
import NormalSelect from '../../../../components/Form/NormalSelect';
|
||
|
||
import "./index.less"
|
||
import moment from 'moment';
|
||
const { RangePicker } = DatePicker
|
||
const { Dragger } = Upload;
|
||
const url = "http://223.75.53.141:9102/test.by-lyf.tmp"
|
||
|
||
|
||
const ModalForm = ({ mode, record, onEdit, onSave, onSimilarSave }) => {
|
||
const accidentOptions = [
|
||
{label:"一般事故",value:1},
|
||
{label:"较大事故",value:2},
|
||
{label:"重大事故",value:3},
|
||
{label:"特别重大事故",value:4},
|
||
]
|
||
const [form] = Form.useForm();
|
||
const [fileList, setFileList] = useState([]) //上传文件列表
|
||
const [fileIds, setFileIds] = useState([])
|
||
const [iframeSrc, setIframeSrc] = useState('')
|
||
const [pdfViewOPen, setPdfViewOPen] = useState(false)
|
||
|
||
const [loading, setLoading] = useState(false)
|
||
const [imgloading, setImgLoading] = useState(false)
|
||
const [imgfileList, setImgFileList] = useState([]) //上传文件列表
|
||
|
||
|
||
/**
|
||
* @description 文件下载
|
||
* @param {String} params 文件fileId
|
||
*/
|
||
const download = (params) => {
|
||
let downloadLink = document.createElement("a");
|
||
downloadLink.href = `http://local.gunshiiot.com:18083/gunshiApp/tsg/safety/accident/reg/file/download/${params.fileId}`;
|
||
downloadLink.download = `${params.fileName}`;
|
||
downloadLink.style.display = "none";
|
||
// 将链接添加到页面中
|
||
document.body.appendChild(downloadLink);
|
||
|
||
// 模拟点击事件,开始下载
|
||
downloadLink.click();
|
||
}
|
||
/**
|
||
* @description 上传图片
|
||
* @param {string} file 上传的文件
|
||
*/
|
||
const fileChange = (info) => {
|
||
if (info.file.status === "done") {
|
||
setLoading(false);
|
||
}
|
||
if (info.file.status === "uploading") {
|
||
setLoading(true);
|
||
}
|
||
if (info.file.status === "error") {
|
||
message.error("文件上传失败")
|
||
setLoading(false);
|
||
}
|
||
let fileIds = info.fileList.map(file => {
|
||
return file.response?.data?.fileId
|
||
})
|
||
setFileIds(fileIds)
|
||
setFileList(info.fileList)
|
||
}
|
||
/**
|
||
* @description pdf文件预览
|
||
* @param {String} params 文件预览url
|
||
*/
|
||
const viewPdf = (params) => {
|
||
setIframeSrc(params)
|
||
setPdfViewOPen(true)
|
||
}
|
||
|
||
|
||
const onfinish = (values) => {
|
||
values.accidentDate = values.accidentDate?moment(values.accidentDate).format("YYYY-MM-DD 00:00:00"):''
|
||
values.closeCaseDate = values.closeCaseDate?moment(values.closeCaseDate).format("YYYY-MM-DD 00:00:00"):''
|
||
let oldFiles = fileList.map(item => ({fileId:item.response?.data?.fileId}) )
|
||
let oldFiles1 = imgfileList.map(item => ({fileId:item.response?.data?.fileId}) )
|
||
if (mode === 'edit') {
|
||
values.accidentHandle = oldFiles;
|
||
values.accidentPic = oldFiles1;
|
||
values.id = record.id;
|
||
onEdit(apiurl.rcgl.aqgl.aqsgdj.edit,values)
|
||
}
|
||
if (mode === 'save') {
|
||
values.accidentHandle = oldFiles;
|
||
values.accidentPic = oldFiles1;
|
||
onSave(apiurl.rcgl.aqgl.aqsgdj.save,values)
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @description 删除上传的图片
|
||
* @param {string} id 删除的id
|
||
*/
|
||
const deleteFile = (fileId) => {
|
||
console.log(fileId);
|
||
let filterFile = fileList.filter(item => item.response?.data?.fileId !== fileId);
|
||
setFileList(filterFile)
|
||
}
|
||
|
||
const imgbeforeUpload = (file) => {
|
||
const isJpgOrPng =
|
||
file.type === 'image/jpeg' ||
|
||
file.type === 'image/jpg' ||
|
||
file.type === 'image/png';
|
||
|
||
if (!isJpgOrPng) {
|
||
message.error('请上传图片格式的文件!');
|
||
}
|
||
const isLt2M = file.size / 1024 / 1024 < 5;
|
||
if (!isLt2M) {
|
||
message.error('图片大小需小于5M!');
|
||
}
|
||
return isJpgOrPng && isLt2M ? true : Upload.LIST_IGNORE;
|
||
};
|
||
|
||
const imgdeleteFile = (fileId) => {
|
||
let filterFile = imgfileList.filter(item => item.response?.data?.fileId !== fileId);
|
||
setImgFileList(filterFile)
|
||
}
|
||
const imgfileChange = (info) => {
|
||
console.log("info",info);
|
||
if (info.file.status === "done") {
|
||
setImgLoading(false);
|
||
}
|
||
if (info.file.status === "uploading") {
|
||
setImgLoading(true);
|
||
}
|
||
if (info.file.status === "error") {
|
||
message.error("文件上传失败")
|
||
setImgLoading(false);
|
||
}
|
||
setImgFileList(info.fileList)
|
||
}
|
||
useEffect(() => {
|
||
if (mode != 'save') {
|
||
const imgFile = record?.accidentHandle?.map(o => ({
|
||
name: o.fileName,
|
||
response: {
|
||
data: {
|
||
filePath: o.filePath,
|
||
fileId:o.fileId
|
||
}
|
||
},
|
||
}))
|
||
const imgFile1 = record?.accidentPic?.map(o => ({
|
||
name: o.fileName,
|
||
response: {
|
||
data: {
|
||
filePath: o.filePath,
|
||
fileId:o.fileId
|
||
}
|
||
},
|
||
}))
|
||
setFileList(imgFile)
|
||
setImgFileList(imgFile1)
|
||
}
|
||
}, [record, mode])
|
||
|
||
|
||
|
||
return (
|
||
<div style={{maxHeight:"70vh",overflowY:"auto"}}>
|
||
<div style={{marginBottom:20,borderBottom:"1px solid #dfdfdf",width:"100%",paddingBottom:5}}><span style={{padding:"0px 3px",backgroundColor:"#0079fe",marginRight:20}}></span> 基本信息</div>
|
||
<Form
|
||
form={form}
|
||
{...formItemLayout}
|
||
onFinish={onfinish}
|
||
initialValues={record}
|
||
>
|
||
<Row>
|
||
<Col span={12}>
|
||
<Form.Item
|
||
label="事故名称"
|
||
name="name"
|
||
>
|
||
<Input disabled={mode==='view'} style={{width:'100%'}} allowClear />
|
||
</Form.Item>
|
||
</Col>
|
||
<Col span={12}>
|
||
<Form.Item
|
||
label="事故发生时间"
|
||
name="accidentDate"
|
||
getValueFromEvent={(e,dateString) => dateString}
|
||
getValueProps={(value) => ({ value: value ? moment(value) : undefined })}
|
||
rules={[
|
||
{
|
||
required: true,
|
||
},
|
||
]}
|
||
>
|
||
<DatePicker disabled={mode==='view'} format={'YYYY-MM-DD'} style={{width:'100%'}} allowClear />
|
||
</Form.Item>
|
||
</Col>
|
||
</Row>
|
||
|
||
<Row>
|
||
<Col span={12}>
|
||
<Form.Item
|
||
label="事故级别"
|
||
name="accidentLevel"
|
||
rules={[
|
||
{
|
||
required: true,
|
||
},
|
||
]}
|
||
>
|
||
<NormalSelect disabled={mode==='view'} style={{width:'100%'}} allowClear options={accidentOptions} />
|
||
</Form.Item>
|
||
</Col>
|
||
</Row>
|
||
|
||
<Row>
|
||
<Col span={24}>
|
||
<Form.Item
|
||
label="事故情况描述"
|
||
name="accidentDesc"
|
||
labelCol={{ span: 3 }}
|
||
wrapperCol={{ span: 19 }}
|
||
>
|
||
<Input.TextArea disabled={mode==='view'} style={{width:'100%',minHeight:'100px'}} allowClear />
|
||
</Form.Item>
|
||
</Col>
|
||
</Row>
|
||
<Row>
|
||
<Col span={12}>
|
||
<Form.Item
|
||
label="直接经济损失(万元)"
|
||
name="economicLosses"
|
||
labelCol={{style:{whiteSpace: "wrap",textAlign:"center", width: 120}}}
|
||
|
||
>
|
||
<Input disabled={mode==='view'} style={{width:'100%'}} allowClear />
|
||
</Form.Item>
|
||
</Col>
|
||
<Col span={12}>
|
||
<Form.Item
|
||
label="死亡人数"
|
||
name="deadNumber"
|
||
>
|
||
<Input disabled={mode==='view'} style={{width:'100%'}} allowClear />
|
||
</Form.Item>
|
||
</Col>
|
||
</Row>
|
||
<Row>
|
||
<Col span={12}>
|
||
<Form.Item
|
||
label="受伤人数"
|
||
name="injureNumber"
|
||
>
|
||
<Input disabled={mode==='view'} style={{width:'100%'}} allowClear />
|
||
</Form.Item>
|
||
</Col>
|
||
</Row>
|
||
<Row>
|
||
<Col span={24}>
|
||
<Form.Item
|
||
label="现场图片"
|
||
name="fieldId"
|
||
labelCol={{ span: 3 }}
|
||
wrapperCol={{ span: 19 }}
|
||
>
|
||
{mode !== "view" &&
|
||
<Dragger
|
||
name='file'
|
||
action="/gunshiApp/tsg/safety/accident/reg/file/upload/singleSimple"
|
||
onChange={imgfileChange}
|
||
beforeUpload={imgbeforeUpload}
|
||
onDrop={(info) => { console.log(info); }}
|
||
fileList={imgfileList}
|
||
disabled={imgloading}
|
||
>
|
||
<p className="ant-upload-text">点击或拖拽文件到此区域上传</p>
|
||
<p className="ant-upload-hint">
|
||
支持扩展名:.jpg .png
|
||
</p>
|
||
</Dragger>
|
||
}
|
||
<Row gutter={[16]}>
|
||
{
|
||
loading ? <span>文件正在上传中,请等待</span> :
|
||
imgfileList.length > 0 && imgfileList.map(file => {
|
||
return (
|
||
<Col span={12}>
|
||
<div className={mode == "view" ? 'file-item view-file' : 'file-item'} >
|
||
<div className='file-description'>
|
||
<Image width={60} src={url +file.response?.data?.filePath} alt='' />
|
||
<span>{file.name}</span>
|
||
</div>
|
||
<div
|
||
className={mode == "view" ? 'delete-icon disable-icon' : 'delete-icon'}
|
||
onClick={() => imgdeleteFile(file.response?.data?.fileId)}
|
||
>
|
||
<DeleteOutlined
|
||
/>
|
||
</div>
|
||
</div>
|
||
</Col>
|
||
)
|
||
})
|
||
}
|
||
|
||
</Row>
|
||
</Form.Item>
|
||
</Col>
|
||
</Row>
|
||
<div style={{ marginBottom: 20, borderBottom: "1px solid #dfdfdf", width: "100%", paddingBottom: 5 }}><span style={{ padding: "0px 3px", backgroundColor: "#0079fe", marginRight: 20 }}></span>事故处理</div>
|
||
<Row>
|
||
<Col span={12}>
|
||
<Form.Item
|
||
label="事故调查单位"
|
||
name="investOrg"
|
||
>
|
||
<Input disabled={mode==='view'} style={{width:'100%'}} allowClear />
|
||
</Form.Item>
|
||
</Col>
|
||
<Col span={12}>
|
||
<Form.Item
|
||
label="事故结案日期"
|
||
name="closeCaseDate"
|
||
getValueFromEvent={(e,dateString) => dateString}
|
||
getValueProps={(value) => ({ value: value ? moment(value) : undefined })}
|
||
rules={[
|
||
{
|
||
required: true,
|
||
},
|
||
]}
|
||
>
|
||
<DatePicker disabled={mode==='view'} format={'YYYY-MM-DD'} style={{width:'100%'}} allowClear />
|
||
</Form.Item>
|
||
</Col>
|
||
</Row>
|
||
<Row>
|
||
<Col span={24}>
|
||
<Form.Item
|
||
label="事故调查情况"
|
||
name="investDesc"
|
||
labelCol={{ span: 3 }}
|
||
wrapperCol={{ span: 19 }}
|
||
>
|
||
<Input.TextArea disabled={mode==='view'} style={{width:'100%',minHeight:'100px'}} allowClear />
|
||
</Form.Item>
|
||
</Col>
|
||
</Row>
|
||
<Row>
|
||
<Col span={24}>
|
||
<Form.Item
|
||
label="处理结果"
|
||
name="handleResult"
|
||
labelCol={{ span: 3 }}
|
||
wrapperCol={{ span: 19 }}
|
||
>
|
||
<Input.TextArea disabled={mode==='view'} style={{width:'100%',minHeight:'100px'}} allowClear />
|
||
</Form.Item>
|
||
</Col>
|
||
</Row>
|
||
<Row>
|
||
<Col span={24}>
|
||
<Form.Item
|
||
label="事故调查及处理资料"
|
||
name="fieldId"
|
||
// labelCol={{ span: 3 }}
|
||
wrapperCol={{ span: 19 }}
|
||
labelCol={{style:{whiteSpace: "wrap",textAlign:"center", width: 120}}}
|
||
>
|
||
{mode !== "view" &&
|
||
<Dragger
|
||
name='file'
|
||
// multiple
|
||
action="/gunshiApp/tsg/safety/accident/reg/file/upload/singleSimple"
|
||
onChange={fileChange}
|
||
onDrop={(info) => { console.log(info.dataTransfer.files); }}
|
||
fileList={fileList}
|
||
disabled={loading}
|
||
// onSuccess={handleSuccess}
|
||
>
|
||
<p className="ant-upload-text">点击或拖拽文件到此区域上传</p>
|
||
<p className="ant-upload-hint">
|
||
支持扩展名:.doc .docx .pdf .jpg .png .xlsx .xls
|
||
</p>
|
||
</Dragger>
|
||
}
|
||
<Row gutter={[16]}>
|
||
{
|
||
fileList?.length > 0 && fileList.map(file => {
|
||
return (
|
||
<Col span={12}>
|
||
<div className="file-item" style={{width:"75%"}}>
|
||
<div className='file-description'>
|
||
{file.name.indexOf('.docx') > -1 ?
|
||
<div
|
||
onClick={() => { download(file.response?.data?.fileId) }}
|
||
style={{ cursor: 'pointer' }}
|
||
>
|
||
<FileWordOutlined
|
||
style={{ fontSize: 40 }}
|
||
/>
|
||
</div>
|
||
:
|
||
file.name.indexOf('.pdf') > -1 ?
|
||
<div
|
||
onClick={() => { viewPdf(file.response?.data?.fileId) }}
|
||
style={{ cursor: 'pointer' }}
|
||
>
|
||
<FilePdfOutlined style={{ fontSize: 40 }} />
|
||
</div>
|
||
:
|
||
file.name.indexOf('.zip') > -1 ?
|
||
<div
|
||
onClick={() => { download(file.response?.data?.fileId) }}
|
||
style={{ cursor: 'pointer' }}
|
||
>
|
||
<FileZipOutlined style={{ fontSize: 40 }} />
|
||
</div>
|
||
:
|
||
file.name.indexOf('.xlsx') > -1 ?
|
||
<div
|
||
onClick={() => { download(file.response?.data?.fileId) }}
|
||
style={{ cursor: 'pointer' }}
|
||
>
|
||
<FileExcelOutlined style={{ fontSize: 40 }} />
|
||
</div>
|
||
:
|
||
<Image width={60} src={url +file.response?.data?.filePath} alt='' />
|
||
}
|
||
<span>{file.name}</span>
|
||
</div>
|
||
<div className={mode == "view" ? 'delete-icon disable-icon' : 'delete-icon'} onClick={() => deleteFile(file.response?.data?.fileId)}>
|
||
<DeleteOutlined />
|
||
</div>
|
||
</div>
|
||
</Col>
|
||
)
|
||
})
|
||
}
|
||
</Row>
|
||
</Form.Item>
|
||
</Col>
|
||
</Row>
|
||
{
|
||
mode==='view'?null:(
|
||
<>
|
||
<Form.Item {...btnItemLayout}>
|
||
<Button type="primary" htmlType="submit">
|
||
{mode === 'save' ? '提交' : '修改'}
|
||
</Button>
|
||
</Form.Item>
|
||
</>
|
||
)
|
||
}
|
||
</Form>
|
||
<Modal
|
||
open={pdfViewOPen}
|
||
width={1000}
|
||
title=""
|
||
footer={null}
|
||
style={{marginTop:"-5%"}}
|
||
onCancel={() => {
|
||
setPdfViewOPen(false)
|
||
}}
|
||
>
|
||
<iframe
|
||
style={{
|
||
height: '80vh',
|
||
width: '100%',
|
||
border: 0,
|
||
marginTop: 20,
|
||
}}
|
||
src={`${process.env.PUBLIC_URL}/static/pdf/web/viewer.html?file=${encodeURIComponent(`/gunshiApp/tsg/safety/accident/reg/file/download/${iframeSrc}`)}`}
|
||
/>
|
||
</Modal>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
export default ModalForm;
|