/**
 * 基础数据维护
 * ShowMaintainModal
 */
/**
 * 
 * 确认医嘱错误
 * 信息弹框
 */

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

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

class ShowMaintainModal 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();
        }
    }

    componentDidMount() {
        this.loadData()
    }

    loadData() {
        var params = {
            params: [{
                ClassName: "User.CBModuleConfigType"
            }]
        }
        $http.post('urlS', this, {
            code: "4007",
            data: params,
            success: function (res) {
                if (res.errorCode === '0') {
                    this.setState({ FieldType: res.result.FieldTypeDr })
                }
            }
        })
    }

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

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

    changeSelect(e) {
        this.setState({
            hide: e
        })
    }

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

    render() {
        var { FieldType } = this.state;
        let { getFieldDecorator } = this.props.form;
        let formItemLayout = {
            labelCol: { span: 8 },
            wrapperCol: { span: 15 }
        };

        let searchColConfig = {
            xs: { span: 24 },
            sm: { span: 12 },
            md: { span: 10 },
            lg: { span: 12 }
        }

        var FieldTypeOption = []
        FieldType && FieldType.map((item, index) => {
            FieldTypeOption.push(<Option key={index} value={item.ID}>{item.Desc}</Option>)
        })

        return <div>
            <Modal className='confirm-maintain-modal'
                title={'医嘱维护'}
                maskClosable={false}
                visible={this.props.isShow}
                onCancel={this.closeModal.bind(this)}
                onOk={this.onSubmit.bind(this)}>
                <Form>
                    <Row gutter={40}>
                        <Col {...searchColConfig}>
                            <FormItem {...formItemLayout} label="代码">
                                {getFieldDecorator('code', {
                                    initialValue: this.state.code ? this.state.code : (this.props.editData ? this.props.editData.code : undefined),
                                    rules: [{ required: true, message: '代码不能为空' }],
                                })(
                                    <Input placeholder='请输入代码' onChange={Util.commonInputChange.bind(this, 'code')} />
                                )}
                            </FormItem>
                        </Col>

                        <Col {...searchColConfig}>
                            <FormItem {...formItemLayout} label="描述">
                                {getFieldDecorator('descripts', {
                                    initialValue: this.state.descripts ? this.state.descripts : (this.props.editData ? this.props.editData.descripts : undefined),
                                    rules: [{ required: true, message: '描述不能为空' }],
                                })(
                                    <Input placeholder='请输入中文描述' onChange={Util.commonInputChange.bind(this, 'descripts')} />
                                )}
                            </FormItem>
                        </Col>

                        <Col {...searchColConfig}>
                            <FormItem {...formItemLayout} label="英文描述">
                                {getFieldDecorator('enDescripts', {
                                    initialValue: this.state.enDescripts ? this.state.enDescripts : (this.props.editData ? this.props.editData.enDescripts : undefined),
                                    // rules: [{ required: true, message: '英文描述不能为空' }],
                                })(
                                    <Input placeholder='请输入英文描述' onChange={Util.commonInputChange.bind(this, 'enDescripts')} />
                                )}
                            </FormItem>
                        </Col>

                        <Col {...searchColConfig}>
                            <FormItem {...formItemLayout} label="宽度">
                                {getFieldDecorator('width', {
                                    initialValue: this.state.width ? this.state.width : (this.props.editData ? this.props.editData.width : undefined),
                                    rules: [{ required: true, message: '宽度不能为空' }],
                                })(
                                    <Input placeholder='请输入宽度' onChange={Util.commonInputChange.bind(this, 'width')} />
                                )}
                            </FormItem>
                        </Col>

                        <Col {...searchColConfig}>
                            <FormItem {...formItemLayout} label="是否隐藏">
                                {getFieldDecorator('hide', {
                                    initialValue: this.state.hide ? this.state.hide : (this.props.editData ? this.props.editData.hide : undefined),
                                    rules: [{ required: true, message: '是否隐藏不能为空' }],
                                })(
                                    <Select onChange={this.changeSelect.bind(this)} placeholder='请选择是否隐藏'>
                                        <Option key='Y' value='Y'>是</Option>
                                        <Option key='N' value='N'>否</Option>
                                    </Select>
                                )}
                            </FormItem>
                        </Col>

                        <Col {...searchColConfig}>
                            <FormItem {...formItemLayout} label="其他样式">
                                {getFieldDecorator('style', {
                                    initialValue: this.state.style ? this.state.style : (this.props.editData ? this.props.editData.style : undefined),
                                    // rules: [{ required: true, message: '其他样式不能为空' }],
                                })(
                                    <Input placeholder='请输入其他样式' onChange={Util.commonInputChange.bind(this, 'style')} />
                                )}
                            </FormItem>
                        </Col>

                        <Col {...searchColConfig}>
                            <FormItem {...formItemLayout} label="字段类型">
                                {getFieldDecorator('fieldTypeID', {
                                    initialValue: this.state.fieldTypeID ? this.state.fieldTypeID : (this.props.editData ? this.props.editData.fieldTypeID : undefined),
                                    rules: [{ required: true, message: '字段类型不能为空' }],
                                })(
                                    // <Input placeholder='请输入字段类型' onChange={Util.commonInputChange.bind(this,'fieldTypeID')} />
                                    <Select placeholder='请选择字段类型' onChange={Util.handleSelectChange.bind(this, 'fieldTypeID')}>
                                        {FieldTypeOption}</Select>
                                )}
                            </FormItem>
                        </Col>
                        <Col {...searchColConfig}>
                            <FormItem {...formItemLayout} label="数据获取方法">
                                {getFieldDecorator('dataMethod', {
                                    initialValue: this.state.dataMethod ? this.state.dataMethod : (this.props.editData ? this.props.editData.dataMethod : undefined),
                                })(
                                    <Input placeholder='请输入数据获取方法' onChange={Util.commonInputChange.bind(this, 'dataMethod')} />
                                )}
                            </FormItem>
                        </Col>
                        <Col {...searchColConfig}>
                            <FormItem {...formItemLayout} label="数据属性名">
                                {getFieldDecorator('attribute', {
                                    initialValue: this.state.attribute ? this.state.attribute : (this.props.editData ? this.props.editData.attribute : undefined),
                                })(
                                    <Input placeholder='请输入数据属性名' onChange={Util.commonInputChange.bind(this, 'attribute')} />
                                )}
                            </FormItem>
                        </Col>
                        <Col {...searchColConfig}>
                            <FormItem {...formItemLayout} label="数据校验规则">
                                {getFieldDecorator('validateRules', {
                                    initialValue: this.state.validateRules ? this.state.validateRules : (this.props.editData ? this.props.editData.validateRules : undefined),
                                })(
                                    <Input placeholder='请输入数据校验规则' onChange={Util.commonInputChange.bind(this, 'validateRules')} />
                                )}
                            </FormItem>
                        </Col>
                    </Row>
                </Form>
            </Modal>
        </div>
    }
}

export default Form.create()(ShowMaintainModal);