/*
 * Creator:     ML
 * CreatDate:   2019-12-11
 * 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 PrescriptClassification from './PrescriptClassification'; // 管制分类
import PrescriptSub from './PrescriptSub'; // 关联医嘱子类
import PrescriptLoc from './PrescriptLoc'; // 关联科室
import '../style/index.less';
const TabPane = Tabs.TabPane;

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

    componentDidMount() {
        this.props.onTabChild(this);
        // var x = document.querySelectorAll(".ant-table-body");
        // for (var i = 0; i < x.length; i++) {
        //     x[i].style.height = store.getState().tableHeight.y-229 + 'px';
        //     x[i].style.overflow = "auto";
        //   }
        // this.getBigClass()
        // this.getAdviceType()
    }
//调用子组件 管制分类
prescriptClass=(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() {
        // let tabsHeight = store.getState().tableHeight.y-106  + 'px'
        return (
        
                <Tabs
                    activeKey={this.state.activeKey}
                    onChange={this.callback}
                    type="card"
                    className="prescriptsDom"
                    style={{ width: '100%', height:"auto",overflowY: "auto" }}
                >
                            {/* disabled={this.state.disTabs} */}
                    <TabPane tab="管制分类" disabled={this.state.disTabs} key="1">
                        <PrescriptClassification prescriptClass={this.prescriptClass} getSubLocDa={this.getSubLocDa} sendSubId={this.props.sendSubId}/>
                    </TabPane>
                    <TabPane tab="关联医嘱子类"  disabled={this.state.disTabs} key="2">
                        <PrescriptSub  onHopChild={this.onHopChild} getSubHopDa={this.getSubHopDa} sendSubId={this.state.subID}/>
                    </TabPane>
                    <TabPane tab="关联科室" disabled={this.state.disTabs} key="3">
                        <PrescriptLoc  onUsageChild={this.onUsageChild} getSubUsageData={this.getSubUsageData} sendSubId={this.state.subID}/>
                    </TabPane>
                </Tabs>
        )
    }
}
export default PrescriptRulesTabs