// 核心库
import React, { Component } from 'react'
import { connect } from 'dva'
import { withRouter } from 'dva/router'
// 组件库
import { Modal, Form, Input, Icon, message, DatePicker, Upload, Button } from 'antd'
import MD5 from 'md5'

const FormItem = Form.Item

class FeedbackQuestion extends Component {
  constructor(props) {
    super(props)
    this.state = {
      visible: false,
      name: ''
    }
  }

  visibleModal = () => {
    this.setState({ visible: true })
  }

  handleCanceMessage = () => { 
    const { form } = this.props
    form.resetFields()
    this.setState({ visible: false })
  };
  onChange = (value) => {
    this.setState({
        name: value
    })
}
  saveMessage = () => {
    const { login, form, dispatch} = this.props;
    dispatch({
      type: 'app/getDataByPost',
      url: 'PF/QuestionFeedback/Update',
      payload: {
        USER_NAME: this.state.name,
        DEAPARTMENT_NAME: this.state.DEAPARTMENT_NAME,
        QUESTION_DESCRIPTION: this.state.QUESTION_DESCRIPTION,
      },
    }).then(res => {
      if (res) {
        message.success('执行成功！');
        this.BtnClose();
      }
    })
  }

  render() {
    const { children, form } = this.props
    const { getFieldDecorator } = form
    const { visible } = this.state

    const customValidator = (rule, value, callBack) => {
      const newPassword = form.getFieldValue("newPassword")
      if (newPassword !== value) {
        callBack('密码输入不一致，请重新输入！')
      } else {
        callBack()
      }
    }
    return <React.Fragment>
      <span onClick={this.visibleModal}>{children}</span>
      <Modal
        title="问题反馈"
        visible={visible}
        onOk={this.saveMessage}
        onCancel={this.handleCanceMessage}
      >
        <Form>
          <FormItem>
            <Input onChange={(evt) => this.onChange(evt.target.value)} id="name" placeholder="姓名" />
            <Input id="departmentname" placeholder="部门" />
          </FormItem>
          <FormItem>
            <DatePicker />
          </FormItem>
          <FormItem>
            <Input rows={4} id = "QUESTION_DESCRIPTION" placeholder="问题描述" />
          </FormItem>
          <FormItem>
            <Upload>
              <Button>上传附件</Button>
            </Upload>
          </FormItem>
         
        </Form>
      </Modal>
    </React.Fragment>
  }
}

export default withRouter(connect(({ login }) => ({ login }))(Form.create()(FeedbackQuestion)))
