Blame view

src/pages/Order/components/OrderDrawer.tsx 43.6 KB
zhongnanhuang authored
1
import { RESPONSE_CODE } from '@/constants/enum';
2
import {
3
4
  postKingdeeRepCustomer,
  postKingdeeRepCustomerDetail,
5
  postKingdeeRepMaterial,
zhongnanhuang authored
6
7
  postKingdeeRepMaterialUnit,
  postKingdeeRepMeasureUnit,
8
  postServiceOrderAddOrder,
zhongnanhuang authored
9
  postServiceOrderAfterSalesQuerySnapshotOrder,
10
  postServiceOrderApplyAfterSales,
11
  postServiceOrderQuerySalesCode,
zhongnanhuang authored
12
  postServiceOrderUpdateOrder,
13
} from '@/services';
zhongnanhuang authored
14
import {
15
16
  FloatAdd,
  FloatMul,
zhongnanhuang authored
17
18
19
20
  enumToSelect,
  getAliYunOSSFileNameFromUrl,
  getUserInfo,
} from '@/utils';
21
import { getTeacherCustomFieldNumber } from '@/utils/kingdee';
sanmu authored
22
23
24
25
import {
  DrawerForm,
  FormListActionType,
  ProCard,
26
  ProFormDateTimePicker,
27
  ProFormDigit,
sanmu authored
28
  ProFormList,
29
  ProFormSelect,
sanmu authored
30
  ProFormText,
31
  ProFormTextArea,
zhongnanhuang authored
32
  ProFormUploadDragger,
sanmu authored
33
} from '@ant-design/pro-components';
zhongnanhuang authored
34
import { Button, Form, message } from 'antd';
zhongnanhuang authored
35
import { cloneDeep } from 'lodash';
zhongnanhuang authored
36
import { useEffect, useRef, useState } from 'react';
37
import {
38
  AFTE_SALES_PLAN_OPTIONS,
39
  INVOCING_STATUS_OPTIONS,
zhongnanhuang authored
40
  INVOCING_STATUS_OPTIONS_OLD,
zhongnanhuang authored
41
  PAYEE_OPTIONS,
42
43
44
45
  PAYMENT_CHANNEL_OPTIONS,
  PAYMENT_METHOD_OPTIONS,
  PRODUCT_BELONG_DEPARTMENT_OPTIONS,
} from '../constant';
46
import KingdeeCustomerModal from './KingdeeCustomerModal';
sanmu authored
47
48
export default ({ onClose, data, subOrders, orderOptType }) => {
zhongnanhuang authored
49
  const [invoicingStatus, setInvoicingStatus] = useState('');
50
  const [salesCodeOptions, setSalesCodeOptions] = useState([]);
51
  const [submitBtnLoading, setSubmitBtnLoading] = useState(false);
52
  const [drawerTitle, setDrawerTitle] = useState('');
53
54
55
  const [customer, setCustomer] = useState({});
  const [kingdeeCstomerModalVisible, setKingdeeCstomerModalVisible] =
    useState(false);
zhongnanhuang authored
56
57
58
59
  const [
    productParametersDisabledFlagList,
    setProductParametersDisabledFlagList,
  ] = useState([]);
60
61
62
63
64
65
  // const [productInvStockOptionsList, setProductInvStockOptionsList] = useState(
  //   [],
  // ); //商品的仓库选项
  const [productUnitOptionsList, setProductUnitOptionsList] = useState([]); //商品的单位选项
  const [productCustomerContactOptions, setProductCustomerContactOptions] =
    useState([]); //客户的收货人选项
zhongnanhuang authored
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
  const [form] = Form.useForm<{
    salesCode: '';
    customerName: '';
    customerContactNumber: '';
    institution: '';
    institutionContactName: '';
    customerShippingAddress: '';
    totalPayment: '';
    paymentChannel: '';
    paymentMethod: '';
    productBelongBusiness: '';
    invoicingStatus: '';
    invoiceIdentificationNumber: '';
    invoicingTime: '';
    bank: '';
    bankAccountNumber: '';
    deleteSubOrderLists: [];
83
    filePaths: [];
zhongnanhuang authored
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
    notes: '';
    list: [
      {
        productCode: '';
        productName: '';
        quantity: '';
        productPrice: '';
        parameters: '';
        subOrderPayment: '';
        unit: '';
        serialNumber: '';
        notes: '';
      },
    ];
  }>();
zhongnanhuang authored
100
101
  let copyData = cloneDeep(data);
zhongnanhuang authored
102
  let originSubOrders = cloneDeep(subOrders);
103
104
105
106
107
108
109
  /**
   * 获取当前的操作类型boolean值
   * @param type 操作类型,如果与当前匹配返回true
   */
  function optType(type: string) {
    return orderOptType === type;
  }
zhongnanhuang authored
110
zhongnanhuang authored
111
  /**
zhongnanhuang authored
112
   * 获取销售代码枚举,在复制和编辑的时候判断是否为旧的代码
zhongnanhuang authored
113
   */
114
  const getSalesCodeOptions = async () => {
zhongnanhuang authored
115
116
    const res = await postServiceOrderQuerySalesCode();
    let options = res.data?.map((item) => {
117
118
119
120
121
      return {
        label: item.userName,
        value: item.userName,
        number: item.number,
      };
122
123
    });
    setSalesCodeOptions(options);
zhongnanhuang authored
124
125
126
127
128

    if (optType('copy') || optType('edit')) {
      let includeFlag = false;
      //销售代码校验,如果是旧的销售代码,则提示并清空
      for (let option of options) {
zhongnanhuang authored
129
        if (option.value === copyData.salesCode) {
zhongnanhuang authored
130
131
132
          includeFlag = true;
        }
      }
133
      console.log(includeFlag);
zhongnanhuang authored
134
135
136
137
138
      if (!includeFlag) {
        form.resetFields(['salesCode']);
        message.warning('检测到销售代码为旧的,已清空,请重新选择');
      }
    }
139
140
  };
zhongnanhuang authored
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
   * 选择客户后自动为收货人Select添加选项,填充课题组和单位信息
   * @param option 客户选项
   */
  async function autoFillCustomerContactSelectOptions(customerId: any) {
    //查询单位详细信息
    let res = await postKingdeeRepCustomerDetail({
      data: {
        id: customerId,
      },
    });

    //erp客户名称
    form.setFieldValue('erpCustomerName', res?.name);

    //重新设置当前option
    form.setFieldValue('erpCustomerId', {
      label: res?.name,
      value: res?.id,
      id: res?.id,
    });

    //查询客户自定义字段,课题组
    let entity_number = await getTeacherCustomFieldNumber();

    //在单位详细信息中拿到自定义字段的值
    let customField = res?.custom_field;
    if (customField) {
      let teacherName = customField[entity_number];
      //填充到课题组老师表单字段中
      form.setFieldValue('institutionContactName', teacherName);
    }

    //单位名称,从客户名称中获取,客户名称规则<单位名称>-<联系人名称和电话>
    let namePortions = res?.name?.split('-');
    if (namePortions && namePortions.length >= 2) {
      form.setFieldValue('institution', namePortions[0]);
    }

    //如果原来的收货信息没有包含在这次查询出来的收货人选项中,那么清除原来的收货人信息
    let existFlag = false;

    //填充收货人选项
    let newProductCustomerContactOptions = res?.bomentity?.map((item) => {
      let address =
        item.contact_person + ',' + item.mobile + ',' + item.contact_address;
      if (address === data.contactAddress) {
        existFlag = true;
      }
      return { ...item, label: address, value: address };
    });

    setProductCustomerContactOptions(newProductCustomerContactOptions);

    if (!existFlag) {
      //清空原来的收货人信息
      form.setFieldValue('customerShippingAddress', undefined);
      form.setFieldValue('customerContactNumber', undefined);
      form.setFieldValue('customerName', undefined);
      form.setFieldValue('erpCustomerAddress', undefined);
    }
  }

  /**
   * 回显金蝶信息
   */
  async function showKindeeInfo() {
208
    console.log(copyData);
209
    //客户信息
210
    if (copyData.customerId) {
211
      //客户回显
212
      autoFillCustomerContactSelectOptions(copyData.customerId);
213
214
215
    }

    //商品单位回显
216
    let list = copyData?.subOrderInformationLists;
217
218
219
220
221
222
223
224
225
226
227
228
    if (list) {
      let newProductUnitOptionsList = [...productUnitOptionsList];
      for (let i = 0; i < list.length; i++) {
        newProductUnitOptionsList[i] = [
          { label: list[i].unit, value: list[i].unitId },
        ];
      }
      setProductUnitOptionsList(newProductUnitOptionsList);
    }
  }

  /**
zhongnanhuang authored
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
   * 构建回显数据
   */
  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']);
    }
