
import React from 'react'
import {
    Collapse, Row, Col, Button, Table, Input, message,
} from 'antd';
import ColumnAuthoritysModel from '../columnAuthority/ColumnAuthoritysModel'
import { $http } from '../../containers/config/https';
import store from '../../store';
import './CSS/opNurse.less';

const Panel = Collapse.Panel;
let user;
class OPPatientList extends React.Component {
    constructor(props) {
        super(props);
        user = window.sessionStorage.userData ? JSON.parse(window.sessionStorage.userData) : {};
        this.state = {
            dataSYPat: [],
            dataZLPat: [],
            dataPSPat: [],
            patNo: '',
            rowPatNo: '',
            column: [],
        }
    }
    //渲染完成时调用
    componentDidMount() {
        this.props.onRef(this);
        this.handleQueryPat("dataSYPat");
        this.loadColumn();
    }
    //接收nextProps
    componentWillReceiveProps(nextProps) {

    }
    // 组件销毁前将静止让setState修改state的状态
    componentWillUnmount() {
        this.setState = (state, callback) => { return; }
    }
    //查询列头数据
    loadColumn = (compontName) => {
        let data = {
            params: [{
                compontName: 'InfusionPatientList',
                type: "C",
                reactCode: ['InfusionPatientList']
            }]
        }
        $http.post('urlDeault', this, {
            code: "01040073",
            data: data,
            success: (res) => {
                if (+res.errorCode === 0) {
                    let column = res.result.C;
                    if (user.language == 'EN') {
                        for (let i = 0; i < column.length; i++) {
                            column[i].title = column[i].enDescripts
                        }
                    }
                    this.setState({
                        column: column,
                    })
                }
            }
        })
    }
    //查询患者列表
    handleQueryPat = (patFlag) => {
        let data = {
            params: [{
                locID: user.locID,
                patNo: this.state.patNo,
            }]
        }
        $http.post('urlDeault', this, {
            code: "04080009",
            data: data,
            success: (res) => {
                if (+res.errorCode === 0) {
                    this.setState({
                        [patFlag]: res.result,
                        rowPatNo: '',
                    })
                }
            }
        })
    }
    //点击患者
    onRow = (row) => {
        this.props.handelThis.childPatient.getPatientInfo(row.admID);
        this.props.handelThis.handelQueryOrder(row.patNo, "", row.admID);
        this.setState({ rowPatNo: row.patNo });
    }
    ///行背景色
    setRowClassName = (row) => {
        return row.patNo === this.state.rowPatNo ? 'clickRowStyle' : '';
    }

    //叫号
    handelCallPat = (e) => {
        if (this.state.rowPatNo === '') {
            message.warn(user.language != 'EN' ? "请先选择患者!" : 'Please select a patient first');
            return;
        }
        message.success(user.language != 'EN' ? "呼叫成功!" : 'Call successful');
    }
    ///切换患者列表触发
    onPanelChange = (key) => {
        let patFlag = "data" + key + "Pat";
        this.handleQueryPat(patFlag);
    }

    //登记号改变
    onPatNoChange = (e) => {
        this.setState({
            patNo: e.target.value,
        })
    }
    //登记号回车
    onPatNoEnter = (flag) => {
        this.handleQueryPat(flag);
        message.success(this.state.patNo + (user.language != 'EN' ? "查询成功!" : 'Search successful'));
    }
    onColumnRef = (ref) => {
        this.columnRef = ref;
    }

    render() {
        const callBtn = (
            <Button onClick={this.handelCallPat} style={{ margin: '7px 15px 0 10px', background: 'rgba(255,255,255,1)' }}>{user.language != 'EN' ? "呼叫" : 'call'}</Button>
        )
        return (
            <div style={{ width: '100%', height: '100%' }} className="OPPatientList">
                <ColumnAuthoritysModel
                    clientWidth='800px'
                    compontName="InfusionPatientList"
                    configType="C"
                    onRef={this.onColumnRef}
                    reloadData={this.loadColumn}
                />

                <Collapse defaultActiveKey="SY" accordion={true}
                    onChange={this.onPanelChange}
                >
                    <Panel showArrow={false} header={user.language != 'EN' ? "输液患者" : 'Infusion patient'} key="SY" className="Panel" disabled>
                        <div style={{ height: '100%', overflow: 'hidden' }}>
                            <div className="table-operations">
                                <Row style={{ minHeight: '45', paddingBottom: '5px' }}>
                                    <Col>
                                        {callBtn}
                                        <Input
                                            value={this.state.patNo}
                                            onPressEnter={this.onPatNoEnter.bind(this, "dataSYPat")}
                                            onChange={this.onPatNoChange}
                                            style={{ width: '150px' }}
                                            placeholder={user.language != 'EN' ? "输入患者ID(enter)" : 'Enter the registration number(enter)'} />

                                    </Col>
                                </Row>
                            </div>
                            <div style={{ widht: '100%', height: '6px', background: '#f0f2f5' }}></div>
                            <Table
                                pagination={false}
                                style={{ height: 'calc(100% - 50px)' }}
                                scroll={{ y: 'calc(100% - 36px)' }}
                                bordered
                                columns={this.state.column}
                                dataSource={this.state.dataSYPat}
                                rowKey={(row) => {
                                    return row.patNo;
                                }}
                                onHeaderRow={column => {
                                    return {
                                        onDoubleClick: () => {
                                            this.columnRef.onOpenModel();
                                        }
                                    };
                                }
                                }

                                rowClassName={this.setRowClassName}
                                onRow={(row) => {
                                    return {
                                        onClick: (event) => {
                                            this.onRow(row);
                                        },
                                    };
                                }}
                            >
                            </Table>
                        </div>
                    </Panel>
                    {/* <Panel header="皮试患者" key="PS">
                        <div style={{ height: store.getState().tableHeight.y + 65 + 'px' }}>
                            <div className="table-operations">
                                <Row style={{ minHeight: '45', paddingBottom: '5px' }}>
                                    <Col>
                                        {callBtn}
                                    </Col>
                                </Row>
                            </div>
                            <div style={{ widht: '100%', height: '6px', background: '#f0f2f5' }}></div>
                            <Table
                                pagination={false}
                                style={{ height: (store.getState().tableHeight.y + 20) + 'px' }}
                                scroll={{ y: store.getState().tableHeight.y - 25 }}
                                bordered
                                columns={this.column}
                                dataSource={this.state.dataPSPat}
                                rowKey={(row) => {
                                    return row.patNo;
                                }}
                                rowClassName={this.setRowClassName}
                                onRow={(row) => {
                                    return {
                                        onClick: (event) => {
                                            this.onRow(row);
                                        },
                                    };
                                }}
                            >
                            </Table>

                        </div>
                    </Panel> */}
                    {/* <Panel header="治疗患者" key="ZL">
                        <div style={{ height: store.getState().tableHeight.y + 65 + 'px' }}>
                            <div className="table-operations">
                                <Row style={{ minHeight: '45', paddingBottom: '5px' }}>
                                    <Col>
                                        {callBtn}
                                    </Col>
                                </Row>
                            </div>
                            <div style={{ widht: '100%', height: '6px', background: '#f0f2f5' }}></div>

                        </div>
                    </Panel> */}
                </Collapse>
            </div>
        );

    }
}
export default OPPatientList;