Commit 8fe064735bc930a26d5534954e41bea0d38c399f

Authored by 徐欣
1 parent 5eead9b7

feat(carinsur): 贷款期客户保险优化筛选

src/components/Condition/BrandToSeries/index.tsx
... ... @@ -5,47 +5,50 @@ import * as API from './api';
5 5  
6 6 interface BrandToSeriesProps extends CascaderProps {
7 7 /** 第一层 品牌列表 */
8   - brandList?: API.Brand[] | API.optionItem[],
9   - labelInValue?: boolean,
10   - value?: any[],
11   - onChange?: (value: any, ...other: any) => any,
  8 + brandList?: API.Brand[] | API.optionItem[];
  9 + labelInValue?: boolean;
  10 + value?: any[];
  11 + onChange?: (value: any, ...other: any) => any;
12 12 /** 是否授权品牌(授权品牌接口是admin,非授权品牌接口是oop) */
13   - authBrand?: boolean
  13 + authBrand?: boolean;
  14 + placeholder?: string;
14 15 }
15 16  
16 17 /**
17 18 * 基于Cascader封装的品牌车系级联选择框
18 19 */
19 20 export default function BrandToSeries(props: BrandToSeriesProps) {
20   - const { value = [], onChange, labelInValue, brandList, placeholder = "请选择品牌/车系", authBrand, ...other } = props;
  21 + const { value = [], onChange, labelInValue, brandList, placeholder = '请选择品牌/车系', authBrand, ...other } = props;
21 22 const [options, setOptions] = useState<any[]>([]);
22 23 const [selected, setSelected] = useState<any[]>([]);
23 24  
24 25 useEffect(() => {
25 26 if (!brandList) {
26 27 const brandApi: any = authBrand ? API.authBrandsApi : API.brandByOopApi;
27   - brandApi().then(res => {
28   - const { data = [] } = res;
29   - const _data = data.map(brand => ({ id: brand.brandId || brand.id, name: brand.brandName || brand.name, isLeaf: false }));
30   - setOptions([..._data]);
31   - }).catch(e => {
32   - message.error(e.message);
33   - });
  28 + brandApi()
  29 + .then((res) => {
  30 + const { data = [] } = res;
  31 + const _data = data.map((brand) => ({ id: brand.brandId || brand.id, name: brand.brandName || brand.name, isLeaf: false }));
  32 + setOptions([..._data]);
  33 + })
  34 + .catch((e) => {
  35 + message.error(e.message);
  36 + });
34 37 } else {
35   - setOptions(brandList.map(brand => ({ id: brand.brandId || brand.id, name: brand.brandName || brand.name, isLeaf: false })))
  38 + setOptions(brandList.map((brand) => ({ id: brand.brandId || brand.id, name: brand.brandName || brand.name, isLeaf: false })));
36 39 }
37   - }, [])
  40 + }, []);
38 41  
39 42 useEffect(() => {
40 43 if (selected.length === 0 && value.length > 0) {
41 44 const valueBrandId = labelInValue ? value[0].id : value[0];
42   - loadData(options.filter(item => item.id === valueBrandId));
  45 + loadData(options.filter((item) => item.id === valueBrandId));
43 46 }
44 47 if (value[1] !== selected[1]) {
45   - const _value = labelInValue ? value.map(item => item.id) : value;
  48 + const _value = labelInValue ? value.map((item) => item.id) : value;
46 49 setSelected(_value);
47 50 }
48   - }, [value[1]])
  51 + }, [value[1]]);
