Commit a60f9f4a4222f2e2c4b33bb6921287db8d8f45bd

Authored by Shinner
1 parent e53e82c2

调试批量设置接口

src/pages/order3/SaleTask/api.ts
... ... @@ -124,10 +124,32 @@ export interface AutoAssignSaleTaskReq {
124 124 }
125 125  
126 126 /** 自动分配零售任务 */
127   -export function autoAssignSaleTask(params: AutoAssignSaleTaskReq): PromiseResp<boolean> {
  127 +export function autoAssignSaleTask(
  128 + params: AutoAssignSaleTaskReq
  129 +): PromiseResp<boolean> {
128 130 return request.post(`${ORDER3_HOST}/erp/sales/task/auto/assign`, params);
129 131 }
130 132  
  133 +interface BatchSetSaleTaskItem {
  134 + shopIdList: number[];
  135 + taskAims: number;
  136 +}
  137 +
  138 +export interface BatchSetSaleTaskReq {
  139 + grossProfitTaskList?: BatchSetSaleTaskItem[];
  140 + tackCarTaskList?: BatchSetSaleTaskItem[];
  141 + testDriveTaskList?: BatchSetSaleTaskItem[];
  142 + assignTask: boolean;
  143 + orderTaskApplyId: number;
  144 +}
  145 +
  146 +/** 批量设置零售任务 */
  147 +export function batchSetSaleTask(
  148 + params: BatchSetSaleTaskReq
  149 +): PromiseResp<boolean> {
  150 + return request.post(`${ORDER3_HOST}/erp/sales/task/batch/shop/set`, params);
  151 +}
  152 +
131 153 export interface BrandItem {
132 154 id: number;
133 155 initial: string;
... ...
src/pages/order3/SaleTask/components/SaleTaskAutoAssign.tsx
... ... @@ -74,17 +74,13 @@ interface SaleTaskAutoAssignProps {
74 74 onRefresh: () => void;
75 75 }
76 76  
77   -export default function SaleTaskAutoAssign({
78   - id,
79   - value,
80   - onRefresh,
81   -}: SaleTaskAutoAssignProps) {
  77 +export default function SaleTaskAutoAssign(props: SaleTaskAutoAssignProps) {
82 78 const EditableContext = React.createContext<FormInstance<any> | null>(null);
83 79 const [dataSource, setDataSource] = useState<API.ShopTaskItem[]>([]);
84 80  
85 81 useEffect(() => {
86   - setDataSource(value ? [...value] : []);
87   - }, [value]);
  82 + setDataSource(props.value ? [...props.value] : []);
  83 + }, [props.value]);
88 84  
89 85 const EditableRow: React.FC<EditableRowProps> = ({ index, ...props }) => {
90 86 const [form] = Form.useForm();
... ... @@ -196,7 +192,7 @@ export default function SaleTaskAutoAssign({
196 192 onOk: async () => {
197 193 const hide = message.loading("分配中,请稍候", 0);
198 194 API.autoAssignSaleTask({
199   - id,
  195 + id: props.id,
200 196 shopTaskList: dataSource.map((item) => ({
201 197 shopId: item.shopId,
202 198 taskCount: item.taskCount,
... ... @@ -208,7 +204,7 @@ export default function SaleTaskAutoAssign({
208 204 })
209 205 .then((res) => {
210 206 message.success("分配成功");
211   - onRefresh();
  207 + props.onRefresh();
212 208 })
213 209 .catch((error: any) => {
214 210 message.error(error.message ?? "请求失败");
... ... @@ -254,7 +250,7 @@ export default function SaleTaskAutoAssign({
254 250 columns={columns as ColumnTypes}
255 251 />
256 252 <Row align="middle" justify="center" style={{ marginTop: 20 }}>
257   - <Button onClick={onRefresh}>取消</Button>
  253 + <Button onClick={props.onRefresh}>取消</Button>
258 254 <Button
259 255 type="primary"
260 256 style={{ marginLeft: 10 }}
... ...
src/pages/order3/SaleTask/components/SaleTaskBatchSet.tsx
1 1 import { PlusOutlined } from "@ant-design/icons";
2   -import { Button, Card, Col, Form, InputNumber, Row, Select } from "antd";
  2 +import {
  3 + Button,
  4 + Card,
  5 + Col,
  6 + Form,
  7 + InputNumber,
  8 + Modal,
  9 + Row,
  10 + message,
  11 +} from "antd";
3 12 import styles from "./index.less";
4   -import React from "react";
  13 +import React, { useState } from "react";
5 14 import { MAX_NUM } from "../entity";
  15 +import * as API from "../api";
  16 +import ShopSelectNew from "@/components/ShopSelectNew";
6 17  
7   -export default function SaleTaskBatchSet() {
  18 +interface SaleTaskBatchSetProps {
  19 + id: number;
  20 + onRefresh: () => void;
  21 +}
  22 +
  23 +export default function SaleTaskBatchSet(props: SaleTaskBatchSetProps) {
8 24 const [form] = Form.useForm();
  25 + // 过滤各项已经选择的门店
  26 + // const [selectedShopIds, setSelectedShopIds] = useState({
  27 + // grossProfit: [],
  28 + // tackCar: [],
  29 + // testDrive: [],
  30 + // });
9 31  
10   - const assignToShop = async () => {
  32 + const batchSetSaleTask = async (isAssignToAdviser: boolean) => {
11 33 await form.validateFields();
12 34 const values = form.getFieldsValue();
13   - console.log(values);
  35 + const newValues = {};
  36 + Array.from(Object.keys(values)).forEach((valueKey: any) => {
  37 + if (values[valueKey]) {
  38 + newValues[valueKey] = values[valueKey].map((valueItem: any) => ({
  39 + taskAims: valueItem.taskAims,
  40 + shopIdList: valueItem.shopIdList.map(
  41 + (shopItem: any) => shopItem.shopId
  42 + ),
  43 + }));
  44 + }
  45 + });
  46 + Modal.confirm({
  47 + title: isAssignToAdviser
  48 + ? "确认分配到门店和顾问吗?"
  49 + : "确认分配到门店吗?",
  50 + zIndex: 1002,
  51 + onOk: async () => {
  52 + const hide = message.loading("分配中,请稍候", 0);
  53 + API.batchSetSaleTask({
  54 + assignTask: isAssignToAdviser,
  55 + orderTaskApplyId: props.id,
  56 + ...newValues,
  57 + })
  58 + .then((res) => {
  59 + message.success("分配成功");
  60 + props.onRefresh();
  61 + })
  62 + .catch((error: any) => {
  63 + message.error(error.message ?? "请求失败");
  64 + })
  65 + .finally(() => {
  66 + hide();
  67 + });
  68 + },
  69 + });
14 70 };
15 71  
16   - const assignToBoth = async () => {
17   - await form.validateFields();
18   - const values = form.getFieldsValue();
19   - console.log(values);
20   - };
  72 + // const handleFormChange = (changedValues: any) => {
  73 + // const labelKey: any = Object.keys(changedValues)[0];
  74 + // const list: any = Object.values(changedValues)[0];
  75 + // console.log(list);
  76 + // if (!list[0]) return;
  77 + // if (Object.keys(list[0])[0] === "shopIdList") {
  78 + // const newSelectedIds = { ...selectedShopIds };
  79 + // newSelectedIds[labelKey] = Object.values(list[0])[0];
  80 + // setSelectedShopIds(newSelectedIds);
  81 + // }
  82 + // };
21 83  
22 84 return (
23   - <Form form={form} name="sale-task-batch-set-form" autoComplete="off">
24   - <Form.List name="vehicleGrossProfitTask">
  85 + <Form
  86 + form={form}
  87 + name="sale-task-batch-set-form"
  88 + autoComplete="off"
  89 + // onValuesChange={handleFormChange}
  90 + >
  91 + <Form.List name="grossProfitTaskList">
25 92 {(fields, { add, remove }) => (
26 93 <Card>
27 94 <Row
... ... @@ -39,7 +106,7 @@ export default function SaleTaskBatchSet() {
39 106 <Col className="gutter-row" span={6}>
40 107 <Form.Item
41 108 {...restField}
42   - name={[name, "vehicleGrossProfitTask"]}
  109 + name={[name, "taskAims"]}
43 110 rules={[{ required: true, message: "请填写单车毛利任务" }]}
44 111 >
45 112 <InputNumber
... ... @@ -56,18 +123,14 @@ export default function SaleTaskBatchSet() {
56 123 <Col className="gutter-row" span={15}>
57 124 <Form.Item
58 125 {...restField}
59   - name={[name, "shop"]}
  126 + name={[name, "shopIdList"]}
60 127 rules={[{ required: true, message: "请选择适用门店" }]}
61 128 >
62   - <Select
63   - showSearch
64   - allowClear
65   - labelInValue
66   - loading={false}
  129 + <ShopSelectNew
  130 + multiple
  131 + defaultOptions={{ bizTypes: "1" }}
67 132 placeholder="请选择适用门店"
68   - style={{ width: "100%" }}
69   - fieldNames={{ value: "id", label: "name" }}
70   - options={[]}
  133 + // disabledShopIds={selectedShopIds.grossProfit}
71 134 />
72 135 </Form.Item>
73 136 </Col>
... ... @@ -85,7 +148,7 @@ export default function SaleTaskBatchSet() {
85 148 </Card>
86 149 )}
87 150 </Form.List>
88   - <Form.List name="testDriveTaskCount">
  151 + <Form.List name="testDriveTaskList">
89 152 {(fields, { add, remove }) => (
90 153 <Card style={{ marginTop: 20 }}>
91 154 <Row
... ... @@ -103,7 +166,7 @@ export default function SaleTaskBatchSet() {
103 166 <Col className="gutter-row" span={6}>
104 167 <Form.Item
105 168 {...restField}
106   - name={[name, "testDriveTaskCount"]}
  169 + name={[name, "taskAims"]}
107 170 rules={[{ required: true, message: "请填写首客试驾成交" }]}
108 171 >
109 172 <InputNumber
... ... @@ -120,18 +183,14 @@ export default function SaleTaskBatchSet() {
120 183 <Col className="gutter-row" span={15}>
121 184 <Form.Item
122 185 {...restField}
123   - name={[name, "shop"]}
  186 + name={[name, "shopIdList"]}
124 187 rules={[{ required: true, message: "请选择适用门店" }]}
125 188 >
126   - <Select
127   - showSearch
128   - allowClear
129   - labelInValue
130   - loading={false}
  189 + <ShopSelectNew
  190 + multiple
  191 + defaultOptions={{ bizTypes: "1" }}
131 192 placeholder="请选择适用门店"
132   - style={{ width: "100%" }}
133   - fieldNames={{ value: "id", label: "name" }}
134   - options={[]}
  193 + // disabledShopIds={selectedShopIds.testDrive}
135 194 />
136 195 </Form.Item>
137 196 </Col>
... ... @@ -149,7 +208,7 @@ export default function SaleTaskBatchSet() {
149 208 </Card>
150 209 )}
151 210 </Form.List>
152   - <Form.List name="tackCarTaskCount">
  211 + <Form.List name="tackCarTaskList">
153 212 {(fields, { add, remove }) => (
154 213 <Card style={{ marginTop: 20 }}>
155 214 <Row
... ... @@ -167,7 +226,7 @@ export default function SaleTaskBatchSet() {
167 226 <Col className="gutter-row" span={6}>
168 227 <Form.Item
169 228 {...restField}
170   - name={[name, "tackCarTaskCount"]}
  229 + name={[name, "taskAims"]}
171 230 rules={[{ required: true, message: "请填写攻坚车任务" }]}
172 231 >
173 232 <InputNumber
... ... @@ -184,18 +243,14 @@ export default function SaleTaskBatchSet() {
184 243 <Col className="gutter-row" span={15}>
185 244 <Form.Item
186 245 {...restField}
187   - name={[name, "shop"]}
  246 + name={[name, "shopIdList"]}
188 247 rules={[{ required: true, message: "请选择适用门店" }]}
189 248 >
190   - <Select
191   - showSearch
192   - allowClear
193   - labelInValue
194   - loading={false}
  249 + <ShopSelectNew
  250 + multiple
  251 + defaultOptions={{ bizTypes: "1" }}
195 252 placeholder="请选择适用门店"
196   - style={{ width: "100%" }}
197   - fieldNames={{ value: "id", label: "name" }}
198   - options={[]}
  253 + // disabledShopIds={selectedShopIds.tackCar}
199 254 />
200 255 </Form.Item>
201 256 </Col>
... ... @@ -214,18 +269,18 @@ export default function SaleTaskBatchSet() {
214 269 )}
215 270 </Form.List>
216 271 <Row align="middle" justify="center" style={{ marginTop: 20 }}>
217   - <Button onClick={() => {}}>取消</Button>
  272 + <Button onClick={props.onRefresh}>取消</Button>
218 273 <Button
219 274 type="primary"
220 275 style={{ marginLeft: 10 }}
221   - onClick={assignToShop}
  276 + onClick={() => batchSetSaleTask(false)}
222 277 >
223 278 分配到门店
224 279 </Button>
225 280 <Button
226 281 type="primary"
227 282 style={{ marginLeft: 10 }}
228   - onClick={assignToBoth}
  283 + onClick={() => batchSetSaleTask(true)}
229 284 >
230 285 分配到门店和顾问
231 286 </Button>
... ...
src/pages/order3/SaleTask/index.tsx
... ... @@ -222,6 +222,15 @@ function SaleTaskList() {
222 222 setStpVisible(true);
223 223 };
224 224  
  225 + const handleAutoAssignRefresh = () => {
  226 + setAutoVisible(false);
  227 + setParams({}, true);
  228 + };
  229 + const handleBatchSetRefresh = () => {
  230 + setBatchVisible(false);
  231 + setParams({}, true);
  232 + };
  233 +
225 234 return (
226 235 <PageHeaderWrapper title="零售任务分配">
227 236 <Card>
... ... @@ -459,31 +468,27 @@ function SaleTaskList() {
459 468 width={800}
460 469 title="零售任务快捷分配"
461 470 open={autoVisible}
462   - onCancel={() => {
463   - setAutoVisible(false);
464   - setParams({}, true);
465   - }}
  471 + onCancel={handleAutoAssignRefresh}
466 472 destroyOnClose
467 473 footer={null}
  474 + maskClosable={false}
468 475 >
469 476 <SaleTaskAutoAssign
470 477 id={data.id}
471 478 value={data.shopTaskList}
472   - onRefresh={() => {
473   - setAutoVisible(false);
474   - setParams({}, true);
475   - }}
  479 + onRefresh={handleAutoAssignRefresh}
476 480 />
477 481 </Modal>
478 482 <Modal
479 483 width={800}
480 484 title="批量设置"
481 485 open={batchVisible}
482   - onCancel={() => setBatchVisible(false)}
  486 + onCancel={handleBatchSetRefresh}
483 487 destroyOnClose
484 488 footer={null}
  489 + maskClosable={false}
485 490 >
486   - <SaleTaskBatchSet />
  491 + <SaleTaskBatchSet id={data.id} onRefresh={handleBatchSetRefresh} />
487 492 </Modal>
488 493 <ApprovalProgressModal
489 494 visible={approve.visible}
... ...