lanjianrong 3 gadi atpakaļ
vecāks
revīzija
466bdff71a

+ 9 - 4
src/pages/Institutions/Staff/components/DebounceSelect.tsx

@@ -1,6 +1,6 @@
 import { Select, Spin } from 'antd'
 import type { SelectProps } from 'antd'
-import { useRef, useState, useMemo } from 'react'
+import { useRef, useState, useMemo, useEffect } from 'react'
 import debounce from 'lodash/debounce'
 
 export interface DebounceSelectProps<ValueType = any>
@@ -30,12 +30,12 @@ function DebounceSelect<
   const fetchRef = useRef(0)
 
   const debounceFetcher = useMemo(() => {
-    const loadOptions = (value: string) => {
+    const loadOptions = params => {
       fetchRef.current += 1
       const fetchId = fetchRef.current
       setState({ ...state, options: [], fetching: true })
 
-      fetchOptions(value).then(newOptions => {
+      fetchOptions(params).then(newOptions => {
         if (fetchId !== fetchRef.current) {
           // for fetch callback order
           return
@@ -47,6 +47,11 @@ function DebounceSelect<
 
     return debounce(loadOptions, debounceTimeout)
   }, [fetchOptions, debounceTimeout])
+  useEffect(() => {
+    if (!state.options?.length && state.val) {
+      debounceFetcher({ ID: state.val })
+    }
+  }, [state.val])
 
   const triggerChange = v => {
     setState({ ...state, val: v })
@@ -64,7 +69,7 @@ function DebounceSelect<
       value={state.val}
       onChange={triggerChange}
       filterOption={false}
-      onSearch={debounceFetcher}
+      onSearch={v => debounceFetcher({ search: v })}
       notFoundContent={state.fetching ? <Spin size="small" /> : null}
       {...props}
       options={state.options}

+ 2 - 2
src/pages/Institutions/Staff/components/StaffDrawer.tsx

@@ -99,9 +99,9 @@ const StaffDrawer: React.FC<StaffModalProps> = ({
     }
   })
 
-  const queryInstitutionOptions = async search => {
+  const queryInstitutionOptions = async params => {
     const { code = -1, data = {} } = await queryInstitutionList({
-      search,
+      ...params,
       current: 1,
       pageSize: 100
     })