/* eslint-disable */
|
/**liuwh
|
* 4/6/2020, 3:53:15 PM
|
* doc comment for the file goes here
|
*/
|
|
/** Happy Coding */
|
import React, { ReactNode, ReactEventHandler, Component } from 'react';
|
import { Card, Row, Col, Select, Button, Input, Upload, Icon, Spin, message } from 'antd';
|
import E from 'wangeditor';
|
import './index.scss';
|
const Option = Select.Option;
|
const { TextArea } = Input;
|
|
import fetch from '../../../api/request';
|
import { BASE_URL } from '../../../api/httpurl';
|
import moment from 'moment';
|
|
const param = [{ value: 'DT00002', name: '通知公告' }, { value: 'DT00001', name: '规章制度' }]
|
export default class DocumentDetailPage extends Component {
|
constructor(props) {
|
super(props);
|
this.config = {
|
};
|
this.state = {
|
loading: false,//页面加载loading
|
iconLoading: false,//提交按钮loading
|
saveData: {},//表单提交数据
|
fileList: [],//附件列表
|
disabled: false,
|
editorContent: null//富文本编辑内容
|
};
|
}
|
|
componentWillMount() { }
|
|
componentDidMount() {
|
this.loadData()
|
}
|
|
loadData = () => {
|
let _this = this;
|
const { id } = _this.props.match.params;
|
_this.setState({
|
loading: true,
|
disabled: true
|
})
|
fetch({
|
url: 'api/document/findDetail',
|
params: {
|
id: id || 'new'
|
}
|
}).then(res => {
|
console.log(res)
|
_this.setState({
|
saveData: {
|
...res,
|
documentType: res.documentType || 'DT00002'
|
},
|
loading: false,
|
fileList: res.attachmentList && res.attachmentList.map((a) => ({ ...a, key: a.id, uid: a.id, name: a.fileName + '.' + a.suffix, status: 'done' })) || []
|
});
|
});
|
}
|
|
|
saveInputChange = ({ target: { value, name } }) => {
|
this.setState(({ saveData }) => ({
|
saveData: {
|
...saveData,
|
[name]: value
|
}
|
}))
|
}
|
|
submit = () => {
|
const { saveData, editorContent } = this.state;
|
console.log(saveData)
|
if (!saveData.documentTitle) {
|
return message.warning(this.switchWordByType(saveData.documentType).title + '标题不能为空');
|
}
|
if (!editorContent) {
|
return message.warning('通知内容不能为空');
|
}
|
let _this = this;
|
_this.setState({
|
iconLoading: true
|
})
|
fetch({
|
url: 'api/document/saveOrUpdateNotice',
|
method: 'POST',
|
data: {
|
...saveData,
|
documentContent: editorContent
|
}
|
}).then(res => {
|
console.log(res)
|
_this.setState({
|
iconLoading: false,
|
});
|
message.success("提交成功!");
|
this.props.history.push("/index/rules")
|
});
|
|
}
|
|
cancle = () => {
|
const { id } = this.props.match.params;
|
if (id) {
|
this.props.history.goBack()
|
} else {
|
this.props.history.push("/index/workbench");
|
}
|
}
|
|
// wen
|
switchWordByType = (type) => {
|
switch (type) {
|
case 'DT00002':
|
return {
|
title: '通知',
|
associateId: 1001
|
};
|
case 'DT00001':
|
return {
|
title: '规章制度',
|
associateId: 1002
|
}
|
}
|
}
|
|
render() {
|
const { saveData, fileList, loading, disabled } = this.state;
|
const props = {
|
action: BASE_URL + `api/attachment/materials?associateId=${saveData.documentType == 'DT00002' ? 1001 : 1002}&entityId=` + saveData.id,
|
header: {
|
Authorization: window.localStorage.getItem('token')
|
},
|
showUploadList: {
|
showDownloadIcon: true,
|
showRemoveIcon: false,
|
showPreviewIcon: true
|
},
|
onDownload: (file) => {
|
// console.log('file', file)
|
window.open(file.downloadUrl);
|
|
},
|
onChange: ({ file, fileList }) => {
|
fileList = fileList.slice(-2);
|
fileList = fileList.map(file => {
|
if (file.response) {
|
// Component will show file.url as link
|
file.url = file.response.data[0].url;
|
}
|
return file;
|
});
|
this.setState({ fileList });
|
},
|
fileList: fileList,
|
onPreview: (file) => {
|
window.open(file.url);
|
},
|
};
|
|
return (
|
<div className="document-detail-page-main">
|
<Spin spinning={loading}>
|
|
<Card style={{ border: 20, margin: 20, padding: 20 }}>
|
<Row className="document-detail-page-main-title">
|
{saveData.documentTitle || '无'}
|
</Row>
|
|
<Row className="document-detail-page-main-documentType marginTop">
|
<div className="marginTop">
|
{
|
saveData.documentType ? param.find(({ value }) => value == saveData.documentType).name : '无'
|
}
|
</div>
|
</Row>
|
|
<Row className="document-detail-page-main-detail marginTop">
|
<Row gutter={16} type="flex" className="marginTop">
|
<Col>广州恒巨信息科技有限公司</Col>
|
<Col>{saveData.createTime && moment(saveData.createTime).format("YYYY-MM-DD HH:mm")}</Col>
|
</Row>
|
<Row className="marginTop">
|
{saveData.readNumber}人已读,{saveData.noticeNumber - saveData.readNumber}人未读
|
</Row>
|
</Row>
|
|
<Row className="marginTop">
|
<div>
|
{
|
saveData.documentContent ? <div dangerouslySetInnerHTML={{
|
__html: saveData.documentContent
|
}} style={{ width: '70%' }} /> : <div className="document-detail-page-main-value">
|
无
|
</div>
|
}
|
</div>
|
</Row>
|
|
<Row gutter={16} className="marginTop">
|
<Col className="gutter-row marginTop flex-box-row flex-start">
|
<div className="document-detail-page-main-label">
|
附件:
|
</div>
|
{
|
saveData.attachmentList && saveData.attachmentList.length > 0 ?
|
<div className="flex-1">
|
<Upload {...props} >
|
<Button disabled={disabled} style={{ display: disabled ? 'none' : 'inline-block' }}>
|
<Icon type="upload" />上传文件</Button>
|
</Upload>
|
</div> : '未上传附件'
|
}
|
</Col>
|
</Row>
|
|
<Row type="flex" gutter={20} style={{ marginTop: '20px' }}>
|
<Col className="gutter-row" ><Button onClick={this.cancle}>返回</Button></Col>
|
</Row>
|
</Card>
|
</Spin>
|
</div>
|
)
|
}
|
}
|