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, extendInclude, extendIgnoreDataRule, setDataFieldValue, guid, initQueryFilter, showFiles, showApprove, showUserSign, showUsersSign } 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 OH012ShowPrint 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 orgId = this.props.login ? this.props.login.OrgId : '';
        let json = initFilter(orgId);
        extendRule(json, 'ID', 1, id);
        extendInclude(json, 'Nav_NoticeRegister.Nav_ExamBatch');
        extendInclude(json, 'Nav_NoticeRegister.Nav_User');
        extendInclude(json, 'Nav_OccDiseaseList.Nav_OccDisease');
        extendInclude(json, 'Nav_OccDiseaseList.Nav_OccDiseaseSeverity');
        extendInclude(json, 'Nav_OccDiseaseList.Nav_Files.Nav_ImgFile.Nav_File');
        extendIgnoreDataRule(json)
        this.props.dispatch({
            type: 'app/getDataByPost',
            payload: json,
            url: 'OH/HealthExamResult/Get',
            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 style={{ padding: '10px' }}>
                <table>
                    <tr>
                        <td><Button onClick={() => this.onClickApprove(true)} style={{ marginRight: '8px' }} icon='export'>审批详情</Button></td>
                        <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 ? <div style={{ width: '95%' }}>
                        <Descriptions title='' size='middle' bordered>
                            <Descriptions.Item label="体检批次">{
                                data?.Nav_NoticeRegister?.Nav_ExamBatch.BATCH
                                // data?.Nav_NoticeRegister?.Nav_ExamBatch?.map((item, i) => {
                                //     return (i > 0 ? ',' : '') + item.BATCH
                                // })
                            }

                            </Descriptions.Item>
                            <Descriptions.Item label="体检人员">{data?.Nav_NoticeRegister?.Nav_User.NAME}</Descriptions.Item>
                            <Descriptions.Item label="体检人身份证号">{data?.Nav_User?.ID_CARD}</Descriptions.Item>
                            <Descriptions.Item label="体检结论">{enums.OHHealthExamResultEdit.enums[data.RESULT_ENUM]}</Descriptions.Item>
                            <Descriptions.Item label="结果描述">{data.DESCRIPTION}</Descriptions.Item>
                            <Descriptions.Item label="处理意见">{data.SUGGESTION}</Descriptions.Item>
                        </Descriptions>
                    </div> : null
                }
                {
                    (data?.Nav_OccDiseaseList && data?.Nav_OccDiseaseList.length > 0) ?

                        <table className={styles.PrintFormLight}>
                            <tbody>
                                <tr>
                                    <td colSpan={8} 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>
                                </tr>
                                {data?.Nav_OccDiseaseList?.map((item, i) => {
                                    return <tr>
                                        <td>{item.Nav_OccDisease?.NAME}</td>
                                        <td>{item.DIAGNOSE_AGENCY} </td>
                                        <td>{item.DIAGNOSE_METHOD} </td>
                                        <td>{item.Nav_OccDiseaseSeverity?.NAME}</td>
                                        <td>{item.DESCRIPTION} </td>
                                        <td>{item.OCC_HISTORY} </td>
                                        <td>{enums.YesNoEnum.enums[item.MEDICAL_AID]} </td>
                                        <td>{showFiles(item.Nav_Files, config.picServerHost)} </td>
                                    </tr>
                                })}
                            </tbody>
                        </table>
                        : null
                }
            </div>
        </div>
    }
}
export default connect(({ login, app }) => ({ login, app }))(OH012ShowPrint)

