import React, { Component } from 'react';
import DoctorOrder from './DoctorOrder'

import { Tabs, message, Form, Row, Col, Checkbox, Input, Select } from 'antd';
import { $http } from '../../containers/config/https';
import './style/nurseConfig.less';//引入样式

const TabPane = Tabs.TabPane;
const Option = Select.Option;
let user;
class DoctorOrderConfig extends Component {    
    constructor(props) {
        user= window.sessionStorage.userData ? JSON.parse(window.sessionStorage.userData) : {};
        super(props);
        this.state = {
            ConfigType: [
                {
                    code: "LONG",
                    descripts: "长期医嘱"
                },
                {
                    code: "TEMP",
                    descripts: "临时医嘱"
                }
            ],
            hospID: user.hospID,
            hospital: [],
        }       
    }
 
    getHospital = () => {
        let data = {
            params: [{
                hospID: user.hospID,
                logonGroupID: user.groupID,
                logonHospID: user.hospID,
            }]
        }

        $http.post('urlDeault', this, {
            code: "01040001",
            data: data,
            success: (res) => {
                if (+res.errorCode === 0) {
                    this.setState({ hospital: res.depDoctor, hospID: user.hospID })
                } else {
                    message.error('保存失败' + res.errorMessage);
                }
            }
        })
    }
    onSelectChange = (value) => {
        this.setState({ hospID: value })
    }
    componentDidMount() {
        this.getHospital();
    }
    componentWillUnmount() {
        this.setState = (state, callback) => {
            return
        }
    }
    render() {
        let hospID = this.state.hospID;
        return (
            <Row className="nurseConfig">
                <Col span={24}>
                    <Select style={{ width: 300 }} defaultValue={user.hospID + ""} onChange={this.onSelectChange}>
                        {
                            this.state.hospital.map((item) => {
                                return (
                                    <Option key={item.id} value={item.id + ""} title={item.descspell} >{item.descripts}</Option>
                                )
                            })
                        }
                    </Select>
                </Col>
                <Col span={24}>
                    <Tabs>
                        {
                            this.state.ConfigType.map(function (value, key) {
                                return (
                                    <TabPane key={key} tab={value.descripts} style={{ height: "80%" }}>
                                        <DoctorOrder hospID={hospID} ConfigType={value.code}></DoctorOrder>
                                    </TabPane>
                                )
                            })
                        }
                    </Tabs>
                </Col>
            </Row>
        );
    }

}

export default DoctorOrderConfig;