280
    getSalesCodeOptions();
281
282
283
    if (!optType('after-sales-check')) {
      showKindeeInfo();
    }
zhongnanhuang authored
284
285
  }
286
287
288
289
  /**
   * 获取旧订单信息
   * @param id
   */
zhongnanhuang authored
290
291
292
293
294
295
296
297
298
299
300
  async function getOldOrderData(id: any) {
    let res = await postServiceOrderAfterSalesQuerySnapshotOrder({
      data: {
        mainOrderId: id,
      },
    });

    copyData = res.data.mainOrder;
    copyData.subOrderInformationLists = res.data.subOrders;
    originSubOrders = res.data.subOrders;
301
302
303
304
305
306
    //客户显示
    form.setFieldValue('erpCustomerId', {
      label: copyData.erpCustomerName,
      value: copyData.customerId,
    });
zhongnanhuang authored
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
    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 = [];
322
zhongnanhuang authored
323
  useEffect(() => {
324
325
326
327
328
329
330
331
332
333
334
335
336
    //弹窗标题
    if (optType('add')) {
      setDrawerTitle('新增订单');
    }
    if (optType('copy')) {
      setDrawerTitle('复制订单');
    }
    if (optType('edit')) {
      setDrawerTitle('修改订单');
    }
    if (optType('after-sales')) {
      setDrawerTitle('申请售后');
    }
zhongnanhuang authored
337
338
    if (optType('after-sales-check')) {
      setDrawerTitle('订单信息');
339
    }
340
341
342
    if (optType('order-change-normal')) {
      setDrawerTitle('申请修改');
    }
zhongnanhuang authored
343
  }, []);
344
345
346
347
348
349
  const actionRef = useRef<
    FormListActionType<{
      name: string;
    }>
  >();
sanmu authored
350
351
352
353
354
355
356
357
358
  useEffect(() => {
    form.setFieldsValue({ ...data });
    //如果是新建,需要清空list
    if (optType('add')) {
      form.resetFields(['list']);
    }
  }, [data]);
zhongnanhuang authored
359
360
361
362
363
  /**
   *
   * @param option 商品名称所对应的商品数据
   * @param currentRowData list中当前行的数据
   */
364
365
366
367
368
  async function autoFillProductInfo(
    option: any,
    currentRowData: any,
    index: any,
  ) {
zhongnanhuang authored
369
370
371
372
373
    let newProductParametersDisabledFlagList = [
      ...productParametersDisabledFlagList,
    ];
    let newProductUnitOptionsList = [...productUnitOptionsList];
    newProductUnitOptionsList[index] = [];
374
zhongnanhuang authored
375
376
377
378
    //是新增商品
    if (option.type === 'add') {
      //商品参数开放权限可以编辑
      newProductParametersDisabledFlagList[index] = false;
379
zhongnanhuang authored
380
381
382
383
384
385
386
387
388
389
      //清空商品信息
      let copyList = form.getFieldValue('list');
      let currentData = copyList[index];
      currentData.productCode = undefined;
      currentData.parameters = undefined;
      currentData.unit = undefined;
      currentData.subOrderPayment = undefined;
      currentData.quantity = undefined;
      currentData.notes = undefined;
      currentData.productPrice = undefined;
390
391
392

      currentData.unitId = undefined;
      currentData.materialId = undefined;
zhongnanhuang authored
393
      form.setFieldValue('list', copyList);
394
395
396
397
398
399
400
401
402
403
404
      //todo 查询计量单价列表
      if (false) {
        let res = await postKingdeeRepMeasureUnit({ data: {} });
        if (res && res?.rows) {
          for (let row of res?.rows) {
            newProductUnitOptionsList[index].push({
              label: row.name,
              value: row.id,
            });
          }
zhongnanhuang authored
405
406
407
408
409
410
411
412
413
        }
      }
    } else {
      //选择的是已有的商品,进行内容自动填充
      let copyList = form.getFieldValue('list');
      let currentData = copyList[index];
      currentData.productCode = option?.number;
      currentData.parameters = option?.model;
      currentData.unit = option?.base_unit_name;
414
zhongnanhuang authored
415
416
      //商品id
      currentData.materialId = option?.id;
417
zhongnanhuang authored
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
      //单位
      currentData.unit = option.base_unit_name;
      currentData.unitId = option.base_unit_id;

      form.setFieldValue('list', copyList);

      //商品所在的仓库选项填充
      // let res = await postKingdeeRepMaterialStock({
      //   data: {
      //     material_id: option.id,
      //   },
      // });
      // let newProductInvStockOptionsList = [...productInvStockOptionsList];
      // newProductInvStockOptionsList[index] = res?.rows?.map((item) => {
      //   return { label: item.inv_stock, value: item.inv_stock_id };
      // });
      // setProductInvStockOptionsList(newProductInvStockOptionsList);

      //商品单位填充,查询商品单位列表
      let res = await postKingdeeRepMaterialUnit({
        data: { material_id: option.id },
      });
      if (res && res.rows) {
        for (let row of res.rows) {
          newProductUnitOptionsList[index].push({
            label: row.unit_name,
            value: row.unit_id,
          });
        }
      }
      //商品参数不允许编辑
      newProductParametersDisabledFlagList[index] = true;
    }

    setProductParametersDisabledFlagList(newProductParametersDisabledFlagList);
453
    setProductUnitOptionsList(newProductUnitOptionsList);
454
  }
zhongnanhuang authored
455
456
457
458
459

  /**
   * 选择收货人后自动填充信息
   * @param option 收货人信息
   */
460
461
462
463
464
465
  async function autoFillCustomerInfo(option: any) {
    form.setFieldValue('customerShippingAddress', option.contact_address);
    form.setFieldValue('customerContactNumber', option.mobile);
    form.setFieldValue('customerName', option.contact_person);

    //erp收货地址:需要与客户联系人中的地址一样:姓名,手机号,地址
466
    form.setFieldValue('contactAddress', option.value);
467
468
469
470
471
472
473
  }

  /**
   * 填充销售代表的信息
   * @param option
   */
  function autoFillSalesInfo(option: any) {
474
    console.log(option);
475
    //销售代表对应职员编码填充
476
    form.setFieldValue('empNumber', option.number);
zhongnanhuang authored
477
478
479
  }

  /**
480
   * todo 选择商品单位后自动填充
zhongnanhuang authored
481
482
483
   * @param option
   * @param index
   */
484
485
486
487
488
489
  // function autoFillUnit(option: any, index: any) {
  //   let copyList = form.getFieldValue('list');
  //   let currentData = copyList[index];
  //   currentData.unit = option?.label;
  //   form.setFieldValue('list', copyList);
  // }
zhongnanhuang authored
490
491

  /**
zhongnanhuang authored
492
493
494
495
496
497
498
499
500
   * 计算子订单金额
   * @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;
501
502
    quantity = parseInt(quantity);
    productPrice = parseFloat(productPrice);
zhongnanhuang authored
503
504
    listMeta.subOrderPayment = FloatMul(quantity, productPrice);
zhongnanhuang authored
505
    let list = form.getFieldValue('list');
506
    list[listMeta?.index].subOrderPayment = FloatMul(quantity, productPrice);
zhongnanhuang authored
507
508
509
510
511
512
513
514
515
516
517
    form.setFieldValue('list', list);
  }

  /**
   * 计算支付总额
   */
  function computeTotalPayment() {
    let list = form.getFieldValue('list');
    let totalPayment = 0;
    list?.forEach((subOrder: any) => {
      let subOrderPayment = subOrder?.subOrderPayment;
518
519
      if (subOrderPayment !== '' && subOrderPayment !== undefined) {
        totalPayment = FloatAdd(subOrderPayment, totalPayment);
zhongnanhuang authored
520
521
522
523
524
      }
    });
    form.setFieldValue('totalPayment', totalPayment);
  }
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
  /**
   * 检查客户是否可以编辑
   * @returns
   */
  const customerEditable = () => {
    let erpCustomerId = form.getFieldValue('erpCustomerId');
    if (
      optType('after-sales-check') ||
      erpCustomerId === null ||
      erpCustomerId === undefined
    ) {
      return false;
    }

    return true;
  };
zhongnanhuang authored
542
543
544
545
546
547
548
549
  useEffect(() => {
    if (optType('after-sales-check')) {
      getOldOrderData(data.id);
    } else {
      buildOrderData();
    }
  }, []);
sanmu authored
550
  return (
551
552
553
554
555
556
557
558
    <>
      <DrawerForm<{
        deleteSubOrderLists: any;
        name: string;
        company: string;
      }>
        open
        width="35%"
559
        title={drawerTitle}
560
561
562
563
564
565
566
        resize={{
          onResize() {
            console.log('resize!');
          },
          maxWidth: window.innerWidth * 0.8,
          minWidth: 400,
        }}
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
        submitter={{
          render: (props) => {
            return [
              <Button
                key="cancel"
                onClick={() => {
                  onClose();
                }}
              >
                取消
              </Button>,
              <Button
                key="ok"
                type="primary"
                loading={submitBtnLoading}
                disabled={optType('after-sales-check')}
                onClick={() => {
                  setSubmitBtnLoading(true);
                  props.submit();
586
                  setSubmitBtnLoading(false);
587
588
589
590
591
592
593
                }}
              >
                确定
              </Button>,
            ];
          },
        }}
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
        form={form}
        autoFocusFirstInput
        drawerProps={{
          destroyOnClose: true,
          maskClosable: false,
        }}
        submitTimeout={2000}
        onFinish={async (values) => {
          let res = {};
          //附件处理
          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;
zhongnanhuang authored
612
613
          });
614
615
616
          values.list = list;
          values.institution = values.institution?.trim();
          values.institutionContactName = values.institutionContactName?.trim();
617
618
619
          if (typeof values.erpCustomerId !== 'string') {
            values.erpCustomerId = values.erpCustomerId?.id;
620
621
          }
622
          //新增
623
624
          if (optType('add') || optType('copy')) {
            res = await postServiceOrderAddOrder({ data: values });
625
          }
626
627
628
629
630
631
          //修改或者申请售后或者申请修改
          if (
            optType('edit') ||
            optType('after-sales') ||
            optType('order-change-normal')
          ) {
632
            //计算已删除的子订单id
633
634
635
636
637
638
639
640

            let originIds = [];
            if (originSubOrders !== undefined && originSubOrders.length > 0) {
              originIds = originSubOrders?.map((item) => {
                return item.id;
              });
            }
641
642
643
644
645
            const curIds = form.getFieldValue('list')?.map((item) => {
              return item.id;
            });
            let diff = originIds.filter((item) => !curIds.includes(item));
            values.deleteSubOrderLists = diff;
zhongnanhuang authored
646
647
648
649
            if (optType('edit')) {
              res = await postServiceOrderUpdateOrder({ data: values });
            }
650
651
652
            values.applyType = orderOptType;
            if (optType('after-sales') || optType('order-change-normal')) {
653
654
655
656
657
              values.filePaths = values.filePaths?.map((file) => {
                return { url: file.response.data[0] };
              });
              res = await postServiceOrderApplyAfterSales({ data: values });
            }
658
          }
659
660
661
662
663
664
665
          if (res.result === RESPONSE_CODE.SUCCESS) {
            message.success(res.message);
            // 不返回不会关闭弹框
            onClose(true);
            return true;
          }
666
667

          setSubmitBtnLoading(false);
668
669
670
        }}
        onOpenChange={(val) => {
          return !val && onClose();
zhongnanhuang authored
671
        }}
