import React, { useState, useEffect } from 'react';
import request from 'axios';
import { Message } from '@alifd/next';

import { createUser } from '@/apis';
import BasicForm from '@/components/BasicForm';

const EditBasicForm = ()=> {
  // const [loading, setLoading] = useState(false);
  // const [user ,setUser] = useState({});
  // useEffect(() => {
  //   const getUser = async () => {
  //     if (name) {
  //       setLoading(true);
  //       try {
  //         const result = await request.get(props.initUrl, {
  //           params: { name },
  //         });
  //         if (result && result.data) {
  //           setUser(result.data);
  //         }
  //       } catch (err) {
  //         Message.error(err.message || '网络错误');
  //       }
  //       setLoading(false);
  //     }
  //   }

  //   getUser();
  // }, []);
  const handleSubmit = (value) => {
    request.post(createUser, value).then(() => {
      Message.success('新增用户成功');
      window.history.back();
    }).catch(err => {
      Message.error(err || '网络错误');
    });
  };
  const handleCancel = () => {
    window.history.back();
  };

  return (<BasicForm onSubmit={handleSubmit} onCancel={handleCancel} />);
};

export default EditBasicForm;
