/**
 * 坐诊医生信息
 */

import React from 'react';
import {
    Card, Table, Input, Form, Select, Row, Col,
    Modal, Button, Popconfirm, Tabs, message
} from 'antd';
import './style/index.less';
import { $http } from 'containers/config/https';
import { Util } from 'tools/index';
import AddMechanism from 'components/addMechanism/index';
const FormItem = Form.Item;
const Option = Select.Option;
const InputGroup = Input.Group;
const doctorImg = require('./image/doctor.png');

class Consultation extends React.Component {
    constructor(props) {
        super(props)
        var userData = JSON.parse(sessionStorage.getItem('userData'));
        this.state = {
            data: [],
            hospitalData: [],
            departmentData: [],
            doctorData: [],
            sumData: [],
            doctorRoom: [],
            userData: userData,
            newAmTimeData: [],
            newPmTimeData: [],
            bookMethodDetail: [],
            doctorDta: {},
            newData: {},
            dataSource: [],
            detail: [],
            saveStatus: false,
            curStatus: false,
            visible: false,
            timeRange: [],
            timeRangeID: '',
            resModel: []
        }
    }

    componentDidMount() {
        this.loadSchedulingTitleType()
    }

    loadSchedulingTitleType() {
        var params = {
            params: [{
                // hospitalId:this.state.userData.hospDr,
                hospID: this.state.userData.hospID,
                active: 'Y'
            }]
        }
        $http.post('urlDeault', this, {
            code: "01040160",
            data: params,
            success: function (res) {
                if (res.errorCode === '0') {
                    var data = res.result.data;
                    var resourceTypeID = ''
                    if (!Util.isEmpty(data)) {
                        resourceTypeID = data[0].id
                    }
                    this.setState({
                        resourceType: res.result.data,
                        resourceTypeID: resourceTypeID
                    }, () => {
                        this.loadHospitalMsg();
                        this.loadBookMethodDetail();
                    })
                }
            }
        });
    }

    //获取预约方式信息
    loadBookMethodDetail() {
        var params = {
            params: [{
                hospID: this.state.userData.hospID
            }]
        }
        $http.post('urlDeault', this, {
            code: "01040033",
            data: params,
            success: function (res) {
                if (res.errorCode === '0') {
                    this.setState({
                        bookMethodDetail: res.method,
                    })
                }
            }
        });
    }

    initData() {
        this.columns = [
            {
                title: '医生名称',
                dataIndex: 'descripts',
                width: 80,
                align: 'left'
            }, {
                title: '医生职称',
                dataIndex: 'title',
                width: 80,
                align: 'left'
            }, {
                title: '操作',
                dataIndex: 'opertion',
                width: 80,
                align: 'left',
                render: (title, data) => {
                    return (
                        data.schedulingFlag == 'Y' ? <span>
                            {/* <Icon type="delete" style={{ color: 'rgba(240,65,52,1)' }}></Icon> */}
                            <Popconfirm title="确定清除该坐诊设置吗?" onConfirm={this.handleDel.bind(this, data)} >
                                <span className='span' style={{ color: 'rgba(240,65,52,1)' }}>清除坐诊设置</span>
                            </Popconfirm>
                        </span> : null)
                }
            },
        ]
    }

    //获取医院信息
    loadHospitalMsg() {
        var params = {
            params: [{
                // hospitalId:this.state.userData.hospDr,
                logonHospID: this.state.userData.hospID,
                logonGroupID: this.state.userData.groupID,
                hospRequired: '1',
                resourceTypeID: this.state.resourceTypeID
            }]
        }
        $http.post('urlDeault', this, {
            code: "01040001",
            data: params,
            success: function (res) {
                if (res.errorCode === '0') {
                    this.setState({
                        hospitalData: res.depDoctor
                    }, () => {//只有当医院有数据的时候才能查出数据
                        this.loadscheduType();
                        this.getDoctorRoom();//获取诊室
                        this.initData();
                        this.getDepartment(this.state.userData.hospID);
                        this.loadConsulation()
                        this.getDoctor();//获取坐诊医生
                        this.getSelectDoctor()
                    })
                }
            }
        });
    }

    //获取医院ID
    handleSelectChangeHos(e) {
        var id = '';
        if (e) {
            id = e.substring(e.indexOf('^') + 1)
        }
        this.setState({
            hospitalId: id,
            departId: undefined,
            depDoctorId: '',
            showDepart: false,

        }, () => {//切换医院，重新渲染排班类型
            this.getDepartment(id);//获取医院信息后调查看科室接口
            this.loadscheduType();
        })
    }

