Blame view

src/pages/Order/components/OrderDrawer.tsx 30.5 KB
zhongnanhuang authored
1
import { RESPONSE_CODE } from '@/constants/enum';
2
3
import {
  postServiceOrderAddOrder,
zhongnanhuang authored
4
  postServiceOrderAfterSalesQuerySnapshotOrder,
5
  postServiceOrderApplyAfterSales,
zhongnanhuang authored
6
  postServiceOrderQueryCustomerNameInformation,
7
  postServiceOrderQueryProductInformation,
8
  postServiceOrderQuerySalesCode,
zhongnanhuang authored
9
  postServiceOrderUpdateOrder,
10
} from '@/services';
zhongnanhuang authored
11
12
13
14
15
import {
  enumToSelect,
  getAliYunOSSFileNameFromUrl,
  getUserInfo,
} from '@/utils';
sanmu authored
16
17
18
19
import {
  DrawerForm,
  FormListActionType,
  ProCard,
20
  ProFormDateTimePicker,
21
  ProFormDigit,
sanmu authored
22
  ProFormList,
23
  ProFormSelect,
sanmu authored
24
  ProFormText,
25
  ProFormTextArea,
zhongnanhuang authored
26
  ProFormUploadDragger,
sanmu authored
27
} from '@ant-design/pro-components';
zhongnanhuang authored
28
import { Button, Form, message } from 'antd';
zhongnanhuang authored
29
import { cloneDeep } from 'lodash';
zhongnanhuang authored
30
import { useEffect, useRef, useState } from 'react';
31
import {
32
  AFTE_SALES_PLAN_OPTIONS,
33
  INVOCING_STATUS_OPTIONS,
zhongnanhuang authored
34
  INVOCING_STATUS_OPTIONS_OLD,
35
36
37
38
  PAYMENT_CHANNEL_OPTIONS,
  PAYMENT_METHOD_OPTIONS,
  PRODUCT_BELONG_DEPARTMENT_OPTIONS,
} from '../constant';
sanmu authored
39
40
export default ({ onClose, data, subOrders, orderOptType }) => {
zhongnanhuang authored
41
  const [invoicingStatus, setInvoicingStatus] = useState('');
42
  const [salesCodeOptions, setSalesCodeOptions] = useState([]);
43
  const [drawerTitle, setDrawerTitle] = useState('');
zhongnanhuang authored
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  const [form] = Form.useForm<{
    salesCode: '';
    customerName: '';
    customerContactNumber: '';
    institution: '';
    institutionContactName: '';
    customerShippingAddress: '';
    totalPayment: '';
    paymentChannel: '';
    paymentMethod: '';
    productBelongBusiness: '';
    invoicingStatus: '';
    invoiceIdentificationNumber: '';
    invoicingTime: '';
    bank: '';
    bankAccountNumber: '';
    deleteSubOrderLists: [];
61
    filePaths: [];
zhongnanhuang authored
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
    notes: '';
    list: [
      {
        productCode: '';
        productName: '';
        quantity: '';
        productPrice: '';
        parameters: '';
        subOrderPayment: '';
        unit: '';
        serialNumber: '';
        notes: '';
      },
    ];
  }>();
zhongnanhuang authored
78
79
  let copyData = cloneDeep(data);
zhongnanhuang authored
80
  let originSubOrders = cloneDeep(subOrders);
81
82
83
84
85
86
87
  /**
   * 获取当前的操作类型boolean值
   * @param type 操作类型,如果与当前匹配返回true
   */
  function optType(type: string) {
    return orderOptType === type;
  }
zhongnanhuang authored
88
zhongnanhuang authored
89
  /**
zhongnanhuang authored
90
   * 获取销售代码枚举,在复制和编辑的时候判断是否为旧的代码
zhongnanhuang authored
91
   */
92
  const getSalesCodeOptions = async () => {
zhongnanhuang authored
93
94
    const res = await postServiceOrderQuerySalesCode();
    let options = res.data?.map((item) => {
95
96
97
      return { label: item.userName, value: item.userName };
    });
    setSalesCodeOptions(options);
zhongnanhuang authored
98
99
100
101
102

    if (optType('copy') || optType('edit')) {
      let includeFlag = false;
      //销售代码校验,如果是旧的销售代码,则提示并清空
      for (let option of options) {
zhongnanhuang authored
103
        if (option.value === copyData.salesCode) {
zhongnanhuang authored
104
105
106
107
108
109
110
111
          includeFlag = true;
        }
      }
      if (!includeFlag) {
        form.resetFields(['salesCode']);
        message.warning('检测到销售代码为旧的,已清空,请重新选择');
      }
    }
112
113
  };
zhongnanhuang authored
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
  /**
   * 构建回显数据
   */
  function buildOrderData() {
    // let mainInfoDisbled = optType('edit');
    if (!optType('add')) {
      //如果是复制,需要开票,不回显是否需要开票字段
      if (optType('copy')) {
        if (copyData.invoicingStatus === 'INVOICED') {
          copyData.invoicingStatus = undefined;

          //复制的时候,如果是不需要开票,要把开票信息清空
          if (copyData.invoicingStatus === 'UN_INVOICE') {
            copyData.invoiceIdentificationNumber = undefined;
          }
        }
      }
      //订单修改和新增的子订单列表命名是list
      copyData.list = copyData.subOrderInformationLists;
      //主订单事业部默认显示子订单第一条的事业部
      copyData.productBelongBusiness = copyData.list[0].productBelongBusiness;
      copyData.paymentMethod = copyData.list[0].paymentMethod;
      copyData.paymentChannel = copyData.list[0].paymentChannel;
      copyData.invoicingStatus = copyData.list[0].invoicingStatus;

      copyData.list = copyData.list?.map((item) => {
        item.filePaths = item.listAnnex?.map((path) => {
          let i = 0;
          return {
            uid: i++,
            name: getAliYunOSSFileNameFromUrl(path),
            status: 'uploaded',
            url: path,
            response: { data: [path] },
          };
        });
        return item;
      });
    }

    if (subOrders !== undefined && subOrders.length > 0) {
      copyData.list = subOrders;
    }

    setInvoicingStatus(copyData.invoicingStatus);

    form.setFieldsValue({ ...copyData });
    //如果是新建,需要清空list
    if (optType('add')) {
      form.resetFields(['list']);
    }
166
    getSalesCodeOptions();
zhongnanhuang authored
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
  }

  async function getOldOrderData(id: any) {
    let res = await postServiceOrderAfterSalesQuerySnapshotOrder({
      data: {
        mainOrderId: id,
      },
    });

    console.log(res);
    copyData = res.data.mainOrder;
    copyData.subOrderInformationLists = res.data.subOrders;
    originSubOrders = res.data.subOrders;

    buildOrderData();
  }

  /**
   *
   * @returns 获取开票选项
   */
  function getInvoicingSelect() {
    if (optType('edit') || optType('after-sales-check')) {
      return enumToSelect(INVOCING_STATUS_OPTIONS_OLD);
    }
    return enumToSelect(INVOCING_STATUS_OPTIONS);
  }

  const fileList: any = [];
196
zhongnanhuang authored
197
  useEffect(() => {
198
199
200
201
202
203
204
205
206
207
208
209
210
    //弹窗标题
    if (optType('add')) {
      setDrawerTitle('新增订单');
    }
    if (optType('copy')) {
      setDrawerTitle('复制订单');
    }
    if (optType('edit')) {
      setDrawerTitle('修改订单');
    }
    if (optType('after-sales')) {
      setDrawerTitle('申请售后');
    }
zhongnanhuang authored
211
212
    if (optType('after-sales-check')) {
      setDrawerTitle('订单信息');
213
    }
zhongnanhuang authored
214
  }, []);
215
216
217
218
219
220
  const actionRef = useRef<
    FormListActionType<{
      name: string;
    }>
  >();
sanmu authored
221
zhongnanhuang authored
222
223
224
225
226
  /**
   *
   * @param option 商品名称所对应的商品数据
   * @param currentRowData list中当前行的数据
   */
227
  function autoFillProductInfo(option: any, currentRowData: any, index: any) {
zhongnanhuang authored
228
    let copyList = form.getFieldValue('list');
229
    let currentData = copyList[index];
230
231
232
    currentData.productCode = option?.productCode;
    currentData.parameters = option?.specifications;
    currentData.unit = option?.unit;
zhongnanhuang authored
233
    form.setFieldValue('list', copyList);
234
  }
zhongnanhuang authored
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

  /**
   * 选择收货人后自动填充信息
   * @param option 收货人信息
   */
  function autoFillCustomerInfo(option: any) {
    form.setFieldValue('institution', option.institution);
    form.setFieldValue('institutionContactName', option.institutionContactName);
    form.setFieldValue(
      'customerShippingAddress',
      option.customerShippingAddress,
    );
    form.setFieldValue('customerContactNumber', option.customerContactNumber);
    form.setFieldValue('customerName', option.customerName);
  }

  /**
   * 计算子订单金额
   * @param listMeta 当前商品信息
   */
  function computeSubOrderPayment(listMeta: any) {
    let quantity = listMeta?.record?.quantity;
    let productPrice = listMeta?.record?.productPrice;
    quantity = quantity === '' || quantity === undefined ? 0 : quantity;
    productPrice =
      productPrice === '' || productPrice === undefined ? 0 : productPrice;

    listMeta.subOrderPayment = quantity * productPrice;
    let list = form.getFieldValue('list');
    list[listMeta?.index].subOrderPayment = quantity * productPrice;
    form.setFieldValue('list', list);
  }

  /**
   * 计算支付总额
   */
  function computeTotalPayment() {
    let list = form.getFieldValue('list');
    let totalPayment = 0;
    list?.forEach((subOrder: any) => {
      let subOrderPayment = subOrder?.subOrderPayment;
      if (subOrderPayment === '' || subOrderPayment === undefined) {
        totalPayment += 0;
      } else {
        totalPayment += subOrderPayment;
      }
    });
    form.setFieldValue('totalPayment', totalPayment);
  }
zhongnanhuang authored
285
286
287
288
289
290
291
292
  useEffect(() => {
    if (optType('after-sales-check')) {
      getOldOrderData(data.id);
    } else {
      buildOrderData();
    }
  }, []);
sanmu authored
293
294
  return (
    <DrawerForm<{
295
      deleteSubOrderLists: any;
sanmu authored
296
297
298
299
      name: string;
      company: string;
    }>
      open
300
      width="35%"
301
      title={drawerTitle}
sanmu authored
302
303
304
305
306
307
308
      resize={{
        onResize() {
          console.log('resize!');
        },
        maxWidth: window.innerWidth * 0.8,
        minWidth: 400,
      }}
zhongnanhuang authored
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
      submitter={{
        render: (props) => {
          return [
            <Button
              key="cancel"
              onClick={() => {
                onClose();
              }}
            >
              取消
            </Button>,
            <Button
              key="ok"
              type="primary"
              disabled={optType('after-sales-check')}
              onClick={() => {
                props.submit();
              }}
            >
              确定
            </Button>,
          ];
        },
      }}
sanmu authored
333
334
335
336
      form={form}
      autoFocusFirstInput
      drawerProps={{
        destroyOnClose: true,
zhongnanhuang authored
337
        maskClosable: false,
sanmu authored
338
339
340
      }}
      submitTimeout={2000}
      onFinish={async (values) => {
341
        let res = {};
zhongnanhuang authored
342
343
344
345
346
347
348
349
350
351
352
353
        //附件处理
        let list = values.list;
        // console.log(list);
        list = list.map((item) => {
          item.filePaths = item.filePaths?.map((file) => {
            console.log(file);
            return { url: file.response.data[0] };
          });
          return item;
        });

        values.list = list;
354
355
356
        values.institution = values.institution?.trim();
        values.institutionContactName = values.institutionContactName?.trim();
357
        //新增
358
        if (optType('add') || optType('copy')) {
359
          res = await postServiceOrderAddOrder({ data: values });
360
361
362
        }
        //修改或者申请售后
        if (optType('edit') || optType('after-sales')) {
363
          //计算已删除的子订单id
zhongnanhuang authored
364
          const originIds = originSubOrders.map((item) => {
365
366
367
368
369
            return item.id;
          });
          const curIds = form.getFieldValue('list')?.map((item) => {
            return item.id;
          });
370
          let diff = originIds.filter((item) => !curIds.includes(item));
371
          values.deleteSubOrderLists = diff;
372
373
374
375
376
377
378
379
380

          if (optType('edit')) {
            res = await postServiceOrderUpdateOrder({ data: values });
          }

          if (optType('after-sales')) {
            values.filePaths = values.filePaths?.map((file) => {
              return { url: file.response.data[0] };
            });
zhongnanhuang authored
381
            res = await postServiceOrderApplyAfterSales({ data: values });
382
          }
zhongnanhuang authored
383
384
        }
385
386
        if (res.result === RESPONSE_CODE.SUCCESS) {
          message.success(res.message);
zhongnanhuang authored
387
          // 不返回不会关闭弹框
zhongnanhuang authored
388
          onClose(true);
zhongnanhuang authored
389
          return true;
zhongnanhuang authored
390
        }
sanmu authored
391
392
      }}
      onOpenChange={(val) => {
sanmu authored
393
        return !val && onClose();
sanmu authored
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
      {optType('after-sales') ? (
        <>
          <h2>售后信息</h2>
          <ProFormSelect
            key="key"
            label="售后方案"
            width="lg"
            showSearch
            name="afterSalesPlan"
            options={enumToSelect(AFTE_SALES_PLAN_OPTIONS)}
            placeholder="请搜索"
            rules={[{ required: true, message: '售后方案必填' }]}
          ></ProFormSelect>
          <ProFormTextArea
            width="lg"
            label="售后原因"
            name="afterSalesNotes"
            rules={[{ required: true, message: '售后原因必填' }]}
          />
          <ProFormUploadDragger
            key="filePaths"
            label="售后附件"
            name="filePaths"
            action="/api/service/order/fileProcess"
            fieldProps={{
              headers: { Authorization: localStorage.getItem('token') },
            }}
          />
        </>
      ) : (
        ''
      )}
sanmu authored
429
430
      <h2>订单基本信息</h2>
      <ProFormText
zhongnanhuang authored
431
        key="id"
zhongnanhuang authored
432
433
434
435
436
437
438
        name="id"
        width="lg"
        disabled
        label="id"
        placeholder="id"
        hidden
      />
zhongnanhuang authored
439
      <ProFormSelect
440
        name="salesCode"
zhongnanhuang authored
441
        key="salesCode"
442
        width="lg"
zhongnanhuang authored
443
        showSearch
444
445
        label="销售代表"
        placeholder="请输入销售代表"
zhongnanhuang authored
446
        rules={[{ required: true, message: '销售代表必填' }]}
447
        options={salesCodeOptions}
zhongnanhuang authored
448
        disabled={optType('after-sales-check')}
449
      />
zhongnanhuang authored
450
      <ProFormSelect
zhongnanhuang authored
451
        key="customerName"
452
        label="收货人"
zhongnanhuang authored
453
454
455
456
        width="lg"
        showSearch
        name="customerName"
        // options={options}
457
        placeholder="请输入收货人"
zhongnanhuang authored
458
        disabled={optType('after-sales-check')}
459
        rules={[{ required: true, message: '收货人必填' }]}
zhongnanhuang authored
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
        onChange={(_, option) => {
          autoFillCustomerInfo(option);
        }}
        fieldProps={{
          optionItemRender(item) {
            if (item.type === 'add') {
              return (
                <div title={item.customerName + '(新增商品信息)'}>
                  <span style={{ color: '#333333' }}>{item.customerName}</span>
                  {' | '}
                  <span style={{ color: 'orange' }}>自定义</span>
                </div>
              );
            }
            return (
              <div
                title={
                  item.customerName +
                  ' | ' +
                  item.customerContactNumber +
                  ' | ' +
                  (item.customerShippingAddress === undefined
                    ? '无地址'
                    : item.customerShippingAddress) +
                  ' | ' +
                  item.institutionContactName +
                  ' | ' +
                  item.institution
                }
              >
                <span style={{ color: '#333333' }}>{item.customerName}</span>
                {' | '}
                <span style={{ color: '#339999' }}>
                  {item.customerContactNumber === undefined
                    ? '无电话号码'
                    : item.customerContactNumber}
                </span>
                {' | '}
                <span style={{ color: '#666666' }}>
                  {item.customerShippingAddress === undefined
                    ? '无地址'
                    : item.customerShippingAddress}
                </span>
                {' | '}
                <span style={{ color: '#666666' }}>
                  {item.institutionContactName === undefined
506
                    ? '无课题组'
zhongnanhuang authored
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
                    : item.institutionContactName}
                </span>
                {' | '}
                <span style={{ color: '#666666' }}>
                  {item.institution === undefined ? '无单位' : item.institution}
                </span>
              </div>
            );
          },
        }}
        request={async (value, { params }) => {
          const keywords = value.keyWords;
          const { data } = await postServiceOrderQueryCustomerNameInformation({
            data: { customerName: keywords },
            params: params,
          });
          let options = data.map((c: any) => {
            return {
              ...c,
              label: c.customerName,
              value: c.id,
              key: c.id,
            };
          });

          //第一个商品默认为要新增的商品
          if (keywords.trim() !== '') {
            options.unshift({
              customerName: keywords,
              type: 'add',
              label: keywords,
              value: 3.1415926,
              key: keywords,
            });
          }
          return options;
        }}
544
545
546
      />
      <ProFormText
        width="lg"
zhongnanhuang authored
547
        key="customerContactNumber"
548
        name="customerContactNumber"
549
550
        label="联系方式"
        placeholder="请输入联系方式"
551
        rules={[{ required: true, message: '联系方式必填' }]}
zhongnanhuang authored
552
        disabled={optType('after-sales-check')}
553
554
555
      />
      <ProFormText
        width="lg"
zhongnanhuang authored
556
        key="institution"
557
558
559
        name="institution"
        label="单位"
        placeholder="请输入单位"
560
        rules={[{ required: true, message: '单位必填' }]}
zhongnanhuang authored
561
        disabled={optType('after-sales-check')}
sanmu authored
562
      />
563
564
      <ProFormText
        width="lg"
zhongnanhuang authored
565
        key="institutionContactName"
566
        name="institutionContactName"
567
568
569
        label="课题组"
        placeholder="请输入课题组"
        rules={[{ required: true, message: '课题组必填' }]}
zhongnanhuang authored
570
        disabled={optType('after-sales-check')}
571
      />
572
573
      <ProFormTextArea
        width="lg"
zhongnanhuang authored
574
        key="customerShippingAddress"
575
576
577
        name="customerShippingAddress"
        label="收货地址"
        placeholder="请输入收货地址"
578
        rules={[{ required: true, message: '收货地址必填' }]}
zhongnanhuang authored
579
        disabled={optType('after-sales-check')}
580
      />
zhongnanhuang authored
581
582
583
584
      <div id="total-payment">
        <ProFormDigit
          name="totalPayment"
          width="lg"
zhongnanhuang authored
585
          key="totalPayment"
zhongnanhuang authored
586
587
588
          label="支付总额(¥)"
          rules={[{ required: true, message: '支付总额必填' }]}
          tooltip="点击计算,合计所有子订单金额"
zhongnanhuang authored
589
          disabled={optType('after-sales-check')}
zhongnanhuang authored
590
591
592
593
594
595
          fieldProps={{
            addonAfter: (
              <Button
                className="rounded-l-none"
                type="primary"
                onClick={computeTotalPayment}
zhongnanhuang authored
596
                disabled={optType('after-sales-check')}
zhongnanhuang authored
597
598
599
600
601
602
603
604
605
              >
                计算
              </Button>
            ),
          }}
          // disabled={mainInfoDisbled}
        />
      </div>
606
607
608
609
      <ProFormSelect
        placeholder="请输入支付渠道"
        name="paymentChannel"
        width="lg"
zhongnanhuang authored
610
        key="paymentChannel"
611
612
        label="支付渠道"
        options={enumToSelect(PAYMENT_CHANNEL_OPTIONS)}
613
        rules={[{ required: true, message: '支付渠道必填' }]}
zhongnanhuang authored
614
        disabled={optType('after-sales-check')}
615
616
617
618
619
      />
      <ProFormSelect
        placeholder="请输入支付方式"
        name="paymentMethod"
        width="lg"
zhongnanhuang authored
620
        key="paymentMethod"
621
622
        label="支付方式"
        options={enumToSelect(PAYMENT_METHOD_OPTIONS)}
623
        rules={[{ required: true, message: '支付方式必填' }]}
zhongnanhuang authored
624
        disabled={optType('after-sales-check')}
625
626
      />
      <ProFormSelect
zhongnanhuang authored
627
        placeholder="选择是否需要开票"
628
629
        name="invoicingStatus"
        width="lg"
zhongnanhuang authored
630
        key="invoicingStatus"
zhongnanhuang authored
631
        label="是否需要开票"
zhongnanhuang authored
632
        options={getInvoicingSelect()}
zhongnanhuang authored
633
        disabled={optType('after-sales-check')}
zhongnanhuang authored
634
635
        onChange={(_, option) => {
          setInvoicingStatus(option.value);
zhongnanhuang authored
636
637
638
639
640
          if (option.value === 'UN_INVOICE') {
            form.setFieldValue('invoiceIdentificationNumber', undefined);
            form.setFieldValue('bank', undefined);
            form.setFieldValue('bankAccountNumber', undefined);
          }
zhongnanhuang authored
641
        }}
642
        rules={[{ required: true, message: '是否需要开票必填' }]}
643
      />
zhongnanhuang authored
644
645
646
647
      <ProFormText
        width="lg"
        name="invoiceIdentificationNumber"
        label="开票信息"
zhongnanhuang authored
648
        key="invoiceIdentificationNumber"
zhongnanhuang authored
649
        disabled={optType('after-sales-check')}
zhongnanhuang authored
650
        hidden={invoicingStatus === 'UN_INVOICE'}
zhongnanhuang authored
651
652
653
        placeholder="请输入开票信息"
        rules={[
          {
zhongnanhuang authored
654
            required: invoicingStatus === 'UN_INVOICE' ? false : true,
zhongnanhuang authored
655
656
657
658
            message: '开票信息必填',
          },
        ]}
      />
659
zhongnanhuang authored
660
      {getUserInfo().roleSmallVO?.code === 'admin' ? (
zhongnanhuang authored
661
662
        <ProFormDateTimePicker
          width="lg"
zhongnanhuang authored
663
          key="invoicingTime"
zhongnanhuang authored
664
          name="invoicingTime"
zhongnanhuang authored
665
          disabled={optType('after-sales-check')}
zhongnanhuang authored
666
          hidden={invoicingStatus === 'UN_INVOICE'}
zhongnanhuang authored
667
668
669
670
671
672
          label="开票时间"
          placeholder="请输入开票时间"
        />
      ) : (
        ''
      )}
673
674
675
      <ProFormText
        width="lg"
        name="bank"
zhongnanhuang authored
676
        key="bank"
677
        label="开户银行"
zhongnanhuang authored
678
        disabled={optType('after-sales-check')}
zhongnanhuang authored
679
        hidden={invoicingStatus === 'UN_INVOICE'}
680
681
682
683
        placeholder="请输入开户银行"
      />
      <ProFormText
        width="lg"
zhongnanhuang authored
684
        key="bankAccountNumber"
685
        name="bankAccountNumber"
zhongnanhuang authored
686
        hidden={invoicingStatus === 'UN_INVOICE'}
687
        label="银行账号"
zhongnanhuang authored
688
        disabled={optType('after-sales-check')}
689
690
        placeholder="请输入银行账号"
      />
zhongnanhuang authored
691
      <ProFormTextArea
692
693
694
        width="lg"
        name="notes"
        label="备注"
zhongnanhuang authored
695
        key="notes"
zhongnanhuang authored
696
        disabled={optType('after-sales-check')}
697
        placeholder="请输入备注"
zhongnanhuang authored
698
699
700
701
702
703
        rules={[
          {
            max: 120, // 最大长度为120个字符
            message: '备注不能超过120个字符',
          },
        ]}
704
705
706
707
      />

      <h2>商品信息</h2>
      <ProFormList
zhongnanhuang authored
708
        creatorButtonProps={{ disabled: optType('after-sales-check') }}
709
        name="list"
710
        label=""
zhongnanhuang authored
711
        copyIconProps={false} //复制按钮不显示
sanmu authored
712
713
714
715
716
717
718
719
720
721
        initialValue={[
          {
            productCode: '',
            productName: '',
            quantity: '',
            productPrice: '',
            parameters: '',
            subOrderPayment: '',
          },
        ]}
722
        actionGuard={{
723
          beforeRemoveRow: async () => {
724
            return new Promise((resolve) => {
725
726
727
              let list = form.getFieldValue('list');
              if (list?.length === 1) {
                message.error('删除失败,至少要有一个商品');
728
729
730
                resolve(false);
                return;
              }
zhongnanhuang authored
731
              resolve(true);
732
733
734
            });
          },
        }}
zhongnanhuang authored
735
        itemRender={(doms, listMeta) => {
zhongnanhuang authored
736
737
738
739
740
741
742
743
744
745
746
747
748
749
          if (optType('edit')) {
            let i = 0;
            let defaultFileList = listMeta.record?.listAnnex?.map((annex) => {
              return {
                uid: i++,
                name: annex,
                status: 'uploaded',
                url: annex,
                response: { data: [annex] },
              };
            });
            fileList[listMeta.index] = defaultFileList;
          }
          let itemFileList = fileList[listMeta.index];
sanmu authored
750
          return (
751
752
            <ProCard
              bordered
zhongnanhuang authored
753
              extra={doms.action}
zhongnanhuang authored
754
              title={'商品' + (listMeta.index + 1)}
755
756
757
758
              style={{
                marginBlockEnd: 8,
              }}
            >
zhongnanhuang authored
759
760
              {[
                <ProFormSelect
761
                  key="key"
zhongnanhuang authored
762
763
764
765
                  label="商品名称"
                  width="lg"
                  showSearch
                  name="productName"
zhongnanhuang authored
766
                  // options={options}
zhongnanhuang authored
767
                  placeholder="请搜索商品"
768
                  rules={[{ required: true, message: '商品名称必填' }]}
zhongnanhuang authored
769
                  onChange={(_, option) => {
770
                    autoFillProductInfo(option, listMeta, listMeta.index);
zhongnanhuang authored
771
                  }}
zhongnanhuang authored
772
                  disabled={optType('after-sales-check')}
zhongnanhuang authored
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
                  fieldProps={{
                    optionItemRender(item) {
                      if (item.type === 'add') {
                        return (
                          <div title={item.productName + '(新增商品信息)'}>
                            <span style={{ color: '#333333' }}>
                              {item.productName}
                            </span>
                            {' | '}
                            <span style={{ color: 'orange' }}>新增商品</span>
                          </div>
                        );
                      }
                      return (
                        <div
                          title={
                            item.label +
                            ' | ' +
                            (item.specifications === undefined
                              ? '无参数'
                              : item.specifications) +
                            ' | ' +
                            item.unit
                          }
                        >
                          <span style={{ color: '#333333' }}>{item.label}</span>
                          {' | '}
                          <span style={{ color: '#339999' }}>
                            {item.specifications === undefined
                              ? '无参数'
                              : item.specifications}
                          </span>
                          {' | '}
                          <span style={{ color: '#666666' }}>
                            {item.unit === undefined ? '无单位' : item.unit}
                          </span>
                        </div>
                      );
                    },
                  }}
                  request={async (value, { params }) => {
                    const keywords = value.keyWords;
zhongnanhuang authored
815
816
                    const { data } =
                      await postServiceOrderQueryProductInformation({
zhongnanhuang authored
817
818
                        data: { productName: keywords },
                        params: params,
zhongnanhuang authored
819
                      });
zhongnanhuang authored
820
                    let options = data.map((p: any) => {
821
822
823
                      return {
                        ...p,
                        label: p.productName,
zhongnanhuang authored
824
                        value: p.id + '|' + p.productName,
825
826
                        key: p.id,
                      };
zhongnanhuang authored
827
                    });
zhongnanhuang authored
828
829
830
831
832
833
834

                    //第一个商品默认为要新增的商品
                    if (keywords.trim() !== '') {
                      options.unshift({
                        productName: keywords,
                        type: 'add',
                        label: keywords,
zhongnanhuang authored
835
836
                        value: 13 + '|' + keywords,
                        key: keywords,
zhongnanhuang authored
837
838
839
                      });
                    }
                    return options;
zhongnanhuang authored
840
841
                  }}
                />,
zhongnanhuang authored
842
                <ProFormText
zhongnanhuang authored
843
                  key={'productCode' + listMeta.index}
zhongnanhuang authored
844
845
846
847
848
849
                  width="lg"
                  name="productCode"
                  disabled
                  label={
                    <>
                      <span>商品编码</span>
850
                      <span className="pl-2 text-xs text-gray-400">
zhongnanhuang authored
851
852
853
854
855
856
857
                        新增商品时,商品编码由系统自动生成
                      </span>
                    </>
                  }
                  placeholder="未输入商品名称"
                />,
                <ProFormText
zhongnanhuang authored
858
                  key={'parameters' + listMeta.index}
zhongnanhuang authored
859
860
861
862
                  width="lg"
                  name="parameters"
                  label="商品参数"
                  placeholder="请输入商品参数"
zhongnanhuang authored
863
                  disabled={optType('after-sales-check')}
zhongnanhuang authored
864
865
866
                  rules={[{ required: true, message: '商品参数必填' }]}
                />,
                <ProFormDigit
zhongnanhuang authored
867
                  key={'quantity' + listMeta.index}
zhongnanhuang authored
868
869
870
871
872
873
874
875
876
877
                  width="lg"
                  name="quantity"
                  label="商品数量"
                  fieldProps={{
                    onChange: (value) => {
                      listMeta.record.quantity = value;
                      computeSubOrderPayment(listMeta);
                    },
                  }}
                  placeholder="请输入商品数量"
zhongnanhuang authored
878
                  disabled={optType('after-sales-check')}
zhongnanhuang authored
879
880
881
                  rules={[{ required: true, message: '商品数量必填' }]}
                />,
                <ProFormDigit
zhongnanhuang authored
882
                  key={'productPrice' + listMeta.index}
zhongnanhuang authored
883
884
885
886
887
888
889
890
891
892
                  width="lg"
                  name="productPrice"
                  label="商品单价"
                  fieldProps={{
                    onChange: (value) => {
                      listMeta.record.productPrice = value;
                      computeSubOrderPayment(listMeta);
                    },
                  }}
                  placeholder="请输入商品单价"
zhongnanhuang authored
893
                  disabled={optType('after-sales-check')}
zhongnanhuang authored
894
895
896
                  rules={[{ required: true, message: '商品单价必填' }]}
                />,
                <ProFormText
zhongnanhuang authored
897
                  key={'unit' + listMeta.index}
zhongnanhuang authored
898
899
900
901
                  width="lg"
                  name="unit"
                  label="商品单位"
                  placeholder="请输入商品单位"
zhongnanhuang authored
902
                  disabled={optType('after-sales-check')}
zhongnanhuang authored
903
904
905
906
907
                  rules={[{ required: true, message: '商品单位必填' }]}
                />,

                <ProFormDigit
                  width="lg"
zhongnanhuang authored
908
                  key={'subOrderPayment' + listMeta.index}
zhongnanhuang authored
909
910
911
912
                  name="subOrderPayment"
                  label="子订单金额"
                  placeholder="请输入子订单金额"
                  tooltip="商品数量和单价变化后会自动计算子订单金额"
zhongnanhuang authored
913
                  disabled={optType('after-sales-check')}
zhongnanhuang authored
914
915
916
                  rules={[{ required: true, message: '子订单金额必填' }]}
                />,
                <ProFormSelect
zhongnanhuang authored
917
                  key={'productBelongBusiness' + listMeta.index}
zhongnanhuang authored
918
919
920
921
922
923
924
                  placeholder="请输入所属事业部"
                  name="productBelongBusiness"
                  width="lg"
                  label="所属事业部"
                  options={enumToSelect(PRODUCT_BELONG_DEPARTMENT_OPTIONS)}
                  initialValue={'EXPERIMENTAL_CONSUMABLES'}
                  rules={[{ required: true, message: '所属事业部必填' }]}
zhongnanhuang authored
925
                  disabled={optType('after-sales-check')}
zhongnanhuang authored
926
                />,
zhongnanhuang authored
927
                <ProFormTextArea
zhongnanhuang authored
928
                  key={'notes' + listMeta.index}
zhongnanhuang authored
929
930
                  width="lg"
                  name="notes"
zhongnanhuang authored
931
                  disabled={optType('after-sales-check')}
zhongnanhuang authored
932
933
934
935
936
937
938
939
                  label={
                    <div>
                      <span>备注</span>
                      <span className="pl-2 text-xs text-gray-400">
                        备注将体现在出货单上,请将需要仓管看见的信息写在备注上,例如需要开收据等信息。
                      </span>
                    </div>
                  }
zhongnanhuang authored
940
                  placeholder="请输入备注"
zhongnanhuang authored
941
942
943
944
945
946
                  rules={[
                    {
                      max: 120, // 最大长度为120个字符
                      message: '备注不能超过120个字符',
                    },
                  ]}
zhongnanhuang authored
947
                />,
zhongnanhuang authored
948
949
                <>
                  <ProFormUploadDragger
zhongnanhuang authored
950
                    key={'filePaths' + listMeta.index}
zhongnanhuang authored
951
952
953
                    label="附件"
                    name="filePaths"
                    action="/api/service/order/fileProcess"
zhongnanhuang authored
954
                    disabled={optType('after-sales-check')}
zhongnanhuang authored
955
956
957
958
959
960
                    fieldProps={{
                      headers: { Authorization: localStorage.getItem('token') },
                      itemFileList,
                    }}
                  />
                </>,
zhongnanhuang authored
961
              ]}
962
            </ProCard>
sanmu authored
963
964
          );
        }}
965
        actionRef={actionRef}
zhongnanhuang authored
966
      ></ProFormList>
sanmu authored
967
968
969
    </DrawerForm>
  );
};