/** 
 * Creator:     
 * CreatDate:   
 * descripts：  床位图新组件
*/
import React, { Component } from 'react';
import { Row, Col, message, Button, Card, Divider, Input } from 'antd';
import { $http } from '../../../containers/config/https';
import PatientProcess from '../Patient/PatientProcess';
import ChildbirthRegister from '../Childbirth/ChildbirthRegister';
import Memorandum from '../BedChart/Memorandum';
import store from 'store';
import './chars.less';
let user;

class BedChartjuery extends Component {
    constructor(props) {
        user = window.sessionStorage.userData ? JSON.parse(window.sessionStorage.userData) : {};
        super(props);
        this.state = {
            ShowChild: false,
            locID: user ? user.locID : "",
            bedIcon: [],
            quickBtn: "ALL",
            searchValue: "",
            searchFlag: false,
            admID: "",
            patBasicInfo: [],
            thatID: "",
            clickID: "",
            birthVisible: false,
            chickedM: false
        }
    }

    componentWillUnmount() {
        this.setState = (state, callback) => {
            return
        }
    }

    componentDidMount() {
        this.getPatients();
    }

    //查询
    getPatients = () => {
        let data = {
            params: [{
                wardID: user ? user.locID : "",
                regStatus: "REG"
            }]
        }
        $http.post('urlDeault', this, {
            code: "04110015",
            data: data,
            success: (res) => {
                if (+res.errorCode === 0) {
                    // console.log('查询回来的数据', res)
                    this.setState({
                        patBasicInfo: res.result
                    });
                } else {
                    message.error('查询失败：' + res.errorMessage);
                }
            }
        })
    }

    //患者ID/床号/姓名(回车查询)
    onSearchClick = (e) => {
        this.setState({
            searchFlag: true,
        })
    }

    //查询输入框改变
    onSearchChange = (e) => {
        this.setState({
            searchFlag: false,
            searchValue: e.target.value,
        })
    }

    onQuickBtnClick = (e) => {
        let id = e.target.value;
        if (e.target.value === this.state.clickIconId) {
            id = "";
        }
        this.setState({
            clickIconId: id,
            quickBtn: id,
        })
    }

    //选中母亲数据
    onpattenClick = (admID, patID, e) => {
        //message.success(admID);
        let thatID = this.state.thatID;
        if (thatID == admID) {
            thatID = "";
        } else {
            thatID = admID;

        }
        this.setState({
            thatID: admID,
            admID: admID,
            clickID: "",
            chickedM: !this.state.chickedM

        })
        let patientData = {}
        patientData = {
            admID: admID,
            patID: patID,
        }
        sessionStorage.setItem('patientData', JSON.stringify(patientData));
    }

    //选中小孩数据
    onBabyClick = (babyID, babyPatID, e) => {
        // message.success(babyID);
        let clickID = this.state.clickID;
        if (clickID == babyID) {
            clickID = "";
        } else {
            clickID = babyID;
        }
        this.setState({
            clickID: clickID,
            thatID: ""

        })
        let patientData = {}
        patientData = {
            admID: babyID,
            patID: babyPatID,
        }
        sessionStorage.setItem('patientData', JSON.stringify(patientData));
    }

    //选中的数据消失
    showChildData = (showId, e) => {
        //  console.log("1111",showId)
        //    let thatID=this.state.clickID;
        this.setState({
            ShowChild: true,
            fouceId: showId
        })
    }

    noneChildData = () => {
        // console.log("22222")
        this.setState({
            ShowChild: false,
            fouceId: ""
        })
    }

    //转出产房
    onChildbirth = (e) => {
        if (this.state.admID == "") {
            message.warn("请选择患者！");
            return;
        }
        this.setState({
            birthVisible: true,
        })
    }

    // 调用公共组件的连接事件
    onRef = (ref) => {
        this.child = ref
    }

