

import React, { useEffect, useState, useCallback } from 'react';
import { Button, Form, Select, Input, InputNumber, Radio, message, Card, DatePicker, } from 'antd';
import router from 'umi/router';
import { fetch, apis, request } from '@/utils/request';
// import { values } from 'lodash';

const FormItem = Form.Item;
const { RangePicker } = DatePicker
const { Option } = Select;
const updateTreeData = fetch(apis.Institution.instiAlert); //接口
// const Treelist = fetch(apis.Institution.instIist)

const TreedataFrom = React.forwardRef((props, ref) => {
  // const [treeData, onChangethis] = useState();
  const [treeData, settreeData] = useState(0)
  const { onChangethis } = props//获取父组件的方法
  // const [data, setData] = useState(treeData);
  const { form, treeTitle, } = props;
  const { getFieldDecorator, setFieldsValue, validateFields } = form;
  // const { institutionId } = history || {}

  const formItemLayout = {
    //布局
    labelCol: { span: 6 },
    wrapperCol: { span: 14 },

  };
  const formRef = React.createRef();

  const onChange = (date, dateString) => {
    onChangethis(value)
    console.log('fomr onChange---', date, dateString);
  }
  //

  const handleSubmitAdd = (value) => {
    let arr = []
    arr = props.form.getFieldsValue()//获取表单的值
    console.log('---------------arr', arr.institutionId)
    onChangethis(arr)//把表单值传入父组件的修改方法
    return arr()

    // setFieldsValue(treeData) 

  }


  const handleSubmit11 = (values) => {

    updateTreeData({ urlData: { id: institutionId }, data: { ...values } }).then((data) => {
    }).catch((err) => {
      message.error(err.msg || err.message)
    })

  }


  const handleSubmit = (e, values) => {
    let arr = []
    arr = props.form.getFieldsValue()
    e.preventDefault();//阻止默认提交
    validateFields((err, value) => {
      updateTreeData({
        data: arr,
        urlData: { id: value.institutionId }
      }).then((data) => {
        setData(treeData)
        message.success('修改成功');
      }).catch((err) => {
        message.error(err.message || err);
      })
    });
  }


  //挂载 
  const componentDidMount = () => {
    console.log('6666666666form挂载', this.props.FromValue)

    this.props.triggerRef(this)
  }


  return (

    <Form   {...formItemLayout} ref={formRef}
      // onChange={onChange}  
      onSubmit={handleSubmit}
    >
      <FormItem hidden >
        {getFieldDecorator('institutionId')(<Input />)}
      </FormItem> <FormItem hidden >
        {getFieldDecorator('key')(<Input />)}
      </FormItem>
      <FormItem label="名称">
        {getFieldDecorator('institutionName', {
          rules: [{ required: true, message: '请输入名称!' }],
        })(<Input />)}
      </FormItem>
      <FormItem wrapperCol={{ span: 12, offset: 5 }}>
        <Button type="primary" htmlType="submit" style={{ marginLeft: '80px', marginTop: '30px' }}>
          修改
        </Button>
        {/* <Button type="danger">
          删除
           </Button> */}
      </FormItem>
    </Form>
  )
})

export default Form.create({})(TreedataFrom);


