/**
 * 
 * 在院病人列表 / 住院医嘱录入
 */
import React from 'react';
import { Card, Table, Input, Select, Row, Col, Checkbox, Tabs, Button, Tree, Icon, Divider, message, Modal, Radio, Tooltip } from 'antd';
import { Util, dayFormat } from 'tools/index';
import { $http } from 'containers/config/https';
import ShowExecutionRecordModal from './ShowExecutionRecordModal';
import ShowStopAdviceReasonModal from './ShowStopAdviceReasonModal';
import DoctorAdviceStepPage from 'pages/workstation/component/DoctorAdviceStepPage';
import ShowStopAdviceModal from './ShowStopAdviceModal';
import RangeDatePicker from 'components/rangePicker/index';
import ColumnAuthoritysModel from 'pages/columnAuthority/ColumnAuthoritysModel';
import { PAGE_NUM_MORE_STATUS } from 'tools/statusConstants';
import CommonPagination from 'components/pagination/index';
import AddTemplateModal from 'pages/workstation/component/AddTemplateModal';
import AddPackageModal from 'pages/workstation/component/AddPackageModal';
import moment from 'moment';
import store from 'store';
import '../style/index.less';

// const { RangePicker } = DatePicker;
const TabPane = Tabs.TabPane;
const Option = Select.Option;
const confirm = Modal.confirm;
const { TreeNode } = Tree;

class DoctorAdviceListPage extends React.Component {
    constructor(props) {
        super(props)
        var userData = JSON.parse(sessionStorage.getItem('userData'))
        var patientData = JSON.parse(sessionStorage.getItem('patientData'))
        this.state = {
            dataSource: [],
            total: 0,
            page: 1,
            pageSize: 200,
            ids: [],
            activeDrags: 0,
            userData: userData,
            column: [],
            size: 'small',
            hideAdviceList: false,
            patientData: patientData,
            adviceStatus: false,
            dropX: 0,
            dropY: 0,
            defaultBtn: 2,
            totalWidth: 0,
            tableFlag: 'N', // 鼠标点击名称规格是否显示相关医保信息
            popoverVisible: false, // 医保信息展示
            medItemTop: '',
            medItemLeft: '',
            medicalInsuranceData: [], // 医保数据
        }
    }

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

    componentWillReceiveProps(nextProp) {
        if (!Util.isEmpty(nextProp.admID)) {
            this.loadData(1)
        } else if (this.props.isShow === false) {
            this.cleanInput();
        }
    }

    componentDidUpdate() {
        if (this.state.adviceStatus === true && this.state.hideAdviceList === false) {
            document.querySelector('.ant-table-body').style.height = this.state.showSelect ?
                store.getState().tableHeight.y - 90 + 'px' : store.getState().tableHeight.y - 40 + 'px'
        } else if (this.state.adviceStatus === false && this.state.hideAdviceList === false) {
            document.querySelector('.ant-table-body').style.height = this.state.showSelect ? '30vh' : '34vh'
        }
    }

    componentDidMount() {
        this.loadWorkstationSetting()
        this.initData()
        this.loadSelectData()
        this.loadColumn()
        this.loadModuleData()
        this.loadLocPersonMsg()
    }

    componentWillUnmount() {
        // 组件销毁前将静止让setState修改state的状态
        this.setState = (state, callback) => { return; }
    }

