/**
 *
 * 住院病人列表 住院患者列表
 */
import React from 'react';
import { Card, Table, Input, Select, DatePicker, Button, Steps, Icon } from 'antd';
import { Util, dayFormat } from 'tools/index';
import { $http } from 'containers/config/https';
import CommonPagination from 'components/pagination/index';
import ShowComponentModal from './component/ShowComponentModal';
import RangeDatePicker from 'components/rangePicker/index';
import { PAGE_NUM_MORE_STATUS } from 'tools/statusConstants';
import ColumnAuthoritysModel from 'pages/columnAuthority/ColumnAuthoritysModel';
import CommonTableSetSorting from 'pages/dynamicComponent/component/CommonTableSetSorting';
import moment from 'moment';
import store from 'store';
import './style/index.less';

const Option = Select.Option;
const { Step } = Steps;

class HospitalPatientPage extends React.Component {
    constructor(props) {
        super(props)
        var userData = JSON.parse(sessionStorage.getItem('userData'))
        var date = new Date();
        this.state = {
            dataSource: [],
            total: 0,
            page: 1,
            pageSize: 50,
            userData: userData,
            btnCode: '',
            btnStatus: 'primary',
            admStatusCode: 'A',
            admStatus: true,
            levelCode: 'BX',
            levelStatus: true,
            wardStatus: true,
            wardSPCode: 'BX',
            medGroupSPCode: 'BX',
            groupStatus: true,
            conditionCode: 'BX',
            defaultValue: '1',
            defaultDate: true,
            dateTo: moment(date).format(dayFormat),
            dateFrom: moment(new Date(date.getTime() - 144 * 60 * 60 * 1000)).format(dayFormat),
            size: 'small',
            current: '',
            tabLoading: false,
            medicalRecord: undefined,
            emrStatusList: [],
            moreConditions: false, // 更多查询条件
        }
    }

    componentDidMount() {
        this.props.onRef(this)
        let inpatientList = store.getState() && store.getState().otherData && store.getState().otherData.inpatientListQueryCriteria ? store.getState().otherData.inpatientListQueryCriteria : {};
        this.setState({ ...inpatientList }, () => {
            this.initData()
            this.loadData(this.state.page ? this.state.page : 1)
            this.loadPatientListData()
            this.loadBedData()
            this.getCBEMRStatus()
        })
    }

    componentDidUpdate() {
        if (this.state.admStatusCode == 'D' || this.state.admStatusCode == 'CHARGE') {
            document.querySelector('.ant-table-body').style.height = (store.getState().tableHeight.y - 24) + 'px'
        } else {
            document.querySelector('.ant-table-body').style.height = (store.getState().tableHeight.y - 50) + 'px'
        }
    }

    componentWillUnmount() {
        // console.log(this.state.page)
        let inpatientList = {
            defaultValue: this.state.defaultValue,
            admStatusCode: this.state.admStatusCode,
            wardID: this.state.wardID,
            medGroupID: this.state.medGroupID,
            competentDoctor: this.state.competentDoctor,
            attendDoctor: this.state.attendDoctor, //主治医生
            levelCode: this.state.levelCode,
            conditionCode: this.state.conditionCode,
            admissionDate: this.state.admissionDate,
            patMessage: this.state.patMessage,
            bedID: this.state.bedID,
            medicalRecord: this.state.medicalRecord,
            medicalNo: this.state.medicalNo,
            diagnose: this.state.diagnose, //诊断类型 YQY
            dateFrom: this.state.dateFrom,
            dateTo: this.state.dateTo,
            pageSize: this.state.pageSize,
            page: this.state.page,
        };
        store.dispatch({
            type: "inpatientListQueryCriteria",
            value: inpatientList
        });
        // 组件销毁前将静止让setState修改state的状态
        this.setState = (state, callback) => { return; }
    }

    loadPatienCourse(status) {
        //04040015{
        let data = {
            params: [{
                admID: this.state.admID,
                cbEventID: "",
                course: "course",
            }]
        }
        $http.post('urlDeault', this, {
            code: "04040015",
            data: data,
            success: (res) => {
                if (+res.errorCode === 0) {
                    this.setState({
                        patient: res.result.Data
                    });
                    if (res.result.Data.length > 0) {
                        // this.selectCourseDetail(res.result.Data[0], status);
                    }
                }
            }
        })
    }

