Commit 8556dfeb8ca9ea763771150c9e51d35be2eeb793

Authored by 徐欣
1 parent 1857800c

feat(carinsur): 新增贷款期客户保险配置功能

src/pages/carinsur/LoanClientRequires/api.ts
... ... @@ -4,7 +4,7 @@ import type { IdNameOption, ShopOption } from '../entity';
4 4 import { ANGEL_Host } from '@/utils/host';
5 5 import type { Pagination } from '@/typing/common';
6 6  
7   -export interface InsuranceItem {
  7 +export interface LoanType {
8 8 type: number;
9 9 amount: number;
10 10 }
... ... @@ -18,12 +18,12 @@ export interface Item {
18 18 allBrandSeries: boolean;
19 19 brandSeries: brandSeriesItem[];
20 20 useShopIds: ShopOption[];
21   - newTci: InsuranceItem;
22   - newVci: InsuranceItem;
23   - newTai: InsuranceItem;
24   - reNewTci: InsuranceItem;
25   - reNewVci: InsuranceItem;
26   - reNewTai: InsuranceItem;
  21 + newTci: LoanType;
  22 + newVci: LoanType;
  23 + newTai: LoanType;
  24 + reNewTci: LoanType;
  25 + reNewVci: LoanType;
  26 + reNewTai: LoanType;
27 27 }
28 28  
29 29 export interface PageParams extends Pagination {
... ...
src/pages/carinsur/LoanClientRequires/components/AddModal/index.tsx
... ... @@ -5,7 +5,7 @@ import { useRequest } from 'umi';
5 5 import BrandSeriesFormItem from '../BrandSeriesFormItem';
6 6 import ShopSelectorByAll from '../ShopSelectorByAll';
7 7 import LoanTypeFormItem from '../LoanTypeFormItem';
8   -import { LabeledValue } from 'antd/lib/select';
  8 +import type { LabeledValue } from 'antd/lib/select';
9 9  
10 10 interface Props {
11 11 visible: boolean;
... ... @@ -83,12 +83,12 @@ function AddModal({ visible, row, onCancel, onRefresh }: Props) {
83 83 <Form.Item label="适用门店" name="useShopIds" rules={[{ required: true, message: '请选择' }]}>
84 84 <ShopSelectorByAll />
85 85 </Form.Item>
86   - <LoanTypeFormItem form={form} name="newTci" label="新保交强险" />
87   - <LoanTypeFormItem form={form} name="newVci" label="新保商业险" />
88   - <LoanTypeFormItem form={form} name="newTai" label="新保驾意险" />
89   - <LoanTypeFormItem form={form} name="reNewTci" label="续保交强险" />
90   - <LoanTypeFormItem form={form} name="reNewVci" label="续保商业险" />
91   - <LoanTypeFormItem form={form} name="reNewTai" label="续保驾意险" />
  86 + <LoanTypeFormItem form={form} key="newTci" name="newTci" label="新保交强险" />
  87 + <LoanTypeFormItem form={form} key="newVci" name="newVci" label="新保商业险" />
  88 + <LoanTypeFormItem form={form} key="newTai" name="newTai" label="新保驾意险" />
  89 + <LoanTypeFormItem form={form} key="reNewTci" name="reNewTci" label="续保交强险" />
  90 + <LoanTypeFormItem form={form} key="reNewVci" name="reNewVci" label="续保商业险" />
  91 + <LoanTypeFormItem form={form} key="reNewTai" name="reNewTai" label="续保驾意险" />
92 92 </Form>
93 93 </Modal>
94 94 );
... ...
src/pages/carinsur/LoanClientRequires/components/BrandSeriesAddModal.tsx
... ... @@ -3,6 +3,7 @@ import { Modal, Form, Select } from &#39;antd&#39;;
3 3 import type { brandSeriesItem } from '../api';
4 4 import type { LabeledValue } from 'antd/lib/select';
5 5 import SeriesSelectorByAll from './SeriesSelectorByAll';
  6 +import _ from 'lodash';
6 7  
7 8 interface Props {
8 9 brands?: CommonApi.OptionVO[];
... ... @@ -49,6 +50,7 @@ export default function Index({ brands, visible, value, onCancel, onChange }: Pr
49 50 <Form form={form} labelCol={{ span: '6' }} onFinish={handleSave}>
50 51 <FormItem label="品牌" name="brand" rules={[{ required: true, message: '请选择品牌' }]}>
51 52 <Select
  53 + disabled={!!value} // 编辑时不可编辑品牌
52 54 placeholder="请选择"
53 55 options={brands}
54 56 fieldNames={{ label: 'name', value: 'id' }}
... ... @@ -60,17 +62,21 @@ export default function Index({ brands, visible, value, onCancel, onChange }: Pr
60 62 <Form.Item
61 63 noStyle
62 64 shouldUpdate={(prev, curr) => {
63   - if (prev.brand !== curr.brand) {
64   - form.setFieldValue('series', []);
  65 + if (!_.isEqual(prev.brand, curr.brand)) {
  66 + if (value) {
  67 + form.setFieldValue('series', value.id === curr.brand.value ? value.series.map((i) => ({ label: i.name, value: i.id })) : []);
  68 + } else {
  69 + form.setFieldValue('series', []);
  70 + }
65 71 }
66   - return prev.brand !== curr.brand;
  72 + return !_.isEqual(prev.brand, curr.brand);
67 73 }}
68 74 >
69 75 {({ getFieldValue }) => {
70 76 const brandId = (getFieldValue('brand') ?? {}).value;
71 77 return (
72 78 <FormItem label="车系" name="series" rules={[{ required: true, message: '请选择车系' }]}>
73   - <SeriesSelectorByAll brandId={brandId} />
  79 + <SeriesSelectorByAll brandId={brandId} disabled={!brandId} disabledTip="请先选择品牌" />
74 80 </FormItem>
75 81 );
76 82 }}
... ...
src/pages/carinsur/LoanClientRequires/components/BrandSeriesFormItem.tsx
... ... @@ -2,7 +2,6 @@ import React, { useEffect, useMemo, useState } from &#39;react&#39;;
2 2 import { Table, Divider, Popconfirm, Button, Row } from 'antd';
3 3 import { PlusOutlined } from '@ant-design/icons';
4 4 import BrandSeriesAddModal from './BrandSeriesAddModal';
5   -import { geneRandomNum } from '@/utils/tools';
6 5 import type { brandSeriesItem } from '../api';
7 6 import TextWithMore from '@/components/TextWithMore';
8 7 import useInitial from '@/hooks/useInitail';
... ... @@ -56,12 +55,11 @@ export default function Index({ readOnly = false, value = [], onChange }: Props)
56 55  
57 56 const handleUpdate = (res: brandSeriesItem) => {
58 57 const newVal = [...value];
59   - if (res.id) {
60   - const currIdx = newVal.findIndex((i) => i.id === res.id);
  58 + const currIdx = newVal.findIndex((i) => i.id === res.id); // 品牌 id
  59 + if (currIdx > -1) {
61 60 newVal[currIdx] = res;
62 61 } else {
63   - const randomId = geneRandomNum(50000, 10000000, 1);
64   - newVal.push({ ...res, id: randomId });
  62 + newVal.push(res);
65 63 }
66 64 onChange && onChange(newVal);
67 65 };
... ...
src/pages/carinsur/LoanClientRequires/components/BrandSeriesModal.tsx 0 → 100644
  1 +import React from 'react';
  2 +import { Modal } from 'antd';
  3 +import BrandSeriesFormItem from './BrandSeriesFormItem';
  4 +import type { brandSeriesItem } from '../api';
  5 +
  6 +interface Props {
  7 + brandSeriesModal: { visible: boolean; brandSeries?: brandSeriesItem[] };
  8 + onCancel: () => void;
  9 +}
  10 +
  11 +export default function Index({ brandSeriesModal, onCancel }: Props) {
  12 + const { visible, brandSeries = [] } = brandSeriesModal;
  13 + return (
  14 + <Modal title="部分品牌部分车系" open={visible} onCancel={() => onCancel()} footer={null} width={600}>
  15 + <BrandSeriesFormItem value={brandSeries} readOnly />
  16 + </Modal>
  17 + );
  18 +}
... ...
src/pages/carinsur/LoanClientRequires/components/SeriesSelectorByAll.tsx
... ... @@ -28,6 +28,13 @@ export default function Index({
28 28 const { data: list, setParams, loading } = useInitial<CommonApi.OptionVO[], number>(getSeriesApi, [], brandId, delay);
29 29  
30 30 useEffect(() => {
  31 + if (brandId) {
  32 + setParams(brandId, true);
  33 + setDelay(false);
  34 + }
  35 + }, [brandId]);
  36 +
  37 + useEffect(() => {
31 38 if (list && list.length > 0) {
32 39 // @ts-ignore
33 40 const newPostList = [{ id: -1, name: '全部车系' }].concat(list); // 前端手动在列表头部增加一个 {id: -1, name: '全部车系'} 的选项
... ... @@ -37,11 +44,6 @@ export default function Index({
37 44 }
38 45 }, [list]);
39 46  
40   - useEffect(() => {
41   - setParams(brandId, true);
42   - setDelay(false);
43   - }, []);
44   -
45 47 return (
46 48 <Spin spinning={loading && !disabled}>
47 49 <Select
... ...
src/pages/carinsur/LoanClientRequires/index.tsx
... ... @@ -10,6 +10,7 @@ import * as API from &#39;./api&#39;;
10 10 import _ from 'lodash';
11 11 import TextWithMore from '@/components/TextWithMore';
12 12 import { LoanTypeEnum } from '../entity';
  13 +import BrandSeriesModal from './components/BrandSeriesModal';
13 14  
14 15 const { Column } = Table;
15 16  
... ... @@ -21,6 +22,14 @@ export default function Index() {
21 22 }>({
22 23 visible: false,
23 24 });
  25 + // 查看部分品牌车系
  26 + const [brandSeriesModal, setBrandSeriesModal] = useState<{
  27 + visible: boolean;
  28 + brandSeries?: API.brandSeriesItem[];
  29 + }>({
  30 + visible: false,
  31 + brandSeries: [],
  32 + });
24 33  
25 34 const { list, paginationConfig, loading, innerParams, setParams } = usePagination<API.Item>(API.getLCRPage);
26 35  
... ... @@ -43,7 +52,7 @@ export default function Index() {
43 52 });
44 53 };
45 54  
46   - const renderLoanTypeEle = (value: API.InsuranceItem) => {
  55 + const renderLoanTypeEle = (value: API.LoanType) => {
47 56 return value ? (value.type !== LoanTypeEnum.购保要求金额 ? LoanTypeEnum[value.type] : `保费 ≥ ${value.amount}元`) : '--';
48 57 };
49 58  
... ... @@ -73,7 +82,24 @@ export default function Index() {
73 82 rowKey="id"
74 83 onChange={(_pagination) => setParams({ ..._pagination }, true)}
75 84 >
76   - <Column title="适用品牌车系" dataIndex="allBrandSeries" render={(value) => (value ? '全部品牌全部车系' : '查看 todo')} />
  85 + <Column
  86 + title="适用品牌车系"
  87 + dataIndex="allBrandSeries"
  88 + render={(value, row: API.Item) =>
  89 + value ? (
  90 + '全部品牌全部车系'
  91 + ) : (
  92 + <a
  93 + onClick={(e) => {
  94 + e.preventDefault();
  95 + setBrandSeriesModal({ visible: true, brandSeries: row.brandSeries });
  96 + }}
  97 + >
  98 + 查看
  99 + </a>
  100 + )
  101 + }
  102 + />
77 103 <Column title="适用门店" dataIndex="useShopIds" render={(value) => <TextWithMore title="适用门店" dataIndex="shopName" list={value} />} />
78 104 <Column title="新保交强险" dataIndex="newTci" render={renderLoanTypeEle} />
79 105 <Column title="新保商业险" dataIndex="newVci" render={renderLoanTypeEle} />
... ... @@ -118,6 +144,12 @@ export default function Index() {
118 144 }}
119 145 onRefresh={() => setParams({ ...innerParams }, true)}
120 146 />
  147 + <BrandSeriesModal
  148 + brandSeriesModal={brandSeriesModal}
  149 + onCancel={() => {
  150 + setBrandSeriesModal({ visible: false });
  151 + }}
  152 + />
121 153 </ConfigProvider>
122 154 </PageHeaderWrapper>
123 155 );
... ...