// 手术医嘱录入
import React, { Component } from 'react';
import { Row, Col } from 'antd';
import { Util } from 'tools/index';
import DoctorDiag from './DoctorDiag.jsx'
import DoctorAdviceStepPage from 'pages/workstation/component/DoctorAdviceStepPage';
import './style/OperationSearch.less';
import PatientInfo from '../Patient/PatientInfo';
let patientData = {};

export default class OperationApplyDoctor extends Component {
    constructor(props) {
        super(props);
        this.ComponentName = "";
        patientData = window.sessionStorage.patientData ? JSON.parse(window.sessionStorage.patientData) : {};
        this.state = {
            leftspan: 5,
            rightspan: 19,
            patient: "",
            admID: "",
            patID: "",
            iconType: "double-left",
            child: "",
        }
    }

    //组件渲染完成前触发事件
    componentDidMount() {
        if (this.props.location) {
            if (this.props.location.state) {
                this.ComponentName = this.props.location.state.ComponentName ? this.props.location.state.ComponentName : "";
            } else {
                this.ComponentName = this.getQueryString("ComponentName") || './DoctorDiag.jsx';
            }
        } else {
            this.ComponentName = this.getQueryString("ComponentName");
        }
        if (this.ComponentName === "") return
    }

    getQueryString = (name) => {
        var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
        var r = this.props.location.search.substr(1).match(reg);
        if (r != null) {
            return decodeURIComponent(r[2]);
        }
        return null;
    }

    onBtnClick = () => {
        this.setState({
            leftspan: 5 - this.state.leftspan,
        });
    }

    updateState = (state) => {
        this.setState(state);
    }

    onClose = () => {
        this.setState({
            visible: true,
        });
    }

    onRef = (ref) => {
        this.setState({
            child: ref
        })
    }

    render() {
        return (
            <div style={{ height: "100%" }} className="operationSearch">
                <Row style={{ border: "2px solid #cccccc", height: "100%", width: "100%", overflowY: "hidden" }}>
                    <Col className={this.state.iconType == "double-left" ? "" : "visibleIcon"} span={this.state.leftspan}
                        style={{ border: this.state.iconType == "double-left" ? "1px solid #cccccc" : "0px", height: "100%", overflowY: 'hidden', background: '#ffffff', boxSizing: 'border-box' }}>
                        {this.ComponentName != "" ? <DoctorDiag child={this.state.child} updateState={this.updateState} iconType={this.state.iconType} /> : ""}
                    </Col>
                    <Col span={this.state.rightspan} style={{ height: '100%' }}>
                        <Row style={{ width: '100%', height: '45px', textAlign: 'center', lineHeight: '45px', borderBottom: '1px solid #cccccc' }}>
                            <PatientInfo admID={(this.state.admID) && (!Util.isEmpty(this.state.admID)) ? this.state.admID : patientData.admID ? patientData.admID : ''} />
                        </Row>
                        <Row>
                            {<DoctorAdviceStepPage
                                billingDoctor="Y"
                                iconType={this.state.iconType}
                                patient={this.state.patient}
                                updateState={this.updateState}
                                admID={this.state.admID}
                                onRef={this.onRef} />}
                        </Row>
                    </Col>
                </Row>
            </div>
        )
    }
}