/*
 * Creator:     ML
 * CreatDate:   2019-12-17
 * 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 BedCostTypeModal = Form.create()(
    class BedCostTypeModal extends React.Component {
        constructor(props) {
            super(props)
            this.state = {
                visible: false,
                baseParms: {},
                edit: -1,
                params: {},
                id: "",
            }
        }
        componentDidMount() {
            this.props.OnChildref(this);
        }
        showModal = (record, num) => {
            this.setState({
                visible: true,
            })
            if (record && num && num == "1") {
                let arr = []
                this.setState({
                    edit: num,
                    params: record,
                    id: record.ID,
                    medItemID: record.medItemID
                })
            }
        }
        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 : "",//修改
                            descripts: values.descripts || "",
                            code: values.code || "",
                            eNDesc: values.eNDesc,
                            createDate: moment().format('YYYY-MM-DD'),
                            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: '01040135',
                        data: data,
                        success: function (res) {
                            if (+res.errorCode === 0) {
                                if (this.state.edit == "1") {
                                    message.success('修改成功');
                                    this.props.getNewData();
                                } else {
                                    message.success('添加成功');
                                    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

            return (
                <div style={{ padding: '4px 2px' }} className="bedDom">
                    <Modal
                        className='findPatients'
                        width='1000px'
                        visible={this.state.visible}
                        title={this.state.edit == "1" ? "编辑床位费类型" : "添加床位费类型"}
                        onOk={this.handleOk}
                        onCancel={this.handleCancel}
                        footer={[
                            <Button key="submit" type="primary" loading={this.setState.loading} disabled={this.state.rowId == ""} onClick={this.handleCreat}>确定</Button>,
                            <Button key="cancel" type="primary" loading={this.setState.loading} onClick={this.handleCancel}>取消</Button>,
                        ]}>
                        <div className="department-header">
                            <Form>
                                <Row gutter={60} style={{ margin: '0' }}>
                                    <Col span={6} style={paddRightCol}>
                                        <FormItem {...formItemLayout} label='代码'>
                                            {getFieldDecorator('code', {
                                                initialValue: params && params.code ? params.code : undefined,
                                                rules: [{ required: true, message: '请输入代码' }],
                                            })(
                                                <Input></Input>
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={6} style={paddRightCol}>
                                        <FormItem {...formItemLayout} label='描述'>
                                            {getFieldDecorator('descripts', {
                                                initialValue: params && params.descripts ? params.descripts : undefined,
                                                rules: [{ required: true, message: '请输入描述' }],
                                            })(
                                                <Input></Input>
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={6} style={paddRightCol}>
                                        <FormItem {...formItemLayout} label='英文描述'>
                                            {getFieldDecorator('eNDesc', {
                                                initialValue: params && params.eNDesc ? params.eNDesc : undefined,
                                                rules: [{ required: false, message: '' }],
                                            })(
                                                <Input></Input>
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={6} style={paddRightCol}>
                                        <FormItem label='生效日期' {...formItemLayout}>
                                            {getFieldDecorator('dateFrom', {
                                                initialValue: params.startDate ? moment(params.startDate, "YYYY-MM-DD") : moment(),
                                                rules: [{ required: true, message: '请选择生效日期' }],
                                            })(
                                                <DatePicker style={{ width: '100%' }} disabledDate={(curDate) => {
                                                    return curDate && curDate > moment().endOf('day');
                                                }} />
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={6} style={paddRightCol}>
                                        <FormItem label='失效日期' {...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 BedCostTypeModal    