index.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import {Modal, ModalSelect} from '@components';
  2. import {FC, useEffect} from 'react';
  3. import {useFormState} from './hooks';
  4. import {useDictionaryWidthCode} from '@hooks';
  5. type Props = {
  6. visible: boolean;
  7. onClose: () => void;
  8. onFetch: () => void;
  9. id: string;
  10. code: string;
  11. softwareCode: string;
  12. };
  13. const PutModal: FC<Props> = function({
  14. visible,
  15. onClose,
  16. onFetch,
  17. id,
  18. code,
  19. softwareCode,
  20. }) {
  21. const [{data: materialOptions, isFetching}, onMaterialSearch]
  22. = useDictionaryWidthCode(
  23. '物料字典',
  24. {findValue: state => state.code},
  25. );
  26. const [
  27. {data: SearviceMaterialOptions, isFetching: searviceMaterialFetching},
  28. onServiceMaterialSearch,
  29. ]
  30. = useDictionaryWidthCode(
  31. '物料字典',
  32. {findValue: state => state.code},
  33. );
  34. useEffect(
  35. function() {
  36. onMaterialSearch(code);
  37. onServiceMaterialSearch(softwareCode);
  38. },
  39. [code, onMaterialSearch, onServiceMaterialSearch, softwareCode],
  40. );
  41. const [
  42. {control, isLoading},
  43. {onSubmit},
  44. ] = useFormState({
  45. visible,
  46. id,
  47. onFetch,
  48. onClose,
  49. code,
  50. softwareCode,
  51. });
  52. return (
  53. <Modal
  54. visible={visible}
  55. title={`${id ? '修改' : '新增'}软件类绑定`}
  56. onClose={onClose}
  57. testId='software_modal'
  58. onSubmit={onSubmit}
  59. isLoading={isLoading}
  60. height='500px'
  61. >
  62. <ModalSelect
  63. control={control}
  64. name='materialCode'
  65. label='物料编号'
  66. data={materialOptions}
  67. onSearch={onMaterialSearch}
  68. loading={isFetching}
  69. />
  70. <ModalSelect
  71. control={control}
  72. name='softwareCode'
  73. label='服务类编号'
  74. data={SearviceMaterialOptions}
  75. onSearch={onServiceMaterialSearch}
  76. loading={searviceMaterialFetching}
  77. />
  78. </Modal>
  79. );
  80. };
  81. export default PutModal;