/*
 * Creator:     ML
 * CreatDate:   2020-04-08
 * descripts：  问卷调查
 * */
import React from 'react';
import {
    Card, Table, Input, Form, Select, Row, Col, Checkbox, Tabs,
    DatePicker, Button, Popconfirm, Icon, Divider, message, Modal,
} from 'antd';
// import { Util, dayFormat } from 'tools/index';
import { $http } from 'containers/config/https';
import store from 'store';
import './style/StatisticalAnalysis.less';
import './style/assessment.less';
import AssessmentLeftList from './component/AssessmentLeftList'

import AssessmentMMSE from './component/AssessmentMMSE.jsx';//MMSE
import AssessmentIADL from './component/AssessmentIADL.jsx';//IADL
import AssessmentHADS from './component/AssessmentHADS.jsx';//HADS
import AssessmentOfPelvicFloorMuscles from './component/AssessmentOfPelvicFloorMuscles.jsx';//盆底肌评估
const TabPane = Tabs.TabPane;
const confirm = Modal.confirm;
class QuestionnaireAtHomePage extends React.Component {
    constructor(props) {
        super(props)
        var userData = JSON.parse(sessionStorage.getItem('userData'))
        this.state = {
            dataSource: [],
            total: 0,
            page: 1,
            pageSize: 10,
            userData: userData,
            activeKey: '6',
        }
    }

    componentDidMount() {
        this.props.ques(this)
    }
    componentWillUnmount() {
        // 组件销毁前将静止让setState修改state的状态
        this.setState = (state, callback) => { return; }
    }
    // 导航栏切换
    callback = (key) => {
        var that = this;
        if (sessionStorage.getItem("noSave") && JSON.parse(sessionStorage.getItem("noSave")) === true) {
            confirm({
                title: '提示',
                content: '当前页面数据还没保存，确定要切换页面吗？',
                okText: that.state.userData.language == 'EN' ? 'Ok' : '确定',
                cancelText: that.state.userData.language == 'EN' ? 'cancel' : '取消',
                onOk() {
                    window.sessionStorage.setItem("noSave",false);
                    that.setState({ activeKey: key },()=>{
                        window.sessionStorage.setItem("noSave",false);
                        that.clearAll()
                        that.getDocID()
                    })
                },
                onCancel() {
                    return
                }
            })
        } else {
            that.setState({ activeKey: key },()=>{
                that.clearAll()
                that.getDocID()
            })
        }
        
    }
    handleTo=(key)=>{
        // console.log(key)
    let obj = {
     
        "6":()=>this.childMMSE.setValue(this.childrecord.state.detailsId),
        "7":()=>this.childIADL.setValue(this.childrecord.state.detailsId),
        "8":()=>this.childHADS.setValue(this.childrecord.state.detailsId),
        "9":()=>this.childFloort.setValue(this.childrecord.state.detailsId),
    }
    if(obj[key]){
        obj[key]()
    }
    // debugger
    }
    //获取体检责任医师
    getDocID = () => {
        // console.log("getDocID",this.childrecord.state.detailsId )
        // console.log("this.state.activeKey22222",this.state.activeKey)
        if (this.childrecord.state.detailsId && this.childrecord.state.detailsId) {
            // console.log(this.childrecord.state.detailsId,"---------",id)
            this.setState({
                doctorID: this.childrecord.state.detailsId
            }, () => {
                // console.log("this.state.activeKey",this.state.activeKey)
                this.handleTo(this.state.activeKey)
                
            })
        }
    }
    handleClear=(key,d)=>{
        // console.log(key)
    let obj = {
      
        "6":()=>this.childMMSE.clear(d),
        "7":()=>this.childIADL.clear(d),
        "8":()=>this.childHADS.clear(d),
        "9":()=>this.childFloort.clear(d),
    }
    if(obj[key]){
        obj[key]()
    }
    // debugger
    }
    //清除调查问卷
    clearAll=()=>{
        this.handleClear(this.state.activeKey,"d")
    }
    //添加问卷调查 新增一条体检记录
    updateList=()=>{
        this.childrecord.initialData()
    }
    onRef = (ref) => {
        this.childrecord = ref
    }
    onSelf = (ref) => {
        this.childSelf = ref
    }
    onConsTab = (ref) => {
        this.childConsTab = ref
    }
    onAdcTab = (ref) => {
        this.childAdcTab = ref
    }
    onConsPsy = (ref) => {
        this.childConsPsy = ref
    }
    onOso=(ref)=>{
        this.childonOso = ref  
    }
    onheart=(ref)=>{
        this.childheart = ref  
    }
    MMSE=(ref)=>{
        this.childMMSE = ref  
    }
    IADL=(ref)=>{
        this.childIADL = ref  
    }
    HADS=(ref)=>{
        this.childHADS = ref  
    }
    onFloort = (ref) => {
        this.childFloort = ref
    }
    render() {
        let tabsHeight = store.getState().tableHeight.y + 352 + 'px';
        return <div className='out-patient-service-body tabs-dom'>
            <Row style={{ display: "flex" }}>
                <Col className='recordingLeft' stryle={{ height: store.getState().tableHeight.y + 82 + 'px' }} >
                    <AssessmentLeftList onRef={this.onRef} tabThis={this} />
                </Col>
                <Col className='recordingRight' style={{ height: store.getState().tableHeight.y + 82 + 'px' }}>
                    <Tabs
                        activeKey={this.state.activeKey}
                        onChange={this.callback}
                        tabPosition="left"
                        type="card"
                        //    className="new_department_tabs"
                        style={{ width: '100%', height: store.getState().tableHeight.y + 82 + 'px' }}
                    >
                        <TabPane  tab="MMSE评分" key="6">
                            <AssessmentMMSE  MMSE={this.MMSE}updateList={this.updateList}  doctorID={this.state.doctorID} />
                        </TabPane>
                        <TabPane  tab="IADL评分" key="7">
                            <AssessmentIADL IADL={this.IADL}updateList={this.updateList} doctorID={this.state.doctorID} />
                        </TabPane>
                        <TabPane tab="HADS评分" key="8">
                            <AssessmentHADS HADS={this.HADS} updateList={this.updateList} doctorID={this.state.doctorID} />
                        </TabPane>
                        <TabPane tab={<span>盆底肌评估</span>} key="9">
                            <AssessmentOfPelvicFloorMuscles onFloort={this.onFloort} updateList={this.updateList} getPress={this.getPress} doctorID={this.state.doctorID} />
                        </TabPane>
                        {/* <TabPane tab="ADC评分" key="9">
                            <AssessmentADCTab onAdcTab={this.onAdcTab} updateList={this.updateList} doctorID={this.state.doctorID} />
                        </TabPane> */}
                    </Tabs>
                </Col>
            </Row>

        </div>
    }

}

export default QuestionnaireAtHomePage;