tsg-web/src/views/fxzb/gczx/ytygc/form.js

480 lines
16 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import React,{useEffect,useState} from 'react';
import { Form, Button, Input, Row, Col, DatePicker, Upload,message,Image,Modal } from 'antd';
import { DeleteOutlined,FileWordOutlined,FilePdfOutlined,FilePptOutlined,FileZipOutlined,FileExcelOutlined } from '@ant-design/icons';
import { formItemLayout, btnItemLayout } from '../../../../components/crud/FormLayoutProps';
import apiurl from '../../../../service/apiurl';
import { createCrudService } from '../../../../components/crud/_';
import NormalSelect from '../../../../components/Form/NormalSelect';
import moment from 'moment';
import "./index.less"
const { Dragger } = Upload;
const ModalForm = ({ mode, record, onEdit, onSave,onDeleteGet,onCrudSuccess }) => {
// 检查结论选项 暂时写死
const checkConclusionOption = [
{
value: '1',
label: '无隐患'
},
{
value: '2',
label: '需整改'
}
]
const url = "http://223.75.53.141:9100/gs-tsg"
const [flag, setFlag] = useState(false)
// if (record.tmStart && record.tmEnd) {
// record.tmStart = moment(record.tmStart)
// record.tmEnd = moment(record.tmEnd)
// // record.meetDate = [moment(record.startDate), moment(record.endDate)]
// }
if (!record.conclusion) {
record.conclusion = '1'
}
console.log("record",record);
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 onFinish = async (values) => {
console.log("values",values)
values.tmStart = moment(values.tmStart).format('YYYY-MM-DD 00:00:00')
values.tmEnd =values.tmEnd ? moment(values.tmEnd).format('YYYY-MM-DD 00:00:00') :''
if (record.adcd) {
values.adcd = record.adcd
}
values.year = record.year
values.relatedObjectId = record.relatedObjectId
values.relatedObjectType = "bzProjectManipulationRecord1"
if (mode === 'edit') {
let oldFiles = fileList.map(item => ({ fileId: item.response?.data?.fileId }))
values.attachList = oldFiles;
values.id = record.id
onEdit(apiurl.fxzb.gczx.ytygc.edit,values)
}
if (mode === 'save') {
values.attachList = fileIds
onSave(apiurl.fxzb.gczx.ytygc.save,values)
}
}
/**
* @description 表单重置
*/
const onReset = () => {
form.resetFields();
};
/**
* @description 删除上传的图片
* @param {string} id 删除的id
*/
const deleteFile = (fileId) => {
let filterFile = fileList.filter(item => item.response?.data?.fileId !== fileId);
setFileList(filterFile)
// if (mode === "edit"&& flag) {
// createCrudService(apiurl.fxzb.gczx.ytygc.deleteFile + `/${record.id}/${fileId}`).delGet().then(res => {
// if (res.code === 200 ) {
// message.success("删除附件成功")
// setFlag(false)
// onCrudSuccess()
// }
// })
// }
}
/**
* @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 {fileId: file.response?.data?.fileId}
})
setFileIds(fileIds)
setFileList(info.fileList)
setFlag(false)
}
/**
* @description 获取查看时文件
* @param {*} type
* @returns
*/
// const getFileInfo = (params) => {
// console.log(params);
// let fileArr=[]
// params?.attachList.forEach(item => {
// createCrudService(apiurl.fxzb.gczx.ytygc.getFile + `/${item.fileId}`).delGet()
// .then(res => {
// if (res.code === 200) {
// setFlag(true)
// fileArr.push({
// name: res.data.fileName,
// response: {
// data: {
// filePath: res.data.filePath,
// fileId:res.data.fileId
// }
// },
// })
// }
// }).catch(err => console.log(err))
// });
// setFileList(fileArr)
// }
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 pdf文件预览
* @param {String} params 文件预览url
*/
const viewPdf = (params) => {
setIframeSrc(params)
setPdfViewOPen(true)
}
/**
* @description 文件下载
* @param {String} params 文件fileId
*/
const download = (params) => {
let downloadLink = document.createElement("a");
downloadLink.href = `http://local.gunshiiot.com:18083/gunshiApp/xfflood/bzProjectManipulationRecord/file/download/${params}`;
downloadLink.download = `${params.fileName}`;
downloadLink.style.display = "none";
// 将链接添加到页面中
document.body.appendChild(downloadLink);
// 模拟点击事件,开始下载
downloadLink.click();
}
useEffect(()=>{
if (mode === "view" || mode === "edit") {
getFileInfo(record)
form.setFieldsValue({
...record,
tmEnd: record.tmEnd ? moment(record.tmEnd) : null,
tmStart: record.tmStart ? moment(record.tmStart) : null
})
}
},[mode,record])
return (
<>
<Form form={form} {...formItemLayout} onFinish={onFinish} >
<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="tmStart"
rules={[{ required: true }]}
>
<DatePicker
showTime
format="YYYY-MM-DD"
style={{width:'100%'}}
disabled={mode === 'view'}
/>
</Form.Item>
</Col>
</Row>
<Row>
<Col span={12}>
<Form.Item
label="主办单位"
name="orgName"
// rules={[{ required: true }]}
>
{/* <NormalSelect disabled={mode!=='save'} style={{width:'100%'}} allowClear options={[]}/> */}
<Input type='num' disabled={mode==='view'} style={{width:'100%'}} allowClear />
</Form.Item>
</Col>
<Col span={12}>
<Form.Item
label="检查人员"
name="personnelIdsType1"
// rules={[{ required: true }]}
>
{/* <DatePicker
showTime
format="YYYY-MM-DD HH:mm"
style={{width:'100%'}}
/> */}
{/* <RangePicker style={{width:'100%'}} disabled={mode==='view'}/> */}
<Input type='num' disabled={mode==='view'} style={{width:'100%'}} allowClear />
</Form.Item>
</Col>
</Row>
<Row>
<Col span={24}>
<Form.Item
label="主要检查内容"
name="content"
labelCol={{ span: 3 }}
wrapperCol={{ span: 19 }}
// rules={[{ required: true }]}
>
<Input.TextArea disabled={mode ==='view'} style={{width:'100%',minHeight:'50px'}} allowClear />
</Form.Item>
</Col>
</Row>
<Row>
<Col span={12}>
<Form.Item
label="检查结论"
name="conclusion"
rules={[{ required: true }]}
>
<NormalSelect
disabled={mode == 'view'}
style={{ width: '100%' }}
allowClear
options={checkConclusionOption}
// defaultValue="1"
/>
</Form.Item>
</Col>
</Row>
<Row>
<Col span={24}>
<Form.Item
label="问题描述"
name="problemDesc"
labelCol={{ span: 3 }}
wrapperCol={{ span: 19 }}
// rules={[{ required: true }]}
>
<Input.TextArea disabled={mode==='view'} style={{width:'100%',minHeight:'50px'}} allowClear />
</Form.Item>
</Col>
</Row>
<Row>
<Col span={24}>
<Form.Item
label="处理意见及建议"
name="suggestion"
labelCol={{ span: 3 }}
wrapperCol={{ span: 19 }}
// rules={[{ required: true }]}
>
<Input.TextArea disabled={mode==='view'} style={{width:'100%',minHeight:'50px'}} allowClear />
</Form.Item>
</Col>
</Row>
<Row>
<Col span={12}>
<Form.Item
label="整改完成时间"
name="tmEnd"
>
<DatePicker
// showTime
format="YYYY-MM-DD"
style={{width:'100%'}}
disabled={mode==='view'}
/>
</Form.Item>
</Col>
</Row>
<Row>
<Col span={24}>
<Form.Item
label="问题整改情况"
name="situation"
labelCol={{ span: 3 }}
wrapperCol={{ span: 19 }}
// rules={[{ required: true }]}
>
<Input.TextArea disabled={mode==='view'} style={{width:'100%',minHeight:'50px'}} allowClear />
</Form.Item>
</Col>
</Row>
<Row>
<Col span={24}>
<Form.Item
label="附件"
// label={mode !== "view" ? "附件" : ''}
name="fieldId"
labelCol={{ span: 3 }}
wrapperCol={{ span: 19 }}
>
{mode !== "view" &&
<Dragger
name='file'
// multiple
action="/gunshiApp/xfflood/bzProjectManipulationRecord/file/upload/singleSimple"
onChange={fileChange}
onDrop={(info) => { console.log(info); }}
fileList={fileList}
disabled={loading}
>
<p className="ant-upload-text">点击或拖拽文件到此区域上传</p>
<p className="ant-upload-hint">
支持扩展名.rar .zip .doc .docx .pdf .jpg .png .ppt
</p>
</Dragger>
}
<Row gutter={[16]}>
{
loading ? <span>文件正在上传中请等待</span> :
fileList.length > 0 && fileList.map(file => {
return (
<Col span={12}>
<div className={mode == "view" ? 'file-item' : '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('.ppt') > -1 ?
<div
onClick={() => { download(file.response?.data?.fileId) }}
style={{ cursor: 'pointer' }}
>
<FilePptOutlined 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>
{
mode !== "view" &&
<div className='delete-icon'
onClick={() => deleteFile(file.response?.data?.fileId)}>
<DeleteOutlined />
</div>
}
</div>
</Col>
)
})
}
</Row>
</Form.Item>
</Col>
</Row>
{
mode==='view' ? null : (
<>
<Form.Item {...btnItemLayout}>
<Button onClick={onReset} style={{marginRight:10}}>
重置
</Button>
<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;