    //获取科室ID
    changeDepartment(e) {
        // var id = '';
        // var departName = '';
        // if (e) {
        //     id = e.substring(e.indexOf('^') + 1)
        //     departName = e.substring(0, e.indexOf('-'))
        // }
        // this.setState({
        //     departId: id,
        //     departName: departName,
        //     depDoctorId: ''
        // })
        this.setState({
            departId: e,
            depDoctorId: '',
            selectDoctorData: [],
            showDepart: false,
            roomDr: undefined
        }, () => {
            this.getDoctor(e, '')
            this.getSelectDoctor(e, '')
            this.getDoctorRoom()
        })
    }

    //获取坐诊医生ID
    changeDoctorId(e) {
        // var id = '';
        // var docName = ''
        // if (e) {
        //     id = e.substring(e.indexOf('^') + 1);
        //     docName = e.substring(0, e.indexOf('-'))
        // }
        // this.setState({
        //     depDoctorId: id,
        //     docName: docName
        // }, () => {
        // })
        this.setState({
            depDoctorId: e,
        }, () => {
            this.getDoctor('', e)
        })
    }

    getDepartment(e) {
        var params = {
            params: [{
                hospID: e,
                resourceTypeID: this.state.resourceTypeID
            }]
        }
        $http.post('urlS', this, {
            code: "03020046",
            data: params,
            success: function (res) {
                if (res.errorCode === '0') {
                    var depart = res.result.Data
                    var showDepart = false
                    if (!Util.isEmpty(depart)) {
                        for (var i = 0; i < depart.length; i++) {
                            if (this.state.userData.locID == depart[i].id) {
                                showDepart = true
                                break
                            }
                        }
                    }
                    this.setState({ departmentData: res.result.Data, showDepart: showDepart }, () => {
                        this.getDoctor()
                        this.getSelectDoctor()
                    })
                }
            }
        })
    }

    //获取坐诊类型
    loadscheduType() {
        var params = {
            params: [
                {
                    hospID: this.state.hospitalId ? this.state.hospitalId : this.state.userData.hospID,
                    resourceTypeID: this.state.resourceTypeID
                }
            ],
            pagination: [{
                pageSize: 1000,
                currentPage: 1
            }]
        }
        $http.post('urlDeault', this, {
            code: "03020004",
            data: params,
            success: function (res) {
                if (res.errorCode === '0') {
                    this.setState({
                        sumData: res.result.Data,
                    })
                }
            }
        });
    }

    getSelectDoctor(departId, depDoctorId) {
        var show = false
        var { departmentData } = this.state;
        if (!Util.isEmpty(departmentData)) {
            for (var i = 0; i < departmentData.length; i++) {
                if (this.state.userData.locID == departmentData[i].id) {
                    show = false
                    break
                } else {
                    show = true
                }
            }
        } else {
            if (this.state.hospitalId) {
                show = true
            } else {
                show = false
            }
        }
        var params = {
            params: [{
                locID: departId ? departId : (this.state.departId ? this.state.departId : (show === false ? this.state.userData.locID : '')),
                groupID: '',
                depDoctorID: depDoctorId || '',
                hospID: this.state.hospitalId ? this.state.hospitalId : this.state.userData.hospID,
                resourceTypeID: this.state.resourceTypeID
            }]
        }
        $http.post('urlDeault', this, {
            code: "03020049",
            data: params,
            success: function (res) {
                if (res.errorCode === '0') {
                    this.setState({
                        selectDoctorData: res.depDoctor
                    })
                }
            }
        });
    }

    //获取坐诊医生
    getDoctor(departId, depDoctorId) {
        var show = false
        var { departmentData } = this.state;
        if (!Util.isEmpty(departmentData)) {
            for (var i = 0; i < departmentData.length; i++) {
                if (this.state.userData.locID == departmentData[i].id) {
                    show = false
                    break
                } else {
                    show = true
                }
            }
        } else {
            if (this.state.hospitalId) {
                show = true
            } else {
                show = false
            }
        }
        var params = {
            params: [{
                locID: departId ? departId : (this.state.departId ? this.state.departId : (show === false ? this.state.userData.locID : '')),
                groupID: '',
                depDoctorID: depDoctorId || '',
                hospID: this.state.hospitalId ? this.state.hospitalId : this.state.userData.hospID,
                resourceTypeID: this.state.resourceTypeID
            }]
        }
        $http.post('urlDeault', this, {
            code: "03020049",
            data: params,
            success: function (res) {
                if (res.errorCode === '0') {
                    this.setState({
                        doctorData: res.depDoctor,
                        rowId: res.depDoctor && res.depDoctor.length > 0 ? res.depDoctor[0].id : '',
                        doctorDta: res.depDoctor && res.depDoctor.length > 0 ? res.depDoctor[0] : '',
                        depDoctorID: res.depDoctor && res.depDoctor.length > 0 ? res.depDoctor[0].depDoctorID : '',
                    }, () => {
                        if (!Util.isEmpty(res.depDoctor) && !Util.isEmpty(res.depDoctor[0])) {
                            this.loadConsulation(res.depDoctor[0])
                        }
                    })
                }
            }
        });
    }

