Blame view

src/pages/Instalment/components/title/title.tsx 18 KB
PurelzMgnead authored
1
2
3
4
5
6
7
8
9
10
11
12
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';
PurelzMgnead authored
13
14
import AddModel from '../detail/detail';
import EditorModel from '../edit/edit';
PurelzMgnead authored
15
import ReadModel from '../read/read';
PurelzMgnead authored
16
import UploadModel from '../upload/uploadModel';
PurelzMgnead authored
17
import './title.less';
PurelzMgnead authored
18
export const waitTimePromise = async (time: number = 100) => {
PurelzMgnead authored
19
20
21
22
23
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(true);
    }, time);
  });
PurelzMgnead authored
24
25
26
};

export const waitTime = async (time: number = 100) => {
PurelzMgnead authored
27
  await waitTimePromise(time);
PurelzMgnead authored
28
29
30
};

type OrderStagesItem = {
PurelzMgnead authored
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
  //文件编号
  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;
PurelzMgnead authored
61
62
63
};

type OrderStagesWithListItem = {
PurelzMgnead authored
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
  //文件编号
  id: number;
  //合同编号
  contract: string;
  //供应商名称
  vendor: string;
  //签合同日期
  dateRange: Date;
  //终端名称
  terminal: string;
  orderStagesDeviceVoList: orderStagesDevice[];
  //合同总金额
  totalPrice: number;
  //付款方式
  payWay: string;
  //附件
  annex: string;
  //备注
  remark: string;
PurelzMgnead authored
83
84
85
};

type orderStagesDevice = {
PurelzMgnead authored
86
87
88
89
90
91
92
93
94
95
96
97
98
  //设备id
  dId: number;
  //设备名称
  deviceName: string;
  //设备型号
  deviceModel: string;
  //数量
  count: number;
  //单价
  unitPrice: number;
  //总价
  price: number;
};
PurelzMgnead authored
99
100

