243 lines
8.1 KiB
JavaScript
243 lines
8.1 KiB
JavaScript
import React, { useEffect, useState } from 'react';
|
|
import { Form, Button, Input, Row, Col, DatePicker, Modal,Image } from 'antd';
|
|
import { DeleteOutlined,FileWordOutlined,FilePdfOutlined,FileZipOutlined,FileExcelOutlined } from '@ant-design/icons';
|
|
import { formItemLayout, btnItemLayout } from '../../../../components/crud/FormLayoutProps';
|
|
import { getDictService } from '../../../../service/SelectValue'
|
|
import { validlgtd, validlttd } from '../../../../utils/validators';
|
|
import apiurl from '../../../../service/apiurl';
|
|
import { createCrudService } from '../../../../components/crud/_';
|
|
import moment from 'moment';
|
|
|
|
const url = "http://223.75.53.141:9100/gs-tsg"
|
|
const ModalForm = ({ mode, record, onEdit, onSave }) => {
|
|
if (record.prodDate) {
|
|
record.myTm = moment(record.prodDate)
|
|
}
|
|
const [form] = Form.useForm();
|
|
const [fileList, setFileList] = useState([]) //上传文件列表
|
|
const [flag, setFlag] = useState(false)
|
|
const [iframeSrc, setIframeSrc] = useState('')
|
|
const [pdfViewOPen, setPdfViewOPen] = useState(false)
|
|
const onFinish = (values) => {
|
|
if (values.myTm) {
|
|
values.prodDate = moment(values.myTm).format('YYYY-MM-DD')
|
|
delete values.myTm
|
|
}
|
|
|
|
if (mode === 'edit') {
|
|
values.id = record.id
|
|
onEdit(apiurl.fxzb.sxfd.fxtj.edit, values)
|
|
}
|
|
if (mode === 'save') {
|
|
onSave(apiurl.fxzb.sxfd.fxtj.save, values)
|
|
}
|
|
}
|
|
|
|
const getFileInfo = (params) => {
|
|
let fetchArr = params?.attachList.map(item => {
|
|
return createCrudService(apiurl.fxzb.gczx.ytygc.getFile + `/${item.fileId}`)
|
|
.delGet()
|
|
}
|
|
);
|
|
Promise.all(fetchArr).then(res => {
|
|
let fileArr = res.map(item => {
|
|
return {
|
|
name: item.data.fileName,
|
|
response: {
|
|
data: {
|
|
filePath: item.data.filePath,
|
|
fileId:item.data.fileId
|
|
}
|
|
},
|
|
}
|
|
})
|
|
setFlag(true)
|
|
setFileList(fileArr)
|
|
}).catch(err => console.log(err))
|
|
}
|
|
/**
|
|
* @description 文件下载
|
|
* @param {String} params 文件fileId
|
|
*/
|
|
const download = (params) => {
|
|
let downloadLink = document.createElement("a");
|
|
downloadLink.href = `${process.env.REACT_APP_API_URL}/gunshiApp/xfflood/bzFldPred/file/download/${params}`;
|
|
downloadLink.download = `${params.fileName}`;
|
|
downloadLink.style.display = "none";
|
|
// 将链接添加到页面中
|
|
document.body.appendChild(downloadLink);
|
|
|
|
// 模拟点击事件,开始下载
|
|
downloadLink.click();
|
|
}
|
|
|
|
/**
|
|
* @description pdf文件预览
|
|
* @param {String} params 文件预览url
|
|
*/
|
|
const viewPdf = (params) => {
|
|
setIframeSrc(params)
|
|
setPdfViewOPen(true)
|
|
}
|
|
useEffect(()=>{
|
|
if ((mode === "view" || mode === "edit") && record?.attachList?.length) {
|
|
getFileInfo(record)
|
|
}
|
|
}, [record, mode])
|
|
return (
|
|
<>
|
|
<Form form={form} {...formItemLayout} onFinish={onFinish} initialValues={record}>
|
|
<Row>
|
|
<Col span={12}>
|
|
<Form.Item
|
|
label="预报单名称"
|
|
name="title"
|
|
rules={[{ required: true }]}
|
|
>
|
|
<Input disabled={mode === 'view'} style={{ width: '100%' }} allowClear />
|
|
</Form.Item>
|
|
</Col>
|
|
<Col span={12}>
|
|
<Form.Item
|
|
label="期数"
|
|
name="period"
|
|
rules={[{ required: true }]}
|
|
>
|
|
<Input disabled={mode === 'view'} style={{ width: '100%' }} allowClear />
|
|
</Form.Item>
|
|
</Col>
|
|
</Row>
|
|
<Row>
|
|
<Col span={12}>
|
|
<Form.Item
|
|
label="预报单位"
|
|
name="org"
|
|
rules={[{ required: true }]}
|
|
>
|
|
<Input disabled={mode === 'view'} style={{ width: '100%' }} allowClear />
|
|
</Form.Item>
|
|
</Col>
|
|
<Col span={12}>
|
|
<Form.Item
|
|
label="预报时间"
|
|
name="tmPred"
|
|
rules={[{ required: true }]}
|
|
>
|
|
<Input disabled={mode === 'view'} style={{ width: '100%' }} allowClear />
|
|
</Form.Item>
|
|
</Col>
|
|
</Row>
|
|
<Row>
|
|
<Col span={24}>
|
|
<Form.Item
|
|
label="接收时间"
|
|
name="tmRecv"
|
|
labelCol={{ span: 3 }}
|
|
wrapperCol={{ span: 19 }}
|
|
rules={[{ required: true }]}
|
|
|
|
>
|
|
<Input disabled={mode === 'view'} style={{ width: '37%' }} allowClear />
|
|
</Form.Item>
|
|
</Col>
|
|
</Row>
|
|
<Row>
|
|
<Col span={24}>
|
|
<Form.Item
|
|
label="附件"
|
|
name=""
|
|
labelCol={{ span: 3 }}
|
|
wrapperCol={{ span: 19 }}
|
|
>
|
|
<Row gutter={[16]}>
|
|
{
|
|
fileList.length > 0 && fileList.map(file => {
|
|
return (
|
|
<Col span={12}>
|
|
<div className='file-item '>
|
|
<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>
|
|
</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/xfflood/bzProjectManipulationRecord/file/download/${iframeSrc}`)}`}
|
|
/>
|
|
</Modal>
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default ModalForm;
|