/** 
 * Creator:     JYW
 * CreatDate:   2019-04-17
 * descripts：  执行医嘱
*/
import React from 'react'
import { Modal, DatePicker, TimePicker, Col, Select, message } from 'antd';
import { $http } from '../../../containers/config/https';
import Moment from 'moment';
import './CSS/nurseexecute.less';//引入样式

const Option = Select.Option;
class Sign extends React.Component {

    constructor() {
        super();
        this.state = {
            type: [
                {
                    code: "A",
                    descripts: "确认",
                }, {
                    code: "R",
                    descripts: "拒绝",
                }
            ],
            nurRefuseReason: [],    // 拒绝处理原因
        }
    }
    componentWillReceiveProps = (nextProps) => {
        if(nextProps.visible){
            this.getNurRefuseReason();
        } 
    }

    handleCancel = () => {
        this.setState({
            visible: false,
        })
    }
    componentWillUnmount() {
        this.setState = (state, callback) => {
            return
        }
    }
    getDisabledHours = () => {
        let hours = []
        if (this.props.preExecFlag != 'Y') {
            let time = Moment().hour()
            for (let i = 0; i < 24; i++) {
                if (i > time) hours.push(i)
            }
        }
        return hours
    }
    getDisabledMinutes = (selectedHour) => {
        let time = Moment().minute()
        let minutes = []
        if (this.props.preExecFlag != 'Y') {
            if (selectedHour == Moment().hour()) {
                for (let i = 0; i < 60; i++) {
                    if (i > time) minutes.push(i);
                }
            }
        }
        return minutes
    }

    // 拒绝处理原因
    getNurRefuseReason = () => {
        let data = {}
        $http.post('urlDeault', this, {
            code: "04010010",
            data: data,
            success: (res) => {
                if (+res.errorCode === 0) {
                    this.setState({
                        nurRefuseReason: res.result.data
                    })
                }
            }
        })
    }
    render() {
        let Execute = (this.props.visible ?
            <div className='SignOrd'>
                {
                    this.props.button.code === "HandlerOrder" ? (
                        <div>
                            <Col style={{ textAlign: 'center' }}>
                                类型:
                                <Select
                                    value={this.props.typeCode}
                                    onChange={this.props.onSelectChange.bind(this, "typeCode")}
                                    style={{ width: "138px", padding: '0 0 10px 12px' }}
                                    allowClear={true}
                                >
                                    {
                                        this.state.type.map(
                                            (item) => {
                                                return (
                                                    <Option
                                                        key={item.code}
                                                        value={item.code}
                                                    >
                                                        {item.descripts}
                                                    </Option>
                                                )
                                            }
                                        )
                                    }
                                </Select>
                            </Col>
                            { this.props.typeCode == 'R' ? <Col style={{ textAlign: 'center' }}>
                                <span style={{ marginLeft: '-10px', paddingRight: '3px' }}>拒绝原因:</span>
                                <Select
                                    value={this.props.refuseReason}
                                    onChange={this.props.onSelectChange.bind(this, "refuseReason")}
                                    style={{ width: "138px", padding: '0 10px 10px 0' }}
                                    allowClear={true}
                                >
                                    {
                                        this.state.nurRefuseReason.map(
                                            (item) => {
                                                return (
                                                    <Option
                                                        key={item.id}
                                                        value={item.descripts}
                                                    >
                                                        {item.descripts}
                                                    </Option>
                                                )
                                            }
                                        )
                                    }
                                </Select>
                            </Col> : ''}
                        </div>
                    ) : ""
                }

                <Col style={{ textAlign: 'center' }}>
                    日期:
                    <DatePicker
                        onChange={this.props.handleDateTimeChange.bind(this, "date")}
                        value={this.props.date === "" ? null : Moment(this.props.date, 'YYYY-MM-DD')}
                        style={{ width: '138px', padding: '0 0 10px 12px' }}
                        disabledDate={(curDate) => {
                            if (this.props.preExecFlag != 'Y') {
                                return curDate && curDate > Moment().endOf('day');
                            }
                        }}
                    >

                    </DatePicker>
                </Col>
                <Col style={{ textAlign: 'center' }}>
                    时间:
                    <TimePicker
                        onChange={this.props.handleDateTimeChange.bind(this, "time")}
                        value={this.props.time === "" ? null : Moment(this.props.time, 'HH:mm:ss')}
                        style={{ width: '138px', padding: '0 0 10px 12px' }}
                        format='HH:mm'
                        disabledHours={this.getDisabledHours}
                        disabledMinutes={this.getDisabledMinutes}
                    >
                    </TimePicker>
                </Col>
                {
                    this.props.button.code === "excuteBtn" ? (
                        <div>
                            <Col style={{ textAlign: 'center' }}>
                                执行人:
                                <Select
                                    value={this.props.execUserID}
                                    onChange={this.props.onSelectChange.bind(this, "execUserID")}
                                    style={{ width: "138px", padding: '0 0 10px 12px' }}
                                    allowClear={true}
                                >
                                    {
                                        this.props.nurseArr.map(
                                            (item) => {
                                                return (
                                                    <Option
                                                        key={item.code}
                                                        value={item.id}
                                                    >
                                                        {item.descripts}
                                                    </Option>
                                                )
                                            }
                                        )
                                    }
                                </Select>
                            </Col>
                        </div>
                    ) : ""
                }
            </div> : ""
        )
        return (
            <div className="SignOrd">
                <Modal
                    title={this.props.button === "" ? "" : this.props.button.descripts}
                    width='308px'
                    className='SignOrd-color'
                    visible={this.props.visible}
                    onOk={this.props.onOk}
                    onCancel={this.props.onClose}
                    style={{
                        height: '218px',
                        background: '#FFFFFF',
                        borderRadius: '6px',
                        top: '357px'
                    }}
                    okText="确认"
                    cancelText="取消"
                    destroyOnClose
                    maskClosable={false}
                >

                    {
                        Execute
                    }
                </Modal>
            </div>
        );
    }
}
export default Sign;