/*
* 处方详情
* */

import React, { Component } from 'react';
import { Input, Form, Select, Modal, Button, DatePicker, Table, message, Tooltip, Card, Row, Col } from 'antd';
import { Util, dayFormat } from 'tools/index';
import { $http } from 'containers/config/https';
import '../courierStyle/index.less';
import moment from 'moment';

const Option = Select.Option;
const FormItem = Form.Item;
const { RangePicker } = DatePicker;

class BringMedicineModal extends Component {

    constructor(props) {
        super(props);
        var date = new Date();
        var userData = JSON.parse(sessionStorage.getItem('userData'));
        this.state = {
            leftData: [],
            rightData: [],
            userData: userData,
            total: 0,
            page: 1,
            pageSize: 10,
            codePage: 1,
            ids: [],
            totalCount: 0,
            date: date,
        }
    }
    componentWillReceiveProps(nextProp) {
        if (nextProp.isShow === true) {
            this.setState({
                dataSource:nextProp.prescriptData
            })
        } else if (this.props.isShow === false) {
            this.cleanInput();
        }
    }

    componentDidMount() {
        this.initData();
    }

    initData() {
        this.columns = [
            {
                title: this.state.userData.language == 'EN'?'Order Number':'序号',
                dataIndex: 'admDate',
                width: 50,
                align: 'center',
                render: (text, data, index) => <span style={{ width: 50 }}>{index + 1}</span>
            }, {
                title: this.state.userData.language == 'EN'?"doctor's advice":'医嘱内容',
                dataIndex: 'medDesc',
                width: 300,
                align: 'left',
            }, {
                title: this.state.userData.language == 'EN'?'advice type':'医嘱类型',
                dataIndex: 'status',
                width: 100,
                align: 'center',
            },{
                title: this.state.userData.language == 'EN'?'Number':'数量',
                dataIndex: 'ordQty',
                width: 50,
                align: 'right',
            }, {
                title: this.state.userData.language == 'EN'?'department':'开单科室',
                dataIndex: 'locDesc',
                width: 100,
                align: 'left',
            }, {
                title: '开单医生',
                dataIndex: 'doctorName',
                width: 100,
                align: 'left',
            },{
                title: this.state.userData.language == 'EN'?'Date':'开医嘱时间',
                dataIndex: 'ordDate',
                width: 120,
                align: 'left',
            },
        ]
    }

    closeModal(name) {
        let { onHide } = this.props;
        onHide && onHide();
        this.cleanInput();
    }

    //清空输入框
    cleanInput() {
        this.props.form.resetFields();
        this.setState({
            dataSource: []
        })
    }

    render() {

        return <div>
            <Modal className='bring-medicine-body'
                title={this.state.userData.language =='EN'?'Prescription details':'处方详情'}
                maskClosable={false}
                okText={this.state.userData.language =='EN'?'OK':'确定'}
                cancelText={this.state.userData.language =='EN'?'Cancel':'取消'}
                visible={this.props.isShow}
                onCancel={this.closeModal.bind(this)}
                footer={null}
            >
                <Table columns={this.columns} style={{ marginTop: 5 }}
                    dataSource={this.state.dataSource}
                    scroll={{ y: '35vh' }} bordered
                    rowKey={(data) => {
                        return data.id
                    }}
                    pagination={false}></Table>

            </Modal></div>
    }
}

export default Form.create()(BringMedicineModal);