/**
 * 诊断录入tabs 住院医生站
 */
import React from 'react';
import {
    Card, Input, Select, Tree, Radio, Steps, Icon, Divider, Modal, Tooltip
} from 'antd';
import store from 'store';
import moment from 'moment';
import { Util, dayFormat } from 'tools/index';
import { $http } from 'containers/config/https';
import asyncComponent from '../../routers/AsyncComponent.js';

import Drag from './component/Drag';
import HospitalPatientPage from './HospitalPatientPage';
// import Discharge from 'pages/nurse/Discharge/Discharge';
import CMOrderSave from 'pages/workstation/component/CMOrderSave';
import ShowPatientListModal from './component/ShowPatientListModal';
import PatientCourseInfo from 'pages/nurse/Patient/PatientCourseInfo.jsx';
import PatientsClinicalTabPane from './component/PatientsClinicalTabPane';
import ShowExamineModal from "../workstation/component/ShowExamineModal";
import EntryApplicationForm from 'pages/workstation/component/EntryApplicationForm';
import ShowCommonNavigationPage from 'pages/workstation/component/ShowCommonNavigationPage';
import PatientBlacklist from './component/PatientBlacklist';
import './style/index.less';
import 'pages/nurse/BedChart/CSS/bedchart.less';

const icon_name = require('pages/workstation/image/img/icon_name.png');
const icon_name_blocklist = require('pages/workstation/image/img/icon_name_blocklist.png');
const icon_gender = require('pages/workstation/image/img/icon_gender.png');
const icon_expense = require('pages/workstation/image/img/icon_expense.png');
const icon_icon = require('pages/workstation/image/img/icon_icon.png');