    //获取诊室
    getDoctorRoom() {
        var params = {
            params: [{
                hospID: this.state.hospitalId,
                locID: this.state.departId ? this.state.departId : this.state.userData.locID,
                resourceTypeID: this.state.resourceTypeID
            }]
        }
        // var params = []
        $http.post('urlDeault', this, {
            code: "01040023",
            data: params,
            success: function (res) {
                if (res.errorCode === '0') {
                    this.setState({
                        doctorRoom: res.room
                    })
                }
            }
        });
    }

    loadConsulation(data) {
        var params = {
            params: [{
                depDoctorID: data ? data.depDoctorID : '',
                hospID: this.state.hospitalId ? this.state.hospitalId : this.state.userData.hospID,
                resourceTypeID: this.state.resourceTypeID
            }]
        }
        // var params = []
        $http.post('urlDeault', this, {
            code: "03020063",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.setState({
                        resModel: res.resModel,
                        timeRange: res.timeRange,
                    }, () => {
                        this.getModelDetail('resModel');
                        this.addMechanismRef?.setMechanismData(res?.mechanismData || [])
                    })
                }
            }
        });
    }

    //点击行，渲染当前行样式
    onClickRow = (record) => {
        this.props.form.resetFields()
        return {
            onClick: () => {
                this.setState({
                    saveStatus: false,
                    curStatus: false,
                    rowId: record.id,
                    doctorDta: record,
                    depDoctorID: record.depDoctorID,
                    record: record,
                    roomDr: ''
                }, () => {
                    this.loadConsulation(record)
                });
            },
        };
    }

    //点击行，渲染当前行样式
    setRowClassName = (record) => {
        return record.id === this.state.rowId ? 'clickRowStyle' : '';
    }

    //获取所有医生列表
    getDoctorList() {
        var doctorOption = []
        doctorOption.push(
            <Card className='scheduling-list' style={{ marginTop: 5, height: '77%', overflow: 'auto' }}
                title={<span><span className='scheduling-title-borders'></span>
                    <span style={{ fontWeight: 'bold', marginLeft: '20px' }}>医生列表</span></span>}>
                <Table columns={this.columns} bordered
                    style={{ marginTop: '10px', marginLeft: '10px' }}
                    dataSource={this.state.doctorData}
                    loadData={this.getDoctor.bind(this)}
                    // title={() => {
                    //     return <span style={{ fontWeight: 'bold' }}>医生列表</span>
                    // }}
                    onRow={this.onClickRow}
                    rowClassName={this.setRowClassName}
                    rowKey={(data) => {
                        return data.id + '&&' + data.detpDoctorlID
                    }}
                    pagination={false}></Table></Card>
        )
        return doctorOption;
    }

    //删除对应医生
    handleDel(data) {
        var params = {
            params: [{
                depDoctorID: data.depDoctorID,//医生ID
                userID: this.state.userData.userID,
                resourceTypeID: this.state.resourceTypeID
            }]
        }
        $http.post('urlDeault', this, {
            code: "03020034",
            data: params,
            success: function (res) {
                if (res.errorCode === '0') {
                    message.success('删除成功！')
                    this.getDoctor()
                }
            }
        });
    }

    //获取普通门诊医生
    getOrdinaryList() {
        var ordinaryList = []
        this.state.ordinaryData && this.state.ordinaryData.map((item, index) => {
            ordinaryList.push(<p className='borderStyle' key={index} value={item.id + ''}>
                <span style={{ marginRight: '10%' }}>{item.descripts}</span>
                <span style={{ marginRight: '45%' }}>{item.title}</span>
            </p>)
        })
        return ordinaryList;
    }

    //当切换坐诊类型后，当医院和坐诊类型ID不为空，调用取时间段接口
    handleSelectChange(e) {
        if (e && this.state.hospitalId) {
            this.setState({
                regTitleId: e
            })
        }
    }

    //切换时间间隔，获取对应的具体时段
    changeTimeModel(data, index, e) {
        this.state.saveStatus = true;
        this.state.curStatus = true;
        if (Util.isEmpty(this.state.rowId)) {
            message.error('坐诊医生不能为空，请先选择坐诊医生！')
            return
        }
        var params = {
            params: [{
                depDoctorID: this.state.depDoctorID,//医生ID
                timeRangeID: data.timeRangeID,//时段ID
                intervalID: e,//时间间隔id
                resModelID: data.modelID,//
                resourceTypeID: this.state.resourceTypeID
            }]
        }
        // var params = []
        if (!Util.isEmpty(e)) {
            $http.post('urlDeault', this, {
                code: "03020033",
                data: params,
                success: function (res) {
                    if (res.errorCode === '0') {
                        if (data.timeRangeID == res.resModelDetail.timeRangeID) {
                            this.state.newData[index] = res.resModelDetail.data;
                            this.state.resModel[index]['statusData'] = true;
                            this.setState({
                                resModelDetail: res.resModelDetail.data,
                                newTimeRangId: res.resModelDetail.timeRangeID,
                                curStatus: true,
                                // timeId:e
                            }, () => {
                                this.getModelDetail();
                            })
                        }
                    }
                }
            });
            //将时间间隔ID，push进dataSource中
            var { resModel } = this.state;
            for (var i = 0; i < resModel.length; i++) {
                if (i == index) {
                    this.state.dataSource.push({})
                    resModel[i].timeIntervalID = e
                }
            }
        } else {
            //将时间间隔ID，push进dataSource中
            var { resModel } = this.state;
            for (var i = 0; i < resModel.length; i++) {
                if (i == index) {
                    resModel[i].detail = []
                    this.state.newData[index] = []
                    this.state.dataSource.push({})
                    resModel[i].timeIntervalID = undefined
                    this.setState({ timeId: e }, () => {
                        this.getModelDetail();
                    })
                }
            }
        }
    }

    // 获取时段时段下拉数据
    getModelDetail = (type) => {
        const { newData, resModel } = this.state;
        let modelDetail = [];
        if (type === 'resModel') {
            for (let i = 0; i < resModel.length; i++) {
                modelDetail.push(...(resModel[i]?.detail || []));
            }
        } else {
            for (let keys in newData) {
                modelDetail.push(...newData[keys]);
            }
        }
        this.setState({ modelDetail });
    }

    onSubmit(data, status) {
        var { resModel, doctorDta, resModelDetail } = this.state;
        // if(Util.isEmpty(this.state.sessionTypeId) && !Util.isEmpty(this.state.roomDr)){
        //     message.error('坐诊诊室无法单独保存，请选择对应的排班信息再进行保存！')
        //     return
        // }
        let { validateFields } = this.props.form;
        validateFields({ force: true }, (err, params) => {
            for (var i = 0; i < resModel.length; i++) {
                var detail = resModel[i].detail;
                if (detail) {
                    for (var j = 0; j < detail.length; j++) {
                        if (parseInt(detail[j].appointNum) > parseInt(detail[j].registNum)) {
                            message.error('可预约数不能大于总号源数，请重新输入！')
                            return
                        }
                    }
                }
                if (Util.isEmpty(params.roomDr)) {
                    message.error('诊室不能为空，请选择诊室！')
                    return
                }
                resModel[i].depDoctorID = doctorDta.depDoctorID,
                    resModel[i].addNum = "",//空
                    resModel[i].roomID = this.state.roomDr ? this.state.roomDr : resModel[i].roomID,//诊室ID
                    resModel[i]['expertiseID'] = "",//专长
                    resModel[i]['togetherSource'] = "",//空
                    resModel[i]['userID'] = this.state.userData.userID
                resModel[i]['modelID'] = resModel[i].modelID
                resModel[i]['resourceTypeID'] = this.state.resourceTypeID
            }
            var params = {
                params: this.state.resModel,
                mechanismData: this.addMechanismRef?.getMechanismData()
            }
            $http.post('urlDeault', this, {
                code: "03020062",
                data: params,
                success: function (res) {
                    if (res.errorCode == '0') {
                        this.getDoctor()
                        message.success('保存成功！')
                        this.loadConsulation(this.state.record)
                    }
                }
            });
        });
    }

    //获取数组中，排班类型的参数
    handleSelectScheduling(data, index, name, e) {
        if (Util.isEmpty(this.state.rowId)) {
            message.error('坐诊医生不能为空，请先选择坐诊医生！')
            return
        }
        var { resModel } = this.state;
        this.state.saveStatus = true;
        this.state.curStatus = true;
        for (var i = 0; i < resModel.length; i++) {
            if (i == index) {
                resModel[i].regTitleID = e
            }
        }
        this.setState({ sessionTypeId: e })
    }

    //焦点切换
    changeFocusRegistr(data, index, code, e) {
        // if(e.keyCode == '13') {
        //     var inputs = document.getElementsByClassName('input');
        //     console.dir(inputs)
        // }
        var inputs = document.getElementsByClassName('input');
        function init() {
            for (let i = 0; i < inputs.length; i++) {
                inputs[i].onkeydown = focus(i)
            }
        }
        var focus = function handle(i) {
            return function (event) {
                var next = (i + 1) < inputs.length ? i + 1 : 0;  // 判断是否为最后一个输入框，是则返回第一个，否则继续下一个
                var eve = event ? event : window.event;
                if (eve.keyCode === 13) {
                    if (inputs[next].tagName === 'INPUT') {
                        inputs[next].focus();    //获取焦点
                    } else {
                        console.log(22)
                    }
                }
            }
        }
        init()
    }

    //获取总挂号限额框参数
    changeRegistNum(data, index, code, e) {
        var regNum = 0;
        this.state.saveStatus = true;
        this.state.curStatus = true;
        var data = e.target.value;
        if (!(/(^[1-9]\d*$)/.test(data)) && data.length > 0) {
            message.error('请输入整数')
            return
        }
        var { resModelDetail, resModel, newData } = this.state;
        for (var j = 0; j < resModel.length; j++) {
            if (j == index) {
                for (var i = 0; i < newData[index].length; i++) {
                    resModel[j].registNum = 0
                    if (i == code) {
                        newData[j][i].registNum = 0
                        newData[j][i].registNum = e.target.value
                        this.state.detail.push({})
                        newData[j][i].registNum = e.target.value,
                            newData[j][i].userID = this.state.userData.userID,
                            newData[j][i].timeDetailID = newData[j][i].indexId
                    }
                    regNum += parseInt(newData[j][i].registNum ? newData[j][i].registNum : 0)
                }
                resModel[j].registNum = regNum;
                // this.state.dataSource.push({})
                resModel[j].detail = newData[j]
                // this.state.dataSource[j].details = resModel[j].defaultDataList

                this.setState({})
            }
        }
    }

    //获取总可预约限额参数
    changeAppointNum(data, index, code, e) {
        var appNum = 0;
        this.state.saveStatus = true;
        this.state.curStatus = true;
        var data = e.target.value;
        if (!(/(^[1-9]\d*$)/.test(data)) && data.length > 0) {
            message.error('请输入整数')
            return
        }
        var { resModelDetail, resModel, newData } = this.state;
        for (var j = 0; j < resModel.length; j++) {
            var appNum = 0;
            if (j == index) {
                for (var i = 0; i < newData[index].length; i++) {
                    resModel[j].appointNum = 0
                    if (i == code) {
                        newData[j][i].appointNum = 0
                        this.state.detail.push({})
                        newData[j][i].appointNum = e.target.value,
                            newData[j][i].userID = this.state.userData.userID,
                            newData[j][i].timeDetailID = newData[j][i].indexId
                    }
                    appNum += parseInt(newData[j][i].appointNum ? newData[j][i].appointNum : 0)
                }
                resModel[j].appointNum = appNum;
                // this.state.dataSource.push({details:[]})
                resModel[j].detail = newData[j]
                this.setState({})
            }
        }
    }

    //当为默认参数时
    changeDefRegistNum(data, index, code, e) {
        this.state.saveStatus = true;
        var defRegNum = 0;
        var datas = e.target.value;
        if (!(/(^[1-9]\d*$)/.test(datas)) && datas.length > 0) {
            message.error('请输入整数')
            return
        }
        var { resModelDetail, resModel } = this.state;
        for (var j = 0; j < resModel.length; j++) {
            if (j == index) {
                for (var i = 0; i < data.length; i++) {
                    resModel[j].registNum = 0
                    if (i == code) {
                        this.state.detail.push({})
                        data[i].registNum = 0,
                            data[i].registNum = e.target.value,
                            data[i].userID = this.state.userData.userID,
                            data[i].timeDetailID = data[i].indexId
                    }
                    defRegNum += parseInt(data[i].registNum ? data[i].registNum : 0)
                }
                resModel[j].detail = data
                resModel[j].registNum = defRegNum;

                this.setState({})
            }
        }
    }

    //选中下拉框
    handleSelectChangeRoom(e) {
        this.setState({
            roomDr: e,
            saveStatus: true
        })
    }
    
    handleSelectTimeRange(e) {
        this.setState({
            timeRangeID: e
        })
    }

    changeDefAppointNum(data, index, code, e) {
        this.state.saveStatus = true;
        var difAppNum = 0;
        var datas = e.target.value;
        if (!(/(^[1-9]\d*$)/.test(datas)) && datas.length > 0) {
            message.error('请输入整数')
            return
        }
        var { resModelDetail, resModel } = this.state;
        for (var j = 0; j < resModel.length; j++) {
            if (j == index) {
                for (var i = 0; i < data.length; i++) {
                    resModel[j].appointNum = 0
                    if (i == code) {
                        this.state.detail.push({})
                        data[i].appointNum = 0,
                            data[i].appointNum = e.target.value,
                            data[i].userID = this.state.userData.userID,
                            data[i].timeDetailID = data[i].indexId
                    }
                    difAppNum += parseInt(data[i].appointNum ? data[i].appointNum : 0)
                }
                resModel[j].appointNum = difAppNum;
                resModel[j].detail = data

                this.setState({})
            }
        }
    }

    changeRecorceType(data) {
        this.setState({
            resourceTypeID: data.id
        }, () => {
            this.loadHospitalMsg()
        })
    }

    // 修改弹窗状态
    modifyVisible = (visible) => {
        this.setState({ visible })
    }

    //弹窗确认按钮
    handleOk = () => {
        let { timeRangeID, resModel } = this.state;
        let obj = {}
        for (var i = 0; i < resModel.length; i++) {
            var curtimeRangeID = resModel[i].timeRangeID
            if (curtimeRangeID == timeRangeID) {
                obj = resModel[i]
                break;
            }
        }
        var addObj = {
            appointNum: '',
            depDoctorID: obj.depDoctorID,
            detail: [],
            intervalList: obj.intervalList,
            modelID: '',
            regTitle: '',
            regTitleID: '',
            registNum: '',
            roomID: '',
            timeInterval: '',
            timeIntervalID: '',
            timeRange: obj.timeRange,
            timeRangeID: obj.timeRangeID,
        }
        resModel.push(addObj)
        this.setState({
            resModel: resModel
        })
        this.modifyVisible(false);
    }

    render() {
        let { getFieldDecorator } = this.props.form;
        let formItemLayout = {
            labelCol: { span: 5 },
            wrapperCol: { span: 10 }
        };
        let searchColConfig = {
            xs: { span: 24 },
            sm: { span: 12 },
            md: { span: 13 },
            lg: { span: 8 }
        }
        //所属医院参数
        let hospitalOption = [];
        this.state.hospitalData && this.state.hospitalData.map((item, index) => {
            hospitalOption.push(<Option key={index} value={item.id} name={item.descripts} code={item.descriptsSPCode}>{item.descripts}</Option>)
        })
        //获取科室Department
        let departmentOption = [];
        this.state.departmentData && this.state.departmentData.map((item, index) => {
            departmentOption.push(<Option key={index} endsp={item.descriptsSPCode} code={item.descripts} value={item.id}>{item.descripts}</Option>)
        })

        //坐诊类型sumData
        let sumDataOption = []
        this.state.sumData && this.state.sumData.map((item, index) => {
            sumDataOption.push(<Option key={index} value={item.id}>{item.descripts}</Option>)
        })

        //坐诊医生
        let doctorOption = []
        // value={item.descripts + '-' + item.code + item.descriptsSPCode + '^' + item.depDoctorID + ''}
        this.state.selectDoctorData && this.state.selectDoctorData.map((item, index) => {
            doctorOption.push(<Option key={index} value={item.depDoctorID}
                code={item.descriptsSPCode} name={item.descripts}>
                {item.descripts}</Option>)
        })
        //坐诊时段
        let timeRangeArr = []
        this.state.timeRange && this.state.timeRange.map((item, index) => {
            timeRangeArr.push(<Option key={index} value={item.timeRangeID} name={item.descripts}>
                {item.descripts}</Option>)
        })

        //坐诊诊室
        let doctorRoomOption = []
        this.state.doctorRoom && this.state.doctorRoom.map((item, index) => {
            doctorRoomOption.push(<Option key={index + item} value={item.id + ''}>{item.descripts}</Option>)
        })
        var { resModel, visible } = this.state;
        var modelDetailData = []//总开放号源
        //获取总的号源时间段，push到对应的位置
        resModel && resModel.map((item, index) => {
            modelDetailData.push(
                <div style={{ display: 'flex' }}>
                    <div className='right-card-time'><span className='right-card-span' key={index}>{item.timeRange}</span></div>
                    <div className='right-card-border'>
                        <FormItem label={
                            <span style={{ fontWeight: 'bold', marginLeft: 10 }}>
                                {/* <span key={index}>{item.timeRange}</span> */}
                                <span key={index + '-1'}>总计&nbsp;&nbsp;{item.registNum || '0'} </span>
                                <span key={index + '-3'}>预约限号&nbsp;&nbsp;{item.appointNum || '0'} </span>
                            </span>}>
                            {getFieldDecorator('5', {
                                initialValue: this.state.inputData,
                            })(
                                <div>
                                    <div className='background-title' style={{ display: 'flex' }}>
                                        <div>
                                            <div className='scheduling-backgrd'>排班类型：</div>
                                            <Select placeholder="请选择排班类型" style={{ width: '120px', marginLeft: 10 }}
                                                allowClear
                                                value={this.state.sessionTypeId ? item.regTitleID : (item.regTitleID ? item.regTitleID : undefined)}
                                                onChange={this.handleSelectScheduling.bind(this, item, index, 'sessionTypeDr')}
                                                getPopupContainer={triggerNode => triggerNode.parentNode}>
                                                {sumDataOption}
                                            </Select>
                                        </div>
                                        <div style={{ marginLeft: 5 }}>
                                            <div className='scheduling-backgrd'>时间间隔：</div>
                                            <Select placeholder="请选择时间间隔" style={{ width: '120px' }}
                                                allowClear
                                                getPopupContainer={triggerNode => triggerNode.parentNode}
                                                value={this.state.timeId ? this.state.timeId : (item.timeIntervalID ? item.timeIntervalID : undefined)}
                                                onChange={this.changeTimeModel.bind(this, item, index)}
                                            >
                                                {item.intervalList && item.intervalList.map((data, index) => {
                                                    return (<Option value={data.id} key={data.id + ''}>{data.timeLength || '全时段'}</Option>)
                                                })}
                                            </Select>
                                        </div>
                                        {item.statusData ?
                                            <div className='home-lunbo' style={{ marginLeft: 20 }}>{this.state.newData[index] && this.state.newData[index].map((newData, code) => {
                                                return (
                                                    <span className='schedulingNo'>
                                                        <div className='scheduling-backgrd'>{newData.timeRangDetail}</div>
                                                        <div>
                                                            <InputGroup compact style={{ width: '140px' }}>
                                                                <Input placeholder='号源数' style={{ width: '65px' }} className='input'
                                                                    value={newData.registNum ? newData.registNum : ''}
                                                                    onKeyDown={this.changeFocusRegistr.bind(this, newData, index, code)}
                                                                    onChange={this.changeRegistNum.bind(this, newData, index, code)}
                                                                />
                                                                <Input placeholder='可预约数' style={{ width: '65px' }} className='input'
                                                                    onChange={this.changeAppointNum.bind(this, newData, index, code)}
                                                                    value={newData.appointNum ? newData.appointNum : ''} />
                                                            </InputGroup>
                                                        </div>
                                                    </span>
                                                )
                                            })}</div> :
                                            <div className='home-lunbo' style={{ marginLeft: 20 }}>
                                                {item.detail && item.detail.map((data, code) => {
                                                    return (
                                                        <span className='schedulingNo'>
                                                            <div className='scheduling-backgrd'>{data.timeRangDetail}</div>
                                                            <div>
                                                                <InputGroup compact style={{ width: '140px' }}>
                                                                    <Input placeholder='号源数' style={{ width: '65px' }} className='input'
                                                                        onChange={this.changeDefRegistNum.bind(this, item.detail, index, code)}
                                                                        onKeyDown={this.changeFocusRegistr.bind(this, item.detail, index, code)}
                                                                        value={data.registNum ? data.registNum : ''}
                                                                    />
                                                                    <Input placeholder='可预约数' style={{ width: '65px' }} className='input'
                                                                        onChange={this.changeDefAppointNum.bind(this, item.detail, index, code)}
                                                                        onKeyDown={this.changeFocusRegistr.bind(this, item.detail, index, code)}
                                                                        value={data.appointNum ? data.appointNum : ''}
                                                                    />
                                                                </InputGroup>
                                                            </div>
                                                        </span>
                                                    )
                                                })}</div>}
                                    </div>
                                </div>
                            )}
                        </FormItem></div>
                </div>
            )
        })

        var roomId = ''
        if (resModel) {
            for (var i = 0; i < resModel.length; i++) {
                if (resModel[i].roomID) {
                    roomId = resModel[i].roomID;
                    break
                }
            }
        }

        var resourceTypeOption = []
        this.state.resourceType && this.state.resourceType.map((item, index) => {
            resourceTypeOption.push(<Button key={index} value={item.id} size="large" style={{ marginRight: 5 }}
                className={item.id == this.state.resourceTypeID ? 'resource-btn-bgd' : ''}
                onClick={this.changeRecorceType.bind(this, item)}>{item.descripts}</Button>)
        })

        return (
            <div className='addDoctorBody' style={{ background: '#F5F7FE', height: '100%', width: '100%', overflow: 'hidden' }}>
                <div className='scheduling-broad-title'>
                    <Card>
                        {resourceTypeOption}
                    </Card>
                </div>
                <div className='leftCard' style={{ height: '90%' }}>
                    <Card gutter={0} title={<span style={{ float: 'left' }}><span className='scheduling-title-borders'></span>
                        <span style={{ marginLeft: 10 }}>搜索科室医生</span></span>}>
                        <div className='leftCardHeader'>
                            <Form>
                                <Row>
                                    所属医院：<Select placeholder="请选择所属医院" style={{ width: '170px' }}
                                        defaultValue={this.state.userData.hospDesc}
                                        // allowClear={true}
                                        disabled={this.state.hospitalData && this.state.hospitalData.length < 2 ? true : false}
                                        showSearch
                                        filterOption={(input, option) =>
                                            option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
                                            || option.props.code.toLowerCase().indexOf(input.toLowerCase()) >= 0
                                            || option.props.name.toLowerCase().indexOf(input.toLowerCase()) >= 0
                                        }
                                        onChange={this.handleSelectChangeHos.bind(this)}
                                        getPopupContainer={triggerNode => triggerNode.parentNode}>
                                        {hospitalOption}
                                    </Select>
                                </Row>
                                <Row style={{ marginTop: 5 }}>
                                    所属科室：<Select placeholder="请选择所属科室" style={{ width: '170px' }}
                                        showSearch
                                        // allowClear={true}
                                        filterOption={(input, option) =>
                                            option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
                                            || option.props.code.toLowerCase().indexOf(input.toLowerCase()) >= 0
                                            || option.props.endsp.toLowerCase().indexOf(input.toLowerCase()) >= 0
                                        }
                                        value={this.state.departId ? this.state.departId : ((this.state.showDepart ? this.state.userData.locID : undefined))}
                                        onChange={this.changeDepartment.bind(this)}
                                        getPopupContainer={triggerNode => triggerNode.parentNode}>
                                        {departmentOption}
                                    </Select>
                                </Row>
                                <Row style={{ marginTop: 5 }}>
                                    坐诊医生：<Select placeholder="请选择坐诊医生" style={{ width: '170px' }}
                                        showSearch
                                        allowClear={true}
                                        filterOption={(input, option) =>
                                            option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
                                            || option.props.code.toLowerCase().indexOf(input.toLowerCase()) >= 0
                                            || option.props.name.toLowerCase().indexOf(input.toLowerCase()) >= 0
                                        }
                                        value={this.state.depDoctorId}
                                        onChange={this.changeDoctorId.bind(this)}
                                        getPopupContainer={triggerNode => triggerNode.parentNode}>
                                        {doctorOption}
                                    </Select>
                                </Row>
                            </Form>
                        </div>
                    </Card>
                    <div className='left-doctor-list'>{this.getDoctorList()}</div></div>
                <Card className='rightCard' style={{ height: '94%', minHeight: '600px', overflow: 'auto' }}
                    title={<span style={{ float: 'left' }}><span className='scheduling-title-borders'></span>
                        <span style={{ marginLeft: 10 }}>坐诊医生设置</span></span>}>
                    <Form>
                        <Row gutter={10} style={{ marginTop: 10 }}>
                            <Col {...searchColConfig}>
                                <img className='scheduling-image' src={doctorImg} />
                                <FormItem {...formItemLayout} label="坐诊医生">
                                    {getFieldDecorator('doctorDrId', {
                                        initialValue: this.state.doctorDta ? this.state.doctorDta.descripts : undefined,
                                    })(
                                        <Input style={{ width: 180 }} disabled={true} placeholder='请输入坐诊医生' />
                                    )}
                                </FormItem>
                            </Col>
                            <Col {...searchColConfig}>
                                <FormItem {...formItemLayout} label={<span><span style={{ color: '#f5222d', fontFamily: 'SimSun', marginLeft: '10%' }}>*</span>
                                    <span style={{ marginLeft: 3 }}>{"坐诊诊室"}</span></span>}>
                                    {getFieldDecorator('roomDr', {
                                        initialValue: this.state.roomDr ? this.state.roomDr : (roomId ? roomId : undefined),
                                        // rules: [{ required: true, message: '坐诊诊室不能为空' }],
                                    })(
                                        <Select placeholder="请选择坐诊诊室" style={{ width: '180px' }}
                                            onChange={this.handleSelectChangeRoom.bind(this)}
                                            // value={roomId}
                                            getPopupContainer={triggerNode => triggerNode.parentNode}>
                                            {doctorRoomOption}
                                        </Select>
                                    )}
                                </FormItem>
                            </Col>
                            <Col {...searchColConfig}>
                                <Button disabled={!this.state.saveStatus} className={!this.state.saveStatus ? 'disSaveBtn' : 'saveTableButton'}
                                    onClick={this.onSubmit.bind(this, 'save')}>保存</Button>
                                <Button style={{ marginLeft: "20px" }} onClick={() => this.modifyVisible(true)}>添加号源</Button>
                            </Col>

                        </Row>
                        {modelDetailData}
                        <Row style={{ marginTop: 10 }}>
                            <AddMechanism
                                onRef={ref => this.addMechanismRef = ref}
                                onSubmit={this.onSubmit.bind(this)}
                                bookMethodDetail={this.state.bookMethodDetail}
                                saveStatus={this.state.saveStatus}
                                deptDoctorId={this.state.depDoctorId}
                                regTitleId={this.state.regTitleId}
                                modelDetail={this.state.modelDetail}>
                            </AddMechanism>
                        </Row>
                    </Form>
                </Card>
                <Modal
                    title="请选择时段"
                    visible={visible}
                    destroyOnClose={true}
                    width="600px"
                    onOk={this.handleOk}
                    onCancel={() => this.modifyVisible(false)}
                >
                    <div style={{ textAlign: 'center' }}>
                        时段：
                        <Select placeholder="请选择时段" style={{ width: '180px' }}
                            onChange={this.handleSelectTimeRange.bind(this)}>
                            {timeRangeArr}
                        </Select>
                    </div>
                </Modal>
            </div >
        )
    }
}
export default Form.create()(Consultation);