mh_jy_safe_web/src/components/CustomPages/FM/FM202ShowPrint.js
2026-05-15 13:47:17 +08:00

133 lines
5.4 KiB
JavaScript

import { Button, Descriptions, Modal, Row, Col, Form, Input, Select, Table } from 'antd';
import React from 'react';
import { initFilter, extendRule, extendInclude, extendIgnoreDataRule, setDataFieldValue, guid, GetFileModel, showFiles, approveView } from "../../../utils/common";
import ReactToPrint from "react-to-print";
import stylesStep from '../HI/StepForm.css';
import config from "../../../config";
import XLSX from 'xlsx';
import { connect } from 'dva';
import moment from 'moment';
import { message } from "antd/lib/index";
import FormPage from '../../../components/FormPage'
class FM202ShowPrint extends React.Component {
constructor(props) {
super(props);
this.state = {
data: null,
BtnAgreeDisplay: 'none',
tmpData: {},
fileData: [],
fileForm: {
title: "",
visible: false,
},
};
};
componentDidMount() {
if (this.props.data?.id)
this.loadData(this.props.data?.id);
}
componentWillReceiveProps(NextProps) {
if (NextProps.data?.id && this.props.data?.id != NextProps.data?.id) {
this.loadData(NextProps.data?.id);
}
}
onTableBtnAgree() {
this.props.dispatch({
type: 'app/getDataByPost',
url: 'FM/FMSnapshot/PersonalAgree',
payload: {
ID: this.props.data.id,
TaskID: this.props.data.TaskID,
},
onComplete: (ret) => {
if (ret) {
message.success('确认成功!');
this.setState({ BtnAgreeDisplay: 'none' })
this.BtnClose();
}
}
})
}
BtnClose = () => {
if (typeof this.props.data.onCancel != "undefined" && typeof this.props.data.onCancel == 'function')
this.props.data.onCancel();
}
loadData = (dataId) => {
let that = this;
let json = initFilter(that.props.login.OrgId);
extendRule(json, 'ID', 1, dataId);
extendIgnoreDataRule(json)
that.props.dispatch({
type: 'app/getDataByPost',
payload: json,
url: 'FM/FMSnapshot/GetEdit',
onComplete: (ret) => {
if (ret) {
that.setState({ data: ret });
if (that.props.data.tableKey === "2" || that.props.data.tableKey === undefined) {
that.setState({ BtnAgreeDisplay: 'none' })
} else {
that.setState({ BtnAgreeDisplay: 'inline' })
}
approveView(this, 'inline', false);
//归档才显示打印和导出按钮
// if(ret.PRE_MEETING_STATUS==5){
// this.setState({ isFinished: 'inline' })
// }
}
}
});
}
onTableBtnExport() {
const enums = this.props.data.enums ? this.props.data.enums : this.props.app.enums;
let TableWrap = document.getElementById('tableId' + this.props.data.id);
let Table = TableWrap.getElementsByTagName('table')[0];
const wb = XLSX.utils.table_to_book(Table);
XLSX.writeFile(wb, "随手拍列表.xlsx")
}
render() {
const { data } = this.state;
const enums = this.props.data.enums ? this.props.data.enums : this.props.app.enums;
// let aaa = Math.random();
return <div>
<div style={{ padding: '10px' }}>
{/* <Button onClick={() => this.onClickApprove(true)} style={{ marginRight: '8px' }} icon="export">审批详情</Button>
<ReactToPrint
trigger={() => <Button style={{ marginLeft: '8px', display: data && data.IS_PUBLISH === 5 ? "inline" : "none" }} type={'default'} icon={'printer'} >打印</Button>}
content={() => this.componentRef}
/>
<Button onClick={() => this.onTableBtnExport()} icon="export" style={{ marginLeft: '8px', display: data && data.IS_PUBLISH === 5 ? "inline" : "none" }}>导出</Button> */}
<Button type="primary" style={{ marginLeft: '8px', display: this.state.BtnAgreeDisplay }} onClick={() => this.onTableBtnAgree()} icon="check" >确认</Button>
</div>
<div ref={el => (this.componentRef = el)} style={{ padding: '20px' }} id={'tableId' + this.props.data.id}>
<h1 className={stylesStep.showPrintHead}>随手拍确认</h1>
{
data ?
<div>
<Descriptions size="middle" bordered className={stylesStep.description}>
<Descriptions.Item label="上报人">{data.CREATER_NAME}</Descriptions.Item>
<Descriptions.Item label="随手拍图片">{
showFiles(data.Nav_Files, config.picServerHost, this)
}</Descriptions.Item>
</Descriptions>
</div> : null
}
<FormPage {...this.state.tmpData} />
</div>
{
GetFileModel(Modal, FormPage, this, this.state.fileForm.visible)
}
</div>
}
}
export default connect(({ login, app }) => ({ login, app }))(FM202ShowPrint)