mh_jy_safe_web/src/components/CustomPages/SE/SE005ReportEdit.js

258 lines
11 KiB
JavaScript
Raw Normal View History

2025-08-25 10:08:30 +08:00
import { message } from "antd/lib/index";
2025-11-26 19:59:48 +08:00
import { Button, Popconfirm, Row, Col, Checkbox, Radio, Form, Input, Select, Table, Upload, Icon, PageHeader, Modal, Spin } from 'antd';
2025-08-25 10:08:30 +08:00
import React from 'react';
import { initFilter, extendRule, extendInclude, setDataFieldValue, guid, initQueryFilter } from "../../../utils/common";
import ReactToPrint from "react-to-print";
2025-11-26 19:59:48 +08:00
import styles from '../../CustomPages/HI/StepForm.css';
2025-08-25 10:08:30 +08:00
import XLSX from 'xlsx';
import { connect } from 'dva';
import moment from 'moment';
import config from "../../../config";
const Option = Select.Option;
const answer = {
color: 'blue',
textDecoration: 'underline',
}
class SE005ReportEdit extends React.Component {
constructor(props) {
super(props);
let ALL = props.formCode === 'SE005_ALLREPORT';
this.state = {
ALL,
list: null,
taskid: null,
surveyid: !ALL && this.props.data.id,
data: null,
type: '部门',
loading: false,
};
};
componentDidMount() {
2025-11-26 19:59:48 +08:00
if (this.state.ALL) {
2025-08-25 10:08:30 +08:00
this.loadList();
2025-11-26 19:59:48 +08:00
} else {
2025-08-25 10:08:30 +08:00
this.loadData();
}
}
BtnClose = () => {
if (typeof this.props.data.onCancel != "undefined" && typeof this.props.data.onCancel == 'function')
this.props.data.onCancel();
}
loadList = () => {
let json = initFilter(this.props.login.OrgId);
json.OrgType = 2;
2025-11-26 19:59:48 +08:00
this.setState({ loading: true })
2025-08-25 10:08:30 +08:00
this.props.dispatch({
type: 'app/getDataByPost',
payload: json,
url: 'SE/SESafeSurvey/GetReportList',
onComplete: (ret) => {
2025-11-26 19:59:48 +08:00
this.setState({ loading: false })
2025-08-25 10:08:30 +08:00
if (!ret)
return;
2025-11-26 19:59:48 +08:00
if (ret.length == 0) {
2025-08-25 10:08:30 +08:00
message.warn("当年未查到有效的公司调查问卷报表");
return;
}
let taskid = this.props.data.id;
2025-11-26 19:59:48 +08:00
if (!ret.find(it => it.Key === taskid)) {
2025-08-25 10:08:30 +08:00
taskid = ret[0].Key;
}
this.setState({
list: ret,
taskid,
})
2025-11-26 19:59:48 +08:00
this.loadData();
2025-08-25 10:08:30 +08:00
}
});
2025-11-26 19:59:48 +08:00
2025-08-25 10:08:30 +08:00
}
loadData = () => {
let json = initFilter(this.props.login.OrgId);
json.OrgType = 2;
json.Parameter3 = this.state.type;
2025-11-26 19:59:48 +08:00
if (this.state.ALL) {
2025-08-25 10:08:30 +08:00
if (!this.state.taskid)
return;
json.Parameter2 = this.state.taskid;
2025-11-26 19:59:48 +08:00
} else {
2025-08-25 10:08:30 +08:00
if (!this.state.surveyid)
return;
json.Parameter1 = this.state.surveyid;
}
2025-11-26 19:59:48 +08:00
this.setState({
2025-08-25 10:08:30 +08:00
data: null,
loading: true
});
this.props.dispatch({
type: 'app/getDataByPost',
payload: json,
url: 'SE/SESafeSurvey/GetReport',
onComplete: (ret) => {
2025-11-26 19:59:48 +08:00
this.setState({ loading: false })
if (!ret) {
2025-08-25 10:08:30 +08:00
return;
}
2025-11-26 19:59:48 +08:00
this.setState({ data: ret })
2025-08-25 10:08:30 +08:00
}
});
}
2025-11-26 19:59:48 +08:00
onApprove = () => {
const { ALL, data } = this.state;
2025-08-25 10:08:30 +08:00
let json = {
Parameter1: data.SURVEY[0].ID,
Parameter2: this.props.data.TaskID,
}
this.props.dispatch({
type: 'app/getDataByPost',
payload: json,
url: 'SE/SESafeSurvey/Approve',
onComplete: (ret) => {
message.success("审阅完成");
this.BtnClose();
}
});
}
2025-11-26 19:59:48 +08:00
fmtEnum(name, value) {
2025-08-25 10:08:30 +08:00
const enums = this.props.app.enums;
if (!enums || !enums[name]) return '';
2025-11-26 19:59:48 +08:00
return enums[name].enums[value] || '';
2025-08-25 10:08:30 +08:00
}
onTableBtnExport() {
let TableWrap = document.getElementById('tableId' + this.props.data.id);
let Table = TableWrap.getElementsByTagName('table')[0];
const wb = XLSX.utils.table_to_book(Table);
let name = '安全意识调查问卷';
name += '.xlsx';
XLSX.writeFile(wb, name)
}
2025-11-26 19:59:48 +08:00
getJoinDepartment(depart) {
2025-08-25 10:08:30 +08:00
let arr = [];
2025-11-26 19:59:48 +08:00
for (let it of depart) {
if (it.Nav_Department) {
if (it.Nav_Department.NAME == "宁化行洛坑钨矿有限公司") {
2025-08-25 10:08:30 +08:00
arr.push("公司领导")
2025-11-26 19:59:48 +08:00
} else {
2025-08-25 10:08:30 +08:00
arr.push(it.Nav_Department.NAME)
}
}
}
return arr;
}
render() {
2025-11-26 19:59:48 +08:00
const { ALL, data, list, loading } = this.state;
2025-08-25 10:08:30 +08:00
const count = data && data.ROWS && data.ROWS.length > 0 && data.ROWS[0].length || 1;
const SPAN = Math.floor(24 / count) || 1;
2025-11-26 19:59:48 +08:00
const TITLE_SPAN = Math.max(24 - count * SPAN, 0) + SPAN;
2025-08-25 10:08:30 +08:00
const canApprove = this.props.data.tableKey == "1"
return <div>
<div style={{ padding: '10px' }}>
2025-11-26 19:59:48 +08:00
2025-08-25 10:08:30 +08:00
<ReactToPrint
trigger={() => <Button type={'primary'} icon={'printer'} >打印</Button>}
content={() => this.componentRef}
/>
<Button style={{ marginLeft: '8px' }} onClick={() => this.onTableBtnExport()} icon="export" >导出</Button>
{
2025-11-26 19:59:48 +08:00
ALL &&
<Select style={{ fontSize: 14, width: "100px", marginLeft: '8px' }}
2025-08-25 10:08:30 +08:00
showSearch
value={this.state.taskid}
onChange={val => {
2025-11-26 19:59:48 +08:00
this.setState({ taskid: val })
2025-08-25 10:08:30 +08:00
this.loadData();
2025-11-26 19:59:48 +08:00
}}
2025-08-25 10:08:30 +08:00
>
{
2025-11-26 19:59:48 +08:00
list && list.map(it => {
return <Option key={it.Key} value={it.Key}>{it.Value}</Option>
}
2025-08-25 10:08:30 +08:00
)
}
</Select>
}
2025-11-26 19:59:48 +08:00
<Select style={{ fontSize: 14, width: "100px", marginLeft: '8px' }}
2025-08-25 10:08:30 +08:00
value={this.state.type}
onChange={val => {
this.state.type = val;
this.loadData();
2025-11-26 19:59:48 +08:00
}}
2025-08-25 10:08:30 +08:00
>
<Option value={"部门"}>{"部门"}</Option>
<Option value={"人员"}>{"人员"}</Option>
<Option value={"岗位"}>{"岗位"}</Option>
</Select>
{
canApprove && <Button style={{ marginLeft: '8px' }} type={'primary'} onClick={() => this.onApprove()} icon="check" >同意</Button>
}
</div>
<div ref={el => (this.componentRef = el)} id={'tableId' + this.props.data.id} style={{ padding: '20px' }}>
2025-11-26 19:59:48 +08:00
<h1 style={{ textAlign: 'center' }}>{this.state.ALL ? '安全意识调查问卷公司报表' : '安全意识调查问卷部门报表'}</h1>
2025-08-25 10:08:30 +08:00
<Spin spinning={this.state.loading}>
{
2025-11-26 19:59:48 +08:00
data && <>
2025-08-25 10:08:30 +08:00
<table style={{ width: '100%', textAlign: 'center', borderTop: '1px solid #333', borderLeft: '1px solid #333' }} className={styles.PrintForm}>
<tbody>
{
2025-11-26 19:59:48 +08:00
data.SURVEY && data.SURVEY.map(SURVEY => {
2025-08-25 10:08:30 +08:00
return <>
<tr>
<td colSpan={4} rowSpan={1} className={styles.fontBold}>调查名称</td>
2025-11-26 19:59:48 +08:00
<td colSpan={20} rowSpan={1}>{SURVEY.NAME}</td>
2025-08-25 10:08:30 +08:00
</tr>
<tr>
<td colSpan={3} rowSpan={1} className={styles.fontBold}>发起时间</td>
<td colSpan={3} rowSpan={1}>{SURVEY.LAUNCH_TIME}</td>
<td colSpan={3} rowSpan={1} className={styles.fontBold}>发起部门</td>
<td colSpan={3} rowSpan={1}>{SURVEY.Nav_LaunchDepartment && SURVEY.Nav_LaunchDepartment.NAME}</td>
<td colSpan={3} rowSpan={1} className={styles.fontBold}>发起人员</td>
<td colSpan={3} rowSpan={1}>{SURVEY.Nav_LaunchUser && SURVEY.Nav_LaunchUser.NAME}</td>
<td colSpan={3} rowSpan={1} className={styles.fontBold}>截止时间</td>
<td colSpan={3} rowSpan={1}>{SURVEY.END_TIME}</td>
</tr>
<tr>
<td colSpan={4} rowSpan={1} className={styles.fontBold}>参与人员</td>
<td colSpan={20} rowSpan={1}>{this.getJoinDepartment(SURVEY.Nav_JoinDepartment).join('、')}</td>
</tr>
<tr>
<td colSpan={4} rowSpan={1} className={styles.fontBold}>调查内容</td>
2025-11-26 19:59:48 +08:00
<td colSpan={20} rowSpan={1}>{SURVEY.Nav_Points && SURVEY.Nav_Points.map(it => it.Nav_Point.NAME).join('、')}</td>
2025-08-25 10:08:30 +08:00
</tr>
</>
2025-11-26 19:59:48 +08:00
})
2025-08-25 10:08:30 +08:00
}
<tr>
<td colSpan={24} rowSpan={1} className={styles.fontBold}>答案正确率(百分比)</td>
</tr>
{
2025-11-26 19:59:48 +08:00
data.ROWS && data.ROWS.map((row, ridx) => {
2025-08-25 10:08:30 +08:00
return <tr>
{
2025-11-26 19:59:48 +08:00
row.map((col, cidx) => {
2025-08-25 10:08:30 +08:00
return <td colSpan={cidx == 0 ? TITLE_SPAN : SPAN} rowSpan={1} className={ridx == 0 || cidx == 0 ? styles.fontBold : null}>{col}{ridx == 0 || cidx == 0 ? null : "%"}</td>
})
}
</tr>
2025-11-26 19:59:48 +08:00
})
2025-08-25 10:08:30 +08:00
}
</tbody>
</table>
</>
}
{
2025-11-26 19:59:48 +08:00
!data && !loading && <div style={{ width: '100%', textAlign: 'center' }}> 暂未查到有效数据 </div>
2025-08-25 10:08:30 +08:00
}
</Spin>
</div>
</div>
}
}
export default connect(({ login, app }) => ({ login, app }))(SE005ReportEdit)