/*
 * Creator:     ML
 * CreatDate:   2019-10-08
 * descripts：  医嘱子类表维护  接收科室/关联医院/用法
*/
import React from 'react';
import { Tabs, Row, Col, Icon, Divider,Modal,} from 'antd';
import store from '../../../store';
import { $http } from '../../../containers/config/https';
import SubclassReception from './SubclassReception'; // 接收科室
import SubclassAffHospital from './SubclassAffHospital'; // 关联医院
import SubclassUsage from './SubclassUsage'; // 用法

// import './style/index.less';

const TabPane = Tabs.TabPane;



 class SubclassReceivingTabs extends React.Component {
    constructor( porps ) {
        super(porps);
        this.state = {
            activeKey: '1',
            userInfo: {}, //用户数据
            visible: false,//是否弹个人信息
            disTabs:true
        }

    }
  
    componentDidMount() {
        this.props.onTabChild(this);
    }
//调用子组件 获取接收科室
onReceptionChild=(ref)=>{
    this.onRecChild = ref
}
//调用子组件 获取医院
onHopChild=(ref)=>{
    this.onHopChilds = ref
    }
//调用子组件 获取用法
onUsageChild=(ref)=>{
    this.onUsageChilds = ref
    }    
getRec=(subID)=>{
    if(subID&&subID){
        this.setState({
            subID
        })
        this.onRecChild.initSearch(subID,)
    }
}
//获取接收科室
getSubLocDa=(subID)=>{
    this.onRecChild.initSearch(subID)
    // this.onRecChild.initPagination()
}
//获取关联医院
getSubHopDa=(subID)=>{
    if(this.state.activeKey=="2"){
        setTimeout(()=>{
        this.onHopChilds.initSearch(subID)
        this.onHopChilds.initPagination()
    },800) 
    }
}
//获取用法
getSubUsageData=(subID)=>{
    if(this.state.activeKey=="3"){
        setTimeout(()=>{
            this.onUsageChilds.initSearch(subID)
            this.onUsageChilds.initPagination()
    },800) 
    }
}
//取消之后 tabs下状态变为初始
initTabs=()=>{
    this.setState({
        disTabs:true
    })
    let initObj= {
        "1":()=>this.onRecChild.initData("disSave"),
        "2":()=>this.onHopChilds.initData("disSave"),
        "3":()=>this.onUsageChilds.initData("disSave"),
    }
    if(initObj[this.state.activeKey]){
        setTimeout(()=>{
            initObj[this.state.activeKey]()
        },800) 
    }
}
//切换左侧 右下数据清空
restFile=()=>{
    let restObj = {
        "1":()=>this.onRecChild.handleRightCancel("1"),
        "2":()=>this.onHopChilds.handleRightCancel("1"),
        "3":()=>this.onUsageChilds.handleRightCancel("1"),
    }
    if(restObj[this.state.activeKey]){
        restObj[this.state.activeKey]()
    }
    
}
//保存之后 回归编辑状态 获取当前tabs表格数据
canSave=(subID)=>{
    this.setState({
        disTabs:false
    })
    let saveObj = {
        "1":()=>this.onRecChild.canSaveTab(subID),
        "2":()=>this.onHopChilds.canSaveTab(subID),
        "3":()=>this.onUsageChilds.canSaveTab(subID),
    }
    if(saveObj[this.state.activeKey]){
        setTimeout(()=>{
            saveObj[this.state.activeKey]()
        },800) 
    }
}
    // 导航栏切换
    callback = (key) => {
        this.setState({ activeKey: key })
        const {subID} = this.state
        if(key=="1"){
            if(this.state.subID&&this.state.subID){
                setTimeout(()=>{
                    this.onRecChild.canSaveTab(subID)
                    this.onRecChild.initSearch(subID)
                },800) 
             }
        }
        if(key=="2"){
            if(this.state.subID&&this.state.subID){
               setTimeout(()=>{
                this.onHopChilds.canSaveTab(subID)
                this.onHopChilds.initSearch(this.state.subID)
            },800) 
            }
        }if(key=="3"){
            if(this.state.subID&&this.state.subID){
                setTimeout(()=>{
                    this.onUsageChilds.canSaveTab(subID)
                    this.onUsageChilds.initSearch(subID)
            },800) 
             }
        }
    }
    render() {
        return (
        
                <Tabs
                    activeKey={this.state.activeKey}
                    onChange={this.callback}
                    type="card"
                    className="new_department_tabs"
                    style={{ width: '100%', height:"100%",overflowY: "auto" }}
                >

                    <TabPane tab="接收科室" disabled={this.state.disTabs} key="1">
                        <SubclassReception onReceptionChild={this.onReceptionChild} getSubLocDa={this.getSubLocDa} sendSubId={this.props.sendSubId}/>
                    </TabPane>
                    <TabPane tab="关联医院" disabled={this.state.disTabs} key="2">
                        <SubclassAffHospital  onHopChild={this.onHopChild} getSubHopDa={this.getSubHopDa} sendSubId={this.state.subID}/>
                    </TabPane>
                    <TabPane tab="用法" disabled={this.state.disTabs} key="3">
                        <SubclassUsage  onUsageChild={this.onUsageChild} getSubUsageData={this.getSubUsageData} sendSubId={this.state.subID}/>
                    </TabPane>
                </Tabs>
        )
    }
}
export default SubclassReceivingTabs