Browse Source

update: 仓库和库位的联查,仓库修改时清空库位信息

xyh 2 years ago
parent
commit
f0cc9e654b

+ 10 - 3
packages/app/src/hooks/use-options/index.ts

@@ -13,7 +13,7 @@ import {
 } from '@models';
 import {useQuery} from '@tanstack/react-query';
 import {useLatest} from 'ahooks';
-import {useMemo, useState} from 'react';
+import {useEffect, useMemo, useState} from 'react';
 import {debounce} from 'lodash-es';
 
 type Options<T extends {id: number | string}, P extends unknown[]> = {
@@ -66,14 +66,21 @@ function useQueryOptions<T extends {id: number | string}, P extends unknown[]>(
 export function useStorageOptions(
   addAll = false,
   findValue?: (state: StorageListData) => string,
-  options: {id?: string} = {},
+  options?: {id: string; clear: () => void},
 ) {
+  useEffect(
+    function () {
+      options?.clear();
+    },
+    [options?.clear, options?.id],
+  );
+
   return useQueryOptions({
     fn: getAllStorage,
     findName: state => state.storageLocationName,
     addAll,
     findValue,
-    params: [options.id ?? ''],
+    params: [options?.id ?? ''],
   });
 }
 

+ 4 - 1
packages/app/src/pages/matter/table/modal/Info.tsx

@@ -10,7 +10,7 @@ import {
 type Props = {id: string};
 
 const Info: FC<Props> = function ({id}) {
-  const {control, watch} = useFormContextState();
+  const {control, watch, setValue} = useFormContextState();
   const [{data: materialOptions, isFetching}, onMaterialSearch] =
     useDictionaryWidthCode('物料字典', {
       findValue: state => state.code,
@@ -22,6 +22,9 @@ const Info: FC<Props> = function ({id}) {
   const {data: storageOtions, isFetching: isStorageFetching} =
     useStorageOptions(false, state => state.storageLocationCode, {
       id: warehouseId,
+      clear() {
+        setValue('storageLocationCode', '');
+      },
     });
 
   return (

+ 4 - 5
packages/app/src/pages/semi-draw/table/put-out-modal/hooks.ts

@@ -57,12 +57,11 @@ export function useFormState({
   onClose: () => void;
   onFetch: () => void;
 }) {
-  const {control, handleSubmit, reset, clearErrors, watch} = useForm<FormState>(
-    {
+  const {control, handleSubmit, reset, clearErrors, watch, setValue} =
+    useForm<FormState>({
       resolver: yupResolver(validate),
       defaultValues: {warehouse: '', outNum: 0, location: ''},
-    },
-  );
+    });
 
   useEffect(
     function () {
@@ -108,6 +107,6 @@ export function useFormState({
 
   return [
     {control, isLoading},
-    {onSubmit, watch},
+    {onSubmit, watch, setValue},
   ] as const;
 }

+ 5 - 1
packages/app/src/pages/semi-draw/table/put-out-modal/index.tsx

@@ -11,7 +11,8 @@ type Props = {
 };
 
 const PutOutModal: FC<Props> = function (props) {
-  const [{control, isLoading}, {onSubmit, watch}] = useFormState(props);
+  const [{control, isLoading}, {onSubmit, watch, setValue}] =
+    useFormState(props);
   const {data: warehouse, isFetching: isWarehoseFetching} =
     useDictionaryOptions('仓库');
   const warehouseOptions = useMemo(
@@ -26,6 +27,9 @@ const PutOutModal: FC<Props> = function (props) {
     state => state.storageLocationCode,
     {
       id: warehouseId,
+      clear() {
+        setValue('location', '');
+      },
     },
   );
 

+ 4 - 5
packages/app/src/pages/semi-report/table/put-in-modal/hooks.ts

@@ -48,12 +48,11 @@ export function useFormState({
   onClose: () => void;
   onFetch: () => void;
 }) {
-  const {control, handleSubmit, reset, clearErrors, watch} = useForm<FormState>(
-    {
+  const {control, handleSubmit, reset, clearErrors, watch, setValue} =
+    useForm<FormState>({
       resolver: yupResolver(validate),
       defaultValues: {warehouse: '', location: ''},
-    },
-  );
+    });
 
   useEffect(
     function () {
@@ -100,6 +99,6 @@ export function useFormState({
 
   return [
     {control, isLoading},
-    {onSubmit, watch},
+    {onSubmit, watch, setValue},
   ] as const;
 }

+ 5 - 1
packages/app/src/pages/semi-report/table/put-in-modal/index.tsx

@@ -11,7 +11,8 @@ type Props = {
 };
 
 const PutInModal: FC<Props> = function (props) {
-  const [{control, isLoading}, {onSubmit, watch}] = useFormState(props);
+  const [{control, isLoading}, {onSubmit, watch, setValue}] =
+    useFormState(props);
   const {data: warehouse, isFetching: isWarehouseFetching} =
     useDictionaryOptions('仓库');
   const warehouseOptions = useMemo(
@@ -26,6 +27,9 @@ const PutInModal: FC<Props> = function (props) {
     state => state.storageLocationCode,
     {
       id: warehouseId,
+      clear() {
+        setValue('location', '');
+      },
     },
   );