672
      >
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
        {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') },
              }}
            />
          </>
        ) : (
          ''
        )}
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
        <h2>订单基本信息</h2>
        <ProFormText
          key="id"
          name="id"
          width="lg"
          disabled
          label="id"
          placeholder="id"
          hidden
        />
        <ProFormText
          key="empNumber"
          name="empNumber"
          width="lg"
          label="销售职员编码"
          placeholder="销售职员编码"
          hidden
        />
        <ProFormSelect
          name="salesCode"
          key="salesCode"
          width="lg"
          showSearch
          label="销售代表"
          placeholder="请输入销售代表"
          rules={[{ required: true, message: '销售代表必填' }]}
          options={salesCodeOptions}
          onChange={(_, option) => {
            autoFillSalesInfo(option);
          }}
736
          disabled={optType('after-sales-check')}
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
        />
        <ProFormText
          key="erpCustomerName"
          name="erpCustomerName"
          hidden
        ></ProFormText>

        <ProFormText
          key="contactAddress"
          name="contactAddress"
          hidden
        ></ProFormText>

        <ProFormSelect
          name="erpCustomerId"
          key="erpCustomerId"
          width="lg"
          showSearch
755
          disabled={optType('after-sales-check')}
zhongnanhuang authored
756
          tooltip="空格将作为或条件。例如输入[北京 广东],那么查找出来的将是包含[北京]或者包含[广东]的搜索结果"