export default () => {
PurelzMgnead authored
101
102
  // const actionRef = useRef<ActionType>();
  // const [TableItem, setTableItem] = useState([]);
PurelzMgnead authored
103
PurelzMgnead authored
104
105
106
107
108
109
110
111
  interface ActionType {
    reload: (resetPageIndex?: boolean) => void;
    reloadAndRest: () => void;
    reset: () => void;
    clearSelected?: () => void;
    startEditable: (rowKey: Key) => boolean;
    cancelEditable: (rowKey: Key) => boolean;
  }
PurelzMgnead authored
112
PurelzMgnead authored
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
  const ref = useRef<ActionType>({
    reload: () => {
      // implementation for reload
    },
    reloadAndRest: () => {
      // implementation for reloadAndRest
    },
    reset: () => {
      // implementation for reset
    },
    startEditable: () => {
      // implementation for startEditable
    },
    cancelEditable: () => {
      // implementation for cancelEditable
    },
  });
PurelzMgnead authored
130
PurelzMgnead authored
131
132
133
  function reload() {
    ref.current.reload();
  }
PurelzMgnead authored
134
PurelzMgnead authored
135
136
137
138
139
140
141
142
143
144
145
146
  async function toDelete(value) {
    const res = await deleteOrderErpOrderStagesDelect({
      data: {
        ids: null,
        deviceIds: value,
      },
    });
    if (res) {
      message.success('删除成功');
      ref.current.reload();
    } else {
      message.error('删除失败');
PurelzMgnead authored
147
    }
PurelzMgnead authored
148
  }
PurelzMgnead authored
149
PurelzMgnead authored
150
151
152
  const exportLoadingDestory = () => {
    message.success('导出成功');
  };
PurelzMgnead authored
153
PurelzMgnead authored
154
155
156
157
158
159
160
161
162
163
  async function toExport() {
    // await getOrderErpOrderStagesExport()
    orderExport(
      '/api/order/erp/orderStages/export',
      '分期订单.xlsx',
      'get',
      {},
      exportLoadingDestory,
    );
  }
PurelzMgnead authored
164
PurelzMgnead authored
165
166
167
168
  const columns: ProColumns<OrderStagesItem>[] = [
    {
      title: '文件编号',
      dataIndex: 'id',
PurelzMgnead authored
169
170
171
172
      width: 100,
      disable: true,
      onFilter: true,
      ellipsis: true,
PurelzMgnead authored
173
174
175
176
177
178
179
180
181
182
183
184
      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',
PurelzMgnead authored
185
186
      width: 100,
      disable: true,
PurelzMgnead authored
187
188
189
190
191
192
      onFilter: true,
      ellipsis: true,
    },
    {
      title: '合同编号',
      dataIndex: 'contract',
PurelzMgnead authored
193
194
      width: 200,
      disable: true,
PurelzMgnead authored
195
196
197
198
199
200
      onFilter: true,
      ellipsis: true,
    },
    {
      title: '供应商名称',
      dataIndex: 'vendor',
PurelzMgnead authored
201
202
      width: 200,
      disable: true,
PurelzMgnead authored
203
204
205
206
207
208
      onFilter: true,
      ellipsis: true,
    },
    {
      title: '终端名称',
      dataIndex: 'terminal',
PurelzMgnead authored
209
210
      width: 200,
      disable: true,
PurelzMgnead authored
211
212
213
214
215
216
      onFilter: true,
      ellipsis: true,
    },
    {
      title: '设备名称',
      dataIndex: 'deviceName',
PurelzMgnead authored
217
218
      width: 200,
      disable: true,
PurelzMgnead authored
219
220
221
222
223
224
225
      onFilter: true,
      ellipsis: true,
    },
    {
      title: '设备型号',
      dataIndex: 'deviceModel',
      hideInSearch: true,
PurelzMgnead authored
226
227
228
      width: 200,
      disable: true,
      onFilter: true,
PurelzMgnead authored
229
230
231
232
233
234
      ellipsis: true,
    },
    {
      title: '数量',
      dataIndex: 'count',
      hideInSearch: true,
PurelzMgnead authored
235
236
237
      width: 100,
      disable: true,
      onFilter: true,
PurelzMgnead authored
238
239
240
241
242
243
      ellipsis: true,
    },
    {
      title: '单价',
      dataIndex: 'unitPrice',
      hideInSearch: true,
PurelzMgnead authored
244
245
246
      width: 100,
      disable: true,
      onFilter: true,
PurelzMgnead authored
247
248
249
250
251
252
      ellipsis: true,
    },
    {
      title: '总价',
      dataIndex: 'price',
      hideInSearch: true,
PurelzMgnead authored
253
254
255
      width: 100,
      disable: true,
      onFilter: true,
PurelzMgnead authored
256
257
258
259
260
261
      ellipsis: true,
    },
    {
      title: '合同总金额',
      dataIndex: 'totalPrice',
      hideInSearch: true,
PurelzMgnead authored
262
263
264
      width: 100,
      disable: true,
      onFilter: true,
PurelzMgnead authored
265
266
267
268
269
270
      ellipsis: true,
    },
    {
      title: '付款方式',
      dataIndex: 'payWay',
      hideInSearch: true,
PurelzMgnead authored
271
272
273
      width: 100,
      disable: true,
      onFilter: true,
PurelzMgnead authored
274
275
276
277
278
279
      ellipsis: true,
    },
    {
      title: '附件',
      dataIndex: 'annex',
      hideInSearch: true,
PurelzMgnead authored
280
281
282
      width: 100,
      disable: true,
      onFilter: true,
PurelzMgnead authored
283
284
      ellipsis: true,
      render: (_, record) => {
PurelzMgnead authored
285
286
        if (record.id && record.annex !== null) {
          return <a href={record.annex}>附件文件</a>;
PurelzMgnead authored
287
288
289
290
291
292
293
294
295
296
297
        }
      },
    },
    {
      disable: true,
      title: '备注',
      dataIndex: 'remark',
      filters: true,
      hideInSearch: true,
      onFilter: false,
      ellipsis: true,
PurelzMgnead authored
298
299
300
301
      width: 100,
      disable: true,
      onFilter: true,
      ellipsis: true,
PurelzMgnead authored
302
303
304
305
306
    },
    {
      title: '操作',
      valueType: 'option',
      key: 'option',
PurelzMgnead authored
307
308
309
310
311
      fixed: 'right',
      width: 120,
      disable: true,
      onFilter: true,
      ellipsis: true,
PurelzMgnead authored
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
      render: (_text, record) => {
        if (record?.id) {
          return (
            <>
              <ReadModel currentContract={record.contract}></ReadModel>
              &nbsp;
              <EditorModel
                currentContract={record.contract}
                toReload={reload}
              ></EditorModel>
              &nbsp;
              {/* <a key="delect" target="_blank" rel="noopener noreferrer" onClick={() => { toDelete([record.dId]) }}>
                                删除
                            </a> */}
              <Comfire currtDid={record.dId} sureDelete={toDelete}></Comfire>
            </>
          );
        }
        return null;
      },
    },
  ];
PurelzMgnead authored
334
PurelzMgnead authored
335
336
337
338
339
340
  return (
    <ProTable<OrderStagesItem>
      className="title-index"
      columnEmptyText=""
      columns={columns}
      cardBordered
PurelzMgnead authored
341
342
      actionRef={ref}
      scroll={{ x: 1400, y: 360 }}
PurelzMgnead authored
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
      request={async (params) => {
        if (
          params.id !== null ||
          params.contract !== null ||
          params.vendor !== null ||
          params.terminal !== null ||
          params.deviceName !== null ||
          params.dateRange !== null
        ) {
          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);
PurelzMgnead authored
457
                }
PurelzMgnead authored
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
              }
            }
            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);
PurelzMgnead authored
560
                }
PurelzMgnead authored
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
              }
            }
            return {
              data: orderStagesList || [],
            };
          }
        }
      }}
      editable={{
        type: 'multiple',
      }}
      columnsState={{
        persistenceKey: 'pro-table-singe-demos',
        persistenceType: 'localStorage',
        defaultValue: {
          option: { fixed: 'right', disable: true },
PurelzMgnead authored
577
        },
PurelzMgnead authored
578
579
580
581
582
583
584
585
586
587
        // onChange(value) {
        // },
      }}
      rowKey="dId"
      search={{
        labelWidth: 'auto',
      }}
      options={{
        setting: {
          listsHeight: 800,
PurelzMgnead authored
588
        },
PurelzMgnead authored
589
590
591
592
593
594
595
596
597
598
      }}
      form={{
        syncToUrl: (values, type) => {
          if (type === 'get') {
            return {
              ...values,
              created_at: [values.startTime, values.endTime],
            };
          }
          return values;
PurelzMgnead authored
599
        },
PurelzMgnead authored
600
601
602
603
604
605
606
607
608
609
610
611
612
613
      }}
      pagination={{
        pageSize: 10,
      }}
      dateFormatter="string"
      headerTitle={[]}
      toolBarRender={() => [
        <>
          <AddModel toReload={reload}></AddModel>
          <UploadModel toReload={reload}></UploadModel>
          <Button
            type="primary"
            onClick={() => {
              toExport();
PurelzMgnead authored
614
            }}
PurelzMgnead authored
615
616
617
618
619
620
621
622
623
          >
            <VerticalAlignTopOutlined />
            导出
          </Button>
        </>,
      ]}
    />
  );
};