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 BS044Notice extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            data: 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 json = initFilter(this.props.login.OrgId);
        extendRule(json, 'ID', 1, this.props.data.id);

        extendInclude(json, 'Nav_UserDeal.Nav_UserSignFiles.Nav_ImgFile.Nav_File');
        extendInclude(json, 'Nav_UserDeal.Nav_UserSignFiles.Nav_User');
        extendInclude(json, 'Nav_UserCheck.Nav_UserSignFiles.Nav_ImgFile.Nav_File');
        extendInclude(json, 'Nav_UserActualDeal');
        extendInclude(json, 'Nav_SubmitNoticePerson');
        extendInclude(json, 'Nav_UserDeal.Nav_Department');
        extendInclude(json, 'Nav_SubmitContent.Nav_Question');
        // extendInclude(json, 'Nav_ListUserSign.Nav_User.Nav_UserSignFiles.Nav_ImgFile.Nav_File');
        // extendInclude(json, 'Nav_ListCheckUserSign.Nav_User.Nav_UserSignFiles.Nav_ImgFile.Nav_File');
        extendInclude(json, 'Nav_Files.Nav_ImgFile.Nav_File');
        extendInclude(json, 'Nav_FilesAfter.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供页面调用
                    })
                }
            }
        });
    }

    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")
    }
    sureCheck = () => {
        let json = initFilter(this.props.login.OrgId, this.props.data.id, null, null, null, this.props.data.TaskID);
        // extendRule(json, 'ID', 1, this.props.data.id);
        // extendRule(json, "Parameter1", 1, this.props.data.TaskID)
        this.props.dispatch({
            type: 'app/getDataByPost',
            payload: json,
            url: 'BS/BSRiskSubmit/UpdateActualDealRecord',
            onComplete: (ret) => {
                this.BtnClose()
            }
        });
    }
    BtnClose = () => {
        if (typeof this.props.data.onCancel != "undefined" && typeof this.props.data.onCancel == 'function')
            this.props.data.onCancel();
    }
    render() {
        const { data } = this.state;
        const enums = this.props.data.enums ? this.props.data.enums : this.props.app.enums;;
        return <div>
            <div style={{ padding: '10px' }}>
                <table>
                    <tbody>
                        <tr>
                            <td><ReactToPrint trigger={() => <Button type={'primary'} 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>
                            <td><Button type={'primary'} icon={'save'} onClick={() => this.sureCheck()} >确认</Button>  </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>
                {
                    data ? <div>
                        <Descriptions title="" size="middle" bordered>
                            <Descriptions.Item label="编号">{data.CODE}</Descriptions.Item>
                            <Descriptions.Item label="整改截止时间">{data.Nav_SubmitContent.LastDateUser}</Descriptions.Item>
                            <Descriptions.Item label="整改落实人">{data.Nav_UserActualDeal.NAME}</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_SubmitNoticePerson.CODE}</Descriptions.Item> */}
                            <Descriptions.Item label="完成情况">{enums.DealSituation.enums[data.DEALSITUATION]}</Descriptions.Item>

                            <Descriptions.Item label="检查问题">{data.Nav_SubmitContent != null ? data.Nav_SubmitContent.DESCREPTION : ""}</Descriptions.Item>
                            <Descriptions.Item label="整改建议与措施">{data.Nav_SubmitContent.DEMAND}</Descriptions.Item>
                            <Descriptions.Item label="检查依据">{data.Nav_SubmitContent.PROOF}</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_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.ISDEALSIGN && data.Nav_UserDeal.Nav_UserSignFiles != null && data.Nav_UserDeal.Nav_UserSignFiles.map((item, i) => {
                                    debugger
                                    return <img width={'20%'}  src={config.picServerHost + item.Nav_ImgFile.Nav_File.FILE_PATH} />
                                })

                            }</Descriptions.Item> */}

                            {/* <Descriptions.Item label="验收意见">{data.DEALOPINION}</Descriptions.Item>

                            <Descriptions.Item label="验收人签名">{
                                data.ISCHECKSIGN && data.Nav_UserCheck.Nav_UserSignFiles != null && data.Nav_UserCheck.Nav_UserSignFiles.map((item, i) => {
                                    debugger
                                    return <img width={'20%'} src={config.picServerHost + item.Nav_ImgFile.Nav_File.FILE_PATH} />
                                })

                            }</Descriptions.Item> */}
                        </Descriptions>
                    </div> : null
                }
            </div>
        </div>
    }
}
export default connect(({ login, app }) => ({ login, app }))(BS044Notice) 