757
758
759
760
          label={
            <>
              <span>客户</span>
              <span
761
762
763
764
                className={
                  'pl-2 text-xs cursor-pointer ' +
                  (customerEditable() ? 'text-[#1677ff]' : 'text-gray-400')
                }
765
                onClick={() => {
766
767
768
                  if (!customerEditable()) {
                    return;
                  }
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
                  let customerId = form.getFieldValue('erpCustomerId');
                  if (typeof customerId === 'string') {
                    setCustomer({ ...customer, id: customerId });
                  } else {
                    setCustomer({ ...customer, id: customerId.id });
                  }
                  setKingdeeCstomerModalVisible(true);
                }}
              >
                编辑客户信息
              </span>
            </>
          }
          placeholder="请选择客户"
          rules={[{ required: true, message: '客户必填' }]}
          onChange={(_, option) => {
            //新增客户
786
787
            if (option?.type === 'add') {
              setCustomer({ name: option?.name });
788
789
790
              setKingdeeCstomerModalVisible(true);
              return;
            }
791
            autoFillCustomerContactSelectOptions(option?.id);
792
793
          }}
          initialValue={{
794
795
796
            label: copyData?.erpCustomerName,
            value: copyData?.customerId,
            id: copyData?.customerId,
797
798
          }}
          fieldProps={{
zhongnanhuang authored
799
800
801
            filterOption() {
              return true;
            },
802
803
804
805
806
807
808
809
810
811
            optionItemRender(item) {
              if (item.type === 'add') {
                return (
                  <div title={item.name + '(新增客户)'}>
                    <span style={{ color: '#333333' }}>{item.name}</span>
                    {' | '}
                    <span style={{ color: 'orange' }}>自定义</span>
                  </div>
                );
              }
zhongnanhuang authored
812
              return (
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
                <div
                  title={
                    item.name +
                    ' | ' +
                    item.customerContactNumber +
                    ' | ' +
                    (item.customerShippingAddress === undefined
                      ? '无地址'
                      : item.customerShippingAddress) +
                    ' | ' +
                    item.institutionContactName +
                    ' | ' +
                    item.institution
                  }
                >
828
                  <span style={{ color: '#333333' }}>{item.name}</span>
zhongnanhuang authored
829
830
                </div>
              );
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
            },
          }}
          debounceTime={1000}
          request={async (value, {}) => {
            const keywords = value.keyWords;
            const res = await postKingdeeRepCustomer({
              data: { search: keywords },
            });
            let options = res?.rows?.map((c: any) => {
              return {
                ...c,
                label: c.name,
                value: c.id,
                key: c.id,
              };
            });

            //第一个商品默认为要新增客户
            if (keywords.trim() !== '') {
              options.unshift({
                name: keywords,
                type: 'add',
                label: keywords,
                value: 3.1415926,
                key: keywords,
              });
zhongnanhuang authored
857
            }
zhongnanhuang authored
858
859

            console.log(options);
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
            return options;
          }}
        />
        <ProFormSelect
          key="customerName"
          label="收货人"
          width="lg"
          showSearch
          name="customerName"
          placeholder="请选择收货人"
          rules={[{ required: true, message: '收货人必填' }]}
          onChange={(_, option) => {
            autoFillCustomerInfo(option);
          }}
          initialValue={data.contactAddress}
          options={productCustomerContactOptions}
