import { message } from "antd/lib/index";
import { Button, Popconfirm, Row, Col, Checkbox, Radio, Form, Input, Select, Table, Upload, Icon, PageHeader, Modal } from 'antd';
import React from 'react';
import { initFilter, extendRule, extendInclude, setDataFieldValue, guid, initQueryFilter } from "../../../utils/common";
import ReactToPrint from "react-to-print";
import styles from '../../CustomPages/HI/StepForm.css';
import XLSX from 'xlsx';
import { connect } from 'dva';
import moment from 'moment';
import config from "../../../config";
class OG013ShowPrint extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            data: null,
        };
    };

    componentDidMount() {
        if (window.navigator.userAgent.indexOf("Windows") < 1) {
            this.setState({ isMobile: true })
        }
        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);
        }
    }
    BtnClose = () => {
        if (typeof this.props.data.onCancel != "undefined" && typeof this.props.data.onCancel == 'function')
            this.props.data.onCancel();
    }
    loadData = (dataId) => {
        let json = initFilter(this.props.login.OrgId, '', null, null, null);
        extendRule(json, 'ID', 1, dataId);
        json.OrgType = 2;
        extendInclude(json, 'Nav_User');
        extendInclude(json, 'Nav_LaunchDepartment');
        extendInclude(json, 'Nav_ItemEnum');
        extendInclude(json, 'Nav_FileList.Nav_ImgFile.Nav_File');
        extendInclude(json, 'Nav_Assignee');
        extendInclude(json, 'Nav_ImplementUser');
        extendInclude(json, 'Nav_ImplementDepartment');
        extendInclude(json, 'Nav_InvestigationFileList.Nav_ImgFile.Nav_File');
        json.IgnoreDataRule = true;
        this.props.dispatch({
            type: 'app/getDataByPost',
            payload: json,
            url: 'OG/EmployeeRefuseItemReport/Get',
            onComplete: (ret) => {
                if (!ret)
                    return;
                this.setState({ data: ret });
            }
        });
    }

    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)
    }
    fmtEnum(name, value) {
        const enums = this.props.app.enums;
        if (!enums || !enums[name]) return '';
        return enums[name].enums[value] || '';
    }
    render() {
        const { data } = this.state;
        return <div>
            <div style={{ padding: '10px' }}>
                <ReactToPrint
                    trigger={() => <Button type={'primary'} icon={'printer'} >打印</Button>}
                    content={() => this.componentRef}
                />
                <Button style={{ marginLeft: '8px' }} onClick={() => this.onTableBtnExport()} icon="export" >导出</Button>
            </div>
            <div ref={el => (this.componentRef = el)} id={'tableId' + this.props.data.id} style={{ padding: '20px' }}>
                <h1 style={{ textAlign: 'center' }}>员工拒绝事项上报表</h1>
                <table style={{ width: '100%', textAlign: 'center', borderTop: '1px solid #333', borderLeft: '1px solid #333' }} className={styles.PrintForm}>
                    <tbody>
                        <tr>
                            <td colSpan={2} rowSpan={1} className={styles.fontBold}>上报日期</td>
                            <td colSpan={6} rowSpan={1}>{data ? data.START_TIME : null}</td>
                            <td colSpan={2} rowSpan={1} className={styles.fontBold}>上报员工</td>
                            <td colSpan={6} rowSpan={1}>{data && data.Nav_User ? data.Nav_User.NAME : ''}</td>
                            <td colSpan={2} rowSpan={1} className={styles.fontBold}>所在部门</td>
                            <td colSpan={6} rowSpan={1}>{data && data.Nav_LaunchDepartment ? data.Nav_LaunchDepartment.NAME : ''}</td>
                        </tr>
                        <tr>
                            <td colSpan={2} rowSpan={1} className={styles.fontBold}>拒绝事项名称</td>
                            <td colSpan={22} rowSpan={1}>{data && data.NAME}</td>
                        </tr>
                        <tr>
                            <td colSpan={2} rowSpan={1} className={styles.fontBold}>拒绝事项类别</td>
                            <td colSpan={22} rowSpan={1}>{data && data.Nav_ItemEnum && data.Nav_ItemEnum.NAME}</td>
                        </tr>
                        <tr>
                            <td colSpan={2} rowSpan={1} className={styles.fontBold}>拒绝事项描述</td>
                            <td colSpan={22} rowSpan={1}>{data && data.DESCRIPTION}</td>
                        </tr>
                        <tr>
                            <td colSpan={2} rowSpan={1} className={styles.fontBold}>拒绝事项文件</td>
                            <td colSpan={22} rowSpan={1}>
                                {
                                    data && data.Nav_FileList && data.Nav_FileList.map((item, i) => {
                                        return <a width={'20%'} title={item.Nav_ImgFile.FILE_NAME} target='_blank' href={config.picServerHost + item.Nav_ImgFile.Nav_File.FILE_PATH} >{item.Nav_ImgFile.FILE_NAME} </a>
                                    })
                                }
                            </td>
                        </tr>
                        <tr>
                            <td colSpan={2} rowSpan={1} className={styles.fontBold}>受理人</td>
                            <td colSpan={10} rowSpan={1}>{data && data.Nav_Assignee ? data.Nav_Assignee.NAME : null}</td>
                            <td colSpan={2} rowSpan={1} className={styles.fontBold}>受理状况</td>
                            <td colSpan={10} rowSpan={1}>{data && this.fmtEnum('OGAssigneeStatus', data.ASSIGNEE_STATUS)}</td>
                        </tr>
                        <tr>
                            <td colSpan={2} rowSpan={1} className={styles.fontBold}>受理状况描述</td>
                            <td colSpan={22} rowSpan={1}>{data && data.ASSIGNEE_DESCRIPTION}</td>
                        </tr>
                        <tr>
                            <td colSpan={2} rowSpan={1} className={styles.fontBold}>调查部门</td>
                            <td colSpan={10} rowSpan={1}>{data && data.Nav_ImplementDepartment && data.Nav_ImplementDepartment.NAME}</td>
                            <td colSpan={2} rowSpan={1} className={styles.fontBold}>调查人员</td>
                            <td colSpan={10} rowSpan={1}>{data && data.Nav_ImplementUser && data.Nav_ImplementUser.NAME}</td>
                        </tr>
                        <tr>
                            <td colSpan={2} rowSpan={1} className={styles.fontBold}>调查情况描述</td>
                            <td colSpan={22} rowSpan={1}>{data && data.IMPLEMENT_DESCRIPTION}</td>
                        </tr>
                        <tr>
                            <td colSpan={2} rowSpan={1} className={styles.fontBold}>调查文件</td>
                            <td colSpan={22} rowSpan={1}>
                                {
                                    data && data.Nav_InvestigationFileList && data.Nav_InvestigationFileList.map((item, i) => {
                                        return <a width={'20%'} title={item.Nav_ImgFile.FILE_NAME} target='_blank' href={config.picServerHost + item.Nav_ImgFile.Nav_File.FILE_PATH} >{item.Nav_ImgFile.FILE_NAME} </a>
                                    })
                                }
                            </td>
                        </tr>
                        <tr>
                            <td colSpan={2} rowSpan={1} className={styles.fontBold}>拒绝制度认可</td>
                            <td colSpan={22} rowSpan={1}>{data && this.fmtEnum('OGRefuseSystemApproval', data.SATISFACTION_STATUS)}</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    }
}

export default connect(({ login, app }) => ({ login, app }))(OG013ShowPrint) 