import { ProFormSelect } from '@ant-design/pro-components'; import { debounce } from 'lodash'; import { memo, useState } from 'react'; import { fetchDepartName } from '../server'; interface TypeDepartSelect { /** * @description placeholder */ placeholder?: string; /** * @description 默认300 */ width?: number | string; /** * @description 默认单选 */ mode?: 'multiple' | 'tags' | undefined; rules?: any[]; [propName: string]: any; } const DepartSelect = ({ placeholder, width = 300, mode, label, rules, ...props }: TypeDepartSelect) => { // const { placeholder,width=300, mode="multiple",label }: TypeDepartSelect = props const [departoptions, setDepartOptions] = useState([]); const debounceDepart = async (value) => { if (!value) { return; } const res = await fetchDepartName(value); const list = Array.isArray(res.data) && res.data.map((item) => { return { ...item, value: item?.departId, label: item?.departPath?.reverse().join('-'), }; }); setDepartOptions(list); }; const onSearch = debounce(function (val) { debounceDepart(val.trim()); }, 500); return ( ); }; export default memo(DepartSelect);