import { Button, Descriptions, Badge, Popconfirm, Row, Col, Form, Input, Select, Table } from 'antd';
import React from 'react';
import { initFilter, extendRule, extendInclude, setDataFieldValue, showApprove, guid, initQueryFilter, ShowDateTime, showUsersSign, 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 '../../../components/CustomPages/HI/StepForm.css';
import config from '../../../config.js';
import FormPage from '../../FormPage'
class TL044ShowPrint 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, 'ID', 1, id);
        // extendInclude(json, 'Nav_Tailing')
        this.props.dispatch({
            type: 'app/getDataByPost',
            payload: json,
            url: 'TL/TLWatchSum/GetALL',
            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><ReactToPrint trigger={() => <Button type={'default'} icon={'printer'} >打印</Button>} content={() => this.componentRef} /></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.TAILING_NAME}</Descriptions.Item>
                            <Descriptions.Item label="日期">{data.DATE?.split(' ')[0]}</Descriptions.Item>
                        </Descriptions>
                    </div> : null
                }

                <table className={styles.PrintFormLight}>
                    <tbody>
                        <tr>
                            <td colSpan={8} className={styles.showPrintHead2}>日常观测记录</td>
                        </tr>
                        <tr className={styles.PrintFormLightTh}>
                            <td>序号</td>
                            <td>观测时间（时）</td>
                            <td>干滩长度/m</td>
                            <td>库水位/m</td>
                            <td>降雨量/mm</td>
                            <td>滩顶高程/m</td>
                            <td>安全超高/m</td>
                            <td>观测人</td>
                        </tr>
                        {
                            data && data.Nav_ListDetailDayly && data.Nav_ListDetailDayly.length > 0 ?
                                data.Nav_ListDetailDayly.map((item, i) => {
                                    return <tr>
                                        <td>{i + 1} </td>
                                        <td>{item.DATE?.split(' ')[1]} </td>
                                        <td>{item.LONG} </td>
                                        <td>{item.WATERLINE} </td>
                                        <td>{item.DREEP} </td>
                                        <td>{item.HIGHTEST} </td>
                                        <td>{item.HIGHT_MORE} </td>
                                        <td>{item.Nav_ListUser?.map((itemtype, j) => { return (j > 0 ? '，' : '') + itemtype.Nav_User.NAME })}</td>
                                    </tr>
                                })
                                :
                                <tr><td colSpan={8}>查无数据</td></tr>
                        }
                        {
                            data && data.Nav_ListSignDayly && data.Nav_ListSignDayly.length > 0 ?
                                <tr >
                                    <td > 观测人签名 </td>
                                    <td colSpan={7} style={{ textAlign: "left" }}> {showUsersSign(data.Nav_ListSignDayly, config.picServerHost, 200)}</td>
                                </tr>
                                : null
                        }
                    </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 && data.Nav_ListDetailPercent && data.Nav_ListDetailPercent.length > 0 ?
                                data.Nav_ListDetailPercent.map((item, i) => {
                                    return <tr>
                                        <td>{i + 1} </td>
                                        <td>{item.DATE?.split(' ')[1]} </td>
                                        <td>{item.INT_PERCENT} </td>
                                        <td>{item.OUT_PERCENT} </td>
                                        <td>{item.Nav_ListUser?.map((itemtype, j) => { return (j > 0 ? '，' : '') + itemtype.Nav_User.NAME })}</td>
                                    </tr>
                                })
                                : <tr><td colSpan={5}>查无数据</td></tr>
                        }
                        {
                            data && data.Nav_ListSignPercent && data.Nav_ListSignPercent.length > 0 ?
                                <tr >
                                    <td > 观测人签名 </td>
                                    <td colSpan={7} style={{ textAlign: "left" }}> {showUsersSign(data.Nav_ListSignPercent, config.picServerHost, 200)}</td>
                                </tr>
                                : null
                        }
                    </tbody>
                </table>

                <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>原坐标X/Y/Z</td>
                            <td>观测点号</td>
                            <td>观测值X/Y/Z</td>
                            <td>变化量△X/△Y/△Z</td>
                            <td>观测人</td>
                        </tr>
                        {

                            data && data.Nav_ListDetailMovd && data.Nav_ListDetailMovd.length > 0 ?
                                data.Nav_ListDetailMovd.map((item, i) => {
                                    return <tr>
                                        <td>{i + 1} </td>
                                        <td>{item.DATE?.split(' ')[1]} </td>
                                        <td>{item.Nav_WatchMovePoint?.NAME_BASE}</td>
                                        <td>{item.Nav_WatchMovePoint?.POINT_BASE} </td>
                                        <td>{item.Nav_WatchMovePoint?.NAME_WATCH} </td>
                                        <td>{item.LOOKPOINT} </td>
                                        <td>{item.CHANGELOOKPOINT} </td>
                                        <td>{item.Nav_ListUser?.map((itemtype, j) => { return (j > 0 ? '，' : '') + itemtype.Nav_User.NAME })}</td>
                                    </tr>
                                })
                                : <tr><td colSpan={8}>查无数据</td></tr>
                        }
                        {
                            data && data.Nav_ListSignMovd && data.Nav_ListSignMovd.length > 0 ?
                                <tr >
                                    <td > 观测人签名 </td>
                                    <td colSpan={7} style={{ textAlign: "left" }}> {showUsersSign(data.Nav_ListSignMovd, config.picServerHost, 200)}</td>
                                </tr>
                                : null
                        }
                    </tbody>
                </table>

                <table className={styles.PrintFormLight}>
                    <tbody>
                        <tr>
                            <td colSpan={7} className={styles.showPrintHead2}>浸润线观测记录</td>
                        </tr>
                        <tr className={styles.PrintFormLightTh}>
                            <td>序号</td>
                            <td>观测时间（时）</td>
                            <td>位置</td>
                            <td>孔号</td>
                            <td>孔深</td>
                            <td>浸润线埋深/m</td>
                            <td>观测人员</td>
                        </tr>
                        {
                            data && data.Nav_ListDetailLine && data.Nav_ListDetailLine.length > 0 ?
                                data.Nav_ListDetailLine.map((item, i) => {
                                    return <tr>
                                        <td>{i + 1} </td>
                                        <td>{item.DATE?.split(' ')[1]} </td>
                                        <td>{item.Nav_WatchLinePoint?.LOCATION}</td>
                                        <td>{item.Nav_WatchLinePoint?.POINT_NO} </td>
                                        <td>{item.Nav_WatchLinePoint?.POINT_DEEP} </td>
                                        <td>{item.DEEP} </td>
                                        <td>{item.Nav_ListUser?.map((itemtype, j) => { return (j > 0 ? '，' : '') + itemtype.Nav_User.NAME })}</td>
                                    </tr>
                                })
                                : <tr><td colSpan={7}>查无数据</td></tr>
                        }
                        {
                            data && data.Nav_ListSignLine && data.Nav_ListSignLine.length > 0 ?
                                <tr >
                                    <td > 观测人签名 </td>
                                    <td colSpan={7} style={{ textAlign: "left" }}> {showUsersSign(data.Nav_ListSignLine, config.picServerHost, 200)}</td>
                                </tr>
                                : null
                        }
                    </tbody>
                </table>

            </div>
        </div>
    }
}
export default connect(({ login }) => ({ login }))(TL044ShowPrint) 
