@@ -5,6 +5,8 @@ import { historyColumns } from './util'
5
5
import { stockHistoryPageList , StockQuery } from '../../services/stockHistory'
6
6
import { data2PageData , pageData2Params } from '../../utils/tools'
7
7
import { StockHistory } from '../../types/stockHistory'
8
+ import { debounce } from 'lodash'
9
+ import { stockPageList } from 'services/stock'
8
10
9
11
const StockHistoryList : React . FC = ( ) => {
10
12
@@ -13,37 +15,50 @@ const StockHistoryList: React.FC = () => {
13
15
const [ loading , setLoading ] = useState ( false )
14
16
const [ pageData , setPageData ] = useState ( data2PageData < StockHistory > ( {
15
17
data : [ ] ,
16
- meta : { page : 1 , pageSize : 20 , total : 0 }
18
+ meta : { page : 1 , pageSize : 10 , total : 0 }
17
19
} ) )
20
+ const [ stockOpts , setStockOpts ] = useState < IOption < number > [ ] > ( [ ] )
18
21
19
22
const onQuery = ( params = pageData2Params ( pageData . meta ) ) => {
20
23
const vals = form . getFieldsValue ( )
21
- // if(!vals.code ) {
22
- // return;
23
- // }
24
+ if ( ! vals . id ) {
25
+ return ;
26
+ }
24
27
setLoading ( true )
25
28
stockHistoryPageList ( { ...params , ...vals , } ) . then ( res => {
26
29
const data = data2PageData ( res )
27
30
setPageData ( data )
28
31
} ) . finally ( ( ) => setLoading ( false ) )
29
32
}
30
33
34
+ const onSelectSearch = debounce ( ( v : string ) => {
35
+ if ( ! v . trim ( ) ) {
36
+ return ;
37
+ }
38
+ stockPageList ( {
39
+ code : v ,
40
+ name : v ,
41
+ page : 1 ,
42
+ pageSize : 100 ,
43
+ noPage : true
44
+ } ) . then ( res => {
45
+ const list = res . data . map < IOption < number > > ( item => ( { value : item . id , label : item . name } ) )
46
+ console . log ( res , 'res===' , list )
47
+ setStockOpts ( list )
48
+ } )
49
+ } , 500 )
50
+
31
51
useEffect ( ( ) => {
32
52
onQuery ( )
33
53
} , [ ] )
34
54
35
55
36
56
return < Spin spinning = { loading } >
37
- < Form form = { form } >
57
+ < Form className = "mgb16" form = { form } >
38
58
< Row gutter = { 16 } >
39
59
< Col span = { 6 } >
40
- < Form . Item name = "code" >
41
- < Input allowClear placeholder = "Stock Code" />
42
- </ Form . Item >
43
- </ Col >
44
- < Col span = { 6 } >
45
- < Form . Item name = "name" >
46
- < Input allowClear placeholder = "Stock Name" />
60
+ < Form . Item name = "id" >
61
+ < Select allowClear showSearch filterOption = { false } placeholder = "Name/Code" options = { stockOpts } onSearch = { onSelectSearch } />
47
62
</ Form . Item >
48
63
</ Col >
49
64
</ Row >
@@ -55,7 +70,7 @@ const StockHistoryList: React.FC = () => {
55
70
size = "small"
56
71
columns = { historyColumns ( ) }
57
72
dataSource = { pageData . data }
58
- key = "code "
73
+ rowKey = "id "
59
74
scroll = { { x : 2400 } }
60
75
pagination = { {
61
76
...pageData . meta ,
0 commit comments