/** 
 * Creator:     JYW
 * CreatDate:   2019-12-25
 * descripts：  日间病房患者办理入院
*/

import React from 'react';
import { Modal, Row, Col, Select, Switch, Divider, message, Form } from 'antd';
import PatientInfo from '../Patient/PatientInfo';
import { $http } from '../../../containers/config/https';

import './CSS/bedchart.less'

let user;
const formItemLayout = {
    labelCol: {
        xs: { span: 24 },
        sm: { span: 7 },
    },
    wrapperCol: {
        xs: { span: 24 },
        sm: { span: 14 },
    },
};
class DaytimePat extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            visible: false,
            admReasonID: "",
            admID: "",
            adminID: "",
            patientInfo: "",
            nurID: "",
            docID: "",
            nurse: [],
            doctor: [],
            patStatus: "",
            admReasonList: [],
            adminData: {},
            patInfo: {},
            daytimeFlag:"0"
        }
        user = window.sessionStorage.userData ? JSON.parse(window.sessionStorage.userData) : {};
    }
    componentDidMount() {
        if (this.props.onRef) {
            this.props.onRef(this);
        }
    }
    componentWillUnmount() {
        this.setState = (state, callback) => {
            return
        }
    }
    handleCancel = () => {
        this.setState({
            visible: false,
        })
    }
    handleOk = () => {
        if ((this.state.docID == "") || (this.state.admReasonID == "")) {
            message.warn("患者费别和主管医师不能为空");
            return;
        }
        let data = {
            params: [{
                admID: this.state.admID,
                patID: this.state.patID,
                adminID: this.state.adminID,
                admReasonID: this.state.admReasonID,
                docID: this.state.docID,
                nurID: this.state.nurID,
                daytimeFlag: this.state.daytimeFlag,
            }]
        }
        $http.post('urlDeault', this, {
            code: "03060024",
            data: data,
            success: (res) => {
                if (+res.errorCode === 0) {
                    message.success("患者登记成功!");
                    this.handleCancel();
                    this.props.getPatients();
                    if (this.props.child) {
                        this.props.child.getRooms();
                    }
                }
            }
        })
    }
    show = (patID, admID, adminID,daytimeFlag) => {
        this.setState({
            visible: true,
            admID: admID,
            patID: patID,
            adminID: adminID,
            daytimeFlag:daytimeFlag,
            admReasonID: "",
            patientInfo: "",
            nurID: "",
            docID: "",
            nurse: [],
            doctor: [],
            admReasonList: [],
            adminData: {},
            patInfo: {},
        }, () => {
            this.getRegisterInfo();
        })
    }
    getRegisterInfo = () => {
        let data = {
            params: [{
                admID: this.state.admID,
                patID: this.state.patID,
                adminID: this.state.adminID,
            }]
        }
        $http.post('urlDeault', this, {
            code: "03060025",
            data: data,
            success: (res) => {
                if (+res.errorCode === 0) {
                    this.setState({
                        nurse: res.result.nurse,
                        doctor: res.result.doctor,
                        docID: res.result.docID,
                        admReasonList: res.result.admReason,
                        adminData: res.result.adminData,
                        patInfo: res.result.patInfo,
                    })
                } else {
                    message.error(res.errorMessage);
                }
            }
        })
    }
    onChange = (flag, value) => {
        this.setState({
            [flag]: value,
        });
    }
    render() {
        let admReason = []
        this.state.admReasonList && this.state.admReasonList.map(item => {
            admReason.push(<Select.Option key={item.id} role={item.descriptsSPCode + '^' + item.descripts} >{item.descripts}</Select.Option>)
        });
        return (
            <Modal
                title="登记"
                width='964px'
                className='daytimePat'
                visible={this.state.visible}
                onOk={this.handleOk}
                onCancel={this.handleCancel}
                style={{
                    height: '118px',
                    background: '#FFFFFF',
                    borderRadius: '6px',
                    top: '357px'
                }}
                okText="登记"
                cancelText="取消"
                destroyOnClose
                maskClosable={false}
            >
                <Row style={{ background: 'rgba(248,248,248)', height: '45px', textAlign: 'left', lineHeight: '45px' }}>
                    <div style={{ width: '100%', height: 45, display: 'flex' }}>
                        <div className="ther" style={{ display: 'flex', flexShrink: '1', flex: '0 0 auto', width: 100 }}>
                            <div className={this.state.patInfo.patSexCode == '1' ?
                                'splice-Boy' : this.state.patInfo.patSexCode == '2' ? 'splice-Girl' : 'splice-ther'}></div>
                        </div>
                        <div style={{ display: 'flex', flex: '1 1 auto' }}>
                            <div style={{ padding: '10px 0 0 20px' }} className="item">
                                <div>
                                    <i className="icon"></i>
                                    <span className="patName">{this.state.patInfo.patName}</span>
                                </div>
                                <div>
                                    <i className="icon"></i>
                                    <span className="patSex">{this.state.patInfo.patSexDesc}</span>
                                </div>
                                <div>
                                    <i className="icon"></i>
                                    <span className="patAge">{this.state.patInfo.patAge}</span>
                                </div>
                            </div>
                            <div style={{ fontWeight: 400, color: '#666666', fontSize: '16px', padding: '10px 0 0 20px' }} className="item">
                                <div>
                                    <i className="icon"></i>
                                    <span>住院证科室: {this.state.adminData.locDesc}</span>
                                </div>
                                <div>
                                    <i className="icon"></i>
                                    <span>住院证病区: {this.state.adminData.wardDesc}</span>
                                </div>
                                <div>
                                    <i className="icon"></i>
                                    <span>住院证日期: {this.state.adminData.adminDate}</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </Row>
                <Col className="DivideBed row" span={8}>
                    患者费别:
                       <Select
                        value={this.state.admReasonID}
                        onChange={this.onChange.bind(this, "admReasonID")}
                        style={{ width: "50%", marginLeft: '5px' }}>
                        {admReason}
                    </Select>
                </Col>
                <Col className="DivideBed row" span={8}>
                    主管医师:
                            <Select
                        onChange={this.onChange.bind(this, "docID")}
                        style={{ width: "50%" }}
                        value={this.state.docID}
                    >
                        {
                            this.state.doctor.map(
                                (item) => {
                                    return (
                                        <Select.Option key={item.id} >
                                            {item.descripts}
                                        </Select.Option>
                                    )
                                }
                            )
                        }
                    </Select>
                </Col>
                <Col className="DivideBed row" span={8}>
                    主管护士:
                            <Select
                        value={this.state.nurID}
                        onChange={this.onChange.bind(this, "nurID")}
                        style={{ width: "50%" }}>
                        {
                            this.state.nurse.map(
                                (item) => {
                                    return (
                                        <Select.Option key={item.id} >
                                            {item.descripts}
                                        </Select.Option>
                                    )
                                }
                            )
                        }
                    </Select>
                </Col>
            </Modal >
        )
    }

}
export default DaytimePat