Filter.tsx
1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import React, { useState, useEffect } from "react";
import { Row, Select } from "antd";
import { LabeledValue } from "antd/lib/select";
const Option = Select.Option;
const userData = [
{ value: 7, label: "工作车辆" },
{ value: 8, label: "员工车辆" },
{ value: 9, label: "大客户" },
];
export interface FilterPara {
discountType?: number;
discountTypeName?: string;
[key: string]: any;
}
interface Props {
onChange: Function;
filterParam: FilterPara;
}
export default function Filter({ onChange, filterParam}: Props) {
const [type, setType] = useState<LabeledValue>();
useEffect(() => {
if (filterParam) {
filterParam.discountType && filterParam.discountTypeName
? setType({
key: `${filterParam.discountType}`,
value: filterParam.discountType,
label: filterParam.discountTypeName,
})
: null;
}
}, [filterParam]);
function onTypeChange(value: LabeledValue) {
const _value = value || ({} as LabeledValue);
const { key, label } = _value;
onChange &&
onChange(
{ discountType: key || undefined, current: 1, discountTypeName: label },
true
);
}
return (
<Row style={{ width: "100%", alignItems: "center" }}>
<span>客户类型:</span>
<Select
allowClear={false}
placeholder="请选择"
labelInValue
value={type}
onChange={onTypeChange}
style={{ width: 150, marginLeft: 10 }}
>
{userData.map((r) => (
<Option key={r.value} value={r.value}>
{r.label || ""}
</Option>
))}
</Select>
</Row>
);
}