    selectCourseDetail(item, status) {
        //var patientData = SessionStorage.getItem("patientData")
        let { code, date, nextPrograme, colunmsCode, component } = item;
        var flag = true
        if (code == this.state.stateCode) {
            flag = false
        }
        if (!Util.isEmpty(component)) {
            this.setState({
                component: component,
                stateCode: code,
                isShowComponentModal: true,
                patEventDesc: item.patEventDesc
            })
        } else {
            this.setState({
                stateCode: code,
                startDate: date,
                component: component,
                nextPrograme: nextPrograme,
                patEventDesc: item.patEventDesc
            }, () => {
                if (colunmsCode != "") this.getDetailTableColumns(colunmsCode, status)
            })
        }
    }

    // 获取明系列表头数据
    getDetailTableColumns = (ColunmsCode, status) => {
        let data = {
            params: [{
                reactCode: [ColunmsCode],
                compontName: ColunmsCode,
                type: 'C',
            }]
        }
        $http.post('urlS', this, {
            code: '01040073',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    var columns = []
                    columns = res.result.C
                    if (columns) {
                        if (ColunmsCode == "OrderSearch") {
                            for (var ci = 0; ci < columns.length; ci++) {
                                if (columns[ci].dataIndex == 'lifeCycle') {
                                    var diagColumns = [];
                                    diagColumns.push({
                                        title: this.state.userData.language != 'EN' ? this.state.userData.language != 'EN' ? columns[ci].title : columns[ci].enDescripts : columns[ci].enDescripts,
                                        dataIndex: columns[ci].dataIndex,
                                        //width: width,
                                        align: 'center',
                                        render: (text, data, index) => {
                                            return <span style={{ cursor: "pointer" }} onClick={(e) => this.handleOpen(e, data.ordID)}><span style={{ color: "#096dd9" }}>生命周期</span></span>
                                        }
                                    })
                                    columns[ci] = diagColumns[0]
                                }
                            }
                        }
                    }
                    this.setState({
                        ENObj: res.result.language.EN,
                        CNObj: res.result.language.CN,
                        columns: columns,
                        tableWidth: res.totalWidth,
                        colunmsCode: ColunmsCode
                    }, () => {
                        this.loadCheckInfo(status)
                    })
                }
            }
        })
    };

    loadCheckInfo = (status) => {
        let data = {
            params: [{
                admID: this.state.admID,
                startDate: this.state.startDate,
                code: this.state.nextPrograme,
                state: this.state.stateCode,
            }]
        }
        $http.post('urlS', this, {
            code: '04040022',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    this.setState({
                        data: res.result.data,
                        isShowComponentModal: status == 'hide' ? false : true,
                    })
                }
            }
        })
    }

    handleOpen() { }

    initData() {
        let data = {
            params: [{
                compontName: "residentList",
                type: "C",
            }]
        }
        $http.post('urlDeault', this, {
            code: "01040073",
            data: data,
            success: (res) => {
                if (+res.errorCode === 0) {
                    var columns = res.result.C;
                    var dynColumns = []
                    for (var i = 0; i < columns.length; i++) {
                        columns[i].fixed = columns[i]?.fixed === 'L' ? 'left' : (columns[i]?.fixed === 'R' ? 'right' : (columns[i]?.fixed || undefined))
                        if (columns[i].dataIndex == 'days') {
                            dynColumns.push({
                                ...columns[i],
                                title: this.state.userData.language == 'EN' ? columns[i].enDescripts : columns[i].title,
                                dataIndex: columns[i].dataIndex,
                                width: parseInt(columns[i].width),
                                align: columns[i].align || 'center',
                                render: (text, data) => {
                                    return <span>住院{data.days || 0}天</span>
                                }
                            })
                        } else if (columns[i].dataIndex == 'totalAmt') {
                            dynColumns.push({
                                ...columns[i],
                                title: this.state.userData.language == 'EN' ? columns[i].enDescripts : columns[i].title,
                                dataIndex: columns[i].dataIndex,
                                width: parseInt(columns[i].width),
                                align: columns[i].align || 'center',
                                render: (text, data) => {
                                    return <span style={{ color: '#00C197' }}>{parseFloat(data.totalAmt).toFixed(2) || '--'}</span>
                                }
                            })
                        } else if (columns[i].dataIndex == 'medicalRecord') { // 倒计时
                            dynColumns.push({
                                ...columns[i],
                                title: this.state.userData.language == 'EN' ? columns[i].enDescripts : columns[i].title,
                                dataIndex: columns[i].dataIndex,
                                width: parseInt(columns[i].width),
                                align: columns[i].align || 'center',
                                render: (text, data) => {
                                    return <span style={{ color: data.redFlag === "Y" ? 'red' : 'rgba(0, 0, 0, 0.65)' }}>{data.medicalRecord}</span>
                                }
                            })
                        } else if (columns[i].dataIndex == 'bedNo') {
                            dynColumns.push({
                                ...columns[i],
                                title: this.state.userData.language == 'EN' ? columns[i].enDescripts : columns[i].title,
                                dataIndex: columns[i].dataIndex,
                                width: parseInt(columns[i].width),
                                align: columns[i].align || 'center',
                                className: 'hospital-columns'
                            })
                        } else if (columns[i].dataIndex == 'patName') {
                            dynColumns.push({
                                ...columns[i],
                                title: this.state.userData.language == 'EN' ? columns[i].enDescripts : columns[i].title,
                                dataIndex: columns[i].dataIndex,
                                width: parseInt(columns[i].width),
                                align: columns[i].align || 'center',
                                render: (text, data) => {
                                    return <span style={{ color: data.preFlag === "Y" ? 'red' : '#007AFF' }}>{data.patName}</span>
                                }
                            })
                        } else {
                            dynColumns.push({
                                ...columns[i],
                                title: this.state.userData.language == 'EN' ? columns[i].enDescripts : columns[i].title,
                                dataIndex: columns[i].dataIndex,
                                width: parseInt(columns[i].width),
                                align: columns[i].align || 'center',
                                className: ''
                            })
                        }
                    }
                    this.setState({
                        column: dynColumns,
                    })
                    this.props.hanlderThis.setState({
                        reload: false,
                    })
                }
            }
        })
    }

    loadData(page, pageSize, e) {
        this.setState({ tabLoading: true })
        var params = {
            params: [{
                locID: this.state.userData.locID,
                userID: this.state.userData.userID,
                hospID: this.state.userData.hospID,
                admStatusCode: this.state.admStatusCode,
                wardID: this.state.wardID,
                medGroupID: this.state.medGroupID,
                competentDoctor: this.state.competentDoctor,
                attendDoctor: this.state.attendDoctor, //主治医生
                levelCode: this.state.levelCode,
                conditionCode: this.state.conditionCode,
                admissionDate: this.state.admissionDate,
                patMessage: this.state.patMessage,
                bedID: this.state.bedID,
                // admStatusCode 出院为D 财务结算为CHARGE 在院为A
                medicalRecord: (this.state.admStatusCode == 'A') ? undefined : this.state.medicalRecord,
                medicalNo: this.state.medicalNo,
                diagnose: this.state.diagnose, //诊断 YQY
                dateFrom: (this.state.admStatusCode == 'D' || this.state.admStatusCode == 'CHARGE') ? this.state.dateFrom : '',
                dateTo: (this.state.admStatusCode == 'D' || this.state.admStatusCode == 'CHARGE') ? this.state.dateTo : ''
            }],
            pagination: [{
                pageSize: this.state.size == 'small' ? this.state.pageSize : PAGE_NUM_MORE_STATUS[0].code,
                currentPage: page
            }]
        }
        $http.post('urlDeault', this, {
            code: "03060004",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    // var sessionData = res.result.data;
                    // if (!Util.isEmpty(sessionData)) {
                    //     var patientData = {}
                    //     patientData = {
                    //         admID: sessionData[0].admID,
                    //         patID: sessionData[0].patID,
                    //     }
                    //     sessionStorage.setItem('patientData', JSON.stringify(patientData))
                    // }
                    let dataSource = res.result && res.result.data && res.result.data.length > 0 ? res.result.data : [];
                    for (var i = 0; i < dataSource.length; i++) {
                        dataSource[i].key = i;
                    }
                    this.setState({
                        dataSource,
                        // admID: !Util.isEmpty(res.result.data) ? res.result.data[0].admID : '',
                        admStatusData: res.result.admStatusData,
                        wardData: res.result.wardData,
                        medGroupData: res.result.medGroupData,
                        levelData: res.result.levelData,
                        conditionData: res.result.conditionData,
                        total: res.result.totalCount,
                        tabLoading: false
                    }, () => {
                        this.loadPatienCourse('hide');
                    })
                } else {
                    this.setState({ tabLoading: false })
                }
            },
            error: function () {
                this.setState({ tabLoading: false })
            }
        });
    }

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

    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,
                        doctorList: res.doctorList,
                        attendDoctorList: res.doctorList, //主治医生
                        otherConditionList: res.otherConditionList
                    })
                }
            }
        });
    }

    //获取病人状态
    loadAdmStatusList() {
        var { admStatusList } = this.state;
        var admStatusListOption = [];
        admStatusList && admStatusList.map((item, index) => {
            admStatusListOption.push(
                this.state.admStatus && item.admStatusCode == this.state.admStatusCode ?
                    <Button type='primary' size='small' key={index} value={item.admStatusCode}
                        onClick={this.handleAdmStatus.bind(this, item)}>
                        {item.admStatusDesc}({this.state.admStatusData ? (this.state.admStatusData[item.admStatusCode] || 0) : 0})</Button>
                    : <span style={{ marginLeft: 10 }} key={index} value={item.admStatusCode}
                        onClick={this.handleAdmStatus.bind(this, item)}>
                        {item.admStatusDesc}({this.state.admStatusData ? (this.state.admStatusData[item.admStatusCode] || 0) : 0})</span>
            )
        })
        return admStatusListOption
    }

    handleAdmStatus(data, e) {
        this.setState({
            admStatus: true,
            admStatusCode: data.admStatusCode
        }, () => {
            this.loadData(1)
        })
    }

    //获取病区
    loadWardList() {
        var { wardList } = this.state;
        var wardListOption = []
        wardList && wardList.map((item, index) => {
            wardListOption.push(
                // <div style={{ marginLeft: 10 }} key={index} value={item.wardID}>{item.wardDesc}</div>
                this.state.wardStatus && item.wardSPCode == this.state.wardSPCode ?
                    <Button type='primary' size='small' key={index} value={item.wardSPCode}
                        onClick={this.handleWardStatus.bind(this, item)}>
                        {item.wardDesc}({this.state.wardData ? (this.state.wardData[item.wardSPCode] || 0) : 0})</Button>
                    : <span style={{ marginLeft: 10 }} key={index} value={item.wardSPCode}
                        onClick={this.handleWardStatus.bind(this, item)}>
                        {item.wardDesc}({this.state.wardData ? (this.state.wardData[item.wardSPCode] || 0) : 0})</span>
            )
        })
        return wardListOption
    }

    handleWardStatus(data, e) {
        this.setState({
            wardStatus: true,
            wardSPCode: data.wardSPCode,
            wardID: data.wardID
        }, () => {
            this.loadData(1)
        })
    }

    //获取诊疗组
    loadMedGroupList() {
        var { medGroupList } = this.state;
        var medGroupListOption = []
        medGroupList && medGroupList.map((item, index) => {
            medGroupListOption.push(
                // <div style={{ marginLeft: 10 }} key={index} value={item.medGroupID}>{item.medGroupDesc}</div>
                this.state.groupStatus && item.medGroupSPCode == this.state.medGroupSPCode ?
                    <Button type='primary' size='small' key={index} value={item.medGroupSPCode}
                        onClick={this.handleGroupStatus.bind(this, item)}>
                        {item.medGroupDesc}({this.state.medGroupData ? (this.state.medGroupData[item.medGroupSPCode] || 0) : 0})</Button>
                    : <span style={{ marginLeft: 10 }} key={index} value={item.medGroupSPCode}
                        onClick={this.handleGroupStatus.bind(this, item)}>
                        {item.medGroupDesc}({this.state.medGroupData ? (this.state.medGroupData[item.medGroupSPCode] || 0) : 0})</span>
            )
        })
        return medGroupListOption
    }

    handleGroupStatus(data) {
        this.setState({
            medGroupSPCode: data.medGroupSPCode,
            groupStatus: true,
            medGroupID: data.medGroupID
        }, () => {
            this.loadData(1)
        })
    }

    //获取我的患者
    loadLevelList() {
        var { levelList } = this.state;
        var levelListOption = []
        levelList && levelList.map((item, index) => {
            levelListOption.push(
                this.state.levelStatus && item.levelCode == this.state.levelCode ?
                    <Button type='primary' size='small' key={index} value={item.levelCode}
                        onClick={this.handleLevelStatus.bind(this, item)}>
                        {item.levelDesc}({this.state.levelData ? (this.state.levelData[item.levelCode] || 0) : 0})</Button>
                    : <span style={{ marginLeft: 10 }} key={index} value={item.levelCode}
                        onClick={this.handleLevelStatus.bind(this, item)}>
                        {item.levelDesc}({this.state.levelData ? (this.state.levelData[item.levelCode] || 0) : 0})</span>
            )
        })
        return levelListOption
    }

    handleLevelStatus(data, e) {
        this.setState({
            levelCode: data.levelCode,
            levelStatus: true
        }, () => {
            this.loadData(1)
        })
    }

    //其他条件
    loadOtherConditionList() {
        var { otherConditionList } = this.state;
        var otherConditionListOption = []
        otherConditionList && otherConditionList.map((item, index) => {
            otherConditionListOption.push(
                item.conditionCode == this.state.conditionCode ?
                    <Button type={this.state.btnStatus} size='small'
                        onClick={this.handleChangeCondition.bind(this, item)} style={{ marginLeft: 10, marginTop: 5 }} key={index}
                        value={item.conditionCode}>{item.conditionDesc}
                        ({this.state.conditionData ? (this.state.conditionData[item.conditionCode] || 0) : 0})</Button>
                    : <Button size='small'
                        onClick={this.handleChangeCondition.bind(this, item)} style={{ marginLeft: 10, marginTop: 5 }} key={index}
                        value={item.conditionCode}>{item.conditionDesc}
                        ({this.state.conditionData ? (this.state.conditionData[item.conditionCode] || 0) : 0})</Button>
            )
        })
        return otherConditionListOption
    }

    handleChangeCondition(item) {
        this.setState({
            btnStatus: 'primary',
            btnCode: item.conditionCode,
            conditionCode: item.conditionCode
        }, () => {
            this.loadData(1)
        })
    }

    //展示查询条件
    showSearchMsg() {
        if (this.state.showSearch) {
            this.setState({
                showSearch: false
            })
        } else {
            this.setState({
                showSearch: true
            })
        }
    }

    //分页切换
    onChange(e) {
        this.setState({ page: e }, () => {
            this.loadData(e);
        });
    }

    //分页切换
    changePageSize(current, pageSize) {
        this.setState({ pageSize: pageSize, page: current }, () => {
            this.loadData(current, pageSize);
        });
    }

    changeBedSelect(name, e) {
        this.setState({
            [name]: e
        }, () => {
            this.loadData(1)
        })
    }

    handleChangeDate(name, e) {
        this.setState({
            [name]: e ? moment(e).format(dayFormat) : ''
        }, () => {
            this.loadData(1)
        })
    }

    changeInputMsg(name, e) {
        this.setState({
            [name]: e.target.value
        })
    }

    //搜索诊断类型 Creat By YQY 2022/02/25
    changeDiagnose(name, e) {
        this.setState({
            [name]: e.target.value
        })
    }

    //搜索诊断事件 Creat By YQY 2022/02/25
    keyDownDiagnose(e) {
        if (e.keyCode == '13') {
            this.loadData(1)
        }
    }

    keyDownMsg(e) {
        if (e.keyCode == '13') {
            this.loadData(1)
        }
    }

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

    startChange(e) {
        this.setState({
            defaultValue: "",
            dateFrom: e ? moment(e).format(dayFormat) : ''
        })
    }

    endChange(e) {
        this.setState({
            defaultValue: "",
            dateTo: e ? moment(e).format(dayFormat) : ''
        })
    }

    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)
        }, () => {
            this.loadData(1)
        })
    }

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

    //点击行，渲染当前行样式
    onClickRow = (record) => {
        return {
            onDoubleClick: () => {
                sessionStorage.setItem('recordData', JSON.stringify(record))
                // this.handleToDiagnosis(record.admID)
                var { loadTitleData } = this.props;
                loadTitleData && loadTitleData(record, this.state.admStatusCode)
            },
            onClick: () => {
                var patientData = {}
                patientData = {
                    admID: record.admID,
                    patID: record.patID,
                }
                var updatePatNo = record.patNo
                sessionStorage.setItem('updatePatNo', updatePatNo)
                sessionStorage.setItem('patientData', JSON.stringify(patientData))
                this.setState({
                    admID: record.admID,
                    current: ''
                }, () => {
                    this.loadPatienCourse('hide')
                    var { loadPatientMsg, loadUpdateMessage } = this.props;
                    loadPatientMsg && loadPatientMsg(record.admID)
                    loadUpdateMessage && loadUpdateMessage(record.patNo)
                });
            }
        };
    }

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

    handleToDiagnosis(id) {
        this.props.history.push('./03060003?id=' + id)
    }

    //点击行，渲染当前行样式  redFlag === 'Y' 为病案未提交
    //refused === 'Y' 医嘱被拒绝
    setRowClassName = (record) => {
        return record.admID === this.state.admID ? 'clickRowStyle' : (record.refused === "Y" ? "styleRowRefused" : "");
    };

    ChangeCurrent(e) {
        this.setState({
            current: e
        })
    }

    onColumnRef = (ref) => {
        this.columnRef = ref;
    };

    clearData() {
        this.setState({
            admID: undefined
        })
    }

    // 病案
    handleMedicalRecord = e => {
        this.setState({ medicalRecord: e }, () => {
            this.loadData(1)
        })
    }

    getCBEMRStatus() {
        let data = {
            params: [{

            }]
        }
        $http.post('urlDeault', this, {
            code: "03060033",
            data: data,
            success: (res) => {
                if (+res.errorCode === 0) {
                    this.setState({
                        emrStatusList: res.result
                    });
                }
            }
        })
    };

    // 排序
    handleSort = () => {
        const { column } = this.state;
        this.setSortRef && this.setSortRef.modifyVisible(true, {
            componentName: 'residentList', componentList: column && column.map((item) => {
                return {
                    id: item?.code || '',
                    descripts: item?.descripts || '',
                }
            })
        })
    };

    render() {
        var { bedData, tabLoading, dateFrom, dateTo, patMessage, medicalNo, admissionDate, competentDoctor, attendDoctor, bedID, medicalRecord, diagnose, moreConditions } = this.state;
        var bedDataOption = []
        bedData && bedData.map((item, index) => {
            bedDataOption.push(<Option key={index} value={item.bedID}>{item.bedNo}</Option>)
        })
        let emrStatusList = []
        this.state.emrStatusList.map((item) => {
            emrStatusList.push(<Option key={item.id} value={item.code} title={item.descripts}>{item.descripts}</Option>)
        })

        //主管医生
        var doctorListOption = []
        this.state.doctorList && this.state.doctorList.map((item, index) => {
            doctorListOption.push(<Option key={index} value={item.id} title={item.descriptsSPCode} name={item.descripts}>{item.descripts}</Option>)
        })
        //主治医生
        var attendDoctorListOption = []
        this.state.attendDoctorList && this.state.attendDoctorList.map((item, index) => {
            attendDoctorListOption.push(<Option key={index} value={item.id} title={item.descriptsSPCode} name={item.descripts}>{item.descripts}</Option>)
        })
        let patientCourse = []
        this.state.patient && this.state.patient.map((item, index) => {
            patientCourse.push(
                <Step disabled={item.nextPro == "N"}
                    title={(
                        <div className={((this.state.current == index) && (item.nextPro == "Y")) ? "selected" : item.nextPro == "N" ? "disabledItem" : "unSelected"}>
                            <span style={{ "float": "left" }}>【{item.patEventDesc}】</span>
                        </div>
                    )}
                    onClick={this.selectCourseDetail.bind(this, item)}
                    description={(
                        <div className={((this.state.current == index) && (item.nextPro == "Y")) ? "selected" : 'normalText'}>
                            <span style={{ lineHeight: "36px", verticalAlign: "bottom" }}>{item.patEventStartDate}&nbsp;&nbsp;{item.patEventStartTime}&nbsp;&nbsp;{item.user}</span>
                        </div>
                    )} />
            )
        })
        return <div className='hospital-patient-body' style={{ background: '#F5F7FE', overflow: 'hidden' }}>
            {/**公共组件弹框 */}
            <ShowComponentModal isShow={this.state.isShowComponentModal}
                component={this.state.component}
                dataSource={this.state.data}
                columns={this.state.columns}
                patEventDesc={this.state.patEventDesc}
                onHide={this.hideModal.bind(this, 'isShowComponentModal')} />
            <ColumnAuthoritysModel
                clientWidth='800px'
                compontName="residentList"
                configType="C"
                onRef={this.onColumnRef}
                reloadData={this.initData}
            />

            <Card style={{ height: '10%' }} className='hospital-titlt-btn'>
                <div style={{ float: 'left' }}>
                    <span style={{ marginLeft: 20 }}>我的患者：{this.loadLevelList()}</span>
                    <span style={{ marginLeft: 20 }}>所属病区：{this.loadWardList()}</span>
                    <span style={{ marginLeft: 20 }}>诊疗小组：{this.loadMedGroupList()}</span>
                </div>
                <div style={{ float: 'right' }}>
                    <span>患者类型：{this.loadAdmStatusList()}</span>
                </div>
            </Card>
            <div style={{ marginTop: 10, height: '89%' }}>
                <Card style={{ height: '80vh' }} title={
                    <div>
                        <div style={{ paddingRight: '12px' }} className="flex-between-center">
                            <div style={{ display: 'flex', alignItems: 'center' }}>
                                人员标识：<Input value={patMessage} style={{ width: 240 }} placeholder="病人id/姓名/身份证号/手机号码"
                                    onChange={this.changeInputMsg.bind(this, 'patMessage')}
                                    onKeyDown={this.keyDownMsg.bind(this)} />
                                <span style={{ marginLeft: 10 }}>住院号：<Input value={medicalNo} style={{ width: 120 }} placeholder="输入后回车"
                                    onChange={this.changeInputMsg.bind(this, 'medicalNo')}
                                    onKeyDown={this.keyDownMsg.bind(this)} /></span>
                                <span style={{ marginLeft: 10 }}>床号：<Select value={bedID} style={{ width: 76 }} placeholder="床号"
                                    allowClear showSearch
                                    filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
                                    onChange={this.changeBedSelect.bind(this, 'bedID')}>
                                    {bedDataOption}</Select></span>
                                <span style={{ marginLeft: 10 }}>主管医生：<Select value={competentDoctor} style={{ width: 100 }} placeholder="请选择"
                                    allowClear showSearch
                                    filterOption={(input, option) => option.props.title.toLowerCase().indexOf(input.toLowerCase()) >= 0 ||
                                        option.props.name.toLowerCase().indexOf(input.toLowerCase()) >= 0}
                                    onChange={this.changeBedSelect.bind(this, 'competentDoctor')}>
                                    {doctorListOption}</Select></span>
                                <span style={{ marginLeft: 10 }}>主治医生：<Select value={attendDoctor} style={{ width: 100 }} placeholder="请选择"
                                    allowClear showSearch
                                    filterOption={(input, option) => option.props.title.toLowerCase().indexOf(input.toLowerCase()) >= 0 ||
                                        option.props.name.toLowerCase().indexOf(input.toLowerCase()) >= 0}
                                    onChange={this.changeBedSelect.bind(this, 'attendDoctor')}>
                                    {attendDoctorListOption}</Select></span>
                                {!(this.state.admStatusCode == 'D' || this.state.admStatusCode == 'CHARGE') ? (
                                    <>
                                        <span style={{ marginLeft: 10 }}>
                                            入院日期：<DatePicker
                                                style={{ width: 110 }}
                                                value={admissionDate ? moment(admissionDate) : undefined}
                                                format={dayFormat}
                                                placeholder='请选择'
                                                onChange={this.handleChangeDate.bind(this, 'admissionDate')}
                                            />
                                        </span>
                                        <span style={{ marginLeft: 10 }}>
                                            诊断类型：<Input
                                                style={{ width: 150 }}
                                                value={diagnose}
                                                onChange={this.changeDiagnose.bind(this, 'diagnose')}
                                                onKeyDown={this.keyDownDiagnose.bind(this)}
                                                placeholder="诊断类型/编码"
                                            />
                                        </span>
                                    </>
                                ) : (
                                    <span style={{ marginLeft: 10 }}>
                                        病案：<Select value={medicalRecord} onChange={this.handleMedicalRecord} allowClear style={{ width: 180 }} placeholder='请选择'>
                                            {emrStatusList}
                                            {/* <Option key={0} value="" title="全部">全部</Option>
                                        <Option key={1} value="Y" title="已提交">已提交</Option>
                                        <Option key={2} value="N" title="未提交">未提交</Option> */}
                                        </Select>
                                    </span>
                                )}
                                <Button type="primary" onClick={this.loadData.bind(this, '1')} style={{ marginLeft: 12 }}>查询</Button>
                                {(this.state.admStatusCode == 'D' || this.state.admStatusCode == 'CHARGE') ? (
                                    <Button type="link" onClick={() => this.setState({ moreConditions: !moreConditions })}>{moreConditions ? '隐藏' : '显示'}更多条件</Button>
                                ) : ''}
                            </div>
                            {(this.state.admStatusCode == 'D' || this.state.admStatusCode == 'CHARGE') ? (<>
                                <span style={{ cursor: 'pointer', marginTop: '4px', color: '#666', fontWeight: 600 }} onClick={this.handleSort}>
                                    <Icon type="sort-descending" />
                                    排序
                                </span>
                            </>) : ''}
                        </div>
                        {(this.state.admStatusCode == 'D' || this.state.admStatusCode == 'CHARGE') ? (
                            /**
                             * @ByShizi: 住院医师站-查询条件一行显示不全无法查询
                             * 需求 #407
                             * Create 2022-04-14
                            */
                            <div style={{ display: moreConditions ? 'flex' : 'none', marginTop: '5px' }}>
                                <span>
                                    诊断类型：<Input
                                        style={{ width: 250 }}
                                        value={diagnose}
                                        onChange={this.changeDiagnose.bind(this, 'diagnose')}
                                        onKeyDown={this.keyDownDiagnose.bind(this)}
                                        placeholder="请输入诊断类型或诊断编码"
                                    />
                                </span>
                                <Button style={{ marginLeft: 10 }} onClick={this.changeSevenDate.bind(this)}
                                    type={this.state.defaultDate && this.state.defaultValue == '1' ? 'primary' : ''}>七天内</Button>
                                <Button style={{ margin: '0 10px' }} onClick={this.changeMonthDate.bind(this)}
                                    type={this.state.defaultDate && this.state.defaultValue == '2' ? 'primary' : ''}>一个月内</Button>
                                {/* 自定义时间：<RangePicker onChange={this.changeRegistrTime.bind(this)} /> */}
                                <RangeDatePicker label={'自定义时间：'} format='YYYY-MM-DD' width='320px' startDate={dateFrom} endDate={dateTo}
                                    isChange={true} startChange={this.startChange.bind(this)} endChange={this.endChange.bind(this)} />
                            </div>
                        ) : null}
                    </div>
                }>

                    {(this.state.admStatusCode == 'D' || this.state.admStatusCode == 'CHARGE') ? null : (
                        <div className={this.state.showSearch ? 'patient-show-header' : ''} style={{ display: 'flex', justifyContent: 'space-between', height: 25, lineHeight: '25px', paddingRight: '12px' }}>
                            <div className="flex">
                                {this.loadOtherConditionList()}
                            </div>
                            <span style={{ cursor: 'pointer', marginTop: '4px', color: '#666' }} onClick={this.handleSort}>
                                <Icon type="sort-descending" />
                                排序
                            </span>
                        </div>
                    )}
                    <Table columns={this.state.column} dataSource={this.state.dataSource} style={{ marginTop: 10, borderTop: '1px solid #e8e8e8' }}
                        pagination={false} bordered
                        scroll={{ x: 1800, y: (this.state.admStatusCode == 'D' || this.state.admStatusCode == 'CHARGE') ? (moreConditions ? store.getState().tableHeight.y - 56 : store.getState().tableHeight.y - 24) : store.getState().tableHeight.y - 50 }}
                        onRow={this.onClickRow}
                        loading={tabLoading}
                        rowClassName={this.setRowClassName}
                        onHeaderRow={column => {
                            return {
                                onDoubleClick: () => {
                                    this.columnRef.onOpenModel();
                                },
                            };
                        }}
                    // rowKey={(data) => {
                    //     return data.patNo
                    // }}
                    ></Table>
                    <CommonPagination size={this.state.size} current={this.state.page} total={this.state.total} search={true} curPageSelect={this.state.pageSize}
                        onShowSizeChange={this.changePageSize.bind(this)} complete={true} dataSource={this.state.dataSource} pageSize='50'
                        loading={this.state.loading} onChange={this.onChange.bind(this)} />
                </Card>
            </div>

            <CommonTableSetSorting onRef={ref => this.setSortRef = ref} handleQuery={() => this.loadData(this.state.page ? this.state.page : 1)} />
        </div>
    }

}
export default HospitalPatientPage;
