/**
 *个人基本信息

 */
import React from 'react';
import {
    Card, Table, Input, Form, Select, Row, Col, Checkbox, Tabs,
    DatePicker, Button, Popconfirm, Icon, Divider, message, Menu,Modal
} from 'antd';
import { Util, dayFormat } from 'tools/index';
import { $http } from 'containers/config/https';
import RangeDatePicker from 'components/rangePicker/index';
import ColumnAuthoritysModel from 'pages/columnAuthority/ColumnAuthoritysModel';
import CommonPagination from 'components/pagination/index';
import InformationTabPane from './component/InformationTabPane'
import PhysicalExaminationTabPane from './component/PhysicalExaminationTabPane';
import ShowCommonInformationPage from './component/ShowCommonInformationPage';
import HealthManagementRecordTabpane from './component/HealthManagementRecordTabpane';
import VitalSignsDetectionTabPane from './component/VitalSignsDetectionTabPane';
import HealthExamination from './component/HealthExamination';
import SmartTerminalTabpane from './component/SmartTerminalTabpane';
import store from 'store';
import moment from 'moment';
import './style/index.less';

const { RangePicker } = DatePicker;
const Option = Select.Option;
const { SubMenu } = Menu;
const TabPane = Tabs.TabPane;
const confirm = Modal.confirm;
class PersonalInformationTabs extends React.Component {
    constructor(props) {
        super(props)
        var userData = JSON.parse(sessionStorage.getItem('userData'))
        var patID = JSON.parse(sessionStorage.getItem('patID'))
        this.state = {
            dataSource: [],
            total: 0,
            page: 1,
            pageSize: 10,
            userData: userData,
            activeKey: '1',
            selectedKeys: ['1'],
            code: '1',
            patID: patID
        }
    }

    componentDidMount() {
        this.loadSumData()
        window.sessionStorage.setItem("noSave",false);
        this.setChangeValue();
    }

    loadSumData() {
        var params = {
            params: [{
                patID: this.state.patID,
            }]
        }
        $http.post('urlS', this, {
            code: "03070061",
            data: params,
            success: function (res) {
                this.setState({
                    totalCount: res.result
                })
            }
        })
    }

