index.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import React, { useEffect, useState } from 'react';
  2. import { Select } from 'antd';
  3. import { queryApproval } 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 queryApproval({ pageSize: 9999 }).catch(err => {
  11. console.log(err);
  12. setLoading(false);
  13. });
  14. if (res.code === 200) {
  15. console.log(res.data.list);
  16. setProjectList(res.data.list);
  17. setLoading(false);
  18. }
  19. };
  20. useEffect(() => {
  21. getProjectList();
  22. }, []);
  23. return (
  24. <Select
  25. showSearch
  26. loading={loading}
  27. style={{ width: '100%' }}
  28. disabled={disabled}
  29. defaultValue={value ? Number(value) : undefined}
  30. onChange={val => {
  31. console.log(val);
  32. const project = projectList.find(item => item.id === val);
  33. onChange(`${val}`);
  34. }}
  35. filterOption={(input, option) =>
  36. (option?.label ?? '').toLowerCase().includes(input.toLowerCase())
  37. }
  38. options={projectList.map(item => {
  39. return {
  40. label: `${item.project_name}(${item.project_full_code})`,
  41. value: item.id,
  42. };
  43. })}
  44. />
  45. );
  46. }
  47. export default DDProjectField;