Skip to content

Commit 00657b0

Browse files
committed
history search;add lodash
1 parent a525c2c commit 00657b0

File tree

5 files changed

+37
-15
lines changed

5 files changed

+37
-15
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"axios": "^0.19.0",
2828
"date-fns": "^2.23.0",
2929
"echarts": "^4.2.0-rc.2",
30+
"lodash": "^4.17.21",
3031
"mobx": "^5.15.0",
3132
"mobx-react": "^6.1.4",
3233
"quill": "^1.3.7",
@@ -43,6 +44,7 @@
4344
"@babel/preset-react": "^7.12.10",
4445
"@babel/preset-typescript": "^7.12.7",
4546
"@types/echarts": "^4.1.3",
47+
"@types/lodash": "^4.14.172",
4648
"@types/quill": "^2.0.1",
4749
"@types/react": "^17.0.17",
4850
"@types/react-dom": "^17.0.9",

src/pages/stocks/history.tsx

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { historyColumns } from './util'
55
import { stockHistoryPageList, StockQuery } from '../../services/stockHistory'
66
import { data2PageData, pageData2Params } from '../../utils/tools'
77
import { StockHistory } from '../../types/stockHistory'
8+
import { debounce } from 'lodash'
9+
import { stockPageList } from 'services/stock'
810

911
const 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,

src/services/stock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { pageData2Params } from '@utils/tools'
33
import { Stock } from 'types/stock'
44

55

6-
export type StockQuery = Omit<Stock & IPageParams, 'id' | 'amount'>
6+
export type StockQuery = Omit<Stock & IPageParams, 'id' | 'amount'> & { noPage: boolean }
77

88
export const stockPageList = (params: Partial<StockQuery> = pageData2Params()) => {
99
return $http.get<any, IPageData<Stock>>('/api/stocks', { params })

src/services/stockHistory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Stock } from 'types/stock'
44
import { StockHistory } from 'types/stockHistory'
55

66

7-
export type StockQuery = Omit<Stock & IPageParams, 'id' | 'amount'>
7+
export type StockQuery = Omit<Stock & IPageParams, 'amount'>
88

99
export const stockHistoryPageList = (params: Partial<StockQuery> = pageData2Params()) => {
1010
return $http.get<any, IPageData<StockHistory>>('/api/stockhistory', { params })

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,11 @@
11661166
resolved "https://registry.npm.taobao.org/@types/json-schema/download/@types/json-schema-7.0.6.tgz?cache=0&sync_timestamp=1605053861867&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40types%2Fjson-schema%2Fdownload%2F%40types%2Fjson-schema-7.0.6.tgz#f4c7ec43e81b319a9815115031709f26987891f0"
11671167
integrity sha1-9MfsQ+gbMZqYFRFQMXCfJph4kfA=
11681168

1169+
"@types/lodash@^4.14.172":
1170+
version "4.14.172"
1171+
resolved "https://registry.nlark.com/@types/lodash/download/@types/lodash-4.14.172.tgz?cache=0&sync_timestamp=1629708300068&other_urls=https%3A%2F%2Fregistry.nlark.com%2F%40types%2Flodash%2Fdownload%2F%40types%2Flodash-4.14.172.tgz#aad774c28e7bfd7a67de25408e03ee5a8c3d028a"
1172+
integrity sha1-qtd0wo57/Xpn3iVAjgPuWow9Aoo=
1173+
11691174
"@types/mdast@^3.0.0":
11701175
version "3.0.3"
11711176
resolved "https://registry.npm.taobao.org/@types/mdast/download/@types/mdast-3.0.3.tgz?cache=0&sync_timestamp=1605055087131&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2F%40types%2Fmdast%2Fdownload%2F%40types%2Fmdast-3.0.3.tgz#2d7d671b1cd1ea3deb306ea75036c2a0407d2deb"

0 commit comments

Comments
 (0)