/**
 * 患者有多张住院证时弹框显示
 */
import React from 'react'
import {
    Table, Modal, message
} from 'antd';
import store from '../../store';
import { $http } from 'containers/config/https';

class HospitalizationListNew extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            column: [],
            clickRow: {},
        }
    }
    componentDidMount() {
        this.loadColumn();
    }
    componentWillUnmount() {
        // 组件销毁前将静止让setState修改state的状态
        this.setState = (state, callback) => { return; }
    }
    componentWillReceiveProps(nextProps) {
    }
    //表头
    loadColumn = () => {
        let data = {
            params: [{
                compontName: "HospitalizationList",
                type: "C",
            }]
        }
        $http.post('urlDeault', this, {
            code: "01040073",
            data: data,
            success: (res) => {
                if (+res.errorCode === 0) {
                    this.setState({
                        column: res.result.C,
                    })
                }
            }
        })
    }
    //点击历史住院证行
    onRowClick = (record) => {
        if (record.id === this.state.clickRow.id) {
            this.setState({
                clickRow: {},
            })
        } else {
            this.setState({
                clickRow: record,
            })
        }
    }
    //渲染住院证行
    setRowClassName = (row) => {
        return row.id === this.state.clickRow.id ? 'clickRowStyle' : '';
    }
    //
    onSubmit = () => {
        let clickRow = this.state.clickRow;
        if (clickRow.id) {
            this.props.onSubmit(clickRow);
        } else {
            message.warn("请选中一条记录");
        }
    }
    render() {
        let columns = this.state.column;
        return (
            <Modal className='registr-modal'
                title={'患者住院证列表'}
                maskClosable={false}
                visible={this.props.visible}
                okText={'确定'}
                onCancel={this.props.onCancel}
                onOk={this.onSubmit}>
                <div className="appointmentList" style={{ border: '1px solid #cccccc', height: '100%' }}>
                    <div>
                        <Table
                            style={{ height: '300px' }}
                            scroll={{ y: 260 }}
                            bordered
                            columns={columns}
                            onRow={(record, index) => ({
                                onClick: (e) => {
                                    this.onRowClick(record, index, e)
                                },
                                onDoubleClick: (e) => {
                                    this.props.onSubmit(record);
                                }
                            })}
                            rowClassName={this.setRowClassName}
                            rowKey={(data) => {
                                return data.id
                            }}
                            pagination={false}
                            dataSource={this.props.patAdminList}
                        >
                        </Table>
                    </div>
                </div>
            </Modal >
        )
    }
}
export default HospitalizationListNew;