/**
 *健康检查

 */
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 MedicalExamination from './MedicalExamination';
import DiabeteRiskManagementPage from './DiabeteRiskManagementPage';
import QuestionnairePage from '../QuestionnairePage';
import QuestionnaireAtHome from './QuestionnaireAtHome';
import store from 'store';
import moment from 'moment';
import '../style/Secondary.less';

const confirm = Modal.confirm;
const { RangePicker } = DatePicker;
const Option = Select.Option;
const Search = Input.Search;
const TabPane = Tabs.TabPane;

class HealthExamination extends React.Component {
    constructor(props) {
        super(props)
        var userData = JSON.parse(sessionStorage.getItem('userData'))
        var sessionID = JSON.parse(sessionStorage.getItem('healthRecordID'))?JSON.parse(sessionStorage.getItem('healthRecordID')):''
        this.state = {
            dataSource: [],
            userData: userData,
            activeKey: '1',
            sessionID:sessionID,
        }
    }

    componentDidMount() {

     this.noClickTabs();

    }
    noClickTabs=()=>{
        setTimeout(()=>{
            let sessionID = JSON.parse(sessionStorage.getItem('healthRecordID'))?JSON.parse(sessionStorage.getItem('healthRecordID')):'';
            this.setState({sessionID})
        },500)
    }

    changeExamination=()=>{

        if(JSON.parse(sessionStorage.getItem('changeValue'))){
            return true
        }else {
            return false
        }
    }
    setChangeValue=()=>{
        window.sessionStorage.setItem("changeValue",JSON.stringify(false));
    }

    changeActiveKey(e) {
        var that = this;
        if (sessionStorage.getItem("noSave") && JSON.parse(sessionStorage.getItem("noSave")) === true || this.changeExamination()) {
            confirm({
                title: '提示',
                content: '当前页面数据还没保存，确定要切换页面吗？',
                okText:  '确定',
                cancelText: '取消',
                onOk() {
                    window.sessionStorage.setItem("noSave",false);
                    that.setChangeValue();
                    that.setState({
                        activeKey: e
                    }, () => {
                        if (e == "2") {
                            that.childQues.updateList()
                            setTimeout(()=>{
                                that.childQues.getPress()
                            },500)
                        } else if (e == '1') {
                            that.childMedical.sessionData()
                        } else if (e == '5') {
                            that.onDiaRef.initialData()
                        }else if (e == '4') {
                            that.onHomeRef.initData()
                        }
                    })
                },
                onCancel() {
                    return
                }
            })
        } else {
            that.setState({
                activeKey: e
            }, () => {
                if (e == "2") {
                    that.childQues.updateList()
                    setTimeout(()=>{
                        that.childQues.getPress()
                    },500)
                } else if (e == '1') {
                    that.childMedical.sessionData()
                } else if (e == '5') {
                    that.onDiaRef.initialData()
                }else if (e == '4') {
                    that.onHomeRef.initData()
                }
            })
        }
    }
    ques = (ref) => {
        this.childQues = ref
    }
    Medical = (ref) => {
        this.childMedical = ref
    }
    diaOnRefs = (ref) => {
        this.onDiaRef = ref
    }
    homeOnRefs=(ref)=>{
        this.onHomeRef = ref
    }
    render() {
        return <div className='HealthExamination'>
            <Tabs type='card' activeKey={this.state.activeKey} onChange={this.changeActiveKey.bind(this)}>
                <TabPane tab='体检' key='1'>
                    <MedicalExamination onRef={this.Medical} handle={this} />
                </TabPane>
                <TabPane tab='问卷调查' key='2' disabled={this.state.sessionID ? false : true}>
                    <QuestionnairePage ques={this.ques}/>
                </TabPane>
                {/* <TabPane tab='报告单' key='3'>
                    报告单
                </TabPane> */}
                  <TabPane tab='居家照护评估表' key='4' disabled={this.state.sessionID ? false : true}>
                    <QuestionnaireAtHome homeOnRefs={this.homeOnRefs} />
                </TabPane>
                <TabPane tab='糖尿病风险评分' key='5' disabled={this.state.sessionID ? false : true}>
                    <DiabeteRiskManagementPage onRef={this.diaOnRefs} />
                </TabPane>

                {/* <TabPane tab='体检报告' key='5'>
                    体检报告
                </TabPane> */}
            </Tabs>
        </div>
    }

}

export default HealthExamination;
