index.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import React, { useEffect } from 'react';
  2. import { Select } from 'antd';
  3. import { useModel, useRequest } from '@umijs/max';
  4. import { querySupplierList } from '@/services/contract';
  5. const { Option } = Select;
  6. function ManufacturerField(props) {
  7. const {
  8. initialState: { user },
  9. } = useModel('@@initialState');
  10. const { value, disabled = false, onChange } = props;
  11. //供应商列表
  12. const {
  13. data: option = [],
  14. loading,
  15. run,
  16. } = useRequest((data) => querySupplierList(data), {
  17. manual: true,
  18. formatResult: (res) => {
  19. return res?.data?.list
  20. ? res?.data.list.map((item) => {
  21. return { label: item.name, value: item.id };
  22. })
  23. : [];
  24. },
  25. });
  26. useEffect(() => {
  27. run({
  28. project_id: 1,
  29. is_super: user?.IsSuper,
  30. created_by: user?.CName,
  31. page_size: 99999,
  32. });
  33. }, []);
  34. return (
  35. <Select
  36. showSearch
  37. loading={loading}
  38. style={{ width: '100%' }}
  39. disabled={disabled}
  40. defaultValue={value ? Number(value) : undefined}
  41. onChange={(value) => {
  42. onChange(String(value));
  43. }}
  44. filterOption={(input, option) =>
  45. (option?.label ?? '').toLowerCase().includes(input.toLowerCase())
  46. }
  47. options={option}
  48. ></Select>
  49. );
  50. }
  51. export default ManufacturerField;