// 就诊记录

import React from 'react';
import { Select, Input, Row, Col, Button, Spin, Divider, Popconfirm, message, Icon, Form, DatePicker, Table, Tabs, Modal } from 'antd';
import { $http } from 'containers/config/https';
import TipHeader from './TipHeader'
import RangeDatePicker from 'components/rangePicker/index';

// 组件const
const { Option } = Select;
const { RangePicker } = DatePicker;

export default class HistoryModal extends React.Component {

    constructor(props) {
        super(props)
        this.state = {
            dataHistory: [],  // 历史记录列表
            userInfo: {},  // 用户信息
            StartDate: undefined,  // //开始日期
            EndDate: undefined,  // //结束日期
        }

        this.columnsHistory = [
            {
                title: '时间 ',
                dataIndex: 'admData',
                key: '1',
                align: "center",
                render(text, record) {
                    return (
                        <div>
                            {record.admData} {record.admTime}
                        </div>
                    );
                }
            }, {
                title: '就诊科室',
                dataIndex: 'admLocDesc',
                key: '2',
                align: "center",
            }, {
                title: '就诊医生',
                dataIndex: 'ordDocDesc',
                key: '3',
                align: "center",
            }, {
                title: '人员标识',
                dataIndex: 'PatNO',
                key: '5',
                align: "center",
            }, {
                title: '患者名称',
                dataIndex: 'PatName',
                key: '6',
                align: "center",
            }
        ]

    }
    componentDidMount() {

        //用户数据
        this.setState({
            userInfo: this.props.userInfo,
            StartDate: this.props.StartDate,  // //开始日期
            EndDate: this.props.EndDate,  // //结束日期
        }, () => {
            this.historList() //历史记录
        })

    }

    // 历史记录
    historList = () => {

        let data = {
            "params": [{
                "patID": this.state.userInfo.patID || '', //病人id
                "startDate": this.state.StartDate || '',  //开始日期
                "endDate": this.state.EndDate || '',  //结束日期
            }]
        };
        $http.post('urlS', this, {
            code: "05210009",
            data: data,
            success: function (res) {
                let errorCode = res.errorCode;
                if (errorCode === '0') {
                    let result = res.result;
                    for (var i = 0; i < result.length; i++) {
                        result[i].key = i;
                    }
                    this.setState({
                        dataHistory: result,     // 历史记录列表
                    })

                }
            }
        });
    }

    // 时间
    onChange = (date, dateString) => {
        this.setState({
            StartDate: dateString[0],    //开始日期
            EndDate: dateString[1],  //结束日期
        })

    }

    startChange(date) {
        this.setState({
            StartDate: date,
        })
    }

    endChange(date) {
        this.setState({
            EndDate: date,
        })
    }


    // 双击传值
    confirmSelection = (e) => {
        this.props.updateParent(e)
    }



    render() {
        return (
            <div  >
                <div className='mB20'>
                    <TipHeader userInfo={this.state.userInfo} key={this.state.userInfo.patID + this.state.userInfo.accTSubID} />
                </div>
                <Row>
                    <Col span={24} style={{ lineHeight: '32px' }} >
                        <span style={{ float: 'left' }} > 就诊日期：</span>
                        {/* <RangePicker style={{ float: 'left' }} onChange={this.onChange} /> */}
                        <span style={{ display: 'inline-block' }}><RangeDatePicker format='YYYY-MM-DD' width={280}
                            startDate={this.state.StartDate} endDate={this.state.EndDate} startChange={this.startChange.bind(this)} endChange={this.endChange.bind(this)} /></span>
                        <Button style={{ background: 'rgba(66,185,131,1)', color: '#fff', width: '100px', marginLeft: '20px', verticalAlign: 'top' }} onClick={this.historList}>查询</Button>
                    </Col>
                </Row>
                <Row>
                    <Col span={24} className='mT30'>
                        <Table bordered dataSource={this.state.dataHistory} columns={this.columnsHistory} pagination={false}
                            style={{ minHeight: '260px', maxHeight: '300px', overflow: "auto" }}
                            onRow={(record) => {
                                return {
                                    onDoubleClick: (event) => {
                                        this.confirmSelection(record)
                                    },
                                };
                            }} />
                    </Col>
                </Row>
            </div >

        )
    }
}