    render() {
        const BarExtra = (
            <div style={{ textAlign: "right" }} className="bed">
                <Divider style={{
                    width: '21px',
                    height: '5px',
                    minWidth: '1px',
                    position: "absolute",
                    backgroundColor: "#EB2F96",
                }}>
                </Divider>
                <span style={{
                    position: "absolute",
                    left: '30px',
                }}>女</span>
                <Divider style={{
                    width: '21px',
                    height: '5px',
                    left: '50px',
                    minWidth: '1px', position: "absolute",
                    backgroundColor: "#40A9FF",
                }}></Divider>
                <span style={{
                    position: "absolute",
                    left: '75px',
                }}>男</span>
                <Divider style={{
                    width: '21px',
                    height: '5px',
                    left: '100px',
                    minWidth: '1px', position: "absolute",
                    backgroundColor: "#A0D911",
                }}></Divider>
                <span style={{
                    position: "absolute",
                    left: '125px',
                }}>未知性别</span>
                <Divider style={{
                    width: '21px',
                    height: '5px',
                    left: '190px',
                    minWidth: '1px', position: "absolute",
                    backgroundColor: "#722ED1",
                }}></Divider>
                <span style={{
                    position: "absolute",
                    left: '215px',
                }}>包床</span>
                <Input
                    allowClear={true}
                    onChange={this.onSearchChange}
                    value={this.state.searchValue}
                    placeholder="患者ID/床号/姓名"
                    onPressEnter={this.onSearchClick}
                    style={{ width: '180px', marginRight: "16px" }} />
                <Button
                    className="TransBtn"
                    onClick={this.onChildbirth}
                    style={{ marginRight: "16px" }}
                >
                    转出产房
                </Button>
            </div>
        )

        return (
            <div className="bedChart icon" style={{ height: "100%" }}>
                <Row style={{ height: "100%", overflowX: 'hidden' }}>
                    <Col span={21} className="bedChart-center" >
                        <Row style={{ lineHeight: "50px", borderBottom: '1px solid #cccccc', marginBottom: '2px' }}>
                            <Col span={12} style={{ marginLeft: '500px' }}>
                                {BarExtra}
                            </Col>
                        </Row>
                        <Row style={{ height: store.getState().tableHeight.y + 161 + 'px', overflow: 'auto', overflowX: 'hidden' }}>
                            {this.state.patBasicInfo && this.state.patBasicInfo.map((item, i) => {
                                //console.log("1111111",item.patName)
                                return <Col key={item.patID} span={6} style={{ padding: '10px 10px 0' }}>
                                    <Card
                                        style={{ padding: '0' }}
                                        size="small"
                                        title={`${item.patName && item.patName !== '' && item.patName.length > 0 ? `${item.admBedRoom} - ${item.admBedCode} | ${item.patName} | ${item.patAge}` : ''}`} extra={<span style={{ color: '#FFFFFF' }} >产次：{item.deliveryTimes !== '' ? item.deliveryTimes : 0}</span>}
                                        // style={{ width: '380px' }}
                                        //headStyle={{background: rgb(247, 89, 171)}}
                                        headStyle={{ background: 'rgb(247, 89, 171)' }}
                                        className="medical-advice-list"
                                        onMouseOver={this.showChildData}
                                        onMouseLeave={this.noneChildData}
                                        actions={
                                            item.iconList.map(
                                                (item, iconKey) => {
                                                    return (
                                                        <div
                                                            key={iconKey + ""}
                                                            title={item.title}
                                                            className="bedicon"
                                                            style={{
                                                                width: "18px",
                                                                height: "18px",
                                                                backgroundPosition: (-((item.position % 10 - 1) * 18)) + "px" + " " + (-(parseInt(+item.position / 10) * 18)) + "px"
                                                            }}
                                                        > </div>
                                                    );
                                                })
                                        }
                                    >
                                        <div style={{ display: 'flex' }}>
                                            <div className='card-left-container30' style={{ border: this.state.thatID == item.admID && this.state.clickID == "" && this.state.chickedM ? '1px solid #cc00ee' : '0px', height: '170px' }}
                                                onClick={this.onpattenClick.bind(this, item.admID, item.patID)}>
                                                <Row>
                                                    <Col span={24}
                                                        style={{
                                                            maxHeight: '50px',
                                                            padding: '10px 0',
                                                            overflow: 'hidden',
                                                            whiteSpace: 'nowrap',
                                                            textOverflow: 'ellipsis',
                                                        }}
                                                    >就诊日期：{item.admDate}</Col>
                                                    <Col span={24}
                                                        style={{
                                                            maxHeight: '50px',
                                                            overflow: 'hidden',
                                                            whiteSpace: 'nowrap',
                                                            textOverflow: 'ellipsis',
                                                        }} >登记日期:{item.regDate}</Col>
                                                    <Col span={24} style={{
                                                        maxHeight: '50px',
                                                        overflow: 'hidden',
                                                        padding: '10px 0',
                                                        whiteSpace: 'nowrap',
                                                        textOverflow: 'ellipsis',
                                                    }}>责医/责护:{item.admDocDesc}/{item.admNurDesc}</Col>

                                                    <Col span={24}
                                                        id="lineEllipsis"
                                                        style={{
                                                            maxHeight: '50px',
                                                            overflow: 'hidden',
                                                            textOverflow: 'ellipsis',
                                                        }}>诊断:{item.admDiag}</Col>
                                                </Row>
                                                {/* <div className="card-left-info" 
                                                         style={{ border: this.state.thatID == item.admID &&this.state.clickID==""&&this.state.chickedM? '1px solid #cc00ee' : '0px',width: '100%',height: '170px'}}
                                                     onClick={this.onpattenClick.bind(this, item.admID,item.patID)}>
                                                    <p className='info-line'>
                                                        <span className='info-key'>就诊日期：</span>
                                                        <span className='info-value'>{item.admDate}</span>
                                                    </p>
                                                    <p className='info-line'>
                                                        <span className='info-key'>登记日期：</span>
                                                        <span className='info-value'>{item.regDate}</span>
                                                    </p>
                                                    <p className='info-line'>
                                                        <span className='info-key'>责医/责护：</span>
                                                        <span className='info-value'>{item.admDocDesc}/{item.admNurDesc}</span>
                                                    </p>
                                                    <p className='info-line'>
                                                        <span className='info-key'>诊断：</span>
                                                        <span id='description' title={item.admDiag} className='info-value'>{item.admDiag}</span>
                                                    </p>
                                                </div> */}
                                                {/* <div className="card-left-flag">
                                                    <p className='left-flag-line'>
                                                        <span>三級</span>
                                                        <span>危</span>
                                                    </p>
                                                </div> */}
                                            </div>
                                            <div className="card-right30" style={{ borderLeft: '1px solid #eae3e3', width: '40%', height: '170px', overflow: 'auto', position: 'relative', textAlign: 'center' }}>

                                                {
                                                    item.childInfo.length > 0 ?
                                                        item.childInfo.map((v, k) => {
                                                            return (
                                                                <div className='card-right-container'
                                                                    style={{ border: this.state.clickID == v.babyAdmID && this.state.thatID == "" ? '1px solid #cc00ee' : '0px' }}
                                                                    key={k} onClick={this.onBabyClick.bind(this, v.babyAdmID, v.childPatID)}
                                                                >
                                                                    <div className='card-right-item'>
                                                                        <span className='right-item-index'>{k + 1}</span>
                                                                        <div className='right-item-detail'>
                                                                            <p>{v.childPatNo}</p>
                                                                            <p>{v.childPatName}｜{v.childbirthSexDesc}</p>
                                                                            <p>{v.childbirthWeight}</p>
                                                                        </div>
                                                                    </div>
                                                                </div>
                                                            )
                                                        }) :

                                                        <div style={{
                                                            width: '100%', height: '20px', position: 'absolute', top: '50%', marginTop: '-10px',
                                                            fontSize: '16px', fontWeight: 'bold'
                                                        }}>
                                                            暂无数据
                                                        </div>
                                                }
                                            </div>
                                        </div>
                                    </Card>
                                </Col>
                            })}
                        </Row>
                    </Col>
                    <Col span={3} className="bedChart-right">
                        <Row>
                            <Col>
                                <PatientProcess admID={this.state.admID} locID={this.state.locID ? this.state.locID : user.locID} />
                            </Col>
                        </Row>
                        <Row>
                            <Col>
                                <Memorandum componentType="Delivery" handelThis={this} admID={this.state.admID} locID={this.state.locID ? this.state.locID : user.locID} />
                            </Col>
                        </Row>
                    </Col>
                </Row>
                <ChildbirthRegister handthis={this} onRef={this.onRef} admID={this.state.admID} visible={this.state.birthVisible} onCancel={
                    () => {
                        this.setState({
                            birthVisible: false,
                        })
                    }
                } />
            </div >
        )
    }
};

export default BedChartjuery;





