tsg-web/src/views/fxdd/ddjc/yjxy/form.js

283 lines
10 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 { getDictService } from '../../../../service/SelectValue'
import { validlgtd, validlttd } from '../../../../utils/validators';
import apiurl from '../../../../service/apiurl';
import { mobile } from '../../../../utils/validators'
import AdcdTreeSelect from '../../../../components/Form/AdcdTreeSelect'
import NormalSelect from '../../../../components/Form/NormalSelect';
import { config } from '../../../../config';
import { createCrudService } from '../../../../components/crud/_';
import moment from 'moment';
const { Dragger } = Upload;
const url = "http://223.75.53.141:9100/gs-tsg"
const ModalForm = ({ mode, record, onEdit, onSave,data }) => {
console.log("data",data);
const [form] = Form.useForm();
const [sttp, setSttp] = useState([])
const [frgrd, setFrgrd] = useState([])
const [stbk, setStbk] = useState([])
const [usfl, setUsfl] = useState([])
const [locality, setLocality] = useState([])
const [fileList, setFileList] = useState([]) //上传文件列表
const [fileIds, setFileIds] = useState([])
const [flag, setFlag] = useState(false)
const [iframeSrc, setIframeSrc] = useState('')
const [pdfViewOPen, setPdfViewOPen] = useState(false)
const [loading, setLoading] = useState(false)
const onFinish = (values) => {
let params = {
etm: moment().format("YYYY-MM-DD HH:00:00"),
id:data[0]?.id
}
console.log("values", values);
values.stm = moment(values.tm).format("YYYY-MM-DD HH:00:00")
values.level = record.idx;
values.year = record.year
if (mode === 'save') {
values.attachList = fileIds
// 先解除响应
if (data[0]?.status == 1) {
createCrudService(apiurl.ddjc.yjxy.stop).edit(params).then(res => {
if (res.code === 200) {
// 再启动响应
onSave(apiurl.ddjc.yjxy.save, values)
}
})
} else {
onSave(apiurl.ddjc.yjxy.save, values)
}
}
}
/**
* @description 删除上传的图片
* @param {string} id 删除的id
*/
const deleteFile = (fileId) => {
let filterFile = fileList.filter(item => item.response?.data?.fileId !== fileId);
setFileList(filterFile)
}
/**
* @description 上传图片
* @param {string} file 上传的文件
*/
const fileChange = (info) => {
console.log(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}
})
console.log(fileIds);
setFileIds(fileIds)
setFileList(info.fileList)
setFlag(false)
}
/**
* @description 文件下载
* @param {String} params 文件fileId
*/
const download = (params) => {
let downloadLink = document.createElement("a");
downloadLink.href = `${process.env.REACT_APP_API_URL}/gunshiApp/xfflood/xfEmerRespR/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)
}
return (
<>
{!record.isShow ?
<Form form={form} {...formItemLayout} onFinish={onFinish} initialValues={record}>
<Row>
<Col span={24}>
<Form.Item
label="启动响应时间"
name="tm"
rules={[{ required: true }]}
>
<DatePicker
showTime
format="YYYY-MM-DD HH:00:00"
style={{width:'100%'}}
disabled={mode==='view'}
/>
</Form.Item>
</Col>
</Row>
<Row>
<Col span={24}>
<Form.Item
label="原因"
name="reason"
rules={[{ required: true }]}
>
<Input.TextArea disabled={mode==='view'} style={{width:'100%',minHeight:'100px'}} allowClear />
</Form.Item>
</Col>
</Row>
<Row>
<Col span={24}>
<Form.Item
label={mode !== "view" ? "附件" : ''}
name="fieldId"
>
{mode !== "view" &&
<Dragger
name='file'
// multiple
action="/gunshiApp/xfflood/xfEmerRespR/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">
支持扩展名.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={'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 style={{display: 'inline-block',maxWidth: '180px',overflow: 'hidden',textOverflow: 'ellipsis',whiteSpace: 'nowrap'}}>{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>
: <img
src={`${process.env.PUBLIC_URL}/assets/fxdd/流程图.png`}
alt=""
style={{
width: '100%',
height: '100%',
}}
/>
}
<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/xfEmerRespR/file/download/${iframeSrc}`)}`}
/>
</Modal>
</>
);
}
export default ModalForm;