Commit dc1a8a1bc120b654b413ec7cf540e2000a61897e

Authored by 王强
1 parent 7c7c540f

优化 门店选择组件,可传入默认查询参数;

src/components/ShopSelectNew/api.ts
1 1 /*
2 2 * @Date: 2021-07-08 16:53:36
3 3 * @LastEditors: wangqiang@feewee.cn
4   - * @LastEditTime: 2022-05-25 11:32:53
  4 + * @LastEditTime: 2022-10-08 16:17:27
5 5 */
6 6 import { http } from "@/typing/http";
7 7 import request from "@/utils/request";
8 8 import { OOP_HOST } from "@/utils/host";
9 9 import { LabelValueType } from "rc-tree-select/lib/interface";
10 10  
11   -export interface QueryParams {
12   - type: 1 | 2; // 1 集团维度 2 自定义门店维度
13   - shops?: string; // 门店集合 ,分割
14   - keywords?: string; // 门店关键字搜索
  11 +export interface ShopSelectNewOptions {
15 12 bizTypes?: string; // 业态类型集合 ,分割
16 13 brands?: string; // 品牌id集合 ,分割
17 14 regions?: string; // 区域编码集合 ,分割
18 15 dealers?: string; // 商家id集合 ,分割
19 16 }
20 17  
  18 +export interface QueryParams extends ShopSelectNewOptions {
  19 + type: 1 | 2; // 1 集团维度 2 自定义门店维度
  20 + shops?: string; // 门店集合 ,分割
  21 + keywords?: string; // 门店关键字搜索
  22 +}
  23 +
21 24 export interface ShopItem {
22 25 shopId?: number; //门店id
23 26 shopFullName?: string; //门店全称
... ...
src/components/ShopSelectNew/components/ShopModal.tsx
... ... @@ -2,7 +2,7 @@
2 2 * @Author: wangqiang@feewee.cn
3 3 * @Date: 2022-05-25 10:03:00
4 4 * @LastEditors: wangqiang@feewee.cn
5   - * @LastEditTime: 2022-06-10 15:57:29
  5 + * @LastEditTime: 2022-10-08 16:33:31
6 6 */
7 7 import { InitialReturn } from "@/hooks/useInitail";
8 8 import {
... ... @@ -29,6 +29,7 @@ import {
29 29 Value,
30 30 Option,
31 31 QueryParams,
  32 + ShopSelectNewOptions,
32 33 } from "../api";
33 34  
34 35 interface Props {
... ... @@ -47,6 +48,7 @@ interface Props {
47 48 multiple?: boolean;
48 49 optionInitial: InitialReturn<Option, QueryParams>;
49 50 listInitial: InitialReturn<ShopItem[], QueryParams>;
  51 + defaultOptions?: ShopSelectNewOptions;
50 52 }
51 53  
52 54 export default function ShopModal({
... ... @@ -62,6 +64,7 @@ export default function ShopModal({
62 64 multiple,
63 65 optionInitial,
64 66 listInitial,
  67 + defaultOptions = {},
65 68 }: Props) {
66 69 const fetchListByName = debounce(
67 70 (keywords) => listInitial.setParams({ type, keywords }, true),
... ... @@ -245,14 +248,26 @@ export default function ShopModal({
245 248 ? listInitial.params.bizTypes.split(",")
246 249 : undefined
247 250 }
248   - onChange={(bizs) => listInitial.setParams({ type, bizTypes: bizs?.join(",") }, true)}
  251 + onChange={(bizs) => listInitial.setParams(
  252 + {
  253 + type,
  254 + bizTypes: bizs.length
  255 + ? bizs?.join(",")
  256 + : defaultOptions.bizTypes,
  257 + },
  258 + true
  259 + )}
249 260 showSearch
250 261 optionFilterProp="children"
251 262 style={{ minWidth: 260, marginBottom: 10, marginRight: 10 }}
252 263 getPopupContainer={(triggerNode) => triggerNode.parentNode}
253 264 >
254 265 {optionInitial.data.bizList?.map((biz) => (
255   - <Select.Option key={biz.type} value={"" + biz.type!}>
  266 + <Select.Option
  267 + key={biz.type}
  268 + value={"" + biz.type!}
  269 + disabled={defaultOptions.bizTypes?.includes("" + biz.type)}
  270 + >
256 271 {biz.name}
257 272 </Select.Option>
258 273 ))}
... ... @@ -266,14 +281,26 @@ export default function ShopModal({
266 281 ? listInitial.params.regions.split(",")
267 282 : undefined
268 283 }
269   - onChange={(regions) => listInitial.setParams({ type, regions: regions?.join(",") }, true)}
  284 + onChange={(regions) => listInitial.setParams(
  285 + {
  286 + type,
  287 + regions: regions.length
  288 + ? regions?.join(",")
  289 + : defaultOptions.regions,
  290 + },
  291 + true
  292 + )}
270 293 showSearch
271 294 optionFilterProp="children"
272 295 style={{ minWidth: 260, marginBottom: 10, marginRight: 10 }}
273 296 getPopupContainer={(triggerNode) => triggerNode.parentNode}
274 297 >
275 298 {optionInitial.data.regionList?.map((region) => (
276   - <Select.Option key={region.bh} value={region.bh!}>
  299 + <Select.Option
  300 + key={region.bh}
  301 + value={region.bh!}
  302 + disabled={defaultOptions.regions?.includes("" + region.bh)}
  303 + >
277 304 {region.fullName}
278 305 </Select.Option>
279 306 ))}
... ... @@ -288,7 +315,12 @@ export default function ShopModal({
288 315 : undefined
289 316 }
290 317 onChange={(brandList) => listInitial.setParams(
291   - { type, brands: brandList?.join(",") },
  318 + {
  319 + type,
  320 + brands: brandList.length
  321 + ? brandList?.join(",")
  322 + : defaultOptions.brands,
  323 + },
292 324 true
293 325 )}
294 326 showSearch
... ... @@ -297,7 +329,11 @@ export default function ShopModal({
297 329 getPopupContainer={(triggerNode) => triggerNode.parentNode}
298 330 >
299 331 {optionInitial.data.brandList?.map((brand) => (
300   - <Select.Option key={brand.id} value={"" + brand.id!}>
  332 + <Select.Option
  333 + key={brand.id}
  334 + value={"" + brand.id!}
  335 + disabled={defaultOptions.brands?.includes("" + brand.id)}
  336 + >
301 337 {brand.name}
302 338 </Select.Option>
303 339 ))}
... ... @@ -312,7 +348,12 @@ export default function ShopModal({
312 348 : undefined
313 349 }
314 350 onChange={(dealerList) => listInitial.setParams(
315   - { type, dealers: dealerList?.join(",") },
  351 + {
  352 + type,
  353 + dealers: dealerList.length
  354 + ? dealerList?.join(",")
  355 + : defaultOptions.dealers,
  356 + },
316 357 true
317 358 )}
318 359 showSearch
... ... @@ -321,7 +362,11 @@ export default function ShopModal({
321 362 getPopupContainer={(triggerNode) => triggerNode.parentNode}
322 363 >
323 364 {optionInitial.data.dealerList?.map((dealer) => (
324   - <Select.Option key={dealer.id} value={"" + dealer.id!}>
  365 + <Select.Option
  366 + key={dealer.id}
  367 + value={"" + dealer.id!}
  368 + disabled={defaultOptions.dealers?.includes("" + dealer.id)}
  369 + >
325 370 {dealer.name}
326 371 </Select.Option>
327 372 ))}
... ...
src/components/ShopSelectNew/index.tsx
... ... @@ -2,7 +2,7 @@
2 2 * @Author: wangqiang@feewee.cn
3 3 * @Date: 2022-05-25 09:14:31
4 4 * @LastEditors: wangqiang@feewee.cn
5   - * @LastEditTime: 2022-07-12 09:41:43
  5 + * @LastEditTime: 2022-10-08 16:36:39
6 6 */
7 7 import useInitial from "@/hooks/useInitail";
8 8 import { Tag } from "antd";
... ... @@ -14,7 +14,12 @@ import React, {
14 14 useImperativeHandle,
15 15 useState,
16 16 } from "react";
17   -import { Value, getShopListChooseOptionsApi, getShopListApi } from "./api";
  17 +import {
  18 + Value,
  19 + getShopListChooseOptionsApi,
  20 + getShopListApi,
  21 + ShopSelectNewOptions,
  22 +} from "./api";
18 23 import Close from "./components/Close";
19 24 import ShopModal from "./components/ShopModal";
20 25 import "./style.less";
... ... @@ -28,6 +33,14 @@ interface Props {
28 33 placeholder?: string;
29 34 type?: 1 | 2; // 1 集团维度 2 自定义门店维度
30 35 shopIds?: number[]; // 仅查询门店ID列表,与 type = 2 时搭配使用
  36 + /**
  37 + * 默认筛选参数,下拉框中不可删除;
  38 + * 用于特殊业务,例如 售前CRM-零售任务 选择门店时,需要默认查询 新车销售 的门店信息,则传入
  39 + defaultOptions={{
  40 + bizTypes: "1",
  41 + }}
  42 + */
  43 + defaultOptions?: ShopSelectNewOptions;
31 44 }
32 45  
33 46 export interface ShopSelectNewRef {
... ... @@ -46,6 +59,7 @@ function ShopSelectNew(
46 59 type = 1,
47 60 disabled = false,
48 61 shopIds,
  62 + defaultOptions = {},
49 63 }: Props,
50 64 ref: Ref<ShopSelectNewRef>
51 65 ) {
... ... @@ -62,6 +76,7 @@ function ShopSelectNew(
62 76 [],
63 77 {
64 78 type,
  79 + ...defaultOptions,
65 80 },
66 81 delay
67 82 );
... ... @@ -173,6 +188,7 @@ function ShopSelectNew(
173 188 setVisible={setVisible}
174 189 optionInitial={optionInitial}
175 190 listInitial={listInitial}
  191 + defaultOptions={defaultOptions}
176 192 />
177 193 )}
178 194 </div>
... ...