876
          disabled={optType('after-sales-check')}
877
        />
zhongnanhuang authored
878
879
        <ProFormText
zhongnanhuang authored
880
          width="lg"
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
          key="customerContactNumber"
          name="customerContactNumber"
          label="联系方式"
          placeholder="请输入联系方式"
          rules={[{ required: true, message: '联系方式必填' }]}
          disabled
        />
        <ProFormText
          width="lg"
          key="institution"
          name="institution"
          label="单位"
          placeholder="请输入单位"
          rules={[{ required: true, message: '单位必填' }]}
          disabled
        />
        <ProFormText
          width="lg"
          key="institutionContactName"
          name="institutionContactName"
          label="课题组"
          placeholder="请输入课题组"
          rules={[{ required: true, message: '课题组必填' }]}
          disabled
        />
        <ProFormTextArea
          width="lg"
          key="customerShippingAddress"
          name="customerShippingAddress"
          label="收货地址"
          placeholder="请输入收货地址"
          rules={[{ required: true, message: '收货地址必填' }]}
          disabled
        />
        <div id="total-payment">
          <ProFormDigit
            name="totalPayment"
            width="lg"
            key="totalPayment"
            label="支付总额(¥)"
            rules={[{ required: true, message: '支付总额必填' }]}
            tooltip="点击计算,合计所有子订单金额"
            fieldProps={{
              addonAfter: (
                <Button
                  className="rounded-l-none"
                  type="primary"
928
                  disabled={optType('after-sales-check')}
929
930
931
932
933
934
                  onClick={computeTotalPayment}
                >
                  计算
                </Button>
              ),
            }}
