/*
* 编辑通道
* */

import React, { Component } from 'react';
import { Input, Form, Select, Modal, Button,DatePicker } from 'antd';
import {Util} from 'tools/index';
import '../style/index.less';
import moment from 'moment';

const Option = Select.Option;
const FormItem = Form.Item;

class ShowEditModal extends Component {

    constructor(props) {
        super(props);
        this.state = {
        }
    }

    componentWillReceiveProps(nextProp) {
        if (!this.props.isShow && nextProp.isShow === true) {
            
        } else if (this.props.isShow === false) {
            this.cleanInput();
        }
    }

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

    //清空输入框
    cleanInput() {
        this.props.form.resetFields();
    }

    //提交
    onSubmit() {
        let { validateFields } = this.props.form;
        validateFields({ force: true }, (err, params) => {
            if (err) {
                return;
            }
            let { onSubmit } = this.props;

            onSubmit && onSubmit(params);
        });
    }

    render() {
        let { getFieldDecorator, getFieldValue } = this.props.form;
        let formItemLayout = {
            labelCol: { span: 5 },
            wrapperCol: { span: 19 }
        };

        var modalData = this.props.modalData;

        //所属医院下拉参数
        let hospitalOption = [];
        // this.props.hospitalData && this.props.hospitalData.map((item, index) => {
        //     hospitalOption.push(<Option key={index} value={item.id + ''}>{item.descripts}</Option>)
        // })

        return <Modal className='timeSoltModal'
            title={'编辑信息'}
            maskClosable={false}
            visible={this.props.isShow}
            onCancel={this.closeModal.bind(this)}
            onOk={this.onSubmit.bind(this)}>
            <div>
                <div className=""modal-body>
                    <Form className="card-form-item">
                        <FormItem {...formItemLayout} label="所属医院">
                            {getFieldDecorator('HospitalDr', {
                                // initialValue: Util.isEmpty(modalData.hospitalDescripts) ? undefined : modalData.hospitalDescripts + "",
                            })(
                                <Select placeholder="请选择医院" showSearch={true} getPopupContainer={triggerNode => triggerNode.parentNode}>
                                    {hospitalOption}
                                </Select>
                            )}
                        </FormItem>

                        <FormItem {...formItemLayout} label="类型名称">
                            {getFieldDecorator('Descripts', {
                                // initialValue: Util.isEmpty(modalData.descripts) ? undefined : modalData.descripts + "",
                            })(
                                <Input placeholder='请输入类型名称' />
                            )}
                        </FormItem>

                        <FormItem {...formItemLayout} label="生效日期">
                            {getFieldDecorator('StartDate', {
                                initialValue: this.props.StartDate,
                                rules: [{ required: true, message: '生效日期不能为空' }],
                            })(
                                <DatePicker format="YYYY-MM-DD" />
                            )}
                        </FormItem>

                        <FormItem {...formItemLayout} label="失效日期">
                            {getFieldDecorator('StopDate', {
                                initialValue: this.props.StopDate,
                            })(
                                <DatePicker format="YYYY-MM-DD" />
                            )}
                        </FormItem>
                    </Form>
                </div>
            </div>
        </Modal>
    }
}

export default Form.create()(ShowEditModal);