const { Step } = Steps;
const { TreeNode } = Tree;
const Option = Select.Option;
const confirm = Modal.confirm;
class DiagnosisTabs extends React.Component {
    constructor(props) {
        super(props)
        var patientData = JSON.parse(sessionStorage.getItem('patientData'));
        var userData = JSON.parse(sessionStorage.getItem('userData'));
        let EMRIP = window.location && (window.location.host.indexOf('localhost') !== -1 || window.location.host.indexOf('127.0.0.1') !== -1) ? 'https://172.16.1.6/EMR' : (window.location.protocol + '//' + window.location.host + '/EMR');
        var date = new Date()
        this.state = {
            dataSource: [],
            total: 0,
            page: 1,
            pageSize: 10,
            patientData: patientData,
            userData: userData,
            visible: false,
            openKeys: [],
            defaultValue: '1',
            defaultDate: true,
            dateTo: moment(date).format(dayFormat),
            dateFrom: moment(new Date(date.getTime() - 144 * 60 * 60 * 1000)).format(dayFormat),
            EMRIP,
        }
    }

    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;
    }

    componentDidMount() {
        var updatePatNo = sessionStorage.getItem('updatePatNo')
        this.loadPatientMsg()//获取接诊病人信息
        this.loadPatientListData()
        this.loadBedData()
        this.loadPatientList()
        this.initData()
        this.loadModuleData()
        this.loadStepComponent()
        this.loadCommonModal()
        if (!Util.isEmpty(updatePatNo)) {
            this.loadUpdateMessage()//获取修改病人信息
        }
        setTimeout(() => {
            this.importJquery();
            this.importService();
        }, 1000)
    }

    componentWillUnmount() {
        store.dispatch({
            type: "inpatientListQueryCriteria",
            value: {}
        });
        // 清除子组件需要销毁的状态
        // this.Discharge && this.Discharge.handleClearComponentInformation && this.Discharge.handleClearComponentInformation();
        this.setState = (state, callback) => {
            return;
        };
    }

    // 病历资源文件预加载 - jq文件
    importJquery = () => {
        let jqDOM = document.getElementById('emr-jquery');
        if (!jqDOM) {
            let script = document.createElement('script');
            script.async = true;
            script.type = 'text/javascript';
            script.id = 'emr-jquery';
            script.src = `${this.state.EMRIP}/jquery/jquery-1.7.2.min.js`;
            document.head.appendChild(script);
        }
    }

    // 病历资源文件预加载 - 病历主文件
    importService = () => {
        let serviceDOM = document.getElementById('emr-service');
        if (!serviceDOM) {
            let script = document.createElement('script');
            script.async = true;
            script.id = 'emr-service';
            script.type = 'text/javascript';
            script.src = `${this.state.EMRIP}/DemoDocumentImageService.aspx?js=1`;
            document.head.appendChild(script);
        }
    }

    loadCommonModal() {
        let data = {
            params: [{
                compontName: "DoctorAdviceModal",
                type: "C",
                reactCode: ['DoctorAdviceModal']
            }]
        }
        $http.post('urlDeault', this, {
            code: "01040073",
            data: data,
            success: (res) => {
                if (+res.errorCode === 0) {
                    this.setState({
                        localeProvider: this.state.userData.language == 'EN' ? res.result.language.EN : res.result.language.CN
                    })
                }
            }
        })
    }

    //国际化
    setMessage(name, message) {
        return this.state.localeProvider && this.state.localeProvider[name] ? this.state.localeProvider[name][message] : ''
    }

    //获取动态step组件
    loadStepComponent() {
        var params = {
            params: [{
                locID: this.state.userData.locID,
                hospID: this.state.userData.hospID,
                groupID: this.state.userData.groupID
            }]
        }
        $http.post('urlDeault', this, {
            code: "03050093",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    var data = res.result;
                    var code = ''
                    if (!Util.isEmpty(data)) {
                        for (var i = 0; i < data.length; i++) {
                            if (!Util.isEmpty(data[i].defaultFlag) && data[i].defaultFlag == 'Y') {
                                code = data[i]
                                break;
                            }
                        }
                    }
                    this.setState({
                        dataSource: res.result,
                        componentSource: code
                    })
                }
            }
        });
    }

    initData() {
        this.columns = [
            {
                title: 'id',
                dataIndex: 'patSeqNo',
                width: 100,
                align: 'left',
                render: (text, data) => {
                    return <span>
                        <span>{data.locDesc}</span><Divider type="vertical" />
                        <span>{data.bedNo}</span><Divider type="vertical" />
                        <span>{data.patNo}</span><Divider type="vertical" />
                        <span>{data.patName}</span><Divider type="vertical" />
                        <span>{data.patSexDesc}</span><Divider type="vertical" />
                        <span>{data.patAge}</span>
                    </span>
                }
            }
        ]
    }

    loadModuleData() {
        var params = {
            params: [{
                orderTemplTypeFlag: '1'
            }]
        }
        $http.post('urlS', this, {
            code: '03050017',
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.setState({
                        moduleData: res.orderTemplType,
                        defaultTemplTypeID: res.defaultTemplTypeID
                    }, () => {
                        this.loadTemplateData()
                    })
                }
            }
        })
    }

    /**
    * @shizi: noCheckDetailFlag为Y不返回dataList明细数据，解决数据过多时接口返回很慢
    * Create 2021-06-13
    */
    loadTemplateData() {
        var params = {
            params: [{
                input: this.state.templateInput,
                templetCatCode: '01',
                templetTypeID: this.state.radioValue ? this.state.radioValue : this.state.defaultTemplTypeID,
                noCheckDetailFlag: 'Y'
            }],
        }
        $http.post('urlDeault', this, {
            code: "03050023",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.setState({
                        templateData: res.result
                    })
                }
            }
        });
    }

    loadPatientListData() {
        var params = {
            params: [{
                locID: this.state.userData.locID
            }]
        }
        $http.post('urlDeault', this, {
            code: "03060003",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.setState({
                        admStatusList: res.admStatusList,
                        wardList: res.wardList,
                        medGroupList: res.medGroupList,
                        levelList: res.levelList,
                        otherConditionList: res.otherConditionList
                    })
                }
            }
        });
    }

    loadBedData() {
        var params = {
            params: [{
                locID: this.state.userData.locID,
                admStatusCode: this.state.admStatusCode,
                wardID: this.state.wardID
            }]
        }
        $http.post('urlDeault', this, {
            code: "03060005",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.setState({
                        bedData: res.data
                    })
                }
            }
        });
    }

    loadUpdateMessage(id) {
        var updatePatNo = sessionStorage.getItem('updatePatNo')
        var params = {
            params: [{
                input: id ? id : (updatePatNo ? updatePatNo : ''),
            }],
            pagination: [{
                pageSize: 10,
                currentPage: 1,
            }]
        }
        $http.post('urlDeault', this, {
            code: "03050086",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    if (!Util.isEmpty(res.result)) {
                        let patData = res.result?.Data || [];
                        let updateMessage = patData && patData.length > 0 ? patData[0] : {}
                        sessionStorage.setItem('updateMessage', JSON.stringify(updateMessage));
                        this.setState({
                            updateMessage,
                        })
                    }
                }
            }
        });
    }

    loadPatientMsg(data) {
        var patientData = JSON.parse(sessionStorage.getItem('patientData'));
        var params = {
            params: [{
                patID: patientData ? patientData.patID : '',
                admID: data ? data : '',
                locID: this.state.userData.locID,
                userID: this.state.userData.userID
            }]
        }
        $http.post('urlDeault', this, {
            code: "03050021",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    sessionStorage.setItem('titleData', JSON.stringify(res.data))
                    this.setState({
                        titleData: res.data,
                        codeID: data ? data : ''
                    })
                }
            }
        });
    }

    loadPatientList() {
        var params = {
            params: [{
                locID: this.state.userData.locID,
                userID: this.state.userData.userID
            }]
        }
        $http.post('urlDeault', this, {
            code: "03060006",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.setState({
                        patientList: res.data
                    })
                }
            }
        });
    }

    changeTabs(e) {
        this.setState({
            activeTab: e,
            adviceList: {}
        })
    }

    onClose() {
        this.setState({
            visible: false
        })
    }

    showDrawer() {
        this.setState({
            visible: true
        })
    }

    showSearchMsg() {
        //取反，显示隐藏查询条件
        if (this.state.showMsg) {
            this.setState({
                showMsg: false
            })
        } else {
            this.setState({
                showMsg: true
            })
        }
    }

    changeRadio(e) {
        this.setState({
            radioValue: e.target.value
        }, () => {
            this.loadTemplateData()
        })
    }

    handleGoback() {
        this.props.history.push('./03060002');
    }

    loadSunTemplate(data) {
        var sunData = []
        data && data.map((item, index) => {
            // if(item.data) {
            sunData.push(<TreeNode title={<span>
                <span>{item.locDesc}</span><Divider type="vertical" />
                <span>{item.bedNo}</span><Divider type="vertical" />
                <span>{item.patNo}</span><Divider type="vertical" />
                <span>{item.patName}</span><Divider type="vertical" />
                <span>{item.patSexDesc}</span><Divider type="vertical" />
                <span>{item.patAge}</span>
            </span>} nodeId={item.indexId}
                key={item.indexId || index}>
                {this.loadSunTemplate(item.data)}
            </TreeNode>)
            // }
        })
        return sunData
    }

    showSubData(data) {
    }

    onOpenChange = (openKeys) => {
        const latestOpenKey = openKeys.find(key => this.state.openKeys.indexOf(key) === -1);
        if (openKeys.length === 1) {
            this.setState({ openKeys });
        } else {
            this.setState({
                openKeys: latestOpenKey ? [latestOpenKey] : [],
            });
        }
    }

    handleSelectChange(name, e) {
        this.setState({
            [name]: e
        }, () => {
        })
    }

    commonChangeInput(name, e) {
        this.setState({
            [name]: e.target.value
        })
    }
    keyDownMsg(e) {
        if (e.keyCode == '13') {
        }
    }

    commonCheckBox(name, e) {
        this.setState({
            [name]: e.target.checked ? 'SELF' : 'BX'
        }, () => {
        })
    }

    changeRegistrTime(date, dateStr) {
        this.setState({
            dateFrom: dateStr[0],
            dateTo: dateStr[1]
        })
    }

    changeSevenDate() {
        var date = new Date();
        this.setState({
            defaultDate: true,
            defaultValue: '1',
            dateFrom: moment(new Date(date.getTime() - 144 * 60 * 60 * 1000)).format(dayFormat),
            dateTo: moment(date).format(dayFormat)
        })
    }

    showModal() {
        this.setState({
            showModal: true
        })
    }

    changeMonthDate() {
        var date = new Date();
        var newDate = date.setMonth(date.getMonth() - 1);
        this.setState({
            defaultDate: true,
            defaultValue: '2',
            dateFrom: moment(newDate).format(dayFormat),
        })
    }

    //加载医嘱模版
    loadTemplate() {
        var templateTree = []
        this.state.templateData && this.state.templateData.map((item, index) => {
            templateTree.push(<TreeNode title={item.title} key={index + 'i'}>
                {this.loadSunTemplates(item.data)}
            </TreeNode>)
        })
        return templateTree
    }

    loadSunTemplates(data) {
        var sunData = []
        data && data.map((item, index) => {
            // if(item.data) {
            sunData.push(<TreeNode title={<span className='explice-tree'>{item.title}</span>}
                nodeId={item.ordTempletDetailItemID}
                disabled={this.state.titleData && this.state.titleData.depDoctorFlag == 'N' ? true : false}
                key={item.ordTempletDetailID + '^' + item.ordTempletDetailItemID || item.id || index}>
                {this.loadSunTemplates(item.data)}
            </TreeNode>)
            // }
        })
        return sunData
    }

    loadTableData(data) {
        this.setState({
            adviceList: data
        })
    }

    batchAddTemplate() {
        this.setState({
            showModal: false
        })
    }

    loadSunData() {
        this.loadDoctorData.loadData()
    }


    change(e) {
        this.state.current = e
        var { change } = this.props;
    }

    onCannelPatient() {

    }

    hashROuter(data, disBtn) {
        var that = this;
        var { routeFlag, saveFlag } = this.state;
        if (routeFlag === true) {
            confirm({
                title: '提示',
                content: '当前页面数据还没保存，是否需要保存？',
                okText: that.state.userData.language == 'EN' ? 'Ok' : '是->保存',
                cancelText: that.state.userData.language == 'EN' ? 'cancel' : '否->无需保存',
                onOk() {
                    if (saveFlag && saveFlag == '3') {
                        that.handleUnSaveData()
                        // that.onRefDoctor.checkPoisonMsg()
                    }
                    that.setState({
                        changeComponent: data,
                        routeFlag: [],//组件切换后，销毁自组件数据
                        disBtn: disBtn
                    }, () => {
                        that.onRefApplication && that.onRefApplication.loadDisMessage(that.state.disBtn)
                    })
                },
                onCancel() {
                    that.setState({
                        changeComponent: data,
                        medicineStatus: false,
                        routeFlag: [],//组件切换后，销毁自组件数据
                        disBtn: disBtn
                    }, () => {
                        that.onRefApplication && that.onRefApplication.loadDisMessage(that.state.disBtn)
                    })
                }
            })
        } else {
            that.setState({
                changeComponent: data,
                disBtn: disBtn
            }, () => {
                that.onRefApplication && that.onRefApplication.loadDisMessage(that.state.disBtn)
            })
        }
    }

    saveDiagnosisMsg(id) {
        this.setState({
            current: id
        })
    }

    DischargeRef = (ref) => {
        this.Discharge = ref
    }

    // 切换tabs
    upDataComponentSource = (data) => {
        console.log(data)
        this.setState({
            componentSource: data,
            changeComponent: '2',
            isShowOutPatientModal: true,
            isShowTriageSystemModal: true
        })
    }

    loadStepCompent() {
        //获取父组件的参数，渲染组件
        const { componentSource } = this.state;
        if (!Util.isEmpty(componentSource)) {
            const Component = asyncComponent(() => import('../../' + componentSource.component));
            return (this.state.changeComponent == '1' ? <CMOrderSave hashROuter={this.hashROuter.bind(this)}></CMOrderSave> :
                (this.state.changeComponent == '3' ? <EntryApplicationForm hashROuter={this.hashROuter.bind(this)} disBtnMessage={this.disBtnMessage}
                    disBtn={this.state.disBtn} onRef={this.OnRefApp} /> :
                    (componentSource.code == '03060002' ?
                        <HospitalPatientPage onRef={this.onRefHosp} loadPatientMsg={this.loadPatientMsg.bind(this)}
                            loadUpdateMessage={this.loadUpdateMessage.bind(this)}
                            loadTitleData={this.loadTitleData.bind(this)} /> :
                        <Component hashROuter={this.hashROuter.bind(this)} saveDiagnosisMsg={this.saveDiagnosisMsg.bind(this)}
                            admID={this.state.patientData && this.state.patientData.admID} onRef={this.DischargeRef} deptType='D'
                            onHide={this.hideModal.bind(this, 'isShowDischargeModal')} componentRouter={this.componentRouter.bind(this)}
                            handleEndOperation={this.handleEndOperation.bind(this)} showModal={this.showModal.bind(this)}
                            componentSource={componentSource}
                            upDataComponentSource={this.upDataComponentSource}
                            titleData={this.state.titleData} />)))
        }
    }

    OnRefApp = (ref) => {
        this.onRefApplication = ref
    }

    loadPatientData() {
        this.loadPatientMsg()
        this.loadUpdateMessage()
        this.onRefHospital.loadData(1)
    }

    //获取控费信息
    disBtnMessage = (disBtn) => {
        this.setState({
            disBtn: disBtn
        }, () => {
            console.dir(disBtn)
        })
    }

    onRefHosp = (ref) => {
        this.onRefHospital = ref
    }

    showModal(flag) {
        this.setState({
            showModal: flag
        })
    }

    componentRouter(data, flag, componentData) {
        this.state.routeFlag = data//是否存在未保存数据
        this.state.saveFlag = flag//当前组件标识
        this.state.componentData = componentData//未保存的数据
    }

    //点击结束就诊，返回列表
    handleEndOperation() {
        var { dataSource } = this.state;
        var code = ''
        var num = ''
        for (var i = 0; i < dataSource.length; i++) {
            if (!Util.isEmpty(dataSource[i].defaultFlag) && dataSource[i].defaultFlag == 'Y') {
                code = dataSource[i + 1]
                num = i
            }
        }
        this.setState({
            componentSource: code,
            current: num
        })
    }

    loadTitleData(data, record) {
        // componentSource
        var { dataSource } = this.state;
        var code = ''
        var num = ''
        for (var i = 0; i < dataSource.length; i++) {
            if ((record == 'D' || record == 'CHARGE') && dataSource[i].code == '03050080') {
                code = dataSource[i]
                num = i
            } else {
                if (!Util.isEmpty(dataSource[i].defaultFlag) && dataSource[i].defaultFlag == 'Y') {
                    code = dataSource[i + 1]
                    num = i
                }
            }
        }
        this.setState({
            titleData: data,
            componentSource: code,
            current: record == 'D' || record == 'CHARGE' ? num : (num + 1)
        }, () => {
            // this.props.history.push('./03050002?id=' + record.patAdmID)
        })
    }

    reloadData(data) {
        this.setState({}, () => {
            this.loadPatientMsg(data ? data.admID : '')
            this.onRefHospital.clearData()
        })
    }

    hideModal(name) {
        this.setState({
            [name]: false
        })
    }

    openWindowBySubTab(data) {
        if (this.props.openWindowBySubTab) {
            this.props.openWindowBySubTab({
                title: '医嘱录入',
                path: '/03060003',
                Paras: {
                    targetKey: '住院医嘱录入',
                    flag: 'compile',
                    userInfo: data
                },
                component: "pages/workstation/OutPatientStationTabs.jsx"
            });
        } else {
            this.props.history.push('./03060003?id=' + record.patAdmID)
        }
        this.loadOutPatientModal(data)
    }

    onChangeStepComponent(data, e) {
        var that = this;
        var { routeFlag, saveFlag } = this.state;
        let isModifyMedicalRecord = that.Discharge && that.Discharge.getModified ? that.Discharge.getModified() : false; // 病历信息切换标识
        saveFlag = isModifyMedicalRecord ? "" : saveFlag;
        // console.log("isModifyMedicalRecord", isModifyMedicalRecord, saveFlag)
        let templateDesc = that.Discharge && that.Discharge.getTemplateDesc ? that.Discharge.getTemplateDesc() : "";
        if (routeFlag === true || isModifyMedicalRecord) {
            // if (isModifyMedicalRecord) {
            //     that.Discharge && that.Discharge.handleSave && that.Discharge.handleSave("", "", () => that.handleSwitch(data));
            // } else {
            confirm({
                title: isModifyMedicalRecord ? <div>当前病历 <span style={{ fontWeight: "900" }}>{templateDesc}</span> 已修改，是否需要保存？</div> : '提示',
                content: isModifyMedicalRecord ? "" : '当前页面数据还没保存，是否需要保存？',
                okText: that.state.userData.language == 'EN' ? 'Ok' : '是->保存',
                cancelText: that.state.userData.language == 'EN' ? 'cancel' : '否->无需保存',
                onOk() {
                    //当patinetData为空时，不让step点击
                    var disbledStatus = JSON.parse(sessionStorage.getItem('patientData'))
                    if (Util.isEmpty(disbledStatus)) {
                        return
                    }
                    if (saveFlag && saveFlag == '3') {
                        that.handleUnSaveData();
                    }
                    if (isModifyMedicalRecord) { // 为住院病历信息时
                        that.Discharge && that.Discharge.handleSave && that.Discharge.handleSave("", "", () => that.handleSwitch(data));
                    } else {
                        that.handleSwitch(data)
                    }
                },
                onCancel() {
                    that.setState({
                        componentSource: data,
                        // current: index,
                        changeComponent: '2',
                        // isShowDischargeModal: true,
                        routeFlag: false//组件切换后，销毁自组件数据
                    })
                }
            })
            // }
        } else {
            //当patinetData为空时，不让step点击
            var disbledStatus = JSON.parse(sessionStorage.getItem('patientData'))
            if (Util.isEmpty(disbledStatus)) {
                return
            }

            that.setState({
                componentSource: data,
                // current: parseInt(e.target.innerText) - 1,
                changeComponent: '2',
                // isShowDischargeModal: true,
            }, () => {
                if (data.code == '03060006') {
                    setTimeout(() => {
                        this.Discharge?.showModal(!Util.isEmpty(disbledStatus) ? disbledStatus.admID : '')
                    }, 500)
                }
            })
        }
    }

    // 切换跳转
    handleSwitch = (data) => {
        // console.log("触发了切换跳转")
        var patientData = JSON.parse(sessionStorage.getItem('patientData'));
        var that = this;
        this.setState({
            componentSource: data,
            // current: index,
            changeComponent: '2',
            // isShowDischargeModal: true,
            routeFlag: false//组件切换后，销毁自组件数据
        }, () => {
            if (data.code == '03060006') {
                setTimeout(() => {
                    that.Discharge.showModal(!Util.isEmpty(patientData) ? patientData.admID : '');
                }, 300)
            }
        })
    }

    handleUnSaveData() {
        var patientData = JSON.parse(sessionStorage.getItem('patientData'));
        var temp = []
        var { componentData } = this.state;
        for (var i = 0; i < componentData.length; i++) {
            temp.push({
                ...componentData[i],
                skinTestWayList: undefined,
                admReasonList: undefined,
                doseUnitList: undefined,
                durationList: undefined,
                frequenceList: undefined,
                priorityExtList: undefined,
                priorityList: undefined,
                qtyUnitList: undefined,
                recLocList: undefined,
                specList: undefined,
                usageList: undefined,
                causeList: undefined,
                stageList: undefined
            })
        }
        var params = {
            params: [{
                admID: patientData.admID,
                locID: this.state.userData.locID,
                userID: this.state.userData.userID,
                docID: this.state.userData.userID,
                hospID: this.state.userData.hospID,
                medType: 'WM',
                orders: temp
            }]
        }
        $http.post('urlDeault', this, {
            code: "03050176",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                }
            }
        });
    }

    //病人列表弹框
    onHandlePatient() {
        // this.setState({
        //     isShowPatientListModal: true
        // })
        this.onRefModal.showModal()
    }

    onRefList = (ref) => {
        this.onRefModal = ref
    }

    showTimeout() {
        var admID = '', patID = '';
        var patientData = JSON.parse(sessionStorage.getItem('patientData'))
        if (!Util.isEmpty(patientData)) {
            admID = patientData.admID
            patID = patientData.patID
            this.childConsume.showModal(admID, patID);
        }
    }

    //自费按钮触发事件
    showExamineModal() {
        var admID = '';
        var patientData = JSON.parse(sessionStorage.getItem('patientData'))
        if (!Util.isEmpty(patientData)) {
            admID = patientData.admID
            this.childShowExamine.showModal(admID);
        }
    }

    /**
     * @ByYQL: 事前事中消息模态框
     * Create 2021-12-21
     */
    onShowExamineModalRef = (ref) => {
        this.childShowExamine = ref;
    };

    onConsumeRef = (ref) => {
        this.childConsume = ref;
    };

    // 添加至黑名单
    addToBlacklist = () => {
        const { titleData } = this.state;
        if (!Util.isEmpty(titleData)) {
            this.blacklistRef && this.blacklistRef.modifyVisible(true, { ...titleData });
        }
    }

    render() {
        var { admStatusList, wardList, medGroupList, bedData, titleData, dataSource } = this.state;
        var disbledStatus = JSON.parse(sessionStorage.getItem('patientData'))
        var componentOption = []
        dataSource && dataSource.map((item, index) => {
            componentOption.push(
                <Step key={index} style={{ cursor: 'pointer' }} title={<Tooltip title={this.state.userData.language == 'EN' ? item.ENDesc : item.title}>
                    {this.state.userData.language == 'EN' ? item.ENDesc : item.title}</Tooltip>}
                    disabled={Util.isEmpty(disbledStatus) ? true : false}
                    onClick={this.onChangeStepComponent.bind(this, item)} />)
        })

        //状态
        var admStatusListOption = []
        admStatusList && admStatusList.map((item, index) => {
            admStatusListOption.push(<Option key={index} value={item.admStatusCode}>{item.admStatusDesc}</Option>)
        })

        //病区
        var wardListOption = []
        wardList && wardList.map((item, index) => {
            wardListOption.push(<Option key={index} value={item.wardSPCode}>{item.wardDesc}</Option>)
        })

        //诊疗组
        var medGroupListOption = []
        medGroupList && medGroupList.map((item, index) => {
            medGroupListOption.push(<Option key={index} value={item.medGroupSPCode}>{item.medGroupDesc}</Option>)
        })

        //床号
        var bedDataOption = []
        bedData && bedData.map((item, index) => {
            bedDataOption.push(<Option key={index} value={item.bedID}><Tooltip title={item.bedNo}>{item.bedNo}</Tooltip></Option>)
        })

        var moduleDataOption = []
        if (this.state.moduleData) {
            this.state.moduleData && this.state.moduleData.map((item, index) => {
                moduleDataOption.push(
                    <Radio value={item.id} key={item.id}>{item.descripts}</Radio>
                )
            })
        }

        let windowHost = window.location && window.location.origin ? window.location.origin : (window.location && window.location.protocol ? (window.location.protocol + '//' + window.location.hostname) : "");
        let patientUrl = !Util.isEmpty(this.state.titleData) ? this.state.titleData.patImage : ''
        var patientImg = patientUrl ? patientUrl.indexOf("http") !== -1 ? patientUrl : windowHost + patientUrl : '';

        return <div className='hospital-station-body' style={{ height: '100%', overflow: 'hidden' }}>
            {/**病人列表弹框 */}
            <ShowPatientListModal isShow={this.state.isShowPatientListModal}
                loadTitleData={this.reloadData.bind(this)}
                onRef={this.onRefList}
                onHide={this.hideModal.bind(this, 'isShowPatientListModal')}>
            </ShowPatientListModal>
            <PatientCourseInfo
                onRef={this.onConsumeRef}
            />
            <div className='out-patient-styles'>
                <div style={{ float: 'left', width: '10.7%' }}>
                    <Card>
                        <div>
                            <div>
                                <div style={{ textAlign: 'center' }}>
                                    {
                                        !Util.isEmpty(patientUrl) ? <img className='splice-patient-img' src={patientImg} /> : <div className={this.state.titleData && this.state.titleData.patSexCode == '1' ?
                                            'splice-boys' : (this.state.titleData && this.state.titleData.patSexCode == '2' ? 'splice-girls' : 'splice-girls')}></div>
                                    }
                                </div>
                                <div style={{ fontSize: '14px' }}>
                                    <div style={{ padding: '0 0 0 30px' }}>
                                        <Tooltip placement="topLeft" title={!Util.isEmpty(titleData) ? (titleData?.blackListobj?.blackFlag === 'Y' ? '修改黑名单信息' : '添加至黑名单') : '请先选择患者'}>
                                            <div style={{ color: '#333333', fontWeight: 'bold', cursor: 'pointer' }} onClick={this.addToBlacklist}>
                                                <img
                                                    src={titleData?.blackListobj?.blackFlag === 'Y' ? icon_name_blocklist : icon_name}
                                                    style={{ marginRight: 10, marginBottom: 3 }}
                                                />
                                                <span>{this.state.titleData ? this.state.titleData.patName || '--' : '--'}</span>
                                                <span style={{ color: '#007AFF', marginLeft: 10, fontSize: '16px' }}>{this.state.titleData ? this.state.titleData.bedNo || '--' : '--'}</span>
                                            </div>
                                        </Tooltip>

                                        <div style={{ marginTop: 10 }}><img src={icon_gender} style={{ marginRight: 10, marginBottom: 3 }} />
                                            {this.state.titleData ? this.state.titleData.patSexDesc || '--' : '--'}</div>

                                        <div style={{ marginTop: 10 }}><img src={icon_expense} style={{ marginRight: 10, marginBottom: 3 }} />
                                            {this.state.titleData ? this.state.titleData.patAge || '--' : '--'}</div>

                                        <div style={{ marginTop: 10 }}><img src={icon_icon} style={{ marginRight: 10, marginBottom: 3 }} />
                                            {this.state.titleData ? this.state.titleData.patMobile || '--' : '--'}</div>

                                        {/* <div style={{ marginTop: 10 }}><Icon className='statusdesc-splice' style={{ marginRight: 10 }} />
                                            {this.state.titleData ? this.state.titleData.patSocialStatusDesc || '--' : '--'}</div> */}

                                        <div style={{ marginTop: 10 }} onDoubleClick={this.showExamineModal.bind(this)}><Icon className='typeDesc-splice' style={{ marginRight: 10 }} />
                                            {this.state.titleData ? this.state.titleData.patTypeDesc || '--' : '--'}</div>

                                        <div style={{ color: '#007AFF', marginTop: 10, marginBottom: 10 }}><Icon className='account-splice' style={{ marginRight: 10 }} />
                                            {this.state.titleData ? this.state.titleData.accountBalance || '--' : 0}</div>

                                        <div style={{ marginTop: 10 }}>
                                            {!Util.isEmpty(this.state.titleData) ? <span style={{ color: '#007AFF', cursor: 'pointer' }}
                                                onClick={this.showTimeout.bind(this)}>{'患者就诊历程>>'}</span>
                                                : <span>{'患者就诊历程>>'}</span>}
                                        </div>
                                    </div>
                                </div>
                            </div>

                            {/* <div style={{ float: 'right', width: '5.3%', borderLeft: '1px solid #EEEEEE', height: 79, textAlign: 'center' }}>
                                <span style={{ cursor: 'pointer', color: '#1890FF', lineHeight: '79px' }}
                                    onClick={this.onHandlePatient.bind(this)}>{'病人列表'}</span>
                            </div> */}

                            {/* <div style={{ width: '66.7%', float: 'right' }}>
                                <div style={{ width: '100%', padding: '6px 0' }}></div>
                                <div className='doctor-step-cls' style={{ marginTop: 10, marginLeft: '5%', marginRight: '5%' }}>
                                    <Steps onChange={this.change.bind(this)}
                                        current={this.state.current} size='small'>
                                        {componentOption}
                                    </Steps>
                                </div>
                            </div> */}
                        </div>
                    </Card>
                    <Card className="scroll-bar-style" style={{ marginTop: 5, height: store.getState().tableHeight.y - 165, overflow: 'auto' }}>
                        <ShowCommonNavigationPage patientData={JSON.parse(sessionStorage.getItem('patientData'))}
                            loadPatientData={this.loadPatientData.bind(this)}></ShowCommonNavigationPage>
                    </Card>
                </div>

                <Card style={{ float: 'right', width: '89%' }}>
                    <div style={{ display: 'flex', borderBottom: '1px solid #F5F4F4' }}>
                        <div className='doctor-step-cls' style={{ marginLeft: '5%', marginRight: '5%', width: '94%' }}>
                            <Steps onChange={this.change.bind(this)} type="navigation"
                                current={this.state.current} size='small'>
                                {componentOption}
                            </Steps>
                        </div>
                        <div style={{ float: 'right', width: '5.3%', borderLeft: '1px solid #EEEEEE', height: 57, lineHeight: '57px', textAlign: 'center' }}>
                            <span style={{ cursor: 'pointer', color: '#1890FF' }}
                                onClick={this.onHandlePatient.bind(this)}>{'病人列表'}</span>
                        </div>
                    </div>
                    <PatientsClinicalTabPane current={this.state.current} hashROuter={this.hashROuter.bind(this)}
                        ref={this.onRef} componentSource={this.state.componentSource}
                        openWindowBySubTab={this.openWindowBySubTab.bind(this)}
                        patientData={JSON.parse(sessionStorage.getItem('patientData'))}
                        loadStepCompent={this.loadStepCompent()}
                        changeComponent={this.state.changeComponent}>
                    </PatientsClinicalTabPane>
                </Card>
            </div>

            {/* <PatientsClinicalTabPane current={this.state.current} hashROuter={this.hashROuter.bind(this)}
                ref={this.onRef} componentSource={this.state.componentSource}
                openWindowBySubTab={this.openWindowBySubTab.bind(this)}
                patientData={JSON.parse(sessionStorage.getItem('patientData'))}
                loadStepCompent={this.loadStepCompent()}
                changeComponent={this.state.changeComponent}>
            </PatientsClinicalTabPane> */}


            {/* </Card> */}
            {this.state.showModal ?
                <Drag style={{
                    width: '300px', position: 'absolute',
                    overflow: 'auto', zIndex: 1111
                }}>
                    <div style={{ width: '300px' }}>
                        <Card title={<span style={{ marginLeft: 10 }}><Icon className='card-title-splice' />医嘱模版</span>}
                            extra={<div onClick={this.batchAddTemplate.bind(this)} className='batch-add-temp'><Icon type='close' /></div>}>
                            <Input style={{ width: '90%', marginLeft: '5%' }}
                                prefix={<Icon type="search" style={{ color: 'rgba(0,0,0,.25)' }} />}
                                placeholder='输入模版/套餐名称按回车键查询' onChange={Util.commonInputChange.bind(this, 'templateInput')}
                            // onKeyDown={this.onSearchTemplate.bind(this)}
                            />
                            <div className='doctor-left-radio'>
                                <Radio.Group value={this.state.radioValue}
                                    onChange={this.changeRadio.bind(this)}>
                                    {moduleDataOption}
                                </Radio.Group>
                            </div>
                            {this.state.templateData && this.state.templateData.length > 0 ?
                                <Tree defaultExpandAll={true} defaultExpandedKeys={['1']}
                                    checkedKeys={this.state.newCode}
                                // onCheck={this.checkTreeNode.bind(this)}
                                // onDoubleClick={this.loadTempTableData.bind(this, 'temp')}
                                >
                                    {this.loadTemplate()}
                                </Tree> :
                                <div style={{ marginLeft: '25%', marginTop: 40 }}>
                                    <span style={{ color: 'red', fontSize: '16px' }}>暂无模版数据</span></div>}
                        </Card></div>
                </Drag>
                : null}

            {/*事前事中消息模板*/}
            <ShowExamineModal onRef={this.onShowExamineModalRef} />

            {/* 添加至黑名单 */}
            <PatientBlacklist handleQuery={this.loadPatientMsg.bind(this)} onRef={ref => this.blacklistRef = ref} />
        </div>
    }

}
export default DiagnosisTabs;
