/*
 * Creator:     ML
 * CreatDate:   2020-09-218
 * 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';
import store from 'store';

const FormItem = Form.Item;
const paddRightCol = {
    paddingRight: "0px"
}
const formItemLayout = { // label 和input宽度
    labelCol: { span: 9 },
    wrapperCol: { span: 15 },
}
const formLayoutItenm = {
    labelCol: { span: 4 },
    wrapperCol: { span: 20 },
}
const EditAssistantModal = Form.create()(
    class EditAssistantModal extends React.Component {
        constructor(props) {
            super(props)
            this.state = {
                visible: false,
                baseParms: {},
                edit: -1,
                params: {},
                id: "",
            }
        }
        componentDidMount() {
            this.props.OnChildrefs(this);
        }
        showModal = (e, record,) => {
            this.setState({
                visible: true,
                params: record

            })
        }
        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: [{
                            data: [
                                {
                                    locID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).locID : "",
                                    hospID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).hospID : "",
                                    userID: sessionStorage.userData ? JSON.parse(sessionStorage.userData).userID : "",
                                    docID: this.state.params&&this.state.params.docID||"",
                                    ID: this.state.params&&this.state.params.ID||"",
                                    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: '01040225',
                        data: data,
                        success: function (res) {
                            if (+res.errorCode === 0) {
                                    message.success('修改成功');
                                    this.setState({ visible: false, })
                                    this.props.getAuthorizationList();
                                this.setState({
                                    visible: false,
                                    edit: -1,
                                    params: {},
                                    id: ""
                                })
                                this.props.form.resetFields();
                            }
                        }
                    })
                }
            })
        }
        render() {
            const { getFieldDecorator, } = this.props.form;
            const { params } = this.state

            return (
                <div className="bedDom">
                    <Modal
                        className='serviceDom'
                        width='1000px'
                        visible={this.state.visible}
                        title={"编辑助理医生"}
                        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 label='医院名称' {...formItemLayout}>
                                            {getFieldDecorator('hospDesc', {
                                                initialValue: params && params.hospDesc ? params.hospDesc : undefined,
                                                rules: [{ required: false, message: '' }],
                                            })(
                                                <Input disabled />
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={6} style={paddRightCol}>
                                        <FormItem label='科室名称' {...formItemLayout}>
                                            {getFieldDecorator('locDesc', {
                                                initialValue: params && params.locDesc ? params.locDesc : undefined,
                                                rules: [{ required: false, message: '' }],
                                            })(
                                                <Input disabled />
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={6} style={paddRightCol}>
                                        <FormItem label='医生助理' {...formItemLayout}>
                                            {getFieldDecorator('docDesc', {
                                                initialValue: params && params.docDesc ? params.docDesc : undefined,
                                                rules: [{ required: false, message: '' }],
                                            })(
                                                <Input disabled />
                                            )}
                                        </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 EditAssistantModal    