import { useModel } from '@umijs/max';
import { TreeSelect } from 'antd';
import { useEffect } from 'react';

function DepartmentField(props) {
  const { value, onChange } = props;
  const { depList, run, loading } = useModel('depList');

  const onChangeValue = (newValue) => {
    onChange(String(newValue));
  };
  useEffect(() => {
    run();
  }, []);

  return (
    <TreeSelect
      showSearch
      // multiple
      allowClear
      dropdownStyle={{
        maxHeight: 400,
        overflow: 'auto',
      }}
      loading={loading}
      style={{ width: '100%' }}
      placeholder="请选择部门"
      treeData={depList}
      onChange={onChangeValue}
    />
  );
}

export default DepartmentField;
