index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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}`}
  28. onChange={val => {
  29. onChange(`${val}`);
  30. }}
  31. filterOption={(input, option) =>
  32. (option?.label ?? '').toLowerCase().includes(input.toLowerCase())
  33. }
  34. options={projectList.map(item => {
  35. return {
  36. label: `${item.project_name}(${item.project_full_code})`,
  37. value: `${item.id}`,
  38. };
  39. })}
  40. />
  41. );
  42. }
  43. export default DDProjectField;