/**
 *健康管理记录

 */
import React from 'react';
import {
    Card, Table, Input, Form, Select, Row, Col, Checkbox, Tabs, Tooltip,
    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 moment from 'moment';
import FollowUpRecords from './FollowUpRecords'; //随访
import ConsultingRecords from './ConsultingRecords'; //咨询
import MedicalRecordsTabPane from './MedicalRecordsTabPane'; //诊疗
import '../style/Secondary.less';
import RecordingLeft from "./MedicalExamination";

const TabPane = Tabs.TabPane;

class HealthManagementRecordTabpane extends React.Component {
    constructor(props) {
        super(props)
        var userData = JSON.parse(sessionStorage.getItem('userData'))
        var patID = JSON.parse(sessionStorage.getItem('patID'))
        this.state = {
            data: [],
            activeKey: '1',
            patID: patID,
            contractID: '',//签约id
        }
    }

    componentDidMount() {
        this.loadData();
        this.signContractID();
    }

    loadData() {
        var params = {
            params: [{
                patID: this.props.patID ? this.props.patID : this.state.patID,
            }]
        }
        $http.post('urlDeault', this, {
            code: "03070028",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.setState({
                        titleData: res.result[0],
                    })
                }
            }
        });
    }
    ///获取签约id
    signContractID=()=> {
        var params = {
            params: [{
                patID:this.state.patID
            }]
        }
        $http.post('urlDeault', this, {
            code: "03070019",
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.setState({
                        contractID: res.result[0].personInfo?res.result[0].personInfo.signRecordID:'',
                    })
                }
            }
        });
    };
    changeActiveKey(e) {
        this.setState({
            activeKey: e
        },()=>{
            if(e !== '2'){
                this.childModal && this.childModal.clearTime();
            }
            if(e=='2'){
                this.childModal.startTime();
            }
        })
    }
    onRef = (ref) => {
        this.childModal = ref;
    };
    render() {

        return <div className='health-management-body'>
            <Tabs type='card' activeKey={this.state.activeKey} onChange={this.changeActiveKey.bind(this)} className='title'>
                <TabPane tab='诊疗记录' key='1'>
                    <MedicalRecordsTabPane />
                </TabPane>
                <TabPane tab='咨询记录' key='2' disabled={this.state.contractID ? false : true}>
                    <ConsultingRecords onRef={this.onRef}  handleThis={this} />
                </TabPane>
                <TabPane tab={<Tooltip title={this.state.titleData && (Util.isEmpty(this.state.titleData.hypertension) &&
                    Util.isEmpty(this.state.titleData.diabetes)) ? '该居民非“高血压”或“糖尿病”患者，不能进行随访操作。' : ''}>随访记录</Tooltip>}
                    key='3'
                 disabled={this.state.titleData && (!Util.isEmpty(this.state.titleData.hypertension) ||
                    !Util.isEmpty(this.state.titleData.diabetes)) ? false : true}
                >
                    <FollowUpRecords titleData={this.state.titleData}/>
                </TabPane>

            </Tabs>
        </div>
    }

}

export default HealthManagementRecordTabpane;
