import { Button, Descriptions } from 'antd';
import React from 'react';
import { initFilter, extendRule, extendInclude,extendIgnoreDataRule } from "../../../utils/common";
import ReactToPrint from "react-to-print";
import { ExportToExcel } from '@woowalker/feui'
import XLSX from 'xlsx';
import { connect } from 'dva';
import config from "../../../config.js";


class BS044ShowPrintDOut extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            data: null,
            rules: null,
            BtnAgreeDisplay: 'none',
        };
    };

    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);
        }
    }

    loadData = () => {
        let rulesEmun = this.props.app.enums.BSDelayDaysNoticeEnum.options
        let json = initFilter(this.props.login.OrgId);
        extendRule(json, 'ID', 1, this.props.data.id);
        extendInclude(json, 'Nav_UserDeal');
        extendInclude(json, 'Nav_UserCheck');
        extendInclude(json, 'Nav_UserActualDeal');
        extendInclude(json, 'Nav_SubmitNoticePerson');
        extendInclude(json, 'Nav_UserDeal.Nav_Department');
        extendInclude(json, 'Nav_SubmitContent.Nav_Question');
        extendInclude(json, 'Nav_Files.Nav_ImgFile.Nav_File');
        extendInclude(json, 'Nav_FilesAfter.Nav_ImgFile.Nav_File');
        extendInclude(json, 'Nav_ListUserSign.Nav_ImgFile.Nav_File');
        extendInclude(json, 'Nav_ListCheckUserSign.Nav_ImgFile.Nav_File');
        extendIgnoreDataRule(json)
        this.props.dispatch({
            type: 'app/getDataByPost',
            payload: json,
            url: 'BS/RiskSubmitContentDeal/Get',
            onComplete: (ret) => {
                if (ret) {
                    this.setState({   //设置setState全局变量
                        data: ret,      //将ret对象赋值给data, data供页面调用
                        rules: rulesEmun
                    })
                }
            }
        });
    }

    onTableBtnExport() {
        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, rules } = this.state;
        return <div>
            <div>
                <table>
                    <tbody>
                        <tr>
                            <td><ReactToPrint trigger={() => <Button type={'default'} icon={'printer'} >打印</Button>} content={() => this.componentRef} pageStyle={"#tableId" + this.props.data.id + " { padding:0 40px;} img{width :120px}"} /></td>
                            <td><ExportToExcel fileName='隐患整改记录超时通知整改落实人领导' tableId={'tableId' + this.props.data.id} /></td>
                        </tr>
                    </tbody>
                </table>
            </div>

            {/* 检查表制定 */}
            <div ref={el => (this.componentRef = el)} style={{ padding: '20px', paddingTop: '20px' }} id={'tableId' + this.props.data.id}>
                <h1 style={{ textAlign: 'center', margin: '15px' }}>隐患整改记录超时通知整改落实人领导</h1>
                {
                    //, paddingLeft: '50px' 
                    data ? <div style={{ width: '95%' }}>
                        <Descriptions title="" size="middle" bordered>
                            <Descriptions.Item label="编号">{data.CODE}</Descriptions.Item>
                            <Descriptions.Item label="整改截止时间">{data.ENDDATE}</Descriptions.Item>
                            <Descriptions.Item label="整改部门">{data.Nav_UserDeal.Nav_Department.NAME}</Descriptions.Item>
                            <Descriptions.Item label="整改责任人">{data.Nav_UserDeal.NAME}</Descriptions.Item>
                            <Descriptions.Item label="验收人">{data.Nav_UserCheck.NAME}</Descriptions.Item>
                            <Descriptions.Item label="验收时间">{data.CHCECKTIME}</Descriptions.Item>
                            <Descriptions.Item label="整改落实人">{data.Nav_UserActualDeal.NAME}</Descriptions.Item>
                            <Descriptions.Item label="通知单编号">{data.Nav_SubmitNoticePerson.CODE}</Descriptions.Item>
                            <Descriptions.Item label="检查问题">{data.Nav_SubmitContent.Nav_Question.DESCREPTION}</Descriptions.Item>
                            <Descriptions.Item label="附件（检查前）">{
                                data.Nav_Files && data.Nav_Files.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>
                                })
                            }</Descriptions.Item>
                            <Descriptions.Item label="整改情况描述">{data.DEALDESCRIBE}</Descriptions.Item>
                            {/* <Descriptions.Item label="附件（检查后）">{
                                data.Nav_FilesAfter && data.Nav_FilesAfter.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>
                                })
                            }</Descriptions.Item> */}
                            <Descriptions.Item label="问题等级">{this.props.app.enums.BSQuestionLevelEnum.enums[data.QUESTION_LEVEL]}</Descriptions.Item>
                            {/* <Descriptions.Item label="整改责任人签名">{
                                data.Nav_ListUserSign.map((sign, i) => {
                                    return <img width={'20%'} alt={sign.Nav_User.NAME + "签名"} src={config.picServerHost + sign.Nav_ImgFile.Nav_File.FILE_PATH} />
                                })
                            }</Descriptions.Item>
                            <Descriptions.Item label="完成情况">{this.props.app.enums.BSQuestionLevelEnum.enums[data.DEALSITUATION]}</Descriptions.Item>
                            <Descriptions.Item label="验收人签名">{
                                data.Nav_ListCheckUserSign.map((sign, i) => {
                                    return <img width={'20%'} alt={sign.Nav_User.NAME + "签名"} src={config.picServerHost + sign.Nav_ImgFile.Nav_File.FILE_PATH} />
                                })
                            }</Descriptions.Item> */}

                            <Descriptions.Item label="通知到领导规则" contentStyle='color:red' >{
                                rules.map((item, j) => {
                                    return (j > 0 ? "； " : " ") + "规则" + (j + 1) + "：" + item.label + "：" + item.value + "天"
                                })
                            }</Descriptions.Item>

                        </Descriptions>
                    </div> : null
                }
            </div>
        </div>
    }
}
export default connect(({ login, app }) => ({ login, app }))(BS044ShowPrintDOut) 