/**
 * 添加过敏记录主页
 * 2019-06-28
 * JYW
 */
import React from 'react'
import {
    Card, message
} from 'antd';
import AddAllergyRecords from './AddAllergyRecords';
import AllergyRecordsList from './AllergyRecordsList';
import { Util, dayFormat } from 'tools/index';
import '../style/index.less';
//import { $http } from '../../containers/config/https';
import { $http } from '../../../containers/config/https';

var recordData;
let user;
class AddAllergyRecordsPage extends React.Component {

    constructor(props) {
        user = window.sessionStorage.userData ? JSON.parse(window.sessionStorage.userData) : {};
        recordData = JSON.parse(sessionStorage.getItem('patientData'));
        if (!recordData) {
            recordData = JSON.parse(sessionStorage.getItem('recordData'));
        }
        super(props);
        this.state = {
            editAllergy: {},
            reload: false,
            ENObj: {},
            CNObj: {},
        }
    }

    componentDidMount() {
        this.getDetailTableColumns()
        message.config({ top: 400, duration: 3 });
    }
    componentWillUnmount() {
        // 组件销毁前将静止让setState修改state的状态
        this.setState = (state, callback) => { return; }
    }

    // 获取明系列表头数据
    getDetailTableColumns = () => {
        let { userInfo } = this.state;
        let data = {
            params: [{
                reactCode: ['AddAllergyRecordsPage'],
                compontName: 'AddAllergyRecordsPage',
                type: 'C',
            }]
        }
        $http.post('urlS', this, {
            code: '01040073',
            data: data,
            success: function (res) {
                if (+res.errorCode === 0) {
                    this.setState({
                        ENObj: res.result.language.EN,
                        CNObj: res.result.language.CN
                    }, () => {
                        if (Util.isEmpty(recordData.patID)) {
                            message.warn(user.language == "EN" ? 
                            this.state.ENObj && this.state.ENObj.AddAllergyRecordsPageNotSelectPatient.descripts : this.state.CNObj && this.state.CNObj.AddAllergyRecordsPageNotSelectPatient.descripts);
                        }
                    })
                }
            }
        })
    };

    render() {
        var language = user.language
        var languageObj = {}
        if (language == "EN") {
            languageObj = this.state.ENObj
        } else {
            languageObj = this.state.CNObj
        }
        return (
            <div className="doctor-allergy" style={{ height: this.props.modal == "1" ? "70vh" : '100%', width: '100%', padding: '3px' }}>
                <Card style={{ float: 'left', width: '25%', height: '100%', overflow: 'hidden', }} title={<span>{this.state.editAllergy.id ? languageObj.AddAllergyRecordsPageEdit != null ? languageObj.AddAllergyRecordsPageEdit.descripts : "" : languageObj.AddAllergyRecordsPageAdd != null ? languageObj.AddAllergyRecordsPageAdd.descripts : ""}{languageObj.AddAllergyRecordsPageAllergyRecords != null ? languageObj.AddAllergyRecordsPageAllergyRecords.descripts : ""}</span>}>
                    <AddAllergyRecords modal={this.props.modal} allergy={this.state.editAllergy} hanlderThis={this} />
                </Card>
                <Card style={{ float: 'left', width: '74%', height: '100%', overflow: 'hidden', marginLeft: '5px' }} title={<span>{languageObj.AddAllergyRecordsPageAllergyRecordsList != null ? languageObj.AddAllergyRecordsPageAllergyRecordsList.descripts : ""}</span>}>
                    <AllergyRecordsList modal={this.props.modal} reload={this.state.reload} hanlderThis={this} />
                </Card>
            </div>
        )
    }
}
export default AddAllergyRecordsPage;