曾国涛
authored
|
1
|
import { postServiceConstListInvoiceDetailNames } from '@/services';
|
曾国涛
authored
|
2
3
|
import { Select, Tooltip } from 'antd';
import { useState } from 'react';
|
曾国涛
authored
|
4
|
|
曾国涛
authored
|
5
|
export const InvoiceProjectSelect = ({ readOnly, value, onChange }) => {
|
曾国涛
authored
|
6
7
8
|
const [options, setOptions] = useState<any[]>([]);
// 定义防抖函数
let timeoutId = null;
|
曾国涛
authored
|
9
|
const fetchOptions = async (keywords) => {
|
曾国涛
authored
|
10
11
12
13
14
15
16
17
|
clearTimeout(timeoutId);
timeoutId = setTimeout(async () => {
const res = await postServiceConstListInvoiceDetailNames({
data: {
nameLike: keywords,
},
});
const data = res.data;
|
曾国涛
authored
|
18
|
|
曾国涛
authored
|
19
20
|
setOptions(
data.map((item) => {
|
曾国涛
authored
|
21
|
console.log(item);
|
曾国涛
authored
|
22
|
return {
|
曾国涛
authored
|
23
|
key: item.id,
|
曾国涛
authored
|
24
25
26
27
28
|
label:
'*' +
item.productAndServiceCatagoryAbbreviation +
'*' +
item?.name,
|
曾国涛
authored
|
29
30
31
32
33
|
value:
'*' +
item.productAndServiceCatagoryAbbreviation +
'*' +
item?.name,
|
曾国涛
authored
|
34
35
36
37
38
39
|
...item,
};
}),
);
// 这里可以放置实际的搜索逻辑,比如发起网络请求等
}, 500); // 设置延迟时间,单位毫秒
|
曾国涛
authored
|
40
41
|
};
|
曾国涛
authored
|
42
43
44
45
|
return readOnly ? (
<Tooltip title={value}>{value}</Tooltip>
) : (
<Select
|
曾国涛
authored
|
46
|
key="project"
|
曾国涛
authored
|
47
|
/*readonly={readonly}*/
|
曾国涛
authored
|
48
49
|
showSearch
placeholder="请选择开票项目"
|
曾国涛
authored
|
50
|
filterOption={(input, option) => (option?.label ?? '').includes(input)}
|
曾国涛
authored
|
51
52
|
onChange={(e) => {
onChange(e);
|
曾国涛
authored
|
53
|
}}
|
曾国涛
authored
|
54
55
56
57
|
defaultValue={value}
options={options}
onSearch={(e) => {
fetchOptions(e);
|
曾国涛
authored
|
58
59
60
61
|
}}
/>
);
};
|