    loadWorkstationSetting() {
        var params = {
            params: [{
                hospID: this.state.userData.hospID,
                locID: this.state.userData.locID,
                userID: this.state.userData.userID,
            }]
        }
        $http.post('urlDeault', this, {
            code: "01040230",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.setState({
                        activeKey: !Util.isEmpty(res.result) && res.result.OrderDefaultSetTemp == 'OrderDefaultSet' ? '1' : '2',
                        tableFlag: res?.tableFlag || 'N',
                    })
                }
            }
        });
    }

    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,
        //                 radioValue: !Util.isEmpty(res.orderTemplType) ? res.orderTemplType[0].id : ''
        //             }, () => {
        //                 this.loadTemplateData()
        //             })
        //         }
        //     }
        // })
        var params = {
            params: [{
                userID: this.state.userData.userID,
                locID: this.state.userData.locID,
                hospID: this.state.userData.hospID,
            }]
        }
        $http.post('urlS', this, {
            code: '03050273',
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    var data = res.result
                    var defaultTemplTypeID = ''
                    if (!Util.isEmpty(data)) {
                        for (var i = 0; i < data.length; i++) {
                            if (data[i].default == 'Y') {
                                defaultTemplTypeID = data[i].id
                            }
                        }
                    }
                    this.setState({
                        moduleData: res.result,
                        defaultTemplTypeID: defaultTemplTypeID,
                        radioValue: defaultTemplTypeID ? defaultTemplTypeID : (!Util.isEmpty(res.result) ? res.result[0].id : '')
                    }, () => {
                        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
                    })
                }
            }
        });
    }

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

    //加载医嘱模版
    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.medID} ordSetID={item.ordSetID} ordTempletDetailID={item.ordTempletDetailID}
                disabled={this.state.titleData && this.state.titleData.depDoctorFlag == 'N' ? true : false}
                // key={item.ordTempletDetailID + '^' + item.ordTempletDetailItemID || item.id || index}>
                key={item.ordSetID + '-' + item.ordTempletDetailID + '^' + item.ordTempletDetailItemID || item.id || index}>
                {this.loadSunTemplates(item.data)}
            </TreeNode>)
            // }
        })
        return sunData
    }

    loadColumn() {
        var params = {
            params: [{
                compontName: 'DoctorAdviceListPage',
                type: 'C'
            }]
        }
        $http.post('urlDeault', this, {
            code: "01040073",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    var columns = res.result.C;
                    var dynColumns = []
                    for (var i = 0; i < columns.length; i++) {
                        if (columns[i].dataIndex == 'index') {
                            dynColumns.push({
                                title: columns[i].title,
                                dataIndex: columns[i].dataIndex,
                                width: parseInt(columns[i].width),
                                align: columns[i].align || 'center',
                                render: (text, data, index) => { return <span style={{ width: 80 }}>{data.ordSeqNo}</span> }
                            })
                        } else if (columns[i].dataIndex == 'ordMessage') { // 医嘱内容
                            dynColumns.push({
                                title: columns[i].title,
                                dataIndex: columns[i].dataIndex,
                                width: parseInt(columns[i].width),
                                align: columns[i].align || 'center',
                                render: (text, data) => {
                                    return (
                                        <div id={'hospital-ord-id-' + data.ordID} className="hdb-written-orders" onClick={() => this.handleMedItemDescClick(data)}>
                                            {data && data.writtenOrderFlag === 'Y' ? (
                                                <div className="hdb-written-orders-icon">
                                                    <span>文</span>
                                                </div>
                                            ) : ''}
                                            <span>{text}</span>
                                        </div>
                                    )
                                }
                            })
                        } else if (columns[i].dataIndex == 'ordMessage') {
                            dynColumns.push({
                                title: columns[i].title,
                                dataIndex: columns[i].dataIndex,
                                width: parseInt(columns[i].width),
                                align: columns[i].align || 'center',
                                render: (text, data, index) => {
                                    return <span><span style={{ color: 'red', marginRight: 5 }}>
                                        {!Util.isEmpty(data.refusalMessage) ? data.refusalMessage : ''}</span>
                                        <span style={{ color: data.operationFlag == 'Y' ? 'rgb(0, 122, 255)' : '' }}>{data.ordMessage}</span></span>
                                }
                            })
                        } else if (columns[i].dataIndex == 'ordLinkSign') {
                            dynColumns.push({
                                title: columns[i].title,
                                dataIndex: columns[i].dataIndex,
                                width: parseInt(columns[i].width),
                                align: columns[i].align || 'center',
                                render: (text, data) => {
                                    return <span style={{ color: 'blue' }}>{data.ordLinkSign}</span>
                                }
                            })
                        } else if (columns[i].dataIndex == 'opersion') {
                            dynColumns.push({
                                title: columns[i].title,
                                dataIndex: columns[i].dataIndex,
                                width: parseInt(columns[i].width),
                                align: columns[i].align || 'center',
                                render: (text, data) => {
                                    return <span onClick={this.showExecutionRecord.bind(this, data)}
                                        style={{ color: '#1890FF', cursor: 'pointer' }}>执行记录</span>
                                }
                            })
                        } else if (columns[i].dataIndex == 'ordNote') {
                            dynColumns.push({
                                title: columns[i].title,
                                dataIndex: columns[i].dataIndex,
                                width: parseInt(columns[i].width),
                                align: columns[i].align || 'center',
                                render: (text, data) => {
                                    return <Tooltip title={data.ordNote}><div className='doctor-list-explice'>{data.ordNote}</div></Tooltip>
                                }
                            })
                        } else if (columns[i].dataIndex == 'expenses') {
                            dynColumns.push({
                                title: columns[i].title,
                                dataIndex: columns[i].dataIndex,
                                width: parseInt(columns[i].width),
                                align: columns[i].align || 'center',
                                render: (text, data, index) => {
                                    return data.noINSUValue == 'Y' ? <Checkbox checked={data.noINSUFlag == 'Y' ? true : false}
                                        onChange={this.handleChangeCheckbox.bind(this, 'noINSUFlag', data, index)} /> : null
                                }
                            })
                        } else {
                            dynColumns.push({
                                title: columns[i].title,
                                dataIndex: columns[i].dataIndex,
                                width: parseInt(columns[i].width),
                                align: columns[i].align || 'center',
                            })
                        }

                    }
                    this.setState({
                        column: dynColumns,
                        totalWidth: res?.totalWidth || 0,
                    })
                    this.props.hanlderThis.setState({
                        reload: false,
                    })
                }
            }
        });
    }

    handleChangeCheckbox(name, data, index, e) {
        this.state.dataSource[index]['noINSUFlag'] = e.target.checked
        this.setState({}, () => {
            var params = {
                params: [{
                    ordDetailID: data.ordID,
                    userID: this.state.userData.userID,
                    noINSUFlag: e.target.checked == true ? 'Y' : 'N'
                }]
            }
            $http.post('urlDeault', this, {
                code: "03060032",
                data: params,
                success: function (res) {
                    if (res.errorCode == '0') {
                        message.success('操作成功！')
                        this.loadData(1)
                    }
                }
            });
        })
    }

    loadData(page, pageSize, e) {
        var params = {
            params: [
                {
                    admID: this.state.patientData.admID,
                    priorityID: this.state.priorityID,
                    ordCatID: this.state.ordCatID,
                    searchCode: this.state.searchCode,
                    sortCode: this.state.sortCode,
                    dateFrom: this.state.dateFrom,
                    dateTo: this.state.dateTo,
                    ordStatusID: this.state.ordStatusID,
                    ordLocID: this.state.ordLocID,
                    ordDocID: this.state.ordDocID,
                    ordSheetID: this.state.ordSheetID
                }
            ],
            pagination: [{
                pageSize: this.state.size == 'small' ? this.state.pageSize : PAGE_NUM_MORE_STATUS[0].code,
                currentPage: page
            }]
        }
        $http.post('urlDeault', this, {
            code: "03060006",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.setState({
                        dataSource: res.result.data,
                        total: res.result.totalCount,
                        search: 'search',
                        page: page,
                        loading: false,
                        messageTitle: res.result.message
                    })
                }
            }
        });
    }

    initData() {

    }

    showExecutionRecord(data) {
        this.setState({
            executionData: data,
            isShowExecutionRecordModal: true
        })
    }

    //结束
    loadSelectData() {
        var params = {
            params: [
                {
                    admID: this.state.patientData.admID,
                    priorityFlag: 'Y',
                    ordCatFlag: 'Y',
                    sortFlag: 'Y',
                    ordStatusFlag: 'Y',
                    ordLocFlag: 'Y',
                    ordDocFlag: 'Y',
                    ordSheetFlag: 'Y',
                    doctorFlag: 'Y'
                }
            ]
        }
        $http.post('urlDeault', this, {
            code: '03060007',
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    var ordLocList = res.data.ordLocList
                    var ordStatusList = res.data.ordStatusList
                    var sortList = res.data.sortList
                    var ordLocID = ''
                    if (!Util.isEmpty(ordLocList)) {
                        for (var i = 0; i < ordLocList.length; i++) {
                            if (ordLocList[i].defaultFlag == 'Y') {
                                ordLocID = ordLocList[i].id
                                break
                            }
                        }
                    }
                    var ordStatusID = []
                    if (!Util.isEmpty(ordStatusList)) {
                        for (var i = 0; i < ordStatusList.length; i++) {
                            if (ordStatusList[i].defaultFlag == 'Y') {
                                // ordStatusID = ordStatusList[i].id
                                // break
                                ordStatusID.push(ordStatusList[i].id)
                            }
                        }
                    }

                    var sortCode = ''
                    if (!Util.isEmpty(sortList)) {
                        for (var i = 0; i < sortList.length; i++) {
                            if (!Util.isEmpty(sortList[i].defaultFlag)) {
                                sortCode = sortList[i].id
                                break
                            }
                        }
                    }

                    //医嘱单类型
                    var ordSheetID = ''
                    var ordSheetList = res.data.ordSheetList
                    if (!Util.isEmpty(ordSheetList)) {
                        for (var i = 0; i < ordSheetList.length; i++) {
                            if (ordSheetList[i].defaultFlag == 'Y') {
                                ordSheetID = ordSheetList[i].id
                                break;
                            }
                        }
                    }

                    //医嘱类型
                    var ordPriorityID = ''
                    var priorityList = res.data.priorityList
                    if (!Util.isEmpty(priorityList)) {
                        for (var i = 0; i < priorityList.length; i++) {
                            if (priorityList[i].defaultFlag == 'Y') {
                                ordPriorityID = priorityList[i].id
                                break;
                            }
                        }
                    }
                    this.setState({
                        ordCatList: res.data.ordCatList,//医嘱分类
                        ordDocList: res.data.ordDocList,//开单医生
                        ordLocList: res.data.ordLocList,//开单科室
                        ordStatusList: res.data.ordStatusList,//医嘱状态
                        priorityList: res.data.priorityList,//医嘱类型
                        sortList: res.data.sortList,//排序
                        ordSheetList: res.data.ordSheetList,//医嘱单
                        ordLocID: ordLocID,
                        ordSheetID: ordSheetID,
                        ordStatusID: ordStatusID,
                        priorityID: ordPriorityID,
                        sortCode: sortCode
                    }, () => {
                        this.loadData(1)
                    })
                }
            }
        });
    }

    showMoreSelectMsg() {
        if (this.state.showSelect) {
            this.setState({
                showSelect: false
            })
        } else {
            this.setState({
                showSelect: true
            })
        }
    }

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

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

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

    onSelectChange(ids, useData) {
        this.setState({
            useData: useData
        })
    }

    //根据正选和反选，向对应数据增加一个标识，处理反选下拉依旧置灰问题
    onSelect(data, flag) {
        var { dataSource, ids, useData } = this.state;
        var code = []
        var sourceData = []
        if (Util.isEmpty(data.checkStatus) || data.checkStatus == false) {
            for (var i = 0; i < dataSource.length; i++) {
                if (data.ordID == dataSource[i].ordID || data.ordID == dataSource[i].ordMainID) {
                    // data['checkStatus'] = true
                    this.state.dataSource[i]['checkStatus'] = true
                    this.state.ids.push(dataSource[i].ordID)
                }
            }
        } else if (data.checkStatus == true) {
            data.checkStatus = false
            if (!Util.isEmpty(useData)) {
                for (var i = 0; i < useData.length; i++) {
                    for (var j = 0; j < ids.length; j++) {
                        if ((useData[i].ordID) == ids[j]) {
                            sourceData.push(useData[i])
                        }
                    }
                }
                for (var i = 0; i < sourceData.length; i++) {
                    if ((data.ordID !== sourceData[i].ordID)) {
                        if (data.ordID == sourceData[i].ordMainID) {
                            this.state.ids = []
                            this.setState({})
                        } else {
                            code.push(sourceData[i].ordID)
                            this.setState({ ids: code })
                        }
                    } else if (sourceData.length == 1) {
                        this.state.ids = []
                    }
                }
            } else {
                this.state.ids = []
            }
        }
        this.setState({})
    }

    onSelectAll(flag, selectedRows, changeRows) {
        for (var i = 0; i < changeRows.length; i++) {
            if (flag) {
                changeRows[i]['checkStatus'] = true
                this.state.ids.push(changeRows[i].ordID)
            } else {
                changeRows[i]['checkStatus'] = false
                this.state.ids = []
            }
        }
        this.setState({})
    }

    //鼠标移动添加样式
    addMouseOverStyle(name, e) {
        this.setState({
            addMouseStyle: true,
            indexStyle: name
        })
    }
    addMouseLeaveStyle() {
        this.setState({
            addMouseStyle: false,
            indexStyle: ''
        })
    }

    commonSelectOption(name, e, code) {
        if (name == 'priorityID') {
            var that = this;
            var { routeFlag, saveFlag } = this.state;
            // this.setState({
            //     [name]: e.target.value,
            //     // statusCode: code.props.code
            // }, () => {
            //     this.loadData(1)
            //     this.onLoadData.loadUnSaveData([], [])
            // })
            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.setState({
                            [name]: e.target.value,
                            routeFlag: []//组件切换后，销毁自组件数据
                        })
                    },
                    onCancel() {
                        that.setState({
                            [name]: e.target.value,
                            routeFlag: []//组件切换后，销毁自组件数据
                        }, () => {
                            that.loadData(1)
                            that.onLoadData.loadUnSaveData([], [])
                        })
                    }
                })
            } else {
                this.setState({
                    [name]: e.target.value,
                }, () => {
                    this.loadData(1)
                    this.onLoadData.loadUnSaveData([], [])
                })
            }
        } else {
            this.setState({
                [name]: e,
                // statusCode: code.props.code
            }, () => {
                this.loadData(1)
            })
        }
    }

    handleUnSaveData() {
        var temp = []
        var patientData = JSON.parse(sessionStorage.getItem('patientData'));
        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,
                infuseSpeedList: 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') {
                    this.loadData(1)
                    this.onLoadData.loadUnSaveData([], [])
                }
            }
        });
    }

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

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

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

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

    //隐藏弹出框
    hideModal(name) {
        this.setState({
            [name]: false,//将所有参数置为false
        });
    }

    //作废
    invalidAdvice(reasonID) {
        var { ids } = this.state;
        if (Util.isEmpty(ids)) {
            message.error('请选择您需要作废的医嘱！')
            return
        }
        var params = {
            params: [{
                ordID: this.state.ids,
                userID: this.state.userData.userID,
                locID: this.state.userData.locID,
                reasonID: reasonID
            }]
        }
        $http.post('urlDeault', this, {
            code: '03060011',
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    message.success('操作成功！')
                    this.hideModal('isShowStopAdviceReasonModal')
                    this.loadData(1)
                    this.setState({
                        ids: []
                    })
                }
            }
        });
    }

    //撤销
    handleUndoAdvice(reasonID) {
        var { ids } = this.state;
        if (Util.isEmpty(ids)) {
            message.error('请选择您需要撤销的医嘱！')
            return
        }
        var params = {
            params: [{
                ordID: this.state.ids,
                userID: this.state.userData.userID,
                locID: this.state.userData.locID,
                reasonID: reasonID
            }]
        }
        $http.post('urlDeault', this, {
            code: '03060010',
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    message.success('操作成功！')
                    this.hideModal('isShowStopAdviceReasonModal')
                    this.loadData(1)
                    this.setState({
                        ids: []
                    })
                }
            }
        });
    }

    //停医嘱
    handleStopAdvice() {
        var { ids, dataSource } = this.state;
        if (Util.isEmpty(ids)) {
            message.error('请选择您需要停的医嘱！')
            return
        }
        var modalSource = []
        for (var i = 0; i < ids.length; i++) {
            for (var j = 0; j < dataSource.length; j++) {
                if (ids[i] == dataSource[j].ordID) {
                    modalSource.push(dataSource[j])
                }
            }
        }
        this.setState({
            isShowStopAdviceModal: true,
            modalSource: modalSource
        })
    }

    handleStopDoctorAdvice(stopDate, stopTime, reasonID) {
        var params = {
            params: [{
                ordID: this.state.ids,
                userID: this.state.userData.userID,
                locID: this.state.userData.locID,
                stopDate: stopDate,
                stopTime: stopTime,
                reasonID: reasonID
            }]
        }
        $http.post('urlDeault', this, {
            code: '03060009',
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    message.success('操作成功！')
                    this.hideModal('isShowStopAdviceModal')
                    this.loadData(1)
                    this.setState({
                        ids: [],
                    })
                }
            }
        });
    }

    //复制
    handleCopyAdvice(name) {
        var { ids } = this.state;
        if (Util.isEmpty(ids)) {
            message.error('请选择您需要复制的医嘱！')
            return
        }
        var ordPriorityCode = '';
        if (name == 'long') {
            ordPriorityCode = 'S'
        } else if (name == 'temporary') {
            ordPriorityCode = 'NORM'
        } else {
            ordPriorityCode = 'OUT'
        }
        var params = {
            params: [{
                ordID: this.state.ids,
                userID: this.state.userData.userID,
                locID: this.state.userData.locID,
                groupID: this.state.userData.groupID,
                hospID: this.state.userData.hospID,
                admID: this.state.patientData.admID,
                ordPriorityCode: ordPriorityCode
            }]
        }

        // var { loadTableData } = this.props;
        // loadTableData && loadTableData(params)
        this.setState({
            adviceList: params
        })
    }

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

    showModal(flag) {
        if (this.state.showModal === true) {
            this.setState({
                showModal: false
            })
        } else {
            this.setState({
                showModal: true
            }, () => {
                this.loadModuleData()
                this.loadLocPersonMsg()
            })
        }

        // var { showModal } = this.props;
        // showModal && showModal(flag)
    }

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

    //显示隐藏医嘱列表
    hideHospitalList() {
        if (this.state.hideAdviceList === true) {
            this.setState({
                hideAdviceList: false
            })
        } else if (this.state.hideAdviceList === false) {
            this.setState({
                hideAdviceList: true
            })
        }
    }

    handleHideAdviceList(status) {
        this.setState({
            adviceStatus: status
        })
    }

    dstroyAdviceList() {
        this.setState({
            adviceList: ''
        })
    }

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

    //批量添加模板
    handleBatchTemplete() {
        this.depAdvices.handleBatchTemplete(this.state.nodeId, this.state.nodeCode)
    }

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

    //拖拽
    onMouseDropDwon(ev) {
        var disx = ev.pageX - this.state.dropX
        var disy = ev.pageY - this.state.dropY

        var that = this
        document.onmousemove = function (ev) {
            that.setState({
                dropX: ev.pageX - disx,
                dropY: ev.pageY - disy
            })
        }
        document.onmouseup = function () {
            document.onmousemove = null
            document.onmousedown = null
        }
    }

    depAdvice = (refs) => {
        this.depAdvices = refs
    }

    loadTempTableData(temp, e, code) {
        this.depAdvices.loadTempTableData(temp, e, code)
    }

    loadPackageTempTableData(temp, e, code) {
        this.depAdvices.loadPackageTempTableData(temp, e, code)
    }

    //跳转到草药录入界面
    goCMRrderSave() {
        var { hashROuter } = this.props;
        hashROuter && hashROuter(1);
    }

    //申请单路由跳转
    goDoctorAdviceStepPage = (num) => {
        var { hashROuter } = this.props;
        hashROuter && hashROuter(num, this.state.disBtnMessage);
    }

    showStopAdviceReasonModal(flag) {
        this.setState({
            isShowStopAdviceReasonModal: true,
            stopStatus: flag
        })
    }

    handleStopAdviceReason(reasonID) {
        if (this.state.stopStatus == '1') {
            this.invalidAdvice(reasonID)
        } else {
            this.handleUndoAdvice(reasonID)
        }
    }

    //添加模板
    addTemplateModal() {
        var { ids, useData } = this.state;
        if (!Util.isEmpty(ids)) {
            this.setState({
                isAddTemplateModal: true
            })
        } else {
            message.error('请选择需要添加的数据！')
            return
        }
    }

    onAddTemplateMOdal(data, code, record) {
        var { dataSource, ids, useData } = this.state;
        var source = []
        if (!Util.isEmpty(ids)) {
            for (var i = 0; i < dataSource.length; i++) {
                for (var j = 0; j < ids.length; j++) {
                    if (dataSource[i].ordID == ids[j]) {
                        source.push(dataSource[i])
                    }
                }
            }
        }
        var tempData = []
        for (var i = 0; i < source.length; i++) {
            if (code == 1) {
                tempData.push({
                    ...source[i],
                    ordTempletID: '',
                    ordTempletDetailID: '',
                    ordTempletDetailSeqNo: i,
                    ordTempletDetailTemplItemTypeCode: '01',
                    ordTempletDetailItemID: source[i].medID,
                    // ordTempletDetailQty: source[i].ordQty,
                    ordTempletDetailQtyUnitDr: source[i].ordQtyUomID,
                    bodyPart: source[i].ordbodyPartID,
                    ordPrioID: source[i].ordPriorityID,//优先级
                    dose: source[i].ordDose,//剂量
                    ordStageID: source[i].ordStageID,
                    doseUnitID: source[i].ordDoseUnitID,//剂量单位
                    frequenceID: source[i].ordFreqID,//频次
                    usageID: source[i].ordUsageID,//用法
                    durQty: source[i].ordDurQty,//疗程
                    durationID: source[i].ordDurationID,//疗程单位
                    priorityExtID: source[i].ordPriorityExtID,//附加说明
                    recLocID: source[i].ordRecLocID,//执行科室
                    ordSpecID: source[i].ordSpecID,//标本
                    emergencyFlag: source[i].ordEMFlag,//加急
                    note: source[i].ordNote,//备注
                    ordTempletDetailQty: Util.isEmpty(source[i].ordID) ? (source[i].ordNewQty ? source[i].ordNewQty : source[i].newQty) : source[i].ordQty,
                    skinTestFlag: source[i].ordSkinTestFlag == 'N' ? source[i].ordSkinTestFlagValue : source[i].ordSkinTestFlag,
                    skinTestWayID: source[i].ordSkinTestFlag == 'N' && source[i].ordSkinTestFlagValue == 'N' ? '' : source[i].ordSkinTestWayID,
                })
            } else {
                tempData.push({
                    ...source[i],
                    ordTempletID: record.ordTempletID,
                    ordTempletDetailID: '',
                    ordTempletDetailSeqNo: i,
                    ordTempletDetailTemplItemTypeCode: '01',
                    ordTempletDetailItemID: source[i].medID,
                    // ordTempletDetailQty: source[i].ordQty,
                    ordTempletDetailQtyUnitDr: source[i].ordQtyUomID,
                    bodyPart: source[i].ordbodyPartID,
                    ordStageID: source[i].ordStageID,
                    ordPrioID: source[i].ordPriorityID,//优先级
                    dose: source[i].ordDose,//剂量
                    doseUnitID: source[i].ordDoseUnitID,//剂量单位
                    frequenceID: source[i].ordFreqID,//频次
                    usageID: source[i].ordUsageID,//用法
                    durQty: source[i].ordDurQty,//疗程
                    durationID: source[i].ordDurationID,//疗程单位
                    priorityExtID: source[i].ordPriorityExtID,//附加说明
                    recLocID: source[i].ordRecLocID,//执行科室
                    ordSpecID: source[i].ordSpecID,//标本
                    emergencyFlag: source[i].ordEMFlag,//加急
                    note: source[i].ordNote,//备注
                    ordTempletDetailQty: Util.isEmpty(source[i].ordQty) ? (source[i].ordNewQty ? source[i].ordNewQty : source[i].newQty) : source[i].ordQty,
                    skinTestFlag: source[i].ordSkinTestFlag == 'N' ? source[i].ordSkinTestFlagValue : source[i].ordSkinTestFlag,
                    skinTestWayID: source[i].ordSkinTestFlag == 'N' && source[i].ordSkinTestFlagValue == 'N' ? '' : source[i].ordSkinTestWayID,
                })
            }
        }
        var params = {
            params: [{
                ordTempletID: record ? record.ordTempletID : '',
                ordTempletDesc: data.ordTempletDesc,
                ordTempletTypeID: data.ordTempletTypeID,
                ordTempletCatCode: '01',
                ordTempletAlias: data.ordTempletAlias,
                ordTempletStartDate: data.ordTempletStartDate,
                ordTempletStopDate: data.ordTempletStopDate,
                detailData: tempData
            }]
        }
        $http.post('urlS', this, {
            code: '03050012',
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    message.success('添加成功！')
                    this.hideModal('isAddTemplateModal')
                    this.setState({
                        ids: []
                    })
                }
            }
        })
    }

    //添加套餐
    addPackageModal() {
        var { ids, useData } = this.state;
        if (Util.isEmpty(ids)) {
            message.error('请选择需要添加的数据！')
            return
        }
        this.setState({
            isAddPackageModal: true
        })
    }

    onAddPackageModal(data) {
        var { dataSource, ids } = this.state;
        var source = []
        if (!Util.isEmpty(ids)) {
            for (var i = 0; i < dataSource.length; i++) {
                for (var j = 0; j < ids.length; j++) {
                    if (dataSource[i].ordID == ids[j] || dataSource[i].tabIndex == ids[j]) {
                        source.push({
                            ...dataSource[i],
                            ordSkinTestFlag: dataSource[i].ordSkinTestFlag == 'N' ? dataSource[i].ordSkinTestFlagValue : dataSource[i].ordSkinTestFlag,
                            ordSkinTestWayID: dataSource[i].ordSkinTestFlag == 'N' && dataSource[i].ordSkinTestFlagValue == 'N' ? '' : dataSource[i].ordSkinTestWayID,
                            oPer: this.state.operationID,
                            ordbodyPart: dataSource[i].ordbodyPartID,
                            // ordQty: temp[i].ordNewQty ? temp[i].ordNewQty : temp[i].newQty,
                            // ordQty: temp[i].defaultStatus == true ? temp[i].ordQty : (temp[i].ordNewQty ? temp[i].ordNewQty : temp[i].newQty),
                            ordQty: (dataSource[i].ordNewQty ? dataSource[i].ordNewQty : (dataSource[i].defaultStatus == true ? dataSource[i].ordQty : (dataSource[i] && dataSource[i].newQty ? dataSource[i].newQty : dataSource[i].ordQty))),
                            extvalue: [{
                                code: 'eyePart',
                                value: dataSource[i].eyePartID,
                                refDescripts: 'eyePartDesc',
                            }],
                            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,
                            infuseSpeedList: undefined,
                            degreesList: undefined,
                            eyePartList: undefined,
                            bodyPartList: undefined,
                        })
                    }
                }
            }
        }
        var params = {
            params: [{
                userID: this.state.userData.userID,
                locID: this.state.userData.locID,
                hospID: this.state.userData.hospID,
                ordSetID: data.ordSetID,
                code: data.descripts,
                descripts: data.descripts,
                alias: data.alias,
                authRangeID: data.authRangeID,
                startDate: data.startDate,
                stopDate: data.stopDate,
                orders: source
            }]
        }
        $http.post('urlDeault', this, {
            code: '03050061',
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    message.success('添加成功！')
                    this.hideModal('isAddPackageModal')
                    this.setState({
                        ids: []
                    })
                }
            }
        });
    }

    onRefLoadData = (ref) => {
        this.onLoadData = ref
    }

    changeActiveKey(e) {
        this.setState({
            activeKey: e
        })
    }

    loadLocPersonMsg() {
        // var params = {
        //     params: [{}]
        // }
        // $http.post('urlDeault', this, {
        //     code: '03050073',
        //     data: params,
        //     success: function (res) {
        //         if (res.errorCode == '0') {
        //             this.setState({
        //                 packageData: res.data,
        //                 authRangeID: !Util.isEmpty(res.data) ? res.data[0].id : ''

        //             }, () => {
        //                 this.loadLeftData()//套餐
        //             })
        //         }
        //     }
        // });
        var params = {
            params: [{
                hospID: this.state.userData.hospID,
                userID: this.state.userData.userID,
                locID: this.state.userData.locID,
            }]
        }
        $http.post('urlDeault', this, {
            code: '03050272',
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    var data = res.result
                    var authRangeID = ''
                    if (!Util.isEmpty(data)) {
                        for (var i = 0; i < data.length; i++) {
                            if (data[i].default == 'Y') {
                                authRangeID = data[i].id
                            }
                        }
                    }
                    this.setState({
                        packageData: res.result,
                        authRangeID: !Util.isEmpty(authRangeID) ? authRangeID : (!Util.isEmpty(res.result) ? res.result[0].id : '')

                    }, () => {
                        this.loadLeftData()//套餐
                    })
                }
            }
        });
    }

    loadLeftData(page, pageSize, e) {
        var params = {
            params: [{
                userID: this.state.userData.userID,
                locID: this.state.userData.locID,
                hospID: this.state.userData.hospID,
                groupID: this.state.userData.groupID,
                authRangeID: this.state.authRangeID,
                activeFlag: 'Y',
            }]
        }
        $http.post('urlDeault', this, {
            code: '03050060',
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.setState({
                        packageMsg: res.data.otherList || [],
                    })
                }
            }
        });
    }

    //套餐radio
    changePackageRadio(name, e) {
        this.setState({
            [name]: e.target.value
        }, () => {
            this.loadLeftData()
        })
    }

    loadPackageTemplate() {
        var templateTrees = []
        this.state.packageMsg && this.state.packageMsg.map((item, index) => {
            templateTrees.push(<TreeNode title={item.ordSetDesc} key={index + 'i' + '^'}
                disabled={(!Util.isEmpty(this.state.disMessage) || this.state.disBtn == 'N' ? true :
                    ((item.stock == '0') ? true : false))}
                nodeId={item.medID} ordSetID={item.ordSetID}>
                {this.loadPackageSunTemplate(item.data)}
            </TreeNode>)
        })
        return templateTrees
    }

    loadPackageSunTemplate(data) {
        //depDoctorFlag 非本院医生不允许开医嘱
        var packageSunData = []
        data && data.map((item, index) => {
            // if(item.data) {
            packageSunData.push(<TreeNode title={item.title} nodeId={item.medID} ordSetID={item.ordSetID}
                disabled={(!Util.isEmpty(this.state.disMessage) || this.state.disBtn == 'N' ? true :
                    ((item.stock == '0') ? true : false))} stock={item.stock}
                key={item.ordSetID + '-' + item.ordTempletDetailID + '^' + item.ordTempletDetailItemID || item.id || index}>
                {this.loadSunTemplate(item.data)}
            </TreeNode>)
            // }
        })
        return packageSunData
    }

    disBtnMessage = (disBtn) => {
        this.setState({
            disBtnMessage: disBtn
        }, () => {
            var { disBtnMessage } = this.props;
            disBtnMessage && disBtnMessage(disBtn)
        })
    }

    handleChangeBtn(name, e) {
        this.setState({
            [name]: e.target.value
        }, () => {
            if (this.state.defaultBtn == 1) {
                this.goCMRrderSave()
            } else if (this.state.defaultBtn == 3) {
                this.goDoctorAdviceStepPage(3)
            }
        })
    }


    //点击复选框
    checkTreeNode(e, data) {
        // if(data.node.props.nodeId) {
        var id = []
        var newNode = []
        if (e.length > 0) {
            for (var i = 0; i < e.length; i++) {
                id.push(e[i].substring(e[i].indexOf('^') + 1))
                newNode.push({
                    medID: e[i].substring(e[i].indexOf('^') + 1),
                    ordSetID: e[i].substring(e[i].indexOf('-'), 0),
                    ordTemplateID: e[i].substring(e[i].indexOf('^'), 1)
                })
            }
        }

        //将树结构的父级数据去除
        var code = []
        for (var i = 0; i < id.length; i++) {
            if (!Util.isEmpty(id[i])) {
                code.push(id[i])
            }
        }

        var nodeCode = []
        for (var i = 0; i < newNode.length; i++) {
            if (!Util.isEmpty(newNode[i].medID)) {
                nodeCode.push(newNode[i])
            }
        }

        this.setState({
            nodeId: code,
            newCode: e,
            nodeCode: nodeCode
        })
        // }
    }

    onExpandIcon(e) {
        this.setState({
            expandedKeys: e
        })
    }

    //点击树节点展开树
    onExpand(data, e) {
        var expandedKeys = [] = this.state.expandedKeys;
        var keys = []//该值用于点击同一节点时不会关闭其他的树节点
        if (!Util.isEmpty(e.props.children)) {//判断其点击节点下有子节点
            if (!Util.isEmpty(expandedKeys)) {
                for (var i = 0; i < expandedKeys.length; i++) {
                    if (e.props.eventKey !== expandedKeys[i]) {//用于将所有的树节点展开
                        keys.push(expandedKeys[i])
                        this.setState({
                            expandedKeys: expandedKeys.concat([e.props.eventKey])
                        })
                    } else {
                        this.setState({//当点击的是同一节点时，控制展开，关闭
                            expandedKeys: keys
                        })
                    }
                }
            } else {
                this.setState({
                    expandedKeys: [e.props.eventKey]
                })
            }
        }
    }

    //重新提交
    handleSubmit() {
        if (Util.isEmpty(this.state.ids)) {
            message.error('请选择医嘱')
            return
        }
        var params = {
            params: [{
                userID: this.state.userData.userID,
                ordIDs: this.state.ids,
                resubmit: 'Y',
            }]
        }
        $http.post('urlDeault', this, {
            code: '04030002',
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    message.success('提交成功')
                    this.setState({
                        ids: []
                    }, () => {
                        this.loadData(1)
                    })
                }
            }
        });
    }

    /**
     * @ByShizi: 点击名称规格展示相关医保信息
     * Create 2021-05-07
     * */
    handleMedItemDescClick = item => {
        let { tableFlag } = this.state;
        if (!(item && item.ordID) || tableFlag === 'N') return;
        let domInfo = document.getElementById('hospital-ord-id-' + item.ordID).getBoundingClientRect();
        let clientHeight = document.body.clientHeight;
        let height = domInfo?.height;
        let top = 0;
        if ((domInfo?.bottom + 300) < clientHeight) { // 弹框内容最高300px
            top = domInfo?.top + height + 5 + 'px'
        } else {
            top = domInfo?.top - 144 + 'px'
        }
        let left = domInfo?.left - 3 + 'px';
        this.setState({
            medItemTop: top,
            medItemLeft: left
        }, () => {
            this.getMedicalInsuranceData(item);
        });
    }

    // 获取医保展示数据
    getMedicalInsuranceData = item => {
        var params = {
            params: [{
                medID: item?.ordMedItemID || item?.medID || ''
            }]
        }
        $http.post('urlDeault', this, {
            code: "03050281",
            data: params,
            success: function (res) {
                let medicalInsuranceData = res.result && Array.isArray(res.result) && res.result.length > 0 ? res.result : [];
                if (+res.errorCode === 0 && medicalInsuranceData.length > 0) {
                    this.setState({ medicalInsuranceData, popoverVisible: true });
                } else {
                    message.info('暂无相关医保数据');
                    this.setState({ medicalInsuranceData: [], popoverVisible: false });
                }
            }
        });
    }

    render() {
        var { ids, sortList, ordCatList, ordDocList, ordLocList, ordStatusList, priorityList, ordSheetList, medicalInsuranceData, medItemTop, medItemLeft } = this.state;
        const rowSelection = {
            ids,
            onChange: this.onSelectChange.bind(this),
            onSelect: this.onSelect.bind(this),
            onSelectAll: this.onSelectAll.bind(this),
            getCheckboxProps: record => ({
                disabled: record.ordSelectFlag !== 'Y',
            }),
            selectedRowKeys: ids,
        }

        //排序
        var sortListOption = []
        sortList && sortList.map((item, index) => {
            sortListOption.push(<Option key={index} value={item.id}>{item.descripts}</Option>)
        })

        //医嘱分类
        var ordCatListOption = []
        ordCatList && ordCatList.map((item, index) => {
            ordCatListOption.push(<Option key={index} code={item.descriptsSPCode} value={item.id}>{item.descripts}</Option>)
        })

        //医嘱类型
        var priorityListOption = []
        priorityList && priorityList.map((item, index) => {
            // priorityListOption.push(<Option key={index} code={item.descriptsSPCode} value={item.id}>{item.descripts}</Option>)
            priorityListOption.push(<Radio key={index} code={item.descriptsSPCode} value={item.id}>{item.descripts}</Radio>)
        })

        //开单医生
        var ordDocListOption = []
        ordDocList && ordDocList.map((item, index) => {
            ordDocListOption.push(<Option key={index} value={item.id}>{item.descripts}</Option>)
        })

        //开单科室
        var ordLocListOption = []
        ordLocList && ordLocList.map((item, index) => {
            ordLocListOption.push(<Option key={index} value={item.id}>{item.descripts}</Option>)
        })

        //医嘱状态
        var ordStatusListOption = []
        ordStatusList && ordStatusList.map((item, index) => {
            ordStatusListOption.push(<Option key={index} code={item.code} value={item.id}>{item.descripts}</Option>)
        })

        //医嘱单
        var ordSheetListOption = []
        ordSheetList && ordSheetList.map((item, index) => {
            ordSheetListOption.push(<Option key={index} value={item.id}>{item.descripts}</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>
                )
            })
        }

        //套餐
        var packageDataOption = []
        this.state.packageData && this.state.packageData.map((item, index) => {
            packageDataOption.push(
                <Radio value={item.id} key={item.id}>{item.descripts}</Radio>
            )
        })

        return <div className="hospital-doctorAds-body">
            <ColumnAuthoritysModel
                clientWidth="800px"
                compontName="DoctorAdviceListPage"
                configType="C"
                onRef={this.onColumnRef}
                reloadData={this.loadColumn}
            />

            {/**执行记录弹框 */}
            <ShowExecutionRecordModal isShow={this.state.isShowExecutionRecordModal}
                onHide={this.hideModal.bind(this, 'isShowExecutionRecordModal')}
                executionData={this.state.executionData}>
            </ShowExecutionRecordModal>

            {/**停医嘱 */}
            <ShowStopAdviceModal isShow={this.state.isShowStopAdviceModal}
                modalSource={this.state.modalSource}
                onSubmit={this.handleStopDoctorAdvice.bind(this)}
                onHide={this.hideModal.bind(this, 'isShowStopAdviceModal')}>
            </ShowStopAdviceModal>

            {/**作废、撤销停医嘱原因 */}
            <ShowStopAdviceReasonModal isShow={this.state.isShowStopAdviceReasonModal}
                stopStatus={this.state.stopStatus}
                onSubmit={this.handleStopAdviceReason.bind(this)}
                onHide={this.hideModal.bind(this, 'isShowStopAdviceReasonModal')}>
            </ShowStopAdviceReasonModal>
            {/**添加模板 */}
            <AddTemplateModal isShow={this.state.isAddTemplateModal}
                onSubmit={this.onAddTemplateMOdal.bind(this)}
                onHide={this.hideModal.bind(this, 'isAddTemplateModal')}>
            </AddTemplateModal>
            {/**添加套餐 */}
            <AddPackageModal isShow={this.state.isAddPackageModal}
                onSubmit={this.onAddPackageModal.bind(this)}
                onHide={this.hideModal.bind(this, 'isAddPackageModal')}>
            </AddPackageModal>

            <div style={{ height: this.state.hideAdviceList ? '3vh' : '40vh' }}>
                <Row style={{ marginTop: 5 }}>
                    <Col span={2}>
                        <Icon className={this.state.hideAdviceList === true ? 'hospital-advice-list-hide' : 'hospital-advice-list-show'} style={{ float: 'left' }}
                            onClick={this.hideHospitalList.bind(this)} />
                        <span>
                            <span className='hospital-line-left' style={{ marginRight: 10, marginLeft: 10 }}></span>
                            <span style={{ lineHeight: '32px', color: '#007AFF' }}>医嘱列表</span></span>
                    </Col>
                    {this.state.hideAdviceList ? null : <div>
                        <Col span={6} style={{ marginTop: 5 }}>医嘱类型：
                            {/* <Select style={{ width: '75%' }} allowClear showSearch
                            placeholder='请选择医嘱类型'
                            filterOption={(input, option) =>
                                option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
                                || option.props.code.toLowerCase().indexOf(input.toLowerCase()) >= 0
                            }
                            onChange={this.commonSelectOption.bind(this, 'priorityID')}>{priorityListOption}</Select> */}
                            <Radio.Group onChange={this.commonSelectOption.bind(this, 'priorityID')} value={this.state.priorityID}>
                                {priorityListOption}
                            </Radio.Group>
                        </Col>
                        <Col span={4}>医嘱分类：<Select style={{ width: '69%' }} allowClear showSearch
                            placeholder='请选择医嘱分类'
                            filterOption={(input, option) =>
                                option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
                                || option.props.code.toLowerCase().indexOf(input.toLowerCase()) >= 0
                            }
                            onChange={this.commonSelectOption.bind(this, 'ordCatID')}>{ordCatListOption}</Select></Col>
                        <Col span={4}>医嘱名称：<Input style={{ width: '69%' }} placeholder='输入名称回车查询'
                            onKeyDown={this.keyDownInput.bind(this)}
                            onChange={Util.commonInputChange.bind(this, 'searchCode')} /></Col>
                        <Col span={4}>排序：<Select style={{ width: '79%' }} allowClear showSearch
                            placeholder='请选择排序' value={this.state.sortCode}
                            onChange={this.commonSelectOption.bind(this, 'sortCode')}>{sortListOption}</Select></Col>
                        <Col span={4}><Button style={{ cursor: 'pointer' }} onClick={this.showMoreSelectMsg.bind(this)}>更多条件
                            {this.state.showSelect ? <Icon type='up' /> : <Icon type='down' />}</Button>
                            <Button style={{ marginLeft: 10 }} type='primary' onClick={this.loadData.bind(this, '1')}>查询</Button>
                        </Col></div>}
                </Row>
                {this.state.hideAdviceList ? null : (this.state.showSelect ?
                    <Row style={{ marginTop: 5 }}>
                        <Col span={2}></Col>
                        {/* <Col span={5}>医嘱时间：<RangePicker style={{ width: '75%' }} onChange={this.changeRegistrTime.bind(this)} /></Col> */}
                        <Col span={5}><RangeDatePicker label={'医嘱时间：'} format='YYYY-MM-DD' totalwidth='95%' labelwidth='27%'
                            startChange={this.startChange.bind(this)} endChange={this.endChange.bind(this)} /></Col>
                        <Col span={4}>医嘱状态：<Select style={{ width: '69%' }} allowClear showSearch
                            placeholder='请选择医嘱状态' value={this.state.ordStatusID} mode="multiple"
                            filterOption={(input, option) =>
                                option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
                                || option.props.code.toLowerCase().indexOf(input.toLowerCase()) >= 0
                            }
                            onChange={this.commonSelectOption.bind(this, 'ordStatusID')}>{ordStatusListOption}</Select></Col>
                        <Col span={4}>开单科室：<Select style={{ width: '69%' }} allowClear showSearch
                            placeholder='请选择开单科室' value={this.state.ordLocID}
                            onChange={this.commonSelectOption.bind(this, 'ordLocID')}>{ordLocListOption}</Select></Col>
                        <Col span={4}>开单人员：<Select style={{ width: '69%' }} allowClear showSearch
                            placeholder='请选择开单人员'
                            onChange={this.commonSelectOption.bind(this, 'ordDocID')}>{ordDocListOption}</Select></Col>
                        <Col span={4}>医嘱单类型：<Select style={{ width: '63%' }} allowClear showSearch
                            placeholder='请选择医嘱类型' value={this.state.ordSheetID}
                            onChange={this.commonSelectOption.bind(this, 'ordSheetID')}>{ordSheetListOption}</Select></Col>
                    </Row> : null)}
                {this.state.hideAdviceList ? null : <div style={{ position: 'relative' }}>
                    <Table columns={this.state.column} style={{ marginTop: 5, borderBottom: '1px solid #e8e8e8' }}
                        dataSource={this.state.dataSource}
                        bordered
                        loadData={this.loadData.bind(this, '1')}
                        rowSelection={rowSelection}
                        onHeaderRow={column => {
                            return {
                                onDoubleClick: () => {
                                    this.columnRef.onOpenModel();
                                },
                            };
                        }}
                        scroll={{ x: this.state.totalWidth, y: store.getState().tableHeight.y + 'px' }}
                        // scroll={{ x: 2400, y: document.body.clientWidth > 1900 ? 220 : 140 }}
                        rowClassName={(data) => {
                            return data.ordStatusCode !== 'V' && data.ordStatusCode !== 'E' ? 'rowColorStyle' : (data?.ordHandleStatus === '未处理' ? 'row-untreated-med-bg' : '')
                        }}
                        title={() => {
                            return <div style={{ height: 35, lineHeight: '35px' }}>
                                <span style={{ cursor: 'pointer' }} className={this.state.indexStyle == '15' ? 'mouse-add-Style' : ''}
                                    onMouseLeave={this.addMouseLeaveStyle.bind(this)}
                                    // onClick={this.invalidAdvice.bind(this)}
                                    onClick={this.handleSubmit.bind(this)}
                                    onMouseOver={this.addMouseOverStyle.bind(this, '15')}>
                                    <Icon className='doctor-down-splice' />
                                    <span>重新提交</span>
                                </span><Divider type="vertical" />
                                <span style={{ cursor: 'pointer' }} className={this.state.indexStyle == '1' ? 'mouse-add-Style' : ''}
                                    onMouseLeave={this.addMouseLeaveStyle.bind(this)}
                                    // onClick={this.invalidAdvice.bind(this)}
                                    onClick={this.showStopAdviceReasonModal.bind(this, '1')}
                                    onMouseOver={this.addMouseOverStyle.bind(this, '1')}>
                                    <Icon className='doctor-unuse-splice' />
                                    <span>作废</span>
                                </span><Divider type="vertical" />
                                <span style={{ cursor: 'pointer' }} className={this.state.indexStyle == '2' ? 'mouse-add-Style' : ''}
                                    onMouseLeave={this.addMouseLeaveStyle.bind(this)}
                                    // onClick={this.handleUndoAdvice.bind(this)}
                                    onClick={this.showStopAdviceReasonModal.bind(this, '2')}
                                    onMouseOver={this.addMouseOverStyle.bind(this, '2')}>
                                    <Icon className='doctor-delete-splice' />
                                    <span>撤销</span>
                                </span><Divider type="vertical" />
                                <span style={{ cursor: 'pointer' }} className={this.state.indexStyle == '3' ? 'mouse-add-Style' : ''}
                                    onMouseLeave={this.addMouseLeaveStyle.bind(this)}
                                    onClick={this.handleStopAdvice.bind(this)}
                                    onMouseOver={this.addMouseOverStyle.bind(this, '3')}>
                                    <Icon className='hospital-stop-splice' />
                                    <span>停医嘱</span>
                                </span><Divider type="vertical" />
                                {/* <span style={{ cursor: 'pointer' }} className={this.state.indexStyle == '4' ? 'mouse-add-Style' : ''}
                                    onMouseLeave={this.addMouseLeaveStyle.bind(this)}

                                    onMouseOver={this.addMouseOverStyle.bind(this, '4')}>
                                    <Icon className='doctor-down-splice' />
                                    <span>添加模版</span>
                                </span><Divider type="vertical" />
                                <span style={{ cursor: 'pointer' }} className={this.state.indexStyle == '5' ? 'mouse-add-Style' : ''}
                                    onMouseLeave={this.addMouseLeaveStyle.bind(this)}
                                    onMouseOver={this.addMouseOverStyle.bind(this, '5')}>
                                    <Icon className='doctor-group-splice' />
                                    <span>添加套餐</span>
                                </span><Divider type="vertical" />
                                <span style={{ cursor: 'pointer' }} className={this.state.indexStyle == '6' ? 'mouse-add-Style' : ''}
                                    onMouseLeave={this.addMouseLeaveStyle.bind(this)}
                                    onMouseOver={this.addMouseOverStyle.bind(this, '6')}>
                                    <Icon className='doctor-cannel-group-splice' />
                                    <span>常用用法</span>
                                </span><Divider type="vertical" /> */}
                                <span style={{ cursor: 'pointer' }}
                                    className={this.state.indexStyle == '7' ? 'mouse-add-Style' : ''}
                                    onClick={this.handleCopyAdvice.bind(this, 'long')}
                                    onMouseLeave={this.addMouseLeaveStyle.bind(this)}
                                    onMouseOver={this.addMouseOverStyle.bind(this, '7')}>
                                    <Icon className='hospital-copy-splice' />
                                    <span>复制为长期</span>
                                </span><Divider type="vertical" />
                                <span style={{ cursor: 'pointer' }}
                                    className={this.state.indexStyle == '8' ? 'mouse-add-Style' : ''}
                                    onClick={this.handleCopyAdvice.bind(this, 'temporary')}
                                    onMouseLeave={this.addMouseLeaveStyle.bind(this)}
                                    onMouseOver={this.addMouseOverStyle.bind(this, '8')}>
                                    <Icon className='hospital-plus-square-splice' />
                                    <span>复制为临时</span>
                                </span><Divider type="vertical" />
                                <span style={{ cursor: 'pointer' }}
                                    className={this.state.indexStyle == '9' ? 'mouse-add-Style' : ''}
                                    onMouseLeave={this.addMouseLeaveStyle.bind(this)}
                                    onClick={this.handleCopyAdvice.bind(this, 'out')}
                                    onMouseOver={this.addMouseOverStyle.bind(this, '9')}>
                                    <Icon className='hospital-menu-unfold-splice' />
                                    <span>复制为出院带药</span>
                                </span><Divider type="vertical" />
                                <span style={{ cursor: 'pointer' }}
                                    className={this.state.indexStyle == '10' ? 'mouse-add-Style' : ''}
                                    onMouseLeave={this.addMouseLeaveStyle.bind(this)}
                                    onClick={this.addTemplateModal.bind(this, 'out')}
                                    onMouseOver={this.addMouseOverStyle.bind(this, '10')}>
                                    <Icon className='doctor-plus-square-splice' />
                                    <span>添加模板</span>
                                </span><Divider type="vertical" />
                                <span style={{ cursor: 'pointer' }}
                                    className={this.state.indexStyle == '11' ? 'mouse-add-Style' : ''}
                                    onMouseLeave={this.addMouseLeaveStyle.bind(this)}
                                    onClick={this.addPackageModal.bind(this, 'out')}
                                    onMouseOver={this.addMouseOverStyle.bind(this, '11')}>
                                    <Icon className='doctor-menu-unfold-splice' />
                                    <span>添加套餐</span>
                                </span>
                                <span style={{ float: 'right' }}>
                                    {/* <span style={{ color: '#1890FF', cursor: 'pointer' }} onClick={this.goCMRrderSave.bind(this)}>{'草药录入'}</span>
                                    <Divider type="vertical" />
                                    <span style={{ color: '#1890FF', cursor: 'pointer' }}
                                        onClick={() => this.goDoctorAdviceStepPage(3)}>{'申请单'}</span> */}
                                    <Radio.Group value={this.state.defaultBtn} buttonStyle="solid" onChange={this.handleChangeBtn.bind(this, 'defaultBtn')}>
                                        <Radio.Button value={2}>西药及其他</Radio.Button>
                                        <Radio.Button value={1}>{'草药录入'}</Radio.Button>
                                        <Radio.Button value={3}>{'申请单'}</Radio.Button>
                                    </Radio.Group>
                                </span>

                                <span style={{ marginLeft: 100, color: '#9254de', fontSize: '18px' }}>{this.state.messageTitle}</span>
                            </div>
                        }}
                        rowKey={(data) => {
                            return data.ordID
                        }}
                        pagination={false}>
                    </Table>
                    <CommonPagination current={this.state.page} total={this.state.total} search={this.state.search}
                        onShowSizeChange={this.changePageSize.bind(this)} complete={true} dataSource={this.state.dataSource} pageSize='200' size='large'
                        loading={this.state.loading} onChange={this.onChange.bind(this)} />
                    <div style={{ position: 'absolute', bottom: '12px', left: '6px', color: '#999', fontWeight: 'normal', fontSize: '12px' }} className="flex-align-items">
                        提示：<span className="common-record-color-notes-rect" style={{ background: '#36cfc9' }}></span>未处理
                    </div>
                </div>}
            </div>

            <div>
                <DoctorAdviceStepPage patStatus='1' loadData={this.loadData.bind(this, '1')}
                    handleHideAdviceList={this.handleHideAdviceList.bind(this)} hideStatus={this.state.hideAdviceList}
                    onRef={this.onRefLoadData} disBtnMessage={this.disBtnMessage} ordPriorityID={this.state.priorityID}
                    adviceList={this.state.adviceList} dstroyAdviceList={this.dstroyAdviceList.bind(this)}
                    componentRouter={this.componentRouter.bind(this)} ref={this.depAdvice}
                    showModal={this.showModal.bind(this)}></DoctorAdviceStepPage></div>

            {this.state.showModal ?
                <div style={{
                    width: '300px', position: 'absolute', zIndex: '11111',
                    left: this.state.dropX + 'px', top: this.state.dropY + 'px', cursor: 'move'
                }} className='hospital-drag-modal'
                    onMouseDown={this.onMouseDropDwon.bind(this)}>
                    <Card title={<span style={{ marginLeft: 10 }}><Icon className='card-title-splice' />医嘱模版</span>}
                        extra={
                            <div style={{ display: 'flex' }}>
                                {this.state.activeKey == '1' ? null : <div onClick={this.handleBatchTemplete.bind(this)} className='batch-add-temp'
                                    style={{ marginRight: 10 }}><Icon type='plus-circle' />
                                    {'批量添加'}</div>}
                                <div onClick={this.batchAddTemplate.bind(this)} className='batch-add-temp'><Icon type='close' /></div>
                            </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')}
                        /> */}
                        <Tabs onChange={this.changeActiveKey.bind(this)} activeKey={this.state.activeKey}>
                            <TabPane tab='医嘱套' key='1'>
                                <div className='doctor-left-radio'>
                                    <Radio.Group value={this.state.authRangeID}
                                        onChange={this.changePackageRadio.bind(this, 'authRangeID')}>
                                        {packageDataOption}
                                    </Radio.Group>
                                </div>

                                {this.state.packageMsg && this.state.packageMsg.length > 0 ?
                                    <Tree defaultExpandAll={true} defaultExpandedKeys={['1']}
                                        checkedKeys={this.state.newCode}
                                        onCheck={this.checkTreeNode.bind(this)}
                                        onClick={this.onExpand.bind(this)}
                                        onExpand={this.onExpandIcon.bind(this)}
                                        expandedKeys={this.state.expandedKeys}
                                        onDoubleClick={this.loadPackageTempTableData.bind(this, 'temp')}
                                    >
                                        {this.loadPackageTemplate()}
                                    </Tree> :
                                    <div style={{ marginLeft: '25%', marginTop: 40 }}>
                                        <span style={{ color: 'red', fontSize: '16px' }}>{'暂无医嘱套数据'}</span></div>}
                            </TabPane>
                            <TabPane tab='医嘱模板' key='2'>
                                <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 checkable defaultExpandAll={true} defaultExpandedKeys={['1']}
                                        checkedKeys={this.state.newCode}
                                        onCheck={this.checkTreeNode.bind(this)}
                                        onClick={this.onExpand.bind(this)}
                                        onExpand={this.onExpandIcon.bind(this)}
                                        expandedKeys={this.state.expandedKeys}
                                        onDoubleClick={this.loadTempTableData.bind(this, 'temp')}
                                    >
                                        {this.loadTemplate()}
                                    </Tree> :
                                    <div style={{ marginLeft: '25%', marginTop: 40 }}>
                                        <span style={{ color: 'red', fontSize: '16px' }}>暂无模版数据</span></div>}
                            </TabPane>
                        </Tabs>
                        {/* <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}
                                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>
                : null}

            {/* 医保信息展示 */}
            <Modal
                title=""
                visible={this.state.popoverVisible}
                onCancel={() => this.setState({ popoverVisible: false })}
                mask={false}
                closable={true}
                footer={null}
                width="300px"
                style={{ position: 'absolute', top: medItemTop ? medItemTop : '40%', left: medItemLeft ? medItemLeft : '40%', boxShadow: '0px 1px 4px rgba(0,0,0,0.3), 0px 0px 20px rgba(0,0,0,0.1) inset', paddingBottom: '0' }}
                wrapClassName="hospital-dalp-popover-modal"
            >
                <div className="hospital-dalp-popover-modal-content" onClick={React.$stopPropagation}>
                    {medicalInsuranceData && medicalInsuranceData.map((item, index) => {
                        return (
                            <div key={index} className="hospital-dalp-popover-modal-content-item">
                                <p>收费项代码：<span>{item?.chargeItemCode}</span></p>
                                <p>收费项描述：<span>{item?.chargeItemDesc}</span></p>
                                <p>医保代码：<span>{item?.insuItemCode}</span></p>
                                <p>医保描述：<span>{item?.insuItemDesc}</span></p>
                            </div>
                        )
                    })}
                </div>
            </Modal>
        </div>
    }

}

export default DoctorAdviceListPage;