import React, { useEffect, useState } from 'react'
import { Modal, Form, Input, DatePicker, Button } from 'antd'

const formItemLayout = {
  labelCol: {
    xs: { span: 24 },
    sm: { span: 6 },
  },
  wrapperCol: {
    xs: { span: 24 },
    sm: { span: 12 },
  },
}

const tailFormItemLayout = {
  wrapperCol: {
    xs: {
      span: 24,
      offset: 0,
    },
    sm: {
      span: 16,
      offset: 6,
    },
  },
}

export default Form.create()(props => {
  const handleSubmit = e => {
    e.preventDefault()
    props.form.validateFields((err, values) => {
      if (!err && props.onSubmit) {
        props.onSubmit(values)
      }
    })
  }

  useEffect(() => {
    props.form.setFieldsValue(props.initialData || {})
  }, [props.initialData])

  return (
    <Modal title="收费组信息" visible={props.visible} footer={null} maskClosable={false} destroyOnClose onCancel={props.onCancel}>
      <Form {...formItemLayout} onSubmit={handleSubmit}>
        <Form.Item label="收费组名称">
        {
          props.form.getFieldDecorator('billName', {
            rules: [
              { required: true, message: '请填写收费组名称' },
            ],
          })(<Input placeholder="收费组名称" />)
        }
        </Form.Item>
        <Form.Item label="收费组说明">
        {
          props.form.getFieldDecorator('billExplain', {
            rules: [
              { required: true, message: '请填写收费组说明' },
            ],
          })(<Input placeholder="收费组说明" />)
        }
        </Form.Item>
        <Form.Item label="截止时间">
        {
          props.form.getFieldDecorator('endDate', {
            rules: [
              { required: true, message: '请选择截止时间' },
            ],
          })(
            <DatePicker showTime placeholder="请选择截止时间" />
          )
        }
        </Form.Item>
        <Form.Item {...tailFormItemLayout} >
          <Button type="primary" htmlType="submit">确定</Button>
          <Button style={{ marginLeft: '24px' }} onClick={props.onCancel}>取消</Button>
        </Form.Item>
      </Form>
    </Modal>
  )
})
