title.tsx
18.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
import {
deleteOrderErpOrderStagesDelect,
getOrderErpOrderStagesListAll,
postOrderErpOrderStagesSearch,
} from '@/services';
import { orderExport } from '@/services/order';
import { VerticalAlignTopOutlined } from '@ant-design/icons';
import type { ProColumns } from '@ant-design/pro-components';
import { ProTable } from '@ant-design/pro-components';
import { Button, message } from 'antd';
import { useRef } from 'react';
import Comfire from '../comfire/comfire';
import AddModel from '../detail/detail';
import EditorModel from '../edit/edit';
import ReadModel from '../read/read';
import UploadModel from '../upload/uploadModel';
import './title.less';
export const waitTimePromise = async (time: number = 100) => {
return new Promise((resolve) => {
setTimeout(() => {
resolve(true);
}, time);
});
};
export const waitTime = async (time: number = 100) => {
await waitTimePromise(time);
};
type OrderStagesItem = {
//文件编号
id?: number;
//合同编号
contract?: string;
//供应商名称
vendor?: string;
//签合同日期
dateRange?: Date;
//终端名称
terminal?: string;
//设备编号
dId?: number;
//设备名称
deviceName?: string;
//设备型号
deviceModel?: string;
//数量
count?: number;
//单价
unitPrice?: number;
//总价
price?: number;
//合同总金额
totalPrice?: number;
//付款方式
payWay?: string;
//附件
annex?: string;
//备注
remark?: string;
};
type OrderStagesWithListItem = {
//文件编号
id: number;
//合同编号
contract: string;
//供应商名称
vendor: string;
//签合同日期
dateRange: Date;
//终端名称
terminal: string;
orderStagesDeviceVoList: orderStagesDevice[];
//合同总金额
totalPrice: number;
//付款方式
payWay: string;
//附件
annex: string;
//备注
remark: string;
};
type orderStagesDevice = {
//设备id
dId: number;
//设备名称
deviceName: string;
//设备型号
deviceModel: string;
//数量
count: number;
//单价
unitPrice: number;
//总价
price: number;
};
export default () => {
// const actionRef = useRef<ActionType>();
// const [TableItem, setTableItem] = useState([]);
interface ActionType {
reload: (resetPageIndex?: boolean) => void;
reloadAndRest: () => void;
reset: () => void;
clearSelected?: () => void;
startEditable: (rowKey: Key) => boolean;
cancelEditable: (rowKey: Key) => boolean;
}
const ref = useRef<ActionType>({
reload: () => {
// implementation for reload
},
reloadAndRest: () => {
// implementation for reloadAndRest
},
reset: () => {
// implementation for reset
},
startEditable: () => {
// implementation for startEditable
},
cancelEditable: () => {
// implementation for cancelEditable
},
});
function reload() {
ref.current.reload();
}
async function toDelete(value) {
const res = await deleteOrderErpOrderStagesDelect({
data: {
ids: null,
deviceIds: value,
},
});
if (res) {
message.success('删除成功');
ref.current.reload();
} else {
message.error('删除失败');
}
}
const exportLoadingDestory = () => {
message.success('导出成功');
};
async function toExport() {
// await getOrderErpOrderStagesExport()
orderExport(
'/api/order/erp/orderStages/export',
'分期订单.xlsx',
'get',
{},
exportLoadingDestory,
);
}
const columns: ProColumns<OrderStagesItem>[] = [
{
title: '文件编号',
dataIndex: 'id',
width: 100,
disable: true,
onFilter: true,
ellipsis: true,
render: (_, record) => {
if (record.id) {
const text = record.id.toString();
const paddedText = '0'.repeat(4 - text.length) + text;
return paddedText;
}
},
},
{
title: '签合同日期',
dataIndex: 'dateRange',
valueType: 'date',
width: 100,
disable: true,
onFilter: true,
ellipsis: true,
},
{
title: '合同编号',
dataIndex: 'contract',
width: 200,
disable: true,
onFilter: true,
ellipsis: true,
},
{
title: '供应商名称',
dataIndex: 'vendor',
width: 200,
disable: true,
onFilter: true,
ellipsis: true,
},
{
title: '终端名称',
dataIndex: 'terminal',
width: 200,
disable: true,
onFilter: true,
ellipsis: true,
},
{
title: '设备名称',
dataIndex: 'deviceName',
width: 200,
disable: true,
onFilter: true,
ellipsis: true,
},
{
title: '设备型号',
dataIndex: 'deviceModel',
hideInSearch: true,
width: 200,
disable: true,
onFilter: true,
ellipsis: true,
},
{
title: '数量',
dataIndex: 'count',
hideInSearch: true,
width: 100,
disable: true,
onFilter: true,
ellipsis: true,
},
{
title: '单价',
dataIndex: 'unitPrice',
hideInSearch: true,
width: 100,
disable: true,
onFilter: true,
ellipsis: true,
},
{
title: '总价',
dataIndex: 'price',
hideInSearch: true,
width: 100,
disable: true,
onFilter: true,
ellipsis: true,
},
{
title: '合同总金额',
dataIndex: 'totalPrice',
hideInSearch: true,
width: 100,
disable: true,
onFilter: true,
ellipsis: true,
},
{
title: '付款方式',
dataIndex: 'payWay',
hideInSearch: true,
width: 100,
disable: true,
onFilter: true,
ellipsis: true,
},
{
title: '附件',
dataIndex: 'annex',
hideInSearch: true,
width: 100,
disable: true,
onFilter: true,
ellipsis: true,
render: (_, record) => {
if (record.id && record.annex !== null) {
return <a href={record.annex}>附件文件</a>;
}
},
},
{
disable: true,
title: '备注',
dataIndex: 'remark',
filters: true,
hideInSearch: true,
onFilter: false,
ellipsis: true,
width: 100,
disable: true,
onFilter: true,
ellipsis: true,
},
{
title: '操作',
valueType: 'option',
key: 'option',
fixed: 'right',
width: 120,
disable: true,
onFilter: true,
ellipsis: true,
render: (_text, record) => {
if (record?.id) {
return (
<>
<ReadModel currentContract={record.contract}></ReadModel>
<EditorModel
currentContract={record.contract}
toReload={reload}
></EditorModel>
{/* <a key="delect" target="_blank" rel="noopener noreferrer" onClick={() => { toDelete([record.dId]) }}>
删除
</a> */}
<Comfire currtDid={record.dId} sureDelete={toDelete}></Comfire>
</>
);
}
return null;
},
},
];
return (
<ProTable<OrderStagesItem>
className="title-index"
columnEmptyText=""
columns={columns}
cardBordered
actionRef={ref}
scroll={{ x: 1400, y: 360 }}
request={async (params) => {
// console.log(params);
if (
params.id !== null ||
params.contract !== null ||
params.vendor !== null ||
params.terminal !== null ||
params.deviceName !== null ||
params.dateRange !== null
) {
// console.log(params.id);
// console.log(params.contract);
// console.log(params.vendor);
let PostOrderErpOrderStagesSearchOption = {
id: params.id,
contract: params.contract,
vendor: params.vendor,
terminal: params.terminal,
deviceName: params.deviceName,
dateRange: params.dateRange,
};
let res = await postOrderErpOrderStagesSearch({
data: { ...PostOrderErpOrderStagesSearchOption },
});
await waitTime(2000);
if (res) {
// setTableItem(res.data)
const orderStagesWithList: OrderStagesWithListItem[] = res?.data;
let orderStagesList: OrderStagesItem[] = [];
for (let ind = 0; ind < orderStagesWithList.length; ind++) {
for (
let index = 0;
index < orderStagesWithList[ind].orderStagesDeviceVoList.length;
index++
) {
let item: OrderStagesItem = {
id: undefined,
contract: undefined,
vendor: undefined,
dateRange: undefined,
terminal: undefined,
dId: undefined,
deviceName: undefined,
deviceModel: undefined,
count: undefined,
unitPrice: undefined,
price: undefined,
totalPrice: undefined,
payWay: undefined,
annex: undefined,
remark: undefined,
};
if (index === 0) {
item.id = orderStagesWithList[ind].id;
item.contract = orderStagesWithList[ind].contract;
item.vendor = orderStagesWithList[ind].vendor;
item.dateRange = orderStagesWithList[ind].dateRange;
item.terminal = orderStagesWithList[ind].terminal;
item.dId =
orderStagesWithList[ind].orderStagesDeviceVoList[index].dId;
item.deviceName =
orderStagesWithList[ind].orderStagesDeviceVoList[
index
].deviceName;
item.deviceModel =
orderStagesWithList[ind].orderStagesDeviceVoList[
index
].deviceModel;
item.count =
orderStagesWithList[ind].orderStagesDeviceVoList[
index
].count;
item.unitPrice =
orderStagesWithList[ind].orderStagesDeviceVoList[
index
].unitPrice;
item.price =
orderStagesWithList[ind].orderStagesDeviceVoList[
index
].price;
item.totalPrice = orderStagesWithList[ind].totalPrice;
item.payWay = orderStagesWithList[ind].payWay;
item.annex = orderStagesWithList[ind].annex;
item.remark = orderStagesWithList[ind].remark;
orderStagesList.push(item);
} else {
item.id = orderStagesWithList[ind].id;
item.contract = orderStagesWithList[ind].contract;
item.vendor = orderStagesWithList[ind].vendor;
item.dateRange = orderStagesWithList[ind].dateRange;
item.terminal = orderStagesWithList[ind].terminal;
item.dId =
orderStagesWithList[ind].orderStagesDeviceVoList[index].dId;
item.deviceName =
orderStagesWithList[ind].orderStagesDeviceVoList[
index
].deviceName;
item.deviceModel =
orderStagesWithList[ind].orderStagesDeviceVoList[
index
].deviceModel;
item.count =
orderStagesWithList[ind].orderStagesDeviceVoList[
index
].count;
item.unitPrice =
orderStagesWithList[ind].orderStagesDeviceVoList[
index
].unitPrice;
item.price =
orderStagesWithList[ind].orderStagesDeviceVoList[
index
].price;
item.totalPrice = orderStagesWithList[ind].totalPrice;
item.payWay = orderStagesWithList[ind].payWay;
item.annex = orderStagesWithList[ind].annex;
item.remark = orderStagesWithList[ind].remark;
orderStagesList.push(item);
}
}
}
return {
data: orderStagesList || [],
};
}
} else {
let res = await getOrderErpOrderStagesListAll();
await waitTime(2000);
if (res) {
// setTableItem(res.data)
const orderStagesWithList: OrderStagesWithListItem[] = res?.data;
let orderStagesList: OrderStagesItem[] = [];
for (let ind = 0; ind < orderStagesWithList.length; ind++) {
for (
let index = 0;
index < orderStagesWithList[ind].orderStagesDeviceVoList.length;
index++
) {
let item: OrderStagesItem = {
id: undefined,
contract: undefined,
vendor: undefined,
dateRange: undefined,
terminal: undefined,
dId: undefined,
deviceName: undefined,
deviceModel: undefined,
count: undefined,
unitPrice: undefined,
price: undefined,
totalPrice: undefined,
payWay: undefined,
annex: undefined,
remark: undefined,
};
if (index === 0) {
item.id = orderStagesWithList[ind].id;
item.contract = orderStagesWithList[ind].contract;
item.vendor = orderStagesWithList[ind].vendor;
item.dateRange = orderStagesWithList[ind].dateRange;
item.terminal = orderStagesWithList[ind].terminal;
item.dId =
orderStagesWithList[ind].orderStagesDeviceVoList[index].dId;
item.deviceName =
orderStagesWithList[ind].orderStagesDeviceVoList[
index
].deviceName;
item.deviceModel =
orderStagesWithList[ind].orderStagesDeviceVoList[
index
].deviceModel;
item.count =
orderStagesWithList[ind].orderStagesDeviceVoList[
index
].count;
item.unitPrice =
orderStagesWithList[ind].orderStagesDeviceVoList[
index
].unitPrice;
item.price =
orderStagesWithList[ind].orderStagesDeviceVoList[
index
].price;
item.totalPrice = orderStagesWithList[ind].totalPrice;
item.payWay = orderStagesWithList[ind].payWay;
item.annex = orderStagesWithList[ind].annex;
item.remark = orderStagesWithList[ind].remark;
orderStagesList.push(item);
} else {
item.id = orderStagesWithList[ind].id;
item.contract = orderStagesWithList[ind].contract;
item.vendor = orderStagesWithList[ind].vendor;
item.dateRange = orderStagesWithList[ind].dateRange;
item.terminal = orderStagesWithList[ind].terminal;
item.dId =
orderStagesWithList[ind].orderStagesDeviceVoList[index].dId;
item.deviceName =
orderStagesWithList[ind].orderStagesDeviceVoList[
index
].deviceName;
item.deviceModel =
orderStagesWithList[ind].orderStagesDeviceVoList[
index
].deviceModel;
item.count =
orderStagesWithList[ind].orderStagesDeviceVoList[
index
].count;
item.unitPrice =
orderStagesWithList[ind].orderStagesDeviceVoList[
index
].unitPrice;
item.price =
orderStagesWithList[ind].orderStagesDeviceVoList[
index
].price;
item.totalPrice = orderStagesWithList[ind].totalPrice;
item.payWay = orderStagesWithList[ind].payWay;
item.annex = orderStagesWithList[ind].annex;
item.remark = orderStagesWithList[ind].remark;
orderStagesList.push(item);
}
}
}
return {
data: orderStagesList || [],
};
}
}
}}
editable={{
type: 'multiple',
}}
columnsState={{
persistenceKey: 'pro-table-singe-demos',
persistenceType: 'localStorage',
defaultValue: {
option: { fixed: 'right', disable: true },
},
// onChange(value) {
// console.log('value: ', value);
// },
}}
rowKey="dId"
search={{
labelWidth: 'auto',
}}
options={{
setting: {
listsHeight: 800,
},
}}
form={{
syncToUrl: (values, type) => {
if (type === 'get') {
return {
...values,
created_at: [values.startTime, values.endTime],
};
}
return values;
},
}}
pagination={{
pageSize: 10,
// onChange: (page) => console.log(page),
}}
dateFormatter="string"
headerTitle={[]}
toolBarRender={() => [
<>
<AddModel toReload={reload}></AddModel>
<UploadModel toReload={reload}></UploadModel>
<Button
type="primary"
onClick={() => {
toExport();
}}
>
<VerticalAlignTopOutlined />
导出
</Button>
</>,
]}
/>
);
};