/** 
 * Creator:     JYW
 * CreatDate:   2019-04-11
 * descripts：  病人基本信息组件
*/
import React, { Component } from 'react';
import { message, Row, Col, Divider } from 'antd';
import { $http } from '../../../containers/config/https';
import './style/style.less';

let user;
class PatientDetail extends Component {
    constructor(props) {
        user = window.sessionStorage.userData ? JSON.parse(window.sessionStorage.userData) : {}
        super(props);
        this.state = {
            admID: "",
            patientInfo: "",
            patinfoColumn: [],
        }
    }
    componentWillReceiveProps(nextProps) {
        if ((nextProps.admID !== "") && (nextProps.admID != undefined)) {
            this.getPatientInfo(nextProps.admID);
        }
    }
    componentWillUnmount() {
        this.setState = (state, callback) => {
            return
        }
    }
    componentDidMount() {
        if (this.props.onRef) {
            this.props.onRef(this);
        }
        this.getPatInfoColumn();
    }
    ///获取患者基本信息显示列
    getPatInfoColumn = () => {
        let data = { params: [] }
        $http.post('urlDeault', this, {
            code: "04020019",
            data: data,
            success: (res) => {
                if (+res.errorCode === 0) {
                    this.setState({
                        patinfoColumn: res.result
                    });
                }
            }
        })

    }
    /**  
     *  获取患者基本信息
    */
    getPatientInfo(admID) {
        if ((admID === "") || (admID === undefined)) {
            this.setState({
                patientInfo: ""
            });
            return;
        }
        let data = {
            params: [{
                admID: admID,
                hospID: user.hospID,
            }]
        }
        $http.post('urlDeault', this, {
            code: "04020007",
            data: data,
            success: (res) => {
                console.log(res)
                if (+res.errorCode === 0) {
                    this.setState({
                        patientInfo: res.result
                    });
                } else {
                    message.error('获取病人基本信息失败!:' + res.errorMessage);
                }
            }
        })
    }



    render() {
        let patinfoColumn = [];
        if ((this.state.patientInfo) && (this.state.patientInfo.admTypeCode == "I")) {
            patinfoColumn = this.state.patinfoColumn.inPatInfoColumn;
        } else {
            patinfoColumn = this.state.patinfoColumn.outPatInfoColumn;
        }
        let width = '';
        if (!patinfoColumn) {
            patinfoColumn = [];
        }
        return (
            <div className="patient-body">
                <Row style={{ background: 'rgba(248,248,248)', height: '45px', textAlign: 'left' }}>
                    <Col style={{ float: 'right', textAlign: 'left', width: this.props.width || '100%', display: 'flex' }} span={24}>
                        {this.state.patientInfo !== "" ? <div className="then" style={{ display: 'flex', flexShrink: '1', flex: '0 0 auto', width: 100 }}>
                            <div className={this.state.patientInfo && this.state.patientInfo.basicInfo.patSexCode == '1' ?
                                'splice-Boy' : (this.state.patientInfo && this.state.patientInfo.basicInfo.patSexCode == '2' ? 'splice-Girl' : 'splice-then')}></div>
                        </div> : ""
                        }
                        {
                            this.state.patientInfo !== "" ?
                                (
                                    <div style={{ display: 'flex', flex: '1 1 auto' }}>
                                        {
                                            patinfoColumn.map((item) => {

                                                return (
                                                    <div style={{ fontWeight: 400, color: '#666666', fontSize: '16px', padding: '10px 0 0 20px' }} className="item-tep">
                                                        <div className={item.code}>
                                                            <i className="icon-icon"></i>
                                                            <span>{this.state.patientInfo.admInfo[item.code] || this.state.patientInfo.basicInfo[item.code]}</span>
                                                        </div>
                                                    </div>
                                                )
                                            })
                                        }
                                    </div>
                                )
                                :
                                ""
                        }
                    </Col>
                </Row>
            </div >
        )
    }

}
export default PatientDetail