935
            disabled={optType('after-sales-check')}
936
937
          />
        </div>
938
939
940
941
        <ProFormSelect
          placeholder="请输入支付渠道"
          name="paymentChannel"
zhongnanhuang authored
942
          width="lg"
943
944
945
946
          key="paymentChannel"
          label="支付渠道"
          options={enumToSelect(PAYMENT_CHANNEL_OPTIONS)}
          rules={[{ required: true, message: '支付渠道必填' }]}
947
          disabled={optType('after-sales-check')}
948
949
950
951
952
953
954
955
956
        />
        <ProFormSelect
          placeholder="请输入支付方式"
          name="paymentMethod"
          width="lg"
          key="paymentMethod"
          label="支付方式"
          options={enumToSelect(PAYMENT_METHOD_OPTIONS)}
          rules={[{ required: true, message: '支付方式必填' }]}
957
          disabled={optType('after-sales-check')}
958
959
960
961
962
963
964
965
        />
        <ProFormSelect
          placeholder="选择是否需要开票"
          name="invoicingStatus"
          width="lg"
          key="invoicingStatus"
          label="是否需要开票"
          options={getInvoicingSelect()}
966
          disabled={optType('after-sales-check')}
967
968
969
970
971
972
973
          onChange={(_, option) => {
            setInvoicingStatus(option.value);
            if (option.value === 'UN_INVOICE') {
              form.setFieldValue('invoiceIdentificationNumber', undefined);
              form.setFieldValue('bank', undefined);
              form.setFieldValue('bankAccountNumber', undefined);
            }
zhongnanhuang authored
974
          }}
975
976
          rules={[{ required: true, message: '是否需要开票必填' }]}
        />
977
978

        <ProFormSelect
zhongnanhuang authored
979
          placeholder="收款单位"
980
981
982
          name="receivingCompany"
          width="lg"
          key="receivingCompany"
zhongnanhuang authored
983
984
          showSearch
          label="开票收款单位"
985
          tooltip="财务开票将依据这个字段,选择对应的公司开票"
zhongnanhuang authored
986
          options={enumToSelect(PAYEE_OPTIONS)}
987
988
989
990
          disabled={optType('after-sales-check')}
          hidden={invoicingStatus === 'UN_INVOICE'}
        />
zhongnanhuang authored
991
        <ProFormTextArea
992
993
994
995
          width="lg"
          name="invoiceIdentificationNumber"
          label="开票信息"
          key="invoiceIdentificationNumber"
996
          disabled={optType('after-sales-check')}
997
998
999
1000
1001
1002
1003
1004
          hidden={invoicingStatus === 'UN_INVOICE'}
          placeholder="请输入开票信息"
          rules={[
            {
              required: invoicingStatus === 'UN_INVOICE' ? false : true,
              message: '开票信息必填',
            },
          ]}
zhongnanhuang authored
1005
        />
1006
1007
1008
1009
1010
1011
        {getUserInfo().roleSmallVO?.code === 'admin' ? (
          <ProFormDateTimePicker
            width="lg"
            key="invoicingTime"
            name="invoicingTime"
1012
            disabled={optType('after-sales-check')}
1013
1014
1015
1016
1017
1018
1019
1020
            hidden={invoicingStatus === 'UN_INVOICE'}
            label="开票时间"
            placeholder="请输入开票时间"
          />
        ) : (
          ''
        )}
        <ProFormText
zhongnanhuang authored
1021
          width="lg"
1022
1023
1024
          name="bank"
          key="bank"
          label="开户银行"
1025
          disabled={optType('after-sales-check')}
zhongnanhuang authored
1026
          hidden={invoicingStatus === 'UN_INVOICE'}
1027
          placeholder="请输入开户银行"
zhongnanhuang authored
1028
        />
1029
1030
1031
1032
1033
1034
        <ProFormText
          width="lg"
          key="bankAccountNumber"
          name="bankAccountNumber"
          hidden={invoicingStatus === 'UN_INVOICE'}
          label="银行账号"
1035
          disabled={optType('after-sales-check')}
1036
1037
1038
1039
1040
1041
1042
          placeholder="请输入银行账号"
        />
        <ProFormTextArea
          width="lg"
          name="notes"
          label="备注"
          key="notes"
1043
          disabled={optType('after-sales-check')}
