index.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import React, { useEffect, useState } from 'react';
  2. import { Select } from 'antd';
  3. import { queryProjectListUser } from '@/services/approval';
  4. function DDProjectField(props) {
  5. const { value, disabled = false, onChange } = props;
  6. const [projectList, setProjectList] = useState([]);
  7. const [loading, setLoading] = useState(false);
  8. const getProjectList = async () => {
  9. setLoading(true);
  10. const res = await queryProjectListUser({ pageSize: 9999 }).catch(err => {
  11. setLoading(false);
  12. });
  13. if (res.code === 200) {
  14. setProjectList(res.data);
  15. setLoading(false);
  16. }
  17. };
  18. useEffect(() => {
  19. getProjectList();
  20. }, []);
  21. return (
  22. <Select
  23. showSearch
  24. loading={loading}
  25. style={{ width: '100%' }}
  26. disabled={disabled}
  27. defaultValue={value ? Number(value) : undefined}
  28. onChange={val => {
  29. const project = projectList.find(item => item.ID === val);
  30. onChange(`${val}`);
  31. }}
  32. filterOption={(input, option) =>
  33. (option?.label ?? '').toLowerCase().includes(input.toLowerCase())
  34. }
  35. options={projectList.map(item => {
  36. return {
  37. label: `${item.project_name}(${item.project_full_code})`,
  38. value: item.id,
  39. };
  40. })}
  41. />
  42. );
  43. }
  44. export default DDProjectField;