/*
 * Creator:     ML
 * CreatDate:   2020-04-09
 * 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 AssessmentCons from './AssessmentCons';
import AssessmentConsResult from './AssessmentConsResult';
import AssessmentConsGuidance from './AssessmentConsGuidance';

import store from 'store';
import moment from 'moment';
import '../style/assessment.less';

const { RangePicker } = DatePicker;
const Option = Select.Option;
const Search = Input.Search;
const TabPane = Tabs.TabPane;
const confirm = Modal.confirm;
class AssessmentConsTab extends React.Component {
    constructor(props) {
        super(props)
        var userData = JSON.parse(sessionStorage.getItem('userData'))
        this.state = {
            dataSource: [],
            userData: userData,
            activeKey: '1',
            obj: {}
        }
    }

    componentDidMount = () => {
        this.props.onConsTab(this)
    }

    handleSetValue = (id) => {
        this.setState({
            id,
            // obj:{}
        })
        this.childCons.setValue(id)
    }
    handleClear = (d) => {
        this.childCons.clear(d)
        this.setState({
            obj: {}
        })
    }
    getValue = (obj) => {
        this.setState({
            obj,
        })
    }
    onRef = (ref) => {
        this.childCons = ref
    }
    handleHome = () => {
        this.setState({
            activeKey: '1',
        },()=>{
            this.childCons.setValue(this.state.id, "1")
        })
    }
    changeActiveKey(e, d) {
        var that = this;
        if (d) {
            that.setState({
                activeKey: e
            }, () => {
                that.childCons.setValue(that.state.id, e)
                // console.log("this.childCons.delStatus",this.childCons)
            })
            return
        }
        if (sessionStorage.getItem("noSave") && JSON.parse(sessionStorage.getItem("noSave")) === true && this.childCons.state.delStatus == false) {
            confirm({
                title: '提示',
                content: '当前页面数据还没保存，确定要切换页面吗？',
                okText: '确定',
                cancelText: '取消',
                onOk() {
                    window.sessionStorage.setItem("noSave", false);
                    that.setState({
                        activeKey: e
                    }, () => {
                        that.childCons.setValue(that.state.id, e)
                        // console.log("this.childCons.delStatus",this.childCons)
                    })
                },
                onCancel() {
                    return
                }
            })
        } else {
            // console.log("this.childCons--delStatus",this.childCons.state.delStatus,this.state.activeKey)
            if (this.childCons.state.delStatus == true && this.state.activeKey == 1 && e == 2) {
                // console.log("this.childCons--delStatus0000",this.childCons.state.delStatus,this.state.activeKey)
                confirm({
                    title: '提示',
                    content: '请先保存中医体质辨识',
                    okText: '确定保存',
                    cancelText: '返回录入',
                    onOk() {
                        //    console.log("调保存")
                        that.childCons.handleSave()
                        that.setState({
                            activeKey: e
                        }, () => {
                            that.childCons.setValue(that.state.id, e)
                            // console.log("this.childCons.delStatus",this.childCons)
                        })

                    },
                    onCancel() {
                        return
                    }
                })
            }
            else if (this.childCons.state.delStatus == true && this.state.activeKey == 2 && e == 3) {
                // console.log("this.childCons--delStatus0000",this.childCons.state.delStatus,this.state.activeKey)
                confirm({
                    title: '提示',
                    content: '请先保存体质辨识结果',
                    okText: '确认保存',
                    cancelText: '返回录入',
                    onOk() {
                        //    console.log("调保存")
                        that.childCons.handleSave()
                        that.setState({
                            activeKey: e
                        }, () => {
                            //    that.childCons.setValue(that.state.id,e)
                            // console.log("this.childCons.delStatus",this.childCons)
                        })
                    },
                    onCancel() {
                        return
                    }
                })
            } else {
                if (that.state.activeKey == 1 && e == 3) {
                    // message.warning("请先查看中医辨识结果")
                    if(this.childCons.state.delStatus == true){
                        message.warning("请先录入保存中医辨识")
                        return
                    }
                    this.setState({
                        activeKey: '2',
                    },()=>{
                        this.childCons.setValue(this.state.id, "2")
                       setTimeout(()=>{
                        if(this.childCons.state.delStatus == true){
                            message.warning("请先保存中医辨识结果")
                        }else{
                            // message.success("正在进入中医健康指导....")
                            this.setState({
                                activeKey: '3',
                            },()=>{
                                this.childCons.setValue(this.state.id, "3")
                            })
                            
                            // this.childCons.setValue(this.state.id, "2")
                        }
                       },200)
                    })
                } else {
                    that.setState({
                        activeKey: e
                    }, () => {
                        that.childCons.setValue(that.state.id, e)
                        // console.log("this.childCons.delStatus",this.childCons)
                    })
                }

            }

        }
    }
    updateHeathList = () => {
        this.props.updateList()
    }
    updateHeathgetPress = () => {
        this.props.getPress()
    }
    render() {

        return <div className="adc-tab-dom">
            <div>
                <div>
                    <div style={{ textAlign: "center" }}>
                        <span className={this.state.activeKey == "1" ? "tab-active tab-span" : "tab-span"} onClick={() => this.changeActiveKey("1")}>中医体质辨识</span>
                        <span className={this.state.activeKey == "2" ? "tab-active tab-span" : "tab-span"} onClick={() => this.changeActiveKey("2")}>体质辨识结果</span>
                        <span className={this.state.activeKey == "3" ? "tab-active tab-span" : "tab-span"} onClick={() => this.changeActiveKey("3")}>中医健康指导</span>
                    </div>
                    <p style={{ background: "#f5f4f4", height: "6px", margin: "8px 0" }}>
                    </p>
                    {this.state.activeKey == "1" ?
                        <AssessmentCons onRef={this.onRef} updateHeathgetPress={this.updateHeathgetPress} updateHeathList={this.updateHeathList} getValue={this.getValue} conThis={this} />
                        : this.state.activeKey == "2" ?

                            <div><AssessmentConsResult changeActiveKey={this.changeActiveKey} updateHeathList={this.updateHeathList} objs={this.state.obj} id={this.state.id} onRef={this.onRef} getValue={this.getValue} conThis={this} /></div>
                            : <AssessmentConsGuidance onRef={this.onRef} objs={this.state.obj} id={this.state.id} getValue={this.getValue} updateHeathList={this.updateHeathList} conThis={this} />
                    }
                </div>
            </div>
        </div>
    }

}

export default AssessmentConsTab;
