@@ -5,6 +5,8 @@ import { historyColumns } from './util'
55import { stockHistoryPageList , StockQuery } from '../../services/stockHistory'
66import { data2PageData , pageData2Params } from '../../utils/tools'
77import { StockHistory } from '../../types/stockHistory'
8+ import { debounce } from 'lodash'
9+ import { stockPageList } from 'services/stock'
810
911const StockHistoryList : React . FC = ( ) => {
1012
@@ -13,37 +15,50 @@ const StockHistoryList: React.FC = () => {
1315 const [ loading , setLoading ] = useState ( false )
1416 const [ pageData , setPageData ] = useState ( data2PageData < StockHistory > ( {
1517 data : [ ] ,
16- meta : { page : 1 , pageSize : 20 , total : 0 }
18+ meta : { page : 1 , pageSize : 10 , total : 0 }
1719 } ) )
20+ const [ stockOpts , setStockOpts ] = useState < IOption < number > [ ] > ( [ ] )
1821
1922 const onQuery = ( params = pageData2Params ( pageData . meta ) ) => {
2023 const vals = form . getFieldsValue ( )
21- // if(!vals.code ) {
22- // return;
23- // }
24+ if ( ! vals . id ) {
25+ return ;
26+ }
2427 setLoading ( true )
2528 stockHistoryPageList ( { ...params , ...vals , } ) . then ( res => {
2629 const data = data2PageData ( res )
2730 setPageData ( data )
2831 } ) . finally ( ( ) => setLoading ( false ) )
2932 }
3033
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+
3151 useEffect ( ( ) => {
3252 onQuery ( )
3353 } , [ ] )
3454
3555
3656 return < Spin spinning = { loading } >
37- < Form form = { form } >
57+ < Form className = "mgb16" form = { form } >
3858 < Row gutter = { 16 } >
3959 < 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 } />
4762 </ Form . Item >
4863 </ Col >
4964 </ Row >
@@ -55,7 +70,7 @@ const StockHistoryList: React.FC = () => {
5570 size = "small"
5671 columns = { historyColumns ( ) }
5772 dataSource = { pageData . data }
58- key = "code "
73+ rowKey = "id "
5974 scroll = { { x : 2400 } }
6075 pagination = { {
6176 ...pageData . meta ,
0 commit comments