/*
 * Creator:     ML
 * CreatDate:   2020-02-27
 * descripts：  抗菌药物类别 添加/编辑
 * */
import React from 'react';
import { Form, Row, Col, Input, Select, Button, DatePicker, Modal, Table, Icon, Pagination, message, Divider, Tooltip, Checkbox } from 'antd';
import moment from 'moment';
import { $http } from '../../../containers/config/https';

const FormItem = Form.Item;
const paddRightCol = {
    paddingRight: "0px"
}
const formItemLayout = { // label 和input宽度
    labelCol: { span: 9 },
    wrapperCol: { span: 15 },
}
const AntibacterialConfigModal = Form.create()(
    class AntibacterialConfigModal extends React.Component {
        constructor(props) {
            super(props)
            this.state = {
                visible: false,
                baseParms: {},
                edit: -1,
                params: {},
                id: "",
            }
        }
        componentDidMount() {
            this.props.OnChildrefs(this);
        }
        //国际化
        setMessage(name, message) {
            return this.props.localeProvider ? this.props.localeProvider[name][message] : ''
        }
        showModal = (record, num) => {
            this.setState({
                visible: true,
            })
            if (record && num && num == "1") {
                let arr = []
                this.setState({
                    edit: num,
                    params: record,
                    id: record.ID,
                })
            }
        }
      
        handleCancel = () => {
            this.props.form.resetFields();
            this.setState({ visible: false, params: {}, edit: -1, id: "" });
        }
        //添加/编辑
        handleCreat = () => {
            this.props.form.validateFields((err, values) => {
                if (!err) {
                    let data = {}
                    data = {
                        params: [{
                            updateUserID: JSON.parse(sessionStorage.userData).userID || '',
                            ID: this.state.id && this.state.id ? this.state.id : "",//修改
                            code: values.code || "",
                            descripts: values.descripts || "",
                            eNDesc: values.eNDesc || "",
                            note: values.note || "",
                            // createDate: values.createDate ? moment(values.createDate).format('YYYY-MM-DD') : undefined,//创建日期
                            startDate: values.dateFrom ? moment(values.dateFrom).format('YYYY-MM-DD') : undefined,//生效日期
                            stopDate: values.dateTo ? moment(values.dateTo).format('YYYY-MM-DD') : undefined,//失效日期
                        }]
                    }
                    $http.post('urlS', this, {
                        code: '03050194',
                        data: data,
                        success: function (res) {
                            if (+res.errorCode === 0) {
                                if (this.state.edit == "1") {
                                    message.success(this.props.localeProvider && this.props.localeProvider.AntimicrobialClassInterfaceUpdate? this.setMessage('AntimicrobialClassInterfaceUpdate', 'descripts') : '更新成功');
                                    this.props.getNewData();
                                } else {
                                    message.success(this.props.localeProvider && this.props.localeProvider.AntimicrobialClassInterfaceAddS? this.setMessage('AntimicrobialClassInterfaceAddS', 'descripts') : '添加成功');
                                    this.props.getNewData(res.Id);
                                }
                                this.setState({
                                    visible: false,
                                    edit: -1,
                                    params: {},
                                    id: ""
                                })
                                this.props.form.resetFields();
                            }
                        }
                    })
                }
            })
        }
        render() {
            const { getFieldDecorator, } = this.props.form;
            const { params } = this.state
            //医院
            let hosOp = []
            this.state.hospArr && this.state.hospArr.map((item) => {
                hosOp.push(<Option key={item.id} value={String(item.id)}>{item.descripts}</Option>)
            })
            //费用类别
            let feeOp = []
            this.state.feeArr && this.state.feeArr.map((item) => {
                feeOp.push(<Option key={item.id} value={String(item.id)}>{item.descripts}</Option>)
            })


            return (
                <div style={{ padding: '4px 2px' }} className="bedDom">
                    <Modal
                        className='findPatients'
                        width='1000px'
                        visible={this.state.visible}
                        title={this.state.edit == "1" ? this.props.localeProvider && this.props.localeProvider.AntimicrobialClassInterfaceEditBasicModal? this.setMessage('AntimicrobialClassInterfaceEditBasicModal', 'descripts') : "编辑抗菌药物类别" : this.props.localeProvider && this.props.localeProvider.AntimicrobialClassInterfaceAddBasicModal? this.setMessage('AntimicrobialClassInterfaceAddBasicModal', 'descripts') : "添加抗菌药物类别"}
                        onOk={this.handleOk}
                        onCancel={this.handleCancel}
                        footer={[
                            <Button key="submit" type="primary" loading={this.setState.loading} disabled={this.state.rowId == ""} onClick={this.handleCreat}>{this.props.localeProvider && this.props.localeProvider.AntimicrobialClassInterfaceOk? this.setMessage('AntimicrobialClassInterfaceOk', 'descripts') : "确定"}</Button>,
                            <Button key="cancel" type="primary" loading={this.setState.loading} onClick={this.handleCancel}>{this.props.localeProvider && this.props.localeProvider.AntimicrobialClassInterfaceCancel? this.setMessage('AntimicrobialClassInterfaceCancel', 'descripts') : "取消"}</Button>,
                        ]}>
                        <div className="department-header">
                            <Form>
                                <Row gutter={60} style={{ margin: '0' }}>
                                    <Col span={6} style={paddRightCol}>
                                        <FormItem {...formItemLayout} label={this.props.localeProvider && this.props.localeProvider.AntimicrobialClassInterfaceCode? this.setMessage('AntimicrobialClassInterfaceCode', 'descripts') : "代码"}>
                                            {getFieldDecorator('code', {
                                                initialValue: params && params.code ? String(params.code) : undefined,
                                                rules: [{ required: true, message: this.props.localeProvider && this.props.localeProvider.AntimicrobialClassInterfaceCode? this.setMessage('AntimicrobialClassInterfaceCode', 'message') : "请输入代码" }],
                                            })(
                                               <Input></Input>
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={6} style={paddRightCol}>
                                        <FormItem {...formItemLayout} label={this.props.localeProvider && this.props.localeProvider.AntimicrobialClassInterfaceDescripts? this.setMessage('AntimicrobialClassInterfaceDescripts', 'descripts') : "描述" }>
                                            {getFieldDecorator('descripts', {
                                                initialValue: params && params.descripts ? String(params.descripts) : undefined,
                                                rules: [{ required: true, message: this.props.localeProvider && this.props.localeProvider.AntimicrobialClassInterfaceDescripts? this.setMessage('AntimicrobialClassInterfaceDescripts', 'message') : "请输入描述" }],
                                            })(
                                                <Input></Input>
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={6} style={paddRightCol}>
                                        <FormItem label={this.props.localeProvider && this.props.localeProvider.AntimicrobialClassInterfaceEnglishDescription? this.setMessage('AntimicrobialClassInterfaceEnglishDescription', 'descripts') : "英文描述" } {...formItemLayout}>
                                            {getFieldDecorator('eNDesc', {
                                                initialValue: params && params.eNDesc ? params.eNDesc : undefined,
                                                rules: [{ required: false, message: '' }],
                                                
                                            })(
                                                <Input allowClear />
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={6} style={paddRightCol}>
                                        <FormItem label={this.props.localeProvider && this.props.localeProvider.AntimicrobialClassInterfaceNote? this.setMessage('AntimicrobialClassInterfaceNote', 'descripts') : "备注" } {...formItemLayout}>
                                            {getFieldDecorator('note', {
                                                initialValue: params && params.note ? params.note : undefined,
                                                rules: [{ required: false, message: '' }],
                                                
                                            })(
                                                <Input allowClear />
                                            )}
                                        </FormItem>
                                    </Col>
                                   
                                </Row>
                                <Row gutter={60} style={{ margin: '0' }}>
                                {/* <Col span={6} style={paddRightCol}>
                                        <FormItem label={this.props.localeProvider && this.props.localeProvider.AntimicrobialClassInterfaceCreatData? this.setMessage('AntimicrobialClassInterfaceCreatData', 'descripts') : "创建日期" } {...formItemLayout}>
                                            {getFieldDecorator('createDate', {
                                                initialValue: params.createDate ? moment(params.createDate, "YYYY-MM-DD") : moment(),
                                                rules: [{ required: true, message: this.props.localeProvider && this.props.localeProvider.AntimicrobialClassInterfaceCreatData? this.setMessage('AntimicrobialClassInterfaceCreatData', 'message') : '请选择创建日期' }],
                                            })(
                                                <DatePicker style={{ width: '100%' }} disabledDate={(curDate) => {
                                                    return curDate && curDate > moment().endOf('day');
                                                }} />
                                            )}
                                        </FormItem>
                                    </Col> */}
                                    <Col span={6} style={paddRightCol}>
                                        <FormItem label={this.props.localeProvider && this.props.localeProvider.AntimicrobialClassInterfaceStartData? this.setMessage('AntimicrobialClassInterfaceStartData', 'descripts') : "生效日期" } {...formItemLayout}>
                                            {getFieldDecorator('dateFrom', {
                                                initialValue: params.startDate ? moment(params.startDate, "YYYY-MM-DD") : moment(),
                                                rules: [{ required: true, message: this.props.localeProvider && this.props.localeProvider.AntimicrobialClassInterfaceStartData? this.setMessage('AntimicrobialClassInterfaceStartData', 'message') : '请选择生效日期' }],
                                            })(
                                                <DatePicker style={{ width: '100%' }} disabledDate={(curDate) => {
                                                    return curDate && curDate > moment().endOf('day');
                                                }} />
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={6} style={paddRightCol}>
                                        <FormItem label={this.props.localeProvider && this.props.localeProvider.AntimicrobialClassInterfaceStopData? this.setMessage('AntimicrobialClassInterfaceStopData', 'descripts') : "失效日期" } {...formItemLayout}>
                                            {getFieldDecorator('dateTo', {
                                                initialValue: params.stopDate ? moment(params.stopDate, "YYYY-MM-DD") : undefined,
                                                rules: [{ required: false, message: '' }],
                                            })(
                                                <DatePicker style={{ width: '100%' }} />
                                            )}
                                        </FormItem>
                                    </Col>
                                </Row>
                            </Form>
                        </div>
                    </Modal>
                </div>
            )
        }
    })
export default AntibacterialConfigModal    