/* 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 { Link } from 'react-router-dom';
|
import { Card, Row, Col, Select, Button, Input, Upload, Icon, Spin, message } from 'antd';
|
import './index.scss';
|
const Option = Select.Option;
|
const { TextArea } = Input;
|
|
import fetch from '../../../api/request';
|
import { BASE_URL } from '../../../api/httpurl'
|
|
const param = [{ value: 'DT00002', name: '通知公告' }, { value: 'DT00001', name: '规章制度' }]
|
export default class DocumentEditPage extends Component {
|
constructor(props) {
|
super(props);
|
this.config = {
|
};
|
this.state = {
|
loading: false,
|
iconLoading: false,
|
savedate: {},
|
fileList: [],
|
disabled: false,
|
};
|
}
|
|
componentWillMount() { }
|
|
componentDidMount() {
|
this.loadData()
|
}
|
|
loadData = () => {
|
const { id } = this.props.match.params;
|
console.log(this.props)
|
console.log(id)
|
let _this = this;
|
_this.setState({
|
loading: true,
|
disabled: id ? true : false
|
})
|
fetch({
|
url: 'api/document/findDetail',
|
params: {
|
id: id || 'new'
|
}
|
}).then(res => {
|
console.log(res)
|
_this.setState({
|
savedate: {
|
...res,
|
documentType: res.documentType || 'DT00002'
|
},
|
loading: false,
|
});
|
});
|
}
|
|
|
saveInputChange = ({ target: { value, name } }) => {
|
this.setState(({ savedate }) => ({
|
savedate: {
|
...savedate,
|
[name]: value
|
}
|
}))
|
}
|
|
submit = () => {
|
const { savedate } = this.state;
|
console.log(savedate)
|
if (savedate.documentType == 'DT00001') {
|
if (!savedate.documentTitle) {
|
return message.warning('规章制度标题不能为空')
|
}
|
} else {
|
if (!savedate.documentTitle) {
|
return message.warning('通知标题不能为空')
|
} else if (!savedate.documentContent) {
|
return message.warning('通知内容不能为空')
|
}
|
}
|
let _this = this;
|
_this.setState({
|
iconLoading: true
|
})
|
fetch({
|
url: 'api/document/saveOrUpdateNotice',
|
method: 'POST',
|
data: savedate
|
}).then(res => {
|
console.log(res)
|
_this.setState({
|
iconLoading: false,
|
});
|
message.success("提交成功!");
|
this.props.history.goBack()
|
});
|
// Fetch.savePatrolCom(savedate)
|
// .then(res => {
|
// if (res.code === 0) {
|
// message.success("提交成功!");
|
// this.props.history.push("/companyUpd")
|
// } else {
|
// message.error('保存失败,请联系管理员', 2)
|
// }
|
// });
|
}
|
|
cancle = () => {
|
// this.props.history.push("/index/workbench");
|
const { id } = this.props.match.params;
|
if (id) {
|
this.props.history.goBack()
|
} else {
|
this.props.history.push("/index/workbench");
|
}
|
// console.log(this.props)
|
}
|
|
render() {
|
const { savedate, fileList, loading, disabled } = this.state;
|
const props = {
|
action: BASE_URL + `api/attachment/materials?associateId=${savedate.documentType == 'DT00002' ? 1001 : 1002}&entityId=` + savedate.id,
|
onChange: ({ file, fileList }) => {
|
if (file.status !== 'uploading') {
|
console.log(file);
|
console.log(fileList);
|
|
}
|
this.setState({ fileList });
|
},
|
fileList: fileList,
|
// onDownload: (file) => {
|
// console.log(file)
|
// Fetch.attachmentDownload(file.uid)
|
// .then(res => {
|
// message.success("下载成功!");
|
// });
|
// },
|
// onRemove: (file) => {
|
// Fetch.deleteAttachment(file.uid)
|
// .then(res => {
|
// message.success("移除成功!");
|
// });
|
// this.setState(({ fileList }) => {
|
// const index = fileList.indexOf(file);
|
// const newFileList = fileList.slice();
|
// newFileList.splice(index, 1);
|
// return {
|
// fileList: newFileList,
|
// };
|
// });
|
// }
|
};
|
return (
|
<div className="document-edit-page-main">
|
<Spin spinning={loading}>
|
|
<Card style={{ border: 20, margin: 20, padding: 20 }}>
|
<Row gutter={16}>
|
<Col className="gutter-row" >
|
文档类型:
|
</Col>
|
</Row>
|
<Row gutter={16}>
|
<Col className="gutter-row" style={{ margin: '12px 0' }} >
|
<Select disabled={disabled} style={{ width: "300px" }} onChange={(value) => this.saveInputChange({ target: { name: 'documentType', value } })} value={savedate.documentType}>
|
{
|
param.map((data, key) => (
|
<Option key={key} value={data.value}>{data.name}</Option>
|
))
|
}
|
</Select>
|
</Col>
|
</Row>
|
|
{
|
savedate.documentType == 'DT00002' &&
|
<Row gutter={16} style={{ marginTop: '12px' }}>
|
<Col className="gutter-row" style={{ marginTop: '12px' }}>
|
通知标题:
|
</Col>
|
</Row>
|
}
|
{
|
savedate.documentType == 'DT00001' &&
|
<Row gutter={16} style={{ marginTop: '12px' }}>
|
<Col className="gutter-row" style={{ marginTop: '12px' }}>
|
规章制度标题:
|
</Col>
|
</Row>
|
}
|
<Row gutter={16}>
|
<Col className="gutter-row" style={{ margin: '12px 0' }} >
|
<Input disabled={disabled} style={{ width: '300px' }} name='documentTitle' onChange={this.saveInputChange} value={savedate.documentTitle || ""} />
|
</Col>
|
</Row>
|
|
{
|
savedate.documentType == 'DT00002' &&
|
<Row gutter={16}>
|
<Col className="gutter-row" >
|
通知内容:
|
</Col>
|
</Row>
|
}
|
{
|
savedate.documentType == 'DT00002' &&
|
<Row gutter={16}>
|
<Col className="gutter-row" style={{ margin: '12px 0' }} >
|
<TextArea disabled={disabled} style={{ width: '500px' }} name='documentContent' onChange={this.saveInputChange} value={savedate.documentContent || ""} />
|
</Col>
|
</Row>
|
}
|
{
|
savedate.documentType == 'DT00001' &&
|
<Row gutter={16} style={{ marginTop: '12px' }}>
|
<Col className="gutter-row" style={{ margin: '12px 0' }} >
|
规章制度源文件:
|
</Col>
|
</Row>
|
}
|
{savedate.documentType == 'DT00001' &&
|
<Row gutter={16} >
|
<Col className="gutter-row" >
|
<Upload {...props}>
|
<Button disabled={disabled}>
|
<Icon type="upload" />上传文件</Button>
|
</Upload>
|
</Col>
|
</Row>
|
}
|
{
|
savedate.documentType == 'DT00001' &&
|
<Row gutter={16} style={{ marginTop: '12px' }}>
|
<Col className="gutter-row" >
|
通知范围:
|
</Col>
|
</Row>
|
}
|
{
|
savedate.documentType == 'DT00002' &&
|
<Row gutter={16} style={{ marginTop: '12px' }}>
|
<Col className="gutter-row" style={{ margin: '12px 0' }} >
|
通知范围:
|
</Col>
|
</Row>
|
}
|
{savedate.documentType == 'DT00002' &&
|
<Row gutter={16} >
|
<Col className="gutter-row" >
|
目前仅支持全员通知
|
</Col>
|
</Row>
|
}
|
<Row gutter={16} style={{ marginTop: '12px' }}>
|
<Col span={2} className="gutter-row" ><Button disabled={disabled} style={{ marginRight: '15px', width: '100px' }} type="primary" loading={this.state.iconLoading} onClick={this.submit}>发布</Button></Col>
|
<Col span={2} className="gutter-row" ><Button style={{ marginLeft: '15px', width: '100px' }} onClick={this.cancle}>返回</Button></Col>
|
</Row>
|
</Card>
|
</Spin>
|
</div>
|
)
|
}
|
}
|