import { Checkbox, message, Radio } from "antd/lib/index";
import { Button, Descriptions, Badge, Popconfirm, Row, Col, Form, Input, Select, Table } from 'antd';
import React from 'react';
import { initFilter, extendRule, extendIgnoreDataRule, extendInclude, setDataFieldValue, guid, initQueryFilter, showFiles, showApprove, ShowDateTime } from "../../../utils/common";
import { ExportToExcel } from '@woowalker/feui'
import styles from '../HI/StepForm.css';
import ReactToPrint from "react-to-print";
import moment from 'moment';
import config from "../../../config.js";
import XLSX from 'xlsx';
import { connect } from 'dva';
import FormPage from '../../FormPage'

class AE019ShowPrint extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            data: null,
            item: null,
            btndisplay: 'none',
            ALLTOTAL: 0,
            ALLUSE: 0,
            ALLLEFT: 0
        }
    }

    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' + this.props.record.ID);
        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,
        });
    }

    //审批意见 改变
    NOTJOINREASONCHANGE = (val) => {
        this.state.NOTJOINREASON = val
    }


    //加载数据(传过来的参数都在props里面，包括登录信息)
    loadData = (id) => {
        var orgId = this.props.login ? this.props.login.OrgId : '';   //登录后有存储登录信息
        let json = initFilter(orgId);
        extendRule(json, 'ID', 1, id);
        extendIgnoreDataRule(json)
        this.props.dispatch({
            type: 'app/getDataByPost',
            payload: json,
            url: 'AE/AEAccidentEventReport/LibGet',
            onComplete: (ret) => {    //返回查询结果ret
                this.setState({   //设置setState全局变量
                    data: ret,      //将ret对象赋值给data, data供页面调用
                })
            }
        });
    }

    //渲染页面
    render() {
        const { data, ALLTOTAL, ALLUSE, ALLLEFT } = this.state;
        const enums = this.props.data.enums ? this.props.data.enums : this.props.app.enums;
        return <div>
            <div style={{ padding: '10px' }}>
                <table>
                    <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>
                </table>
            </div>

            <FormPage {...this.state.tmpData} />
            {/* 安全检查 */}
            <div ref={el => (this.componentRef = el)} style={{ padding: '20px', paddingTop: '20px' }} id={'tableId' + this.props.data.id}>
                <h1 className={styles.showPrintHead}>事故事件明细</h1>
                {
                    data?.Report ? <div>
                        <table className={styles.PrintFormLight}>
                            <tbody>
                                {/* <tr>
                                    <td colSpan={4} style={{ fontSize: "25px", color: "#333", margin: "20px 0 20px 0" }}>事故事件原因</td>
                                </tr> */}
                                <tr className={styles.PrintFormLightTh}>
                                    <td>事故事件编号</td>
                                    <td>事故事件名称</td>
                                    <td>事故事件时间</td>
                                    <td>事故事件种类</td>
                                    <td>事故事件等级</td>
                                    <td>事故事件地点</td>
                                    <td>事故类型</td>
                                    {/*事故事件类别 */}
                                    <td>致害物</td>
                                    <td>事故伤亡人数</td>
                                    <td>直接经济损失</td>
                                    <td style={{ maxWidth: "300px" }}>事故事件经过</td>
                                    <td>事故事件部门</td>
                                    <td>事故事件报告人</td>
                                    <td>限制结案时间</td>
                                    <td>实际结案时间</td>
                                    <td>调查报告附件</td>
                                    <td>公示文件附件</td>
                                </tr>
                                <tr >
                                    <td>{data.Report.CODE}</td>
                                    <td>{data.Report.NAME}</td>
                                    <td>{ShowDateTime(data.Report.ACCIDENT_TIME)}</td>
                                    <td>{
                                        data.Report.Nav_ListAccidentListKind.map((item, j) => {
                                            return <p className={styles.pLin}> {item.Nav_AccidentKind.NAME}</p>
                                        })
                                    }</td>
                                    <td>{enums.AEAccidentLevel.enums[data.Report.ACCIDENT_LEVEL]}</td>
                                    <td>{data.Report.ACCIDENT_PLACE}</td>
                                    <td>{
                                        data.Result?.Nav_ListSurveyDamageObject.map((item, j) => {
                                            // return (j > 0 ? "，" : "") + item.Nav_DamageObject.NAME
                                            return <p className={styles.pLin}> {item.Nav_DamageObject.NAME}</p>
                                        })
                                    }</td>
                                    <td>{data.Report.Nav_AccidentType.NAME} </td>
                                    <td>{data.Result?.CASUALTY_COUNT}</td>
                                    <td>{data.Report.ECONOMIC_LOSSES}</td>
                                    <td>{data.Result?.ACCIDENT_COURSE}</td>
                                    <td>{data.Report.Nav_Department.NAME}</td>
                                    <td>{data.Report.Nav_User.NAME}</td>
                                    <td>{ShowDateTime(data.Result?.SYSTEMMAXTIME)}</td>
                                    <td>{ShowDateTime(data.Result?.TIME)}</td>
                                    <td style={{ maxWidth: '100px' }} >{
                                        showFiles(data.Result?.Nav_FilesSurvey, config.picServerHost)
                                    }</td>
                                    <td style={{ maxWidth: '100px' }} >{
                                        showFiles(data.Result?.Nav_FilesP, config.picServerHost)
                                    }</td>
                                </tr>

                            </tbody>
                        </table>
                    </div> : null
                }

                {/* <Descriptions title="" size="middle" bordered>
                            <Descriptions.Item label="事故事件编号">{data.Nav_AccidentEventReport.CODE}</Descriptions.Item>
                            <Descriptions.Item label="事故事件名称">{data.Nav_AccidentEventReport.NAME}</Descriptions.Item>
                            <Descriptions.Item label="事故事件时间">{data.Nav_AccidentEventReport.ACCIDENT_TIME}</Descriptions.Item>
                            <Descriptions.Item label="事故事件地点">{data.Nav_AccidentEventReport.ACCIDENT_PLACE}</Descriptions.Item>
                            <Descriptions.Item label="事故事件种类">{
                                data.Nav_AccidentEventReport?.Nav_ListAccidentListKind?.map((item, i) => {
                                    return (i > 0 ? "，" : "") + item.Nav_AccidentKind.NAME
                                })
                            }</Descriptions.Item>
                            <Descriptions.Item label="事故事件类型">{data.Nav_AccidentEventReport.Nav_AccidentType.NAME}</Descriptions.Item>
                            <Descriptions.Item label="事故事件等级">{enums.AEAccidentLevel.enums[data.Nav_AccidentEventReport.ACCIDENT_LEVEL]}</Descriptions.Item>
                            <Descriptions.Item label="致害物">{
                                data.Nav_ListSurveyDamageObject?.map((item, i) => {
                                    return (i > 0 ? "，" : "") + item.Nav_DamageObject.NAME
                                })
                            }</Descriptions.Item>
                            <Descriptions.Item label="事故伤亡人数">{data.CASUALTY_COUNT}</Descriptions.Item>
                            <Descriptions.Item label="直接经济损失（元）">{data.ECONOMIC_LOSSES}</Descriptions.Item>
                            <Descriptions.Item label="事故事件经过">{data.ACCIDENT_COURSE}</Descriptions.Item>
                            <Descriptions.Item label="限制结案时间">{data.SYSTEMMAXTIME}</Descriptions.Item>
                            <Descriptions.Item label="实际结案时间">{data.TIME}</Descriptions.Item>
                            <Descriptions.Item label="调查报告附件">{
                                showFiles(data.Nav_FilesSurvey, config.picServerHost)
                            }</Descriptions.Item>
                            <Descriptions.Item label="公示文件附件">{
                                showFiles(data.Nav_FilesP, config.picServerHost)
                            }</Descriptions.Item>
                            <Descriptions.Item label="隐患上报表单">{data.Nav_RiskSubmit?.CODE}</Descriptions.Item>
                            <Descriptions.Item label="审批意见">{
                                showApprove(data.Nav_Approve?.Nav_ApproveDetails, this.props.app.enums.NodeApproveStatus.enums, config.picServerHost)
                            }</Descriptions.Item>
                        </Descriptions> */}

                {
                    <table className={styles.PrintFormLight}>
                        <tbody>
                            <tr>
                                <td colSpan={4} className={styles.showPrintHead2}>事故事件原因</td>
                            </tr>
                            <tr className={styles.PrintFormLightTh}>
                                <td>序号</td>
                                <td>直接/间接原因</td>
                                <td>原因类别</td>
                                <td>原因分析</td>
                            </tr>
                            {data?.Result?.Nav_ListReason ? data.Result.Nav_ListReason.map((item, i) => {
                                return <tr>
                                    <td>{i + 1}</td>
                                    <td>{enums.AEReasonModel.enums[item.REASON_MODEL]} </td>
                                    <td>{item.Nav_ListReasonType?.map((itemtype, j) => {
                                        return (j > 0 ? "，" : "") + itemtype.Nav_ReasonType.NAME
                                    })}</td>
                                    <td>{item.REASON_ANALYZE} </td>
                                </tr>
                            }) : <tr><td colSpan={4}>暂无数据</td></tr>}

                        </tbody>
                    </table>
                }

                {
                    <table className={styles.PrintFormLight}>
                        <tbody>
                            <tr>
                                <td colSpan={4} className={styles.showPrintHead2}>调查取证资料</td>
                            </tr>
                            <tr className={styles.PrintFormLightTh}>
                                <td>序号</td>
                                <td>证据来源</td>
                                <td>证据描述</td>
                                <td>附件（证据）</td>
                            </tr>
                            {data?.Result?.Nav_ListForensics ? data.Result.Nav_ListForensics.map((item, i) => {
                                return <tr>
                                    <td>{i + 1}</td>
                                    <td>{enums.AEEvidenceSource.enums[item.EVIDENCE_SOURCE]} </td>
                                    <td>{item.EVIDENCE_DESC} </td>
                                    <td>{
                                        showFiles(item.Nav_FilesSurvey, config.picServerHost)
                                    } </td>
                                </tr>
                            }) : <tr><td colSpan={4}>暂无数据</td></tr>}
                        </tbody>
                    </table>
                }


                {
                    <table className={styles.PrintFormLight}>
                        <tbody>
                            <tr>
                                <td colSpan={5} className={styles.showPrintHead2}>设备设施损失信息</td>
                            </tr>
                            <tr className={styles.PrintFormLightTh}>
                                <td>序号</td>
                                <td>设备/设施名称</td>
                                <td>规格型号</td>
                                <td>责任人员</td>
                                <td>损失情况</td>
                            </tr>
                            {data?.Result?.Nav_ListEquipmentLoss ? data.Result.Nav_ListEquipmentLoss.map((item, i) => {
                                return <tr>
                                    <td>{i + 1}</td>
                                    <td>{item.MACHINE_NAME} </td>
                                    <td>{item.SPEC} </td>
                                    <td>{item.USER_NAME} </td>
                                    <td>{item.LOSS_CONDITION} </td>
                                </tr>
                            }) : <tr><td colSpan={5}>暂无数据</td></tr>}
                        </tbody>
                    </table>
                }
                {
                    <table className={styles.PrintFormLight}>
                        <tbody>
                            <tr>
                                <td colSpan={15} className={styles.showPrintHead2}>人员伤亡信息</td>
                            </tr>
                            <tr className={styles.PrintFormLightTh}>
                                <td>序号</td>
                                <td>姓名</td>
                                <td>受伤时间</td>
                                <td>受伤部位/疾病名称</td>


                                <td>就诊医院</td>
                                <td>是否住院</td>
                                <td>员工报销金额（元）</td>
                                <td>社保报销金额（元）</td>
                                <td>工伤认定时间</td>
                                <td>工伤认定机构</td>
                                <td>伤残等级</td>
                                <td>伤残鉴定时间</td>
                                <td>伤残鉴定机构</td>
                                <td>备注</td>
                                <td>相关附件</td>

                            </tr>
                            {data?.Result?.Nav_ListCasualties ? data.Result.Nav_ListCasualties.map((item, i) => {
                                return <tr>
                                    <td>{i + 1}</td>
                                    <td>{item.Nav_User.NAME} </td>
                                    <td>{ShowDateTime(item.INJURED_TIME)} </td>
                                    <td>{item.INJURED_AREA} </td>
                                    {/* Nav_ClaimRecord */}
                                    <td>{item.Nav_ClaimRecord?.HOSPITAL} </td>
                                    <td>{enums.YesNoEnum.enums[item.Nav_ClaimRecord?.IN_HOSPITAL]} </td>
                                    <td>{item.Nav_ClaimRecord?.USER_CLAIM_AMOUNT} </td>
                                    <td>{item.Nav_ClaimRecord?.INSURANCE_CLAIM_AMOUNT} </td>
                                    <td>{ShowDateTime(item.Nav_ClaimRecord?.INJURE_AFFIRM_TIME)} </td>
                                    <td>{item.Nav_ClaimRecord?.INJURE_AFFIRM_AGENCY} </td>
                                    <td>{enums.TIDisabilityLevelEnum.enums[item.Nav_ClaimRecord?.DISABILITY_LEVEL]} </td>

                                    <td>{ShowDateTime(item.Nav_ClaimRecord?.DISABILITY_AFFIRM_TIME)} </td>
                                    <td>{item.Nav_ClaimRecord?.DISABILITY_AFFIRM_AGENCY} </td>
                                    <td>{item.Nav_ClaimRecord?.REMARK} </td>
                                    <td>{
                                        showFiles(item.Nav_ClaimRecord?.Nav_Files, config.picServerHost)
                                    } </td>
                                </tr>
                            }) : <tr><td colSpan={15}>暂无数据</td></tr>}
                        </tbody>
                    </table>
                }
                {
                    <table className={styles.PrintFormLight}>
                        <tbody>
                            <tr>
                                <td colSpan={5} className={styles.showPrintHead2}>行政处罚信息
                                </td>
                            </tr>
                            <tr className={styles.PrintFormLightTh}>
                                <td>序号</td>
                                <td>责任部门</td>
                                <td>处理人</td>
                                <td>处罚结果</td>
                                <td>处罚原因</td>
                            </tr>
                            {data?.Result?.Nav_ListAdmPunishment ? data.Result.Nav_ListAdmPunishment.map((item, i) => {
                                return <tr>
                                    <td>{i + 1}</td>
                                    <td>{item.Nav_Department.NAME} </td>
                                    <td>{item.Nav_User.NAME} </td>
                                    <td>{item.PUNISHMENT_RESULT} </td>
                                    <td>{item.PUNISHMENT_REASON} </td>
                                </tr>
                            }) : <tr><td colSpan={5}>暂无数据</td></tr>}
                        </tbody>
                    </table>
                }
            </div>
        </div>
    }
}
export default connect(({ login, app }) => ({ login, app }))(AE019ShowPrint) 