1044
1045
1046
          placeholder="请输入备注"
          rules={[
            {
1047
1048
              max: 1000, // 最大长度为1000个字符
              message: '备注不能超过1000个字符',
1049
1050
            },
          ]}
zhongnanhuang authored
1051
        />
1052
1053
1054
        <h2>商品信息</h2>
        <ProFormList
1055
1056
          creatorButtonProps={{ disabled: optType('after-sales-check') }}
          deleteIconProps={!optType('after-sales-check')}
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
          name="list"
          label=""
          copyIconProps={false} //复制按钮不显示
          initialValue={[
            {
              productCode: '',
              productName: '',
              quantity: '',
              productPrice: '',
              parameters: '',
              subOrderPayment: '',
            },
          ]}
          actionGuard={{
1071
            beforeRemoveRow: async () => {
1072
              return new Promise((resolve) => {
1073
1074
1075
                let list = form.getFieldValue('list');
                if (list && list.length === 1) {
                  message.error('至少需要保留一个商品');
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
                  resolve(false);
                  return;
                }
                resolve(true);
              });
            },
          }}
          itemRender={(doms, listMeta) => {
            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];
            return (
              <ProCard
                bordered
                extra={doms.action}
                title={'商品' + (listMeta.index + 1)}
                style={{
                  marginBlockEnd: 8,
                }}
              >
                {[
                  <ProFormText
                    key={'material' + listMeta.index}
                    name="materialId"
                    hidden
                  ></ProFormText>,
                  <ProFormSelect
                    key="key"
                    label="商品名称"
                    width="lg"
                    showSearch
                    name="productName"
1119
                    disabled={optType('after-sales-check')}
1120
                    placeholder="请搜索商品"
zhongnanhuang authored
1121
                    tooltip="空格将作为或条件。例如输入[极片 电池],那么查找出来的将是包含[极片]或者包含[电池]的搜索结果"
1122
1123
1124
1125
1126
1127
1128
1129
1130
                    rules={[{ required: true, message: '商品名称必填' }]}
                    onChange={(_, option) => {
                      autoFillProductInfo(option, listMeta, listMeta.index);
                    }}
                    initialValue={{
                      label: listMeta?.record?.productName,
                      value: listMeta?.record?.materialId,
                    }}
                    fieldProps={{
zhongnanhuang authored
1131
1132
1133
                      filterOption() {
                        return true;
                      },
1134
1135
1136
1137
1138
                      optionItemRender(item) {
                        if (item.type === 'add') {
                          return (
                            <div title={item.name + '(新增商品信息)'}>
                              <span style={{ color: '#333333' }}>
zhongnanhuang authored
1139
                                {item.label}
1140
1141
1142
1143
1144
1145
                              </span>
                              {' | '}
                              <span style={{ color: 'orange' }}>新增商品</span>
                            </div>
                          );
                        }
zhongnanhuang authored
1146
                        return (
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
                          <div
                            title={
                              item.label +
                              ' | ' +
                              (item.model === undefined
                                ? '无参数'
                                : item.model) +
                              ' | ' +
                              item.base_unit_name
                            }
                          >
zhongnanhuang authored
1158
                            <span style={{ color: '#333333' }}>
1159
                              {item.label}
zhongnanhuang authored
1160
1161
                            </span>
                            {' | '}
1162
1163
                            <span style={{ color: '#339999' }}>
                              {item.model === undefined ? '无参数' : item.model}
zhongnanhuang authored
1164
1165
                            </span>
                            {' | '}
1166
1167
1168
1169
1170
                            <span style={{ color: '#666666' }}>
                              {item.base_unit_name === undefined
                                ? '无单位'
                                : item.base_unit_name}
                            </span>
zhongnanhuang authored
1171
1172
                          </div>
                        );
1173
1174
1175
1176
1177
1178
1179
                      },
                    }}
                    debounceTime={1000}
                    request={async (value) => {
                      const keywords = value.keyWords;
                      const res = await postKingdeeRepMaterial({
                        data: { search: keywords },
zhongnanhuang authored
1180
                      });
1181
1182
1183
1184
1185
1186
1187
                      let options = res?.rows?.map((p: any) => {
                        return {
                          ...p,
                          label: p.name,
                          value: p.id + '|' + p.name,
                          key: p.id,
                        };
zhongnanhuang authored
1188
                      });
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
                      //第一个商品默认为要新增的商品
                      if (keywords.trim() !== '') {
                        options.unshift({
                          productName: keywords,
                          type: 'add',
                          label: keywords,
                          value: 13 + '|' + keywords,
                          key: keywords,
                        });
                      }
                      return options;
                    }}
                  />,
                  <ProFormText
1204
1205
1206
1207
1208
1209
1210
1211
1212
                    key="orderStatus"
                    name="orderStatus"
                    width="lg"
                    disabled
                    label="orderStatus"
                    placeholder="orderStatus"
                    hidden
                  />,
                  <ProFormText
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
                    key={'productCode' + listMeta.index}
                    width="lg"
                    name="productCode"
                    disabled
                    label={
                      <>
                        <span>商品编码</span>
                        <span className="pl-2 text-xs text-gray-400">
                          新增商品时,商品编码由系统自动生成
                        </span>
                      </>
zhongnanhuang authored
1224
                    }
1225
                    placeholder="未输入商品名称"
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
                  />,
                  // <ProFormSelect
                  //   key="inv_stock"
                  //   placeholder="请选择仓库"
                  //   name="invStockId"
                  //   width="lg"
                  //   label="仓库"
                  //   options={productInvStockOptionsList[listMeta.index]}
                  // />,
                  <ProFormText
                    key={'parameters' + listMeta.index}
                    width="lg"
                    name="parameters"
                    label="商品参数"
                    placeholder="请输入商品参数"
                    rules={[{ required: true, message: '商品参数必填' }]}
zhongnanhuang authored
1242
1243
                    disabled={
                      productParametersDisabledFlagList[listMeta.index] !==
1244
                        false || optType('after-sales-check')
zhongnanhuang authored
1245
                    }
1246
1247
1248
1249
1250
1251
                  />,
                  <ProFormDigit
                    key={'quantity' + listMeta.index}
                    width="lg"
                    name="quantity"
                    label="商品数量"
zhongnanhuang authored
1252
                    fieldProps={{
1253
1254
1255
1256
                      onChange: (value) => {
                        listMeta.record.quantity = value;
                        computeSubOrderPayment(listMeta);
                      },
zhongnanhuang authored
1257
                    }}
1258
                    placeholder="请输入商品数量"
1259
                    disabled={optType('after-sales-check')}
1260
1261
1262
1263
1264
1265
1266
                    rules={[{ required: true, message: '商品数量必填' }]}
                  />,
                  <ProFormDigit
                    key={'productPrice' + listMeta.index}
                    width="lg"
                    name="productPrice"
                    label="商品单价"
zhongnanhuang authored
1267
                    fieldProps={{
1268
1269
1270
1271
                      onChange: (value) => {
                        listMeta.record.productPrice = value;
                        computeSubOrderPayment(listMeta);
                      },
zhongnanhuang authored
1272
                    }}
1273
                    placeholder="请输入商品单价"
1274
                    disabled={optType('after-sales-check')}
1275
1276
1277
1278
1279
1280
1281
1282
                    rules={[{ required: true, message: '商品单价必填' }]}
                  />,
                  <ProFormText
                    key={'unit' + listMeta.index}
                    width="lg"
                    name="unit"
                    label="商品单位"
                    placeholder="请输入商品单位"
1283
1284
1285
1286
                    disabled={
                      productParametersDisabledFlagList[listMeta.index] !==
                        false || optType('after-sales-check')
                    }
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
                    rules={[{ required: true, message: '商品单位必填' }]}
                  />,

                  <ProFormDigit
                    width="lg"
                    key={'subOrderPayment' + listMeta.index}
                    name="subOrderPayment"
                    label="子订单金额"
                    placeholder="请输入子订单金额"
                    tooltip="商品数量和单价变化后会自动计算子订单金额"
1297
                    disabled={optType('after-sales-check')}
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
                    rules={[{ required: true, message: '子订单金额必填' }]}
                  />,
                  <ProFormSelect
                    key={'productBelongBusiness' + listMeta.index}
                    placeholder="请输入所属事业部"
                    name="productBelongBusiness"
                    width="lg"
                    label="所属事业部"
                    options={enumToSelect(PRODUCT_BELONG_DEPARTMENT_OPTIONS)}
                    initialValue={'EXPERIMENTAL_CONSUMABLES'}
                    rules={[{ required: true, message: '所属事业部必填' }]}
1309
                    disabled={optType('after-sales-check')}
1310
1311
1312
1313
1314
                  />,
                  <ProFormTextArea
                    key={'notes' + listMeta.index}
                    width="lg"
                    name="notes"
1315
                    disabled={optType('after-sales-check')}
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
                    label={
                      <div>
                        <span>备注</span>
                        <span className="pl-2 text-xs text-gray-400">
                          备注将体现在出货单上,请将需要仓管看见的信息写在备注上,例如需要开收据等信息。
                        </span>
                      </div>
                    }
                    placeholder="请输入备注"
                    rules={[
                      {
                        max: 120, // 最大长度为120个字符
                        message: '备注不能超过120个字符',
                      },
                    ]}
                  />,
                  <>
                    <ProFormUploadDragger
                      key={'filePaths' + listMeta.index}
                      label="附件"
                      name="filePaths"
                      action="/api/service/order/fileProcess"
1338
                      disabled={optType('after-sales-check')}
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
                      fieldProps={{
                        headers: {
                          Authorization: localStorage.getItem('token'),
                        },
                        itemFileList,
                      }}
                    />
                  </>,
                ]}
              </ProCard>
            );
          }}
          actionRef={actionRef}
        ></ProFormList>
      </DrawerForm>
      {kingdeeCstomerModalVisible && (
        <KingdeeCustomerModal
          setVisible={setKingdeeCstomerModalVisible}
          data={customer}
          onClose={(customerId: any) => {
            setKingdeeCstomerModalVisible(false);
            //回显已经新建好的客户
            autoFillCustomerContactSelectOptions(customerId);
          }}
        />
      )}
    </>
sanmu authored
1366
1367
  );
};