ebd701f2
by1642146903
配件计划申请页面联调
|
1
|
import {Card, ConfigProvider, Select, Button, message, Popconfirm} from 'antd';
|
12f15fa6
by1642146903
fix
|
2
3
|
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import React, {useEffect, useState} from "react";
|
ebd701f2
by1642146903
配件计划申请页面联调
|
4
5
6
7
|
import DealerModal from './components/DealerModal';
import SuppModal from './components/SuppModal';
import PartDetailModal from './components/PartDetailModal';
import {throttle, sum} from 'lodash';
|
12f15fa6
by1642146903
fix
|
8
9
|
import useInitial from "@/hooks/useInitail";
import * as API from "@/common/api";
|
12f15fa6
by1642146903
fix
|
10
|
import {getList, Params, ListVO} from "@/pages/pms/partPlan/PlanPool/api";
|
79d4a3b6
jiangwei
计划管理增加草稿和继续编辑功能
|
11
|
import {saveApi, draftApi} from './api';
|
12f15fa6
by1642146903
fix
|
12
13
|
import zhCN from "antd/lib/locale-provider/zh_CN";
import st from "@/pages/pms/partPlan/PlanManage/style.less";
|
ebd701f2
by1642146903
配件计划申请页面联调
|
14
15
|
import PartModal from "@/pages/pms/partPlan/PlanManage/subpages/Apply/components/PartModal";
import {groupBys, flattenDeep} from '@/pages/pms/entity';
|
1a88d6f6
jiangwei
小bug
|
16
|
import {PartDetail} from '../../api';
|
79d4a3b6
jiangwei
计划管理增加草稿和继续编辑功能
|
17
18
|
import { history } from 'umi';
import { getDetail, DetailVO, Params as detailParams } from '../Detail/api';
|
12f15fa6
by1642146903
fix
|
19
|
|
12f15fa6
by1642146903
fix
|
20
|
const { Option } = Select;
|
79d4a3b6
jiangwei
计划管理增加草稿和继续编辑功能
|
21
22
23
24
|
const apiObj: { [key: number]: any } = {
1: saveApi,
2: draftApi
};
|
12f15fa6
by1642146903
fix
|
25
|
export default function Index() {
|
79d4a3b6
jiangwei
计划管理增加草稿和继续编辑功能
|
26
27
28
|
const planId = history.location.query;
const [detaildelay, setDetaildelay] = useState(true);
const { data, setParams: detailsetParams } = useInitial<DetailVO[], detailParams>(getDetail, [], { ...planId }, detaildelay);
|
12f15fa6
by1642146903
fix
|
29
30
|
const [delay, setDelay] = useState<boolean>(true);
const [loading, setLoading] = useState<boolean>(false);
|
12f15fa6
by1642146903
fix
|
31
|
const { data: brands } = useInitial(API.getBrandFilterApi, [], {});
|
12f15fa6
by1642146903
fix
|
32
33
|
const [dfParams, setDfParams] = useState<any>({});
const { data: parts, setParams } = useInitial<ListVO[], Params>(getList, [], dfParams, delay);
|
ebd701f2
by1642146903
配件计划申请页面联调
|
34
35
36
|
const [dealerList, setDealerList] = useState<any[]>([]);
const [dealer, setDealer] = useState<any>({});
const [visibleDealer, setVisibleDealer] = useState(false);
|
12f15fa6
by1642146903
fix
|
37
|
const [visibleSupplier, setVisibleSupplier] = useState(false);
|
ebd701f2
by1642146903
配件计划申请页面联调
|
38
39
40
41
|
const [visiblePart, setVisiblePart] = useState(false);
const [visiblePartDetail, setVisiblePartDetail] = useState(false);
const partList = flattenDeep(dealerList.map(it => (it.suppliers || []).map((su: any) => (su.storages || []).map((st: any) => (st.parts || [])))));
const poolIds = partList.map((it: any) => it.poolId);
|
12f15fa6
by1642146903
fix
|
42
|
|
79d4a3b6
jiangwei
计划管理增加草稿和继续编辑功能
|
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
useEffect(() => {
if (planId?.planId) {
setDetaildelay(false);
detailsetParams({ ...planId }, true);
}
}, []);
useEffect(() => {
if (data.length) {
setDfParams({brandId: data[0].brandId});
setParams({}, true);
setDelay(false);
setDealerList(data);
}
}, [data.length]);
|
ebd701f2
by1642146903
配件计划申请页面联调
|
59
60
|
function onOk(parts: ListVO[] = []) {
setDealerList(dealerList.map(it => {
|
79d4a3b6
jiangwei
计划管理增加草稿和继续编辑功能
|
61
|
if (it.settleDealerId == dealer.settleDealerId) {
|
ebd701f2
by1642146903
配件计划申请页面联调
|
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
return {
...it,
suppliers: (it.suppliers || []).map((su: any) => {
if (su.supplierId == dealer.supplierId) {
const pas = [...flattenDeep((su.storages || []).map((st: any) => (st.parts || []))), ...parts];
const sto = groupBys(pas, 'storageId', 'storageName');
return {
...su,
storages: sto.map(st => ({
storageId: st.storageId,
storageName: st.storageName,
parts: st.list,
}))
};
}
return su;
})
};
}
return it;
}));
}
function onOkDealer(dealer: any = {}) {
setDealerList([...dealerList, dealer]);
}
function onOkSupplier(supplier: any = {}) {
setDealerList(dealerList.map(it => {
|
79d4a3b6
jiangwei
计划管理增加草稿和继续编辑功能
|
91
|
if (it.settleDealerId == dealer.settleDealerId) {
|
ebd701f2
by1642146903
配件计划申请页面联调
|
92
93
94
95
96
97
98
99
100
101
102
|
return {
...it,
suppliers: [...(it.suppliers || []), supplier]
};
}
return it;
}));
}
function deleteSupplier(dealer: any = {}, supplier: any = {}) {
setDealerList(dealerList.map(it => {
|
79d4a3b6
jiangwei
计划管理增加草稿和继续编辑功能
|
103
|
if (it.settleDealerId == dealer.settleDealerId) {
|
ebd701f2
by1642146903
配件计划申请页面联调
|
104
105
106
107
108
109
110
111
112
113
114
|
return {
...it,
suppliers: (it.suppliers || []).filter((su: any) => su.supplierId != supplier.supplierId)
};
}
return it;
}));
}
function deletePart(dealer: any = {}, supplier: any = {}, storage: any = {}, part: any = {}) {
setDealerList(dealerList.map(it => {
|
79d4a3b6
jiangwei
计划管理增加草稿和继续编辑功能
|
115
|
if (it.settleDealerId == dealer.settleDealerId) {
|
ebd701f2
by1642146903
配件计划申请页面联调
|
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
return {
...it,
suppliers: (it.suppliers || []).map((su: any) => {
if (su.supplierId == supplier.supplierId) {
return {
...su,
storages: (su.storages || []).map((st: any) => {
if (st.storageId==storage.storageId) {
return {
...st,
parts: (st.parts || []).filter((p: any) => p.poolId!=part.poolId)
};
}
return st;
})
};
}
return su;
})
};
}
return it;
}));
}
function deleteStorage(dealer: any = {}, supplier: any = {}, storage: any = {}) {
setDealerList(dealerList.map(it => {
|
79d4a3b6
jiangwei
计划管理增加草稿和继续编辑功能
|
143
|
if (it.settleDealerId == dealer.settleDealerId) {
|
ebd701f2
by1642146903
配件计划申请页面联调
|
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
return {
...it,
suppliers: (it.suppliers || []).map((su: any) => {
if (su.supplierId == supplier.supplierId) {
return {
...su,
storages: (su.storages || []).filter((st: any) => st.storageId!=storage.storageId)
};
}
return su;
})
};
}
return it;
}));
|
12f15fa6
by1642146903
fix
|
159
160
|
}
|
79d4a3b6
jiangwei
计划管理增加草稿和继续编辑功能
|
161
|
const onSubmit = throttle((isSave) => {
|
12f15fa6
by1642146903
fix
|
162
|
setLoading(true);
|
ebd701f2
by1642146903
配件计划申请页面联调
|
163
164
165
|
let suppliers = flattenDeep(dealerList.map(de => (de.suppliers || []).map((su: any) => ({...de, ...su}))));
suppliers = suppliers.map(su => ({
...su,
|
79d4a3b6
jiangwei
计划管理增加草稿和继续编辑功能
|
166
|
settleDealerId: su.settleDealerId,
|
ebd701f2
by1642146903
配件计划申请页面联调
|
167
168
169
170
171
|
storages: (su.storages || []).map((st: any) => ({
storageId: st.storageId,
poolIds: (st.parts || []).map((pa: any) => pa.poolId)
}))
}));
|
79d4a3b6
jiangwei
计划管理增加草稿和继续编辑功能
|
172
173
|
const type = isSave ? 1 : 2;
apiObj[type]({
|
57b51c35
jiangwei
配件计划池增加查看90天出库详情和...
|
174
|
planId: Number(planId?.planId),
|
12f15fa6
by1642146903
fix
|
175
|
...dfParams,
|
ebd701f2
by1642146903
配件计划申请页面联调
|
176
|
suppliers
|
79d4a3b6
jiangwei
计划管理增加草稿和继续编辑功能
|
177
178
179
180
181
182
183
|
// suppliers: suppliers.map(i => ({
// settleDealerId: i.settleDealerId,
// settleDealerName: i.settleDealerName,
// supplierId: i.supplierId,
// supplierName: i.supplierName,
// storages: i.storages
// }))
|
12f15fa6
by1642146903
fix
|
184
185
|
}).then(() => {
setLoading(false);
|
79d4a3b6
jiangwei
计划管理增加草稿和继续编辑功能
|
186
187
|
history.goBack();
}).catch((e: any) => {
|
12f15fa6
by1642146903
fix
|
188
|
setLoading(false);
|
ebd701f2
by1642146903
配件计划申请页面联调
|
189
190
|
message.error(e.message);
});
|
12f15fa6
by1642146903
fix
|
191
192
193
194
195
196
197
|
}, 3000);
return (
<PageHeaderWrapper title="配件计划管理">
<ConfigProvider locale={zhCN}>
<Card className={st.page}>
<div style={{ display: 'flex', flexDirection: 'column', marginTop: 20, marginBottom: 20 }}>
|
ebd701f2
by1642146903
配件计划申请页面联调
|
198
|
<div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center'}}>
|
12f15fa6
by1642146903
fix
|
199
|
<Select
|
ebd701f2
by1642146903
配件计划申请页面联调
|
200
201
202
203
204
205
206
|
placeholder="请选择品牌"
onSearch={() => {}}
showSearch
filterOption={(input: any, option: any) => option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
style={{ width: 200, marginBottom: 20 }}
value={dfParams.brandId}
onChange={brandId => {
|
0553a34e
jiangwei
fix
|
207
|
setDfParams({ ...dfParams, brandId });
|
80920026
jiangwei
配件池参数fix
|
208
209
|
setParams({}, true);
setDelay(false);
|
ebd701f2
by1642146903
配件计划申请页面联调
|
210
|
setDealerList([]);
|
12f15fa6
by1642146903
fix
|
211
|
}}
|
12f15fa6
by1642146903
fix
|
212
|
>
|
ebd701f2
by1642146903
配件计划申请页面联调
|
213
214
215
|
{brands.map((item: any) => (
<Option value={item.id} key={item.id}>
{item.name}
|
12f15fa6
by1642146903
fix
|
216
217
218
|
</Option>
))}
</Select>
|
ebd701f2
by1642146903
配件计划申请页面联调
|
219
220
221
222
223
224
225
226
227
228
229
230
|
<a
style={{marginLeft: 20, marginBottom: 20}}
onClick={() => {
if (!dfParams.brandId) {
message.error('请选择品牌');
return;
}
setVisibleDealer(true);
}}
>
添加采购商家
</a>
|
12f15fa6
by1642146903
fix
|
231
|
</div>
|
ebd701f2
by1642146903
配件计划申请页面联调
|
232
|
{dealerList.map((dealer: any = {}) => (
|
79d4a3b6
jiangwei
计划管理增加草稿和继续编辑功能
|
233
|
<div key={`dealer${dealer.settleDealerId}`} style={{ marginTop: 10 }}>
|
ebd701f2
by1642146903
配件计划申请页面联调
|
234
|
<div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center'}}>
|
79d4a3b6
jiangwei
计划管理增加草稿和继续编辑功能
|
235
|
<div style={{ fontWeight: "bold" }}>{`商家: ${dealer.settleDealerName || ''}`}</div>
|
ebd701f2
by1642146903
配件计划申请页面联调
|
236
237
238
239
240
|
<a style={{marginLeft: 40}} onClick={() => { setVisibleSupplier(true); setDealer(dealer); }}>
添加指定供应商
</a>
<Popconfirm
title="是否删除"
|
79d4a3b6
jiangwei
计划管理增加草稿和继续编辑功能
|
241
|
onConfirm={() => setDealerList(dealerList.filter(it => it.settleDealerId!=dealer.settleDealerId))}
|
ebd701f2
by1642146903
配件计划申请页面联调
|
242
243
244
245
246
247
248
249
250
251
252
|
okText="确定"
cancelText="取消"
style={{marginLeft: 20}}
>
<Button type="link" danger>
删除
</Button>
</Popconfirm>
</div>
{(dealer.suppliers || []).map((supplier: any = {}) => {
const paList: any[] = flattenDeep((supplier.storages || []).map((st: any) => (st.parts || [])));
|
ebd701f2
by1642146903
配件计划申请页面联调
|
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
|
return (
<div key={`supplier${supplier.supplierId}`} style={{ marginTop: 10, marginLeft: 40 }}>
<div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center'}}>
<div style={{ fontWeight: "bold" }}>{`供应商: ${supplier.supplierName || ''}`}</div>
<a style={{marginLeft: 20}} onClick={() => { setVisiblePart(true); setDealer({...dealer, ...supplier}); }}>
添加采购配件
</a>
<Popconfirm
title="是否删除"
onConfirm={() => deleteSupplier(dealer, supplier)}
okText="确定"
cancelText="取消"
style={{marginLeft: 20}}
>
<Button type="link" danger>
删除
</Button>
</Popconfirm>
</div>
<div style={{display: 'flex', marginLeft: 40, marginTop: 10}}>
<div style={{marginRight: 20}}>
|
79d4a3b6
jiangwei
计划管理增加草稿和继续编辑功能
|
274
|
{`总金额: ${sum(paList.map((it: any) => (it.price || 0) * (it.count || it.partCnt || 0))).toFixed(2)}元`}
|
ebd701f2
by1642146903
配件计划申请页面联调
|
275
|
</div>
|
1a88d6f6
jiangwei
小bug
|
276
|
<div>{`品种数: ${[...new Set((paList || []).map((i: PartDetail) => i.partCode))].length}种`}</div>
|
ebd701f2
by1642146903
配件计划申请页面联调
|
277
278
279
280
281
|
</div>
{(supplier.storages || []).map((storage: any) => (
<div key={`storage${storage.storageId}`} style={{ marginTop: 10, marginLeft: 60 }}>
<div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center'}}>
<div style={{ fontWeight: "bold" }}>{`发运库房: ${storage.storageName || ''}`}</div>
|
79d4a3b6
jiangwei
计划管理增加草稿和继续编辑功能
|
282
|
<div style={{marginLeft: 20}}>{`总金额: ${sum((storage.parts || []).map((it: any) => (it.price || 0) * (it.count || it.partCnt || 0))).toFixed(2)}元`}</div>
|
1a88d6f6
jiangwei
小bug
|
283
|
<div style={{marginLeft: 20}}>{`品种数: ${[...new Set((storage.parts || []).map((i: PartDetail) => i.partCode))].length}种`}</div>
|
ebd701f2
by1642146903
配件计划申请页面联调
|
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
|
<a style={{marginLeft: 20}} onClick={() => { setVisiblePartDetail(true); setDealer({dealer, supplier, storage }); }}>
查看配件
</a>
<Popconfirm
title="是否删除"
onConfirm={() => deleteStorage(dealer, supplier, storage)}
okText="确定"
cancelText="取消"
style={{marginLeft: 20}}
>
<Button type="link" danger>
删除
</Button>
</Popconfirm>
</div>
</div>
))}
</div>
);
})}
</div>
))}
<DealerModal
dealerList={dealerList}
visible={visibleDealer}
onCancel={() => setVisibleDealer(false)}
onOk={onOkDealer}
/>
<SuppModal
|
12f15fa6
by1642146903
fix
|
313
|
brandId={dfParams.brandId}
|
ebd701f2
by1642146903
配件计划申请页面联调
|
314
|
supplierList={dealer.suppliers || []}
|
12f15fa6
by1642146903
fix
|
315
|
visible={visibleSupplier}
|
12f15fa6
by1642146903
fix
|
316
|
onCancel={() => setVisibleSupplier(false)}
|
ebd701f2
by1642146903
配件计划申请页面联调
|
317
318
319
320
321
322
|
onOk={onOkSupplier}
/>
<PartModal
visible={visiblePart}
onCancel={() => setVisiblePart(false)}
parts={parts.filter(it => !poolIds.includes(it.poolId))}
|
12f15fa6
by1642146903
fix
|
323
|
onOk={onOk}
|
f21c07ed
jiangwei
计划管理筛选
|
324
|
setParams={setParams}
|
12f15fa6
by1642146903
fix
|
325
|
/>
|
ebd701f2
by1642146903
配件计划申请页面联调
|
326
327
328
329
330
331
332
333
|
<PartDetailModal
visible={visiblePartDetail}
onCancel={() => setVisiblePartDetail(false)}
dealer={dealer.dealer}
supplier={dealer.supplier}
storage={dealer.storage}
deletePart={deletePart}
/>
|
12f15fa6
by1642146903
fix
|
334
|
</div>
|
79d4a3b6
jiangwei
计划管理增加草稿和继续编辑功能
|
335
|
<div style={{display: 'flex', justifyContent: 'center'}}>
|
57b51c35
jiangwei
配件计划池增加查看90天出库详情和...
|
336
337
338
339
340
|
<Button
disabled={loading}
loading={loading}
style={{marginRight: 20}}
onClick={() => history.goBack()}
|
79d4a3b6
jiangwei
计划管理增加草稿和继续编辑功能
|
341
|
>
|
57b51c35
jiangwei
配件计划池增加查看90天出库详情和...
|
342
343
|
取消
</Button>
|
79d4a3b6
jiangwei
计划管理增加草稿和继续编辑功能
|
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
<Button
disabled={loading}
loading={loading}
onClick={() => onSubmit(false)}
type="primary"
style={{marginRight: 20}}
>
暂存为草稿
</Button>
<Button
disabled={loading}
loading={loading}
onClick={() => onSubmit(true)}
type="primary"
>
确认并提交
</Button>
</div>
|
12f15fa6
by1642146903
fix
|
363
364
365
366
367
|
</Card>
</ConfigProvider>
</PageHeaderWrapper>
);
}
|