/*
 * Creator:     ML
 * CreatDate:   2020-02-26
 * descripts：  服务组右tab
 * */
import React from 'react';
import { Tabs } from 'antd';
import './style/index.less';
import ServiceGroupDoctors from './component/ServiceGroupDoctors.jsx'; // 服务组医生
import ServiceGroupItems from './component/ServiceGroupItems.jsx'; // 服务项目

const TabPane = Tabs.TabPane;

class ServiceGroupTabs extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            activeKey:"1"
        }
    }
    componentDidMount() {
        this.props.onTabs(this)
    }
     // 导航栏切换
     callback = (key) => {
        this.setState({ activeKey: key })
    }
    //服务组 医生
    onDoctord = (ref) => {
        this.onDoctorRef = (ref)
    }
    //获取医生下拉框数据
    getDocData = (record) => {
        this.setState({
            rowIds: record.id,
            hosID: record.hospId,
            locId:record.locId
        }, () => {
            this.onDoctorRef.getDocData(record.id,record.locId)
        })
    }
    //获取医生列表
    onChangeDoc = (n) => {
        this.onDoctorRef.onChangeDoc(n)
    }
    //服务组 项目
    onItems = (ref) => {
        this.onItemsRef = (ref)
    }
    getAuthorizationList = (id) => {
        this.setState({
            rowIdtoHosId: id
        }, () => {
            if(this.state.activeKey=="2"){
                this.onItemsRef.getAuthorizationList(id)
            }
        })
    }
    getOtherLoc = (id) => {
        this.setState({
            rowIdtoHosId: id
        }, () => {
            if(this.state.activeKey=="2"){
                this.onItemsRef.getOtherLoc(id)
            }
        })
    }

    handleRestListchange = () => {
        if(this.state.activeKey=="1"){
            this.onDoctorRef.handleRestListchange()
        }else{
            this.onItemsRef.handleRestListchange()
        }
    }
    handleRestListCancel= () => {
        this.setState({
            rowIds:"",
            hosID: "",
            locId:""
        })
        if(this.state.activeKey=="1"){
            this.onDoctorRef.handleRestListchange()
        }else{
            this.onItemsRef.handleRestListchange()
        }  
        if(this.state.activeKey=="1"){
            this.onDoctorRef.handleRestListCancel()
        }else{
            this.onItemsRef.handleRestListCancel()
        }
      }
    render() {
        return <div className='outpatient-station-body' style={{ height: '100%' }}>
            <Tabs type="card" className='patient-tab-body' style={{ height: '100%' }} size='small'  activeKey={this.state.activeKey}
                    onChange={this.callback}>
                <TabPane tab={<span>服务组医生</span>} key="1">
                    <ServiceGroupDoctors onDoctord={this.onDoctord} rowIds={this.state.rowIds} hosID={this.state.hosID} locId={this.state.locId}/>
                </TabPane>
                <TabPane tab={<span>服务项目</span>} key="2">
                    <ServiceGroupItems onItems={this.onItems} rowIdtoHosId={this.state.rowIdtoHosId} rowIds={this.state.rowIds} />
                </TabPane>
            </Tabs>
        </div>
    }
}
export default ServiceGroupTabs;