index.jsx 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { useEffect, useState } from 'react';
  2. import { Select } from 'antd';
  3. import { getCooperativeList, getCooperativeDetail } from '@/services/cooperative';
  4. const Option = Select.Option;
  5. export default (props) => {
  6. const { value, onChange, ...otherProps } = props;
  7. const [list, setList] = useState([]);
  8. const searchData = (val) => {
  9. getCooperativeList({ name: val, pageSize: 9999 }).then((res) => {
  10. setList(res.records || []);
  11. });
  12. };
  13. const handleSearch = (text) => {
  14. if (text) {
  15. searchData(text);
  16. }
  17. };
  18. useEffect(() => {
  19. if (value) {
  20. getCooperativeDetail(value).then((res) => {
  21. setList([res]);
  22. });
  23. }
  24. }, [value]);
  25. return (
  26. <Select
  27. showSearch
  28. value={value}
  29. defaultActiveFirstOption={false}
  30. showArrow={false}
  31. filterOption={false}
  32. onSearch={handleSearch}
  33. onChange={onChange}
  34. notFoundContent={null}
  35. {...otherProps}
  36. >
  37. {list.map((item) => {
  38. return (
  39. <Option key={item.orgId} value={item.orgId}>
  40. {item.name}
  41. </Option>
  42. );
  43. })}
  44. </Select>
  45. );
  46. };