index.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import {Modal, ModalField, ModalSelect} from '@components';
  2. import {FC, useMemo} from 'react';
  3. import {useFormState} from './hooks';
  4. import {useDictionaryOptions, useStorageOptions} from '@hooks';
  5. type Props = {
  6. visible: boolean;
  7. onClose: () => void;
  8. onFetch: () => void;
  9. id: string;
  10. };
  11. const PutOutModal: FC<Props> = function (props) {
  12. const [{control, isLoading}, {onSubmit, watch, setValue}] =
  13. useFormState(props);
  14. const {data: warehouse, isFetching: isWarehoseFetching} =
  15. useDictionaryOptions('仓库');
  16. const warehouseOptions = useMemo(
  17. function () {
  18. return warehouse.filter(val => val?.type === '1');
  19. },
  20. [warehouse],
  21. );
  22. const warehouseId = watch('warehouse');
  23. const {data: storageOptions, isFetching} = useStorageOptions(
  24. false,
  25. state => state.storageLocationCode,
  26. {
  27. id: warehouseId,
  28. clear() {
  29. setValue('location', '');
  30. },
  31. },
  32. );
  33. return (
  34. <Modal
  35. {...props}
  36. title='选择库位信息'
  37. onSubmit={onSubmit}
  38. isLoading={isLoading}
  39. testId='semi_draw_modal'
  40. >
  41. <ModalField
  42. label='出库数量'
  43. type='number'
  44. name='outNum'
  45. control={control}
  46. />
  47. <ModalSelect
  48. data={warehouseOptions}
  49. control={control}
  50. label='所属仓库'
  51. name='warehouse'
  52. loading={isWarehoseFetching}
  53. />
  54. <ModalSelect
  55. data={storageOptions}
  56. loading={isFetching}
  57. control={control}
  58. label='所属库位'
  59. name='location'
  60. />
  61. </Modal>
  62. );
  63. };
  64. export default PutOutModal;