    changeActiveKey(e) {
        this.setState({
            activeKey: e
        })
    }
    changeExamination=()=>{

        if(JSON.parse(sessionStorage.getItem('changeValue'))){
            return true
        }else {
            return false
        }
    }
    setChangeValue=()=>{
        window.sessionStorage.setItem("changeValue",JSON.stringify(false));
    }
    onSelectComponent(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({
                        selectedKeys: e.selectedKeys,
                        code: e.key
                    })
                },
                onCancel() {
                    return
                }
            })
        } else {
            that.setState({
                selectedKeys: e.selectedKeys,
                code: e.key
            })
        }
    }

    loadTitleMessage(){
        this.onRefresh.loadData()
    }

    loadComponent() {
        if (this.state.code == '1') {
            return <InformationTabPane loadTitleMessage={this.loadTitleMessage.bind(this)}/>
        } else if (this.state.code == '3') {
            return <HealthExamination />
        } else if (this.state.code == '4') {
            return <VitalSignsDetectionTabPane />
        } else if (this.state.code == '5') {
            return <HealthManagementRecordTabpane />
        } else if (this.state.code == '6') {
            return <SmartTerminalTabpane />
        }
    }

    onRefs = ref => {
        this.onRefresh = ref
    }


    render() {

        return <div className='health-control-body'>
            <Card style={{ height: '10%' }}>
                <div>
                    <div style={{ width: '39%', float: 'left' }}>
                        <ShowCommonInformationPage onRef={this.onRefs} />
                    </div>
                    <div style={{ width: '61%', float: 'right', borderLeft: '1px solid #e8e8e8' }}>
                        <div style={{ display: 'flex' }}>
                            <div style={{ width: '20%', borderRight: '1px solid #e8e8e8', height: 85, textAlign: 'center' }}>
                                <div style={{ marginTop: 10,fontWeight:'bold',color:'#333333' }}>医院/社康就诊次数</div>
                                <div style={{ marginTop: 10, fontSize: '18px', color: 'black', fontWeight: 'bold' }}>
                                    {this.state.totalCount ? (this.state.totalCount.hospQty + '/' + this.state.totalCount.shekangQty) : '--'}
                                </div>
                            </div>

                            <div style={{ width: '20%', borderRight: '1px solid #e8e8e8', height: 85, textAlign: 'center' }}>
                                <div style={{ marginTop: 10,fontWeight:'bold',color:'#333333' }}>全科医生（咨询/就诊）</div>
                                <div style={{ marginTop: 10, fontSize: '18px', color: 'black', fontWeight: 'bold' }}>
                                    {this.state.totalCount ? (this.state.totalCount.generalAdvQty + '/' + this.state.totalCount.generaldocQty) : '--'}
                                </div>
                            </div>

                            <div style={{ width: '20%', borderRight: '1px solid #e8e8e8', height: 85, textAlign: 'center' }}>
                                <div style={{ marginTop: 10,fontWeight:'bold',color:'#333333' }}>专科医生（就诊）</div>
                                <div style={{ marginTop: 10, fontSize: '18px', color: 'black', fontWeight: 'bold' }}>
                                    {this.state.totalCount ? (this.state.totalCount.specialistdocQty) : '--'}
                                </div>
                            </div>

                            <div style={{ width: '20%', borderRight: '1px solid #e8e8e8', height: 85, textAlign: 'center' }}>
                                <div style={{ marginTop: 10,fontWeight:'bold',color:'#333333' }}>护理（咨询/平台）</div>
                                <div style={{ marginTop: 10, fontSize: '18px', color: 'black', fontWeight: 'bold' }}>
                                    {this.state.totalCount ? (this.state.totalCount.nursingAdvQty) : '--'}
                                </div>
                            </div>

                            <div style={{ width: '20%', height: 85, textAlign: 'center' }}>
                                <div style={{ marginTop: 10 ,fontWeight:'bold',color:'#333333'}}>社工（咨询/电话）</div>
                                <div style={{ marginTop: 10, fontSize: '18px', color: 'black', fontWeight: 'bold' }}>
                                    {this.state.totalCount ? (this.state.totalCount.socialWorkerAdvQty) : '--'}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </Card>
            <Card style={{ marginTop: 5, height: '89.4%', background: '#F0F2F5' }}>
                <div style={{ float: 'left', width: '15%', background: 'white',color:"#333",fontWeight:"bolder", height: store.getState().tableHeight.y + 121 }}>
                    <Menu style={{ width: '100%' }}
                        defaultSelectedKeys={['1']}
                        selectedKeys={this.state.selectedKeys}
                        defaultOpenKeys={['1', '2']} onSelect={this.onSelectComponent.bind(this)}
                        mode='inline' theme='light'>
                        <Menu.Item key="1">个人基本信息</Menu.Item>
                        <SubMenu
                            key="2"
                            title={
                                <span>
                                    <span>健康体检</span>
                                </span>
                            }
                        >
                            <Menu.Item key="3">健康检查</Menu.Item>
                            <Menu.Item key="4">生命体征监测</Menu.Item>
                            <Menu.Item key="5">健康管理记录</Menu.Item>
                            <Menu.Item key="6">智能终端设备</Menu.Item>
                            {/* <Menu.Item key="6">健康管理计划</Menu.Item> */}
                        </SubMenu>
                    </Menu>
                </div>

                <div style={{ float: 'right', width: '84.9%', background: 'white', height: store.getState().tableHeight.y + 121 }}>
                    {/* <InformationTabPane /> */}
                    {this.loadComponent()}
                </div>

            </Card>
        </div>
    }

}

export default PersonalInformationTabs;
