/**
 * 处理医嘱清单
 */
import React from 'react';
import { Modal, Row, Col, Select, DatePicker, TimePicker } from 'antd';
import { Util, dayFormat, timeFormat } from 'tools/index';
import { $http } from 'containers/config/https';
import '../style/index.less';
import moment from 'moment';

class ShowDealWithAdvice extends React.Component {

    constructor(props) {
        super(props);
        var userData = JSON.parse(sessionStorage.getItem('userData'));
        this.state = {
            userData: userData,
            type: 'A'
        }
    }
    componentWillReceiveProps(nextProp) {
        if (nextProp.isShow === true) {
            this.loadDateTime()
        } else if (this.props.isShow === false) {

        }
    }

    loadDateTime() {
        var params = {
            params: [{}]
        }
        $http.post('urlS', this, {
            code: '04030004',
            data: params,
            success: function (res) {
                if (res.errorCode == '0') {
                    this.setState({
                        dateFrom: res.date,
                        timeFrom: res.time,
                    })
                }
            }
        })
    }


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

    changeDate(e) {
        this.setState({
            dateFrom: e ? moment(e).format(dayFormat) : ''
        })
    }

    changeTime(e) {
        this.setState({
            timeFrom: e ? moment(e).format(dayFormat) : ''
        })
    }

    onSubmit() {
        var { dateFrom, timeFrom, type } = this.state;
        var { onSubmit } = this.props;
        onSubmit && onSubmit(type, dateFrom, timeFrom)
    }

    render() {
        return <div>
            <Modal
                title={'处理'}
                maskClosable={false}
                visible={this.props.isShow}
                onOk={this.onSubmit.bind(this)}
                onCancel={this.closeModal.bind(this)}>
                <div style={{ textAlign: 'center' }}>
                    <Col>
                        处理类型：<Select onChange={Util.handleSelectChange.bind(this, 'type')} style={{ width: '20vh' }}
                            defaultValue='A' placeholder='请选择处理类型' allowClear>
                            <Option key='1' value='A'>确认</Option>
                            <Option key='2' value='R'>拒绝</Option>
                        </Select>
                    </Col>
                    <Col style={{ marginTop: 5 }}>
                        处理日期：<DatePicker value={this.state.dateFrom ? moment(this.state.dateFrom, dayFormat) : ''} style={{ width: '20vh' }}
                            onChange={this.changeDate.bind(this)} />
                    </Col>
                    <Col style={{ marginTop: 5 }}>
                        处理日期：<TimePicker value={this.state.timeFrom ? moment(this.state.timeFrom, timeFormat) : ''} style={{ width: '20vh' }}
                            onChange={this.changeTime.bind(this)} />
                    </Col>
                </div>
            </Modal>
        </div>
    }
}

export default ShowDealWithAdvice;