import { Button, Descriptions, Badge, Popconfirm, Row, Col, Form, Input, Select, Table } from 'antd';
import React from 'react';
import { initFilter, extendRule, extendIgnoreDataRule, extendInclude, setDataFieldValue, showApprove, guid, initQueryFilter, ShowDateTime, ShowPrintClose, showFiles } from '../../../utils/common';
import ReactToPrint from 'react-to-print';
import { ExportToExcel } from '@woowalker/feui'
import XLSX from 'xlsx';
import { connect } from 'dva';
import moment from 'moment';
import { message } from 'antd/lib/index';
import styles from '../HI/StepForm.css';
import config from '../../../config.js';
import FormPage from '../../FormPage'
class DM002ShowPrintCheck extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            data: null,
            btndisplay: 'none',
            isCheck: 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);
        }
    }

    onTableBtnExport() {
        let TableWrap = document.getElementById('table1');
        let Table = TableWrap.getElementsByTagName('table1')[0];
        const wb = XLSX.utils.table_to_book(Table);
        XLSX.writeFile(wb, this.props.record.Nav_Department.NAME + '.xlsx')

    }

    onClickApprove = (appVisible) => {
        const newtmpData = {
            data: { id: this.props.data.id, isShow: true, key: guid(), param: this.props.data.param, appVisible: appVisible, BtnAgreeDisplay: 'none' },
            formCode: 'PF123',
        }
        this.setState({
            tmpData: newtmpData,
        });
    }
    loadData = (id) => {
        var isCheck = (this.props.data.tableKey != undefined && this.props.data.tableKey == '1') ? true : false
        var orgId = this.props.login ? this.props.login.OrgId : '';
        let json = initFilter(orgId);
        extendRule(json, 'BASECHECK_ID', 1, id);
        extendIgnoreDataRule(json)
        this.props.dispatch({
            type: 'app/getDataByPost',
            payload: json,
            url: 'DM/DMDeviceCheckDetail/EntitiesShow',
            onComplete: (ret) => {
                if (ret) {
                    this.setState({
                        data: ret
                    })
                }
            }
        });
    }

    render() {
        const { data } = this.state;
        const enums = this.props.data.enums ? this.props.data.enums : this.props.app.enums;
        return <div>
            <div ref={el => (this.componentRef = el)} style={{ padding: '20px', paddingTop: '20px' }} id={'tableId' + this.props.data.id}>
                {/* <h1 className={styles.showPrintHead}> {(data == null || data.Nav_DeviceCheck == null) ? "设备设施检查记录" : (data.Nav_DeviceCheck.CHECKTYPE == 10 ? "设备设施点检记录" : "设备设施巡检记录")}</h1> */}
                <h1 className={styles.showPrintHead}>设备设施检查记录</h1>
                {
                    <table className={styles.PrintFormLight}>
                        <tbody>
                            <tr className={styles.PrintFormLightTh}>
                                {/* <td>{(data != null && data.Nav_DeviceCheck != null) ? (data.Nav_DeviceCheck.CHECKTYPE == 10 ? "点检时间" : "巡检时间") : "检查时间"} </td> */}
                                <td>检查时间 </td>
                                <td>检查结论</td>
                                <td>问题描述</td>
                            </tr>
                            {data?.map((item, i) => {
                                return <tr>
                                    <td>{item.CREATE_TIME} </td>
                                    <td>{enums.CheckResult.enums[item.CHECK_VALUE]} </td>
                                    <td>{item.DESCRIPTION} </td>
                                </tr>
                            })}
                        </tbody>
                    </table>
                }
            </div>
        </div>
    }
}
export default connect(({ login, app }) => ({ login, app }))(DM002ShowPrintCheck) 