49 52  
50 53 function loadData(selectedOptions?: CascaderOptionType[]) {
51 54 if (selectedOptions && selectedOptions.length > 0) {
... ... @@ -53,23 +56,25 @@ export default function BrandToSeries(props: BrandToSeriesProps) {
53 56 const targetOption = selectedOptions[length - 1];
54 57 targetOption.loading = true;
55 58 if (length === 1) {
56   - API.getSeriesApi(targetOption.id).then(res => {
57   - const { data = [] } = res;
58   - targetOption.loading = false;
59   - targetOption.children = data.map((list, index) => ({
60   - id: list.id,
61   - name: list.name,
62   - }));
63   - setOptions([...options])
64   - }).catch(e => {
65   - message.error(e.message);
66   - });
  59 + API.getSeriesApi(targetOption.id)
  60 + .then((res) => {
  61 + const { data = [] } = res;
  62 + targetOption.loading = false;
  63 + targetOption.children = data.map((list, index) => ({
  64 + id: list.id,
  65 + name: list.name,
  66 + }));
  67 + setOptions([...options]);
  68 + })
  69 + .catch((e) => {
  70 + message.error(e.message);
  71 + });
67 72 }
68 73 }
69 74 }
70 75  
71 76 function _onChange(value: string[], selectedOptions: any[] = []) {
72   - const _value = labelInValue ? selectedOptions.map(item => ({ id: item.id, name: item.name })) : value;
  77 + const _value = labelInValue ? selectedOptions.map((item) => ({ id: item.id, name: item.name })) : value;
73 78 setSelected(value || []);
74 79 onChange && onChange(_value || [], selectedOptions);
75 80 }
... ... @@ -82,9 +87,8 @@ export default function BrandToSeries(props: BrandToSeriesProps) {
82 87 loadData={loadData}
83 88 value={selected.length <= 0 ? undefined : selected}
84 89 onChange={_onChange}
85   - fieldNames={{ value: 'id', label: 'name', }}
  90 + fieldNames={{ value: 'id', label: 'name' }}
86 91 notFoundContent="暂无数据"
87 92 />
88   -
89 93 );
90 94 }
... ...
src/pages/carinsur/LoanClientRequires/components/Filter/index.tsx
1   -import React from 'react';
  1 +import React, { memo } from 'react';
2 2 import { Row, Select } from 'antd';
3 3 import _ from 'lodash';
4 4 import type { PageParams } from '../../api';
5   -import { getBrandFilterApi, getSaleSeries, getShopApi } from '@/common/api';
  5 +import { getShopApi } from '@/common/api';
6 6 import useInitial from '@/hooks/useInitail';
  7 +import BrandToSeries from '@/components/Condition/BrandToSeries';
7 8  
8 9 interface Props {
9 10 innerParams?: any;
... ... @@ -11,8 +12,6 @@ interface Props {
11 12 }
12 13  
13 14 function Filter({ innerParams, setParams }: Props) {
14   - const { data: brands } = useInitial(getBrandFilterApi, [], {});
15   - const { data: series } = useInitial(getSaleSeries, [], {});
16 15 const { data: shops } = useInitial<CommonApi.OptionVO[], undefined>(getShopApi, [], undefined);
17 16  
18 17 const onChange = _.debounce((newParams) => {
... ... @@ -21,35 +20,16 @@ function Filter({ innerParams, setParams }: Props) {
21 20  
22 21 return (
23 22 <Row style={{ display: 'flex', flex: 1 }}>
24   - <Select
25   - style={{ width: 200 }}
26   - showSearch
27   - allowClear
28   - // optionFilterProp="children"
29   - placeholder="筛选品牌"
30   - options={brands}
31   - fieldNames={{ label: 'name', value: 'id' }}
32   - onChange={(value) => {
33   - onChange({ brandId: value });
34   - }}
35   - />
36   - <Select
37   - style={{ width: 200, marginLeft: 20 }}
38   - showSearch
39   - allowClear
40   - // optionFilterProp="children"
41   - placeholder="筛选车系"
42   - options={series}
43   - fieldNames={{ label: 'name', value: 'id' }}
44   - onChange={(value) => {
45   - onChange({ seriesId: value });
46   - }}
  23 + <BrandToSeries
  24 + //@ts-ignore
  25 + style={{ width: 260 }}
  26 + placeholder="筛选品牌车系"
  27 + onChange={(v) => onChange({ brandId: v[0], seriesId: v && v.length === 2 ? v[1] : undefined })}
47 28 />
48 29 <Select
49   - style={{ width: 200, marginLeft: 20 }}
  30 + style={{ width: 260, marginLeft: 20 }}
50 31 showSearch
51 32 allowClear
52   - // optionFilterProp="children"
53 33 placeholder="筛选门店"
54 34 options={shops}
55 35 fieldNames={{ label: 'name', value: 'id' }}
... ...