Blame view

src/pages/Order/OrderWarning/components/OrderDrawer.tsx 64.7 KB
zhongnanhuang authored
1
import { RESPONSE_CODE } from '@/constants/enum';
2
import {
zhongnanhuang authored
3
  postCanrdApiUserAddressList,
4
  postCanrdApiUserDetail,
5
  postCanrdApiUserNowMoneyCheck,
PurelzMgnead authored
6
  postDistrictSelectByLevel,
PurelzMgnead authored
7
8
  postDistrictSelectByNameAndLevel,
  postDistrictSelOrderProvince,
9
  postKingdeeRepCustomerDetail,
10
  postKingdeeRepMaterial,
zhongnanhuang authored
11
12
  postKingdeeRepMaterialUnit,
  postKingdeeRepMeasureUnit,
13
  postPrepaidPhoneAvailableList,
14
  postServiceOrderAddOrder,
zhongnanhuang authored
15
  postServiceOrderAfterSalesQuerySnapshotOrder,
16
  postServiceOrderApplyAfterSales,
17
  postServiceOrderApplyModify,
zhongnanhuang authored
18
  postServiceOrderUpdateOrder,
19
} from '@/services';
zhongnanhuang authored
20
import {
PurelzMgnead authored
21
  enumToSelect,
22
23
  FloatAdd,
  FloatMul,
zhongnanhuang authored
24
25
26
  getAliYunOSSFileNameFromUrl,
  getUserInfo,
} from '@/utils';
27
import { getTeacherCustomFieldNumber } from '@/utils/kingdee';
28
import { getSalesCodeOptions } from '@/utils/order';
PurelzMgnead authored
29
import { getDefaultString } from '@/utils/StringUtil';
sanmu authored
30
31
32
33
import {
  DrawerForm,
  FormListActionType,
  ProCard,
34
  ProFormDateTimePicker,
35
  ProFormDigit,
sanmu authored
36
  ProFormList,
37
  ProFormSelect,
sanmu authored
38
  ProFormText,
39
  ProFormTextArea,
zhongnanhuang authored
40
  ProFormUploadDragger,
sanmu authored
41
} from '@ant-design/pro-components';
PurelzMgnead authored
42
import { Button, Form, message, Modal } from 'antd';
zhongnanhuang authored
43
import { cloneDeep } from 'lodash';
zhongnanhuang authored
44
import { useEffect, useRef, useState } from 'react';
45
import {
46
  AFTE_SALES_PLAN_OPTIONS,
47
  INVOCING_STATUS_OPTIONS,
zhongnanhuang authored
48
  INVOCING_STATUS_OPTIONS_OLD,
zhongnanhuang authored
49
  PAYEE_OPTIONS,
50
51
52
  PAYMENT_CHANNEL_OPTIONS,
  PAYMENT_METHOD_OPTIONS,
  PRODUCT_BELONG_DEPARTMENT_OPTIONS,
zhongnanhuang authored
53
  SHIPPING_WAREHOUSE_OPTIONS,
boyang authored
54
} from '../../constant';
55
import KingdeeCustomerModal from './KingdeeCustomerModal';
sanmu authored
56
57
export default ({ onClose, data, subOrders, orderOptType }) => {
zhongnanhuang authored
58
  const [invoicingStatus, setInvoicingStatus] = useState('');
59
  const [salesCodeOptions] = useState([]);
60
  const [submitBtnLoading, setSubmitBtnLoading] = useState(false);
61
  const [drawerTitle, setDrawerTitle] = useState('');
zhongnanhuang authored
62
  const [hasLocalData, setHasLocalData] = useState(false);
zhongnanhuang authored
63
  // const [customer, setCustomer] = useState({});
zhongnanhuang authored
64
  const [localSaveLoading, setLocalSaveLoading] = useState(false);
65
66
  const [kingdeeCstomerModalVisible, setKingdeeCstomerModalVisible] =
    useState(false);
zhongnanhuang authored
67
68
  const [paymentMethod, setPaymentMethod] = useState('');
  const [customerRequestCount, setCustomerRequestCount] = useState(0);
zhongnanhuang authored
69
70
71
72
  const [
    productParametersDisabledFlagList,
    setProductParametersDisabledFlagList,
  ] = useState([]);
73
74
75
76
  // const [productInvStockOptionsList, setProductInvStockOptionsList] = useState(
  //   [],
  // ); //商品的仓库选项
  const [productUnitOptionsList, setProductUnitOptionsList] = useState([]); //商品的单位选项
PurelzMgnead authored
77
78
79
80
  //省市区
  const [province, setProvince] = useState('');
  const [city, setCity] = useState('');
  const [district, setDistrict] = useState('');
zhongnanhuang authored
81
82
  // const [productCustomerContactOptions, setProductCustomerContactOptions] =
  //   useState([]); //客户的收货人选项
zhongnanhuang authored
83
  const [form] = Form.useForm<{
zhongnanhuang authored
84
    isLocalData: boolean;
zhongnanhuang authored
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
    salesCode: '';
    customerName: '';
    customerContactNumber: '';
    institution: '';
    institutionContactName: '';
    customerShippingAddress: '';
    totalPayment: '';
    paymentChannel: '';
    paymentMethod: '';
    productBelongBusiness: '';
    invoicingStatus: '';
    invoiceIdentificationNumber: '';
    invoicingTime: '';
    bank: '';
    bankAccountNumber: '';
    deleteSubOrderLists: [];
101
    filePaths: [];
zhongnanhuang authored
102
    notes: '';
103
    invoiceFirst: boolean;
zhongnanhuang authored
104
105
106
107
108
109
110
111
112
113
114
115
116
117
    list: [
      {
        productCode: '';
        productName: '';
        quantity: '';
        productPrice: '';
        parameters: '';
        subOrderPayment: '';
        unit: '';
        serialNumber: '';
        notes: '';
      },
    ];
  }>();
118
  const [accountOptions, setAccountOptions] = useState<any>([]);
zhongnanhuang authored
119
zhongnanhuang authored
120
121
  let copyData = cloneDeep(data);
zhongnanhuang authored
122
  let originSubOrders = cloneDeep(subOrders);
123
124
125
126
127
128
129
130
  /**
   * 获取当前的操作类型boolean值
   * @param type 操作类型,如果与当前匹配返回true
   */
  function optType(type: string) {
    return orderOptType === type;
  }
zhongnanhuang authored
131
zhongnanhuang authored
132
  /**
zhongnanhuang authored
133
   * 获取销售代码枚举,在复制和编辑的时候判断是否为旧的代码
zhongnanhuang authored
134
   */
135
136
  const loadSalesCodeOptions = async () => {
    let options = await getSalesCodeOptions();
137
    console.log('options      ', JSON.stringify(options));
zhongnanhuang authored
138
139
140
141
    if (optType('copy') || optType('edit')) {
      let includeFlag = false;
      //销售代码校验,如果是旧的销售代码,则提示并清空
      for (let option of options) {
zhongnanhuang authored
142
        if (option.value === copyData.salesCode) {
zhongnanhuang authored
143
144
145
          includeFlag = true;
        }
      }
zhongnanhuang authored
146
zhongnanhuang authored
147
148
149
150
151
      if (!includeFlag) {
        form.resetFields(['salesCode']);
        message.warning('检测到销售代码为旧的,已清空,请重新选择');
      }
    }
152
153
  };
zhongnanhuang authored
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
   * 选择客户后自动为收货人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;

    //填充收货人选项
zhongnanhuang authored
197
198
199
200
201
202
203
204
    // 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 };
    // });
205
zhongnanhuang authored
206
    // setProductCustomerContactOptions(newProductCustomerContactOptions);
207
208
209
210
211
212
213
214
215
216
217
218
219

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

  /**
   * 回显金蝶信息
   */
zhongnanhuang authored
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
  // async function showKindeeInfo() {
  //   //客户信息
  //   if (copyData.customerId) {
  //     //客户回显
  //     autoFillCustomerContactSelectOptions(copyData.customerId);
  //   }

  //   //商品单位回显
  //   let list = copyData?.subOrderInformationLists;
  //   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);
  //   }
  // }
239
240

  /**
241
242
243
244
245
246
247
248
249
250
251
252
253
254
   * 加载预存账号的options
   */
  async function loadAccountOptions(phone: any) {
    let newAccountOptions = [];
    //预存账号id
    let uid = copyData.prepaidUid;
    let res = await postCanrdApiUserDetail({ data: { uid: uid } });
    if (res && res.result === RESPONSE_CODE.SUCCESS && res.data !== null) {
      let uidDetail = res.data;
      uidDetail.value = uid;
      uidDetail.label = uidDetail.realName;
      newAccountOptions.push(uidDetail);
    }
PurelzMgnead authored
255
    // 查询当前手机号允许使用的预存账号
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
    if (phone) {
      let res = await postPrepaidPhoneAvailableList({ data: { phone: phone } });
      if (res && res.result === RESPONSE_CODE.SUCCESS) {
        let uidDetails = res.data;
        for (let detail of uidDetails) {
          detail.value = detail.uid;
          detail.label = detail.realName;
          newAccountOptions.push(detail);
        }
      }
    }

    console.log(newAccountOptions);
    setAccountOptions(newAccountOptions);
  }

  /**
zhongnanhuang authored
273
274
275
276
277
   * 构建回显数据
   */
  function buildOrderData() {
    // let mainInfoDisbled = optType('edit');
    if (!optType('add')) {
zhongnanhuang authored
278
279
280
281
      if (subOrders !== undefined && subOrders.length > 0) {
        copyData.subOrderInformationLists = subOrders;
      }
zhongnanhuang authored
282
283
284
285
286
287
288
289
290
291
292
293
      //如果是复制,需要开票,不回显是否需要开票字段
      if (optType('copy')) {
        if (copyData.invoicingStatus === 'INVOICED') {
          copyData.invoicingStatus = undefined;

          //复制的时候,如果是不需要开票,要把开票信息清空
          if (copyData.invoicingStatus === 'UN_INVOICE') {
            copyData.invoiceIdentificationNumber = undefined;
          }
        }
      }
      //主订单事业部默认显示子订单第一条的事业部
zhongnanhuang authored
294
295
296
297
298
299
300
301
302
      copyData.productBelongBusiness =
        copyData.subOrderInformationLists[0].productBelongBusiness;
      copyData.paymentMethod =
        copyData.subOrderInformationLists[0].paymentMethod;
      copyData.paymentChannel =
        copyData.subOrderInformationLists[0].paymentChannel;
      copyData.invoicingStatus =
        copyData.subOrderInformationLists[0].invoicingStatus;
zhongnanhuang authored
303
304
305
306
      copyData.customerNameString = copyData.customerName;

      setPaymentMethod(copyData.paymentMethod);
zhongnanhuang authored
307
      //子订单数据处理:子订单在表单中的命名为list
zhongnanhuang authored
308
      let i = 0;
zhongnanhuang authored
309
      let newList = copyData.subOrderInformationLists?.map((item) => {
zhongnanhuang authored
310
311
312
313
314
315
316
317
318
319
320
321
        item.filePaths = item.listAnnex?.map((path) => {
          return {
            uid: i++,
            name: getAliYunOSSFileNameFromUrl(path),
            status: 'uploaded',
            url: path,
            response: { data: [path] },
          };
        });
        return item;
      });
zhongnanhuang authored
322
      copyData['list'] = newList;
zhongnanhuang authored
323
zhongnanhuang authored
324
325
326
327
328
329
330
331
332
333
334
335
336
337
      //发货仓库处理
      for (let listItem of copyData.list) {
        if (listItem.shippingWarehouse === null) {
          listItem.shippingWarehouse = 'DALANG_WAREHOUSE';
        }
      }
      setInvoicingStatus(copyData.invoicingStatus);
      form.setFieldsValue({ ...copyData });
      //如果是新建,需要清空list
      if (optType('add')) {
        form.resetFields(['list']);
      }

      if (!optType('after-sales-check')) {
zhongnanhuang authored
338
        // showKindeeInfo();
zhongnanhuang authored
339
      }
340
341

      loadAccountOptions(form.getFieldValue('customerContactNumber'));
342
    }
zhongnanhuang authored
343
344
  }
345
346
347
348
  /**
   * 获取旧订单信息
   * @param id
   */
zhongnanhuang authored
349
350
351
352
353
354
355
356
357
358
359
  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;
360
361
362
363
364
365
    //客户显示
    form.setFieldValue('erpCustomerId', {
      label: copyData.erpCustomerName,
      value: copyData.customerId,
    });
zhongnanhuang authored
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
    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 = [];
381
zhongnanhuang authored
382
  useEffect(() => {
383
384
385
386
387
388
389
390
391
392
393
394
395
    //弹窗标题
    if (optType('add')) {
      setDrawerTitle('新增订单');
    }
    if (optType('copy')) {
      setDrawerTitle('复制订单');
    }
    if (optType('edit')) {
      setDrawerTitle('修改订单');
    }
    if (optType('after-sales')) {
      setDrawerTitle('申请售后');
    }
zhongnanhuang authored
396
397
    if (optType('after-sales-check')) {
      setDrawerTitle('订单信息');
398
    }
399
400
401
    if (optType('order-change-normal')) {
      setDrawerTitle('申请修改');
    }
zhongnanhuang authored
402
  }, []);
403
404
405
406
407
408
  const actionRef = useRef<
    FormListActionType<{
      name: string;
    }>
  >();
sanmu authored
409
410
411
412
413
414
415
416
417
  useEffect(() => {
    form.setFieldsValue({ ...data });
    //如果是新建,需要清空list
    if (optType('add')) {
      form.resetFields(['list']);
    }
  }, [data]);
zhongnanhuang authored
418
  /**
zhongnanhuang authored
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
   * 所属部门修改事件
   * 如果选择实验耗材事业部,那么发货仓库默认是大朗仓库
   * @param val
   */
  function productBelongBusinessChange(val: any, index: any) {
    if (val === 'EXPERIMENTAL_CONSUMABLES') {
      let list = form.getFieldValue('list');
      let currentData = list[index];
      if (currentData) {
        currentData.shippingWarehouse = 'DALANG_WAREHOUSE';
        form.setFieldValue('list', list);
        message.info('已默认选择大朗仓库');
      }
    }
  }

  /**
zhongnanhuang authored
436
437
438
439
   *
   * @param option 商品名称所对应的商品数据
   * @param currentRowData list中当前行的数据
   */
440
441
442
443
444
  async function autoFillProductInfo(
    option: any,
    currentRowData: any,
    index: any,
  ) {
zhongnanhuang authored
445
446
447
448
449
    let newProductParametersDisabledFlagList = [
      ...productParametersDisabledFlagList,
    ];
    let newProductUnitOptionsList = [...productUnitOptionsList];
    newProductUnitOptionsList[index] = [];
450
zhongnanhuang authored
451
452
453
454
    //是新增商品
    if (option.type === 'add') {
      //商品参数开放权限可以编辑
      newProductParametersDisabledFlagList[index] = false;
455
zhongnanhuang authored
456
457
458
459
460
461
462
463
464
465
      //清空商品信息
      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;
466
467
468

      currentData.unitId = undefined;
      currentData.materialId = undefined;
zhongnanhuang authored
469
      form.setFieldValue('list', copyList);
470
471
472
473
474
475
476
477
478
479
480
      //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
481
482
483
484
485
486
487
488
489
        }
      }
    } else {
      //选择的是已有的商品,进行内容自动填充
      let copyList = form.getFieldValue('list');
      let currentData = copyList[index];
      currentData.productCode = option?.number;
      currentData.parameters = option?.model;
      currentData.unit = option?.base_unit_name;
490
zhongnanhuang authored
491
492
      //商品id
      currentData.materialId = option?.id;
493
zhongnanhuang authored
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
      //单位
      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);
529
    setProductUnitOptionsList(newProductUnitOptionsList);
530
  }
zhongnanhuang authored
531
532
533
534
535

  /**
   * 选择收货人后自动填充信息
   * @param option 收货人信息
   */
536
  async function autoFillCustomerInfo(option: any) {
537
    if (option === undefined || option === null || option.type === 'add') {
zhongnanhuang authored
538
539
540
541
542
      form.setFieldValue('customerShippingAddress', undefined);
      form.setFieldValue('customerContactNumber', undefined);
      form.setFieldValue('institution', undefined);
      form.setFieldValue('institutionContactName', undefined);
      form.setFieldValue('customerShippingAddress', undefined);
543
544
545
546

      if (option !== undefined && option !== null) {
        form.setFieldValue('customerNameString', option.name);
      }
zhongnanhuang authored
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
    } else {
      form.setFieldValue('customerShippingAddress', option.fullAddress);
      form.setFieldValue('customerContactNumber', option.phone);
      form.setFieldValue('institution', option.institution);
      form.setFieldValue(
        'institutionContactName',
        option.institutionContactName,
      );
      form.setFieldValue(
        'customerShippingAddress',
        getDefaultString(option.province) +
          getDefaultString(option.city) +
          getDefaultString(option.district) +
          getDefaultString(option.detail),
      );
      form.setFieldValue('customerNameString', option.realName);
zhongnanhuang authored
563
564

      loadAccountOptions(option.phone);
zhongnanhuang authored
565
    }
566
567

    //erp收货地址:需要与客户联系人中的地址一样:姓名,手机号,地址
zhongnanhuang authored
568
    // form.setFieldValue('contactAddress', option.value);
569
570
571
572
573
574
575
576
  }

  /**
   * 填充销售代表的信息
   * @param option
   */
  function autoFillSalesInfo(option: any) {
    //销售代表对应职员编码填充
577
    form.setFieldValue('empNumber', option.number);
zhongnanhuang authored
578
579
580
  }

  /**
581
   * todo 选择商品单位后自动填充
zhongnanhuang authored
582
583
584
   * @param option
   * @param index
   */
585
586
587
588
589
590
  // 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
591
592

  /**
zhongnanhuang authored
593
594
595
596
597
598
599
600
601
   * 计算子订单金额
   * @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;
602
603
    quantity = parseInt(quantity);
    productPrice = parseFloat(productPrice);
zhongnanhuang authored
604
605
    listMeta.subOrderPayment = FloatMul(quantity, productPrice);
zhongnanhuang authored
606
    let list = form.getFieldValue('list');
607
    list[listMeta?.index].subOrderPayment = FloatMul(quantity, productPrice);
zhongnanhuang authored
608
609
610
611
612
613
614
615
616
617
618
    form.setFieldValue('list', list);
  }

  /**
   * 计算支付总额
   */
  function computeTotalPayment() {
    let list = form.getFieldValue('list');
    let totalPayment = 0;
    list?.forEach((subOrder: any) => {
      let subOrderPayment = subOrder?.subOrderPayment;
619
620
      if (subOrderPayment !== '' && subOrderPayment !== undefined) {
        totalPayment = FloatAdd(subOrderPayment, totalPayment);
zhongnanhuang authored
621
622
623
624
625
      }
    });
    form.setFieldValue('totalPayment', totalPayment);
  }
626
  /**
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
   * 检查用户额度
   * @param option
   */
  const checkAccountMoney = async (uid: any, subPrice: any) => {
    let res = await postCanrdApiUserNowMoneyCheck({
      data: { uid: uid, subPrice: subPrice },
    });
    if (res && res.result === RESPONSE_CODE.SUCCESS && res.data) {
      let data = res.data;
      let isCredit = data.isCredit;
      if (isCredit) {
        return true;
      }

      message.error(
        '用户余额不足,当前预减的金额为:' +
          data.subPrice +
          ',当前账号余额为:' +
          data.nowMoney +
          ',当前账号可赊账额度为:' +
          data.creditLimit,
      );
      return false;
    }

    return false;
  };

  /**
   * 总金额改变触发事件
   * 如果是预存单,需要检查余额
   * @param value
   */
  const totalPaymentChange = (value: any) => {
    let paymentMethod = form.getFieldValue('paymentMethod');
    let prepaidUid = form.getFieldValue('prepaidUid');
    if (
      value &&
      paymentMethod &&
      paymentMethod === 'WITHHOLDING_ADVANCE_DEPOSIT' &&
      prepaidUid
    ) {
      let valid = checkAccountMoney(prepaidUid, value);
      if (!valid) {
        form.setFieldValue('prepaidUid', undefined);
      }
    }
  };

  /**
677
678
679
   * 检查客户是否可以编辑
   * @returns
   */
zhongnanhuang authored
680
681
682
683
684
685
686
687
688
689
690
691
  // const customerEditable = () => {
  //   let erpCustomerId = form.getFieldValue('erpCustomerId');
  //   if (
  //     optType('after-sales-check') ||
  //     erpCustomerId === null ||
  //     erpCustomerId === undefined
  //   ) {
  //     return false;
  //   }

  //   return true;
  // };
692
zhongnanhuang authored
693
  /**
694
695
   * 是否有草稿
   */
zhongnanhuang authored
696
697
  function checkHasLocalData() {
    let preOrderData = localStorage.getItem('preOrderData');
698
699
700
701
    let hasLocalData =
      preOrderData !== null &&
      preOrderData !== undefined &&
      preOrderData !== '';
zhongnanhuang authored
702
703
704
705
706
707
708
709
710
711
    setHasLocalData(hasLocalData);
    return hasLocalData;
  }

  /**
   * 保存表单数据到本地
   */
  function saveFormDataToLocal() {
    let preOrderData = localStorage.getItem('preOrderData');
    let values = form.getFieldsValue();
712
    values.isLocalData = true; //标识为本地草稿数据
zhongnanhuang authored
713
714
715
716
717
    let formData = JSON.stringify(values);

    //检查本地是否已有数据
    if (preOrderData) {
      Modal.confirm({
718
719
        title: '提示',
        content: '检测到本地有订单数据,是否覆盖?',
zhongnanhuang authored
720
        onOk: () => {
721
722
          localStorage.setItem('preOrderData', formData);
          message.success('本地保存成功');
zhongnanhuang authored
723
724
        },
        onCancel: () => {
725
726
727
          message.info('取消保存');
        },
      });
zhongnanhuang authored
728
    } else {
729
730
      localStorage.setItem('preOrderData', formData);
      message.success('本地保存成功');
zhongnanhuang authored
731
732
733
734
735
736
737
738
739
740
741
742
743
    }

    checkHasLocalData();
    setLocalSaveLoading(false);
  }

  /**
   * 使用草稿数据
   */
  function useLocalFormData() {
    let preOrderData = localStorage.getItem('preOrderData');
    if (preOrderData) {
      let formData = JSON.parse(preOrderData);
744
745
746
747
748
      formData.customerName = {
        label: formData.customerNameString,
        value: formData.customerName,
      };
      console.log(formData);
zhongnanhuang authored
749
      form.setFieldsValue(formData);
zhongnanhuang authored
750
      setPaymentMethod(formData.paymentMethod);
zhongnanhuang authored
751
752
753
    }
  }
754
755
  const validateContactNumber = (_: any, value: any) => {
    const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
756
    const phoneRegex = /^\d{1,11}(-\d{1,11})?$/;
757
758
759
760
761
762
763
764
765

    if (emailRegex.test(value) || phoneRegex.test(value)) {
      return Promise.resolve();
    }
    return Promise.reject(
      new Error('联系方式必须是邮箱或手机号格式(不能包含空格等特殊符号)'),
    );
  };
zhongnanhuang authored
766
767
768
  /**
   * 刪除草稿数据
   */
769
770
  function removeLocalFormData() {
    localStorage.removeItem('preOrderData');
zhongnanhuang authored
771
772
  }
zhongnanhuang authored
773
  useEffect(() => {
zhongnanhuang authored
774
    checkHasLocalData();
775
    loadSalesCodeOptions();
zhongnanhuang authored
776
777
778
779
780
781
782
    if (optType('after-sales-check')) {
      getOldOrderData(data.id);
    } else {
      buildOrderData();
    }
  }, []);
sanmu authored
783
  return (
784
785
    <>
      <DrawerForm<{
zhongnanhuang authored
786
        isLocalData: any;
787
788
789
790
791
792
        deleteSubOrderLists: any;
        name: string;
        company: string;
      }>
        open
        width="35%"
793
        title={drawerTitle}
794
795
796
797
798
799
800
        resize={{
          onResize() {
            console.log('resize!');
          },
          maxWidth: window.innerWidth * 0.8,
          minWidth: 400,
        }}
zhongnanhuang authored
801
        onFinishFailed={() => {
802
          message.error('表单项存在错误,请检查');
zhongnanhuang authored
803
804
          setSubmitBtnLoading(false);
        }}
805
806
807
808
809
810
811
812
813
814
815
816
        submitter={{
          render: (props) => {
            return [
              <Button
                key="cancel"
                onClick={() => {
                  onClose();
                }}
              >
                取消
              </Button>,
              <Button
zhongnanhuang authored
817
818
                key="localSave"
                loading={localSaveLoading}
819
                hidden={!optType('add') && !optType('copy')}
zhongnanhuang authored
820
821
822
823
824
825
826
827
                onClick={() => {
                  setLocalSaveLoading(true);
                  saveFormDataToLocal();
                }}
              >
                本地保存
              </Button>,
              <Button
828
829
830
831
832
833
834
835
836
                key="ok"
                type="primary"
                loading={submitBtnLoading}
                disabled={optType('after-sales-check')}
                onClick={() => {
                  setSubmitBtnLoading(true);
                  props.submit();
                }}
              >
zhongnanhuang authored
837
                提交
838
839
840
841
              </Button>,
            ];
          },
        }}
842
843
844
845
846
        form={form}
        autoFocusFirstInput
        drawerProps={{
          destroyOnClose: true,
          maskClosable: false,
847
848
849
850
851
852
853
854
855
856
857
858
          extra: [
            <Button
              key="useLocalData"
              hidden={!hasLocalData}
              type="link"
              onClick={() => {
                useLocalFormData();
              }}
            >
              使用草稿
            </Button>,
          ],
859
860
861
862
863
864
865
866
867
868
869
870
        }}
        submitTimeout={2000}
        onFinish={async (values) => {
          let res = {};
          //附件处理
          let list = values.list;
          // console.log(list);
          list = list.map((item) => {
            item.filePaths = item.filePaths?.map((file) => {
              return { url: file.response.data[0] };
            });
            return item;
zhongnanhuang authored
871
872
          });
873
874
875
          values.list = list;
          values.institution = values.institution?.trim();
          values.institutionContactName = values.institutionContactName?.trim();
zhongnanhuang authored
876
          values.customerName = values.customerNameString.trim();
877
878
          // values.customerShippingAddress =
          //   province + city + district + values.customerShippingAddress;
879
880
881
          if (typeof values.erpCustomerId !== 'string') {
            values.erpCustomerId = values.erpCustomerId?.id;
882
          }
PurelzMgnead authored
883
884
885
          values.province = province;
          values.city = city;
          values.district = district;
886
          //新增
887
888
          if (optType('add') || optType('copy')) {
            res = await postServiceOrderAddOrder({ data: values });
889
          }
890
891
892
893
894
895
          //修改或者申请售后或者申请修改
          if (
            optType('edit') ||
            optType('after-sales') ||
            optType('order-change-normal')
          ) {
896
            //计算已删除的子订单id
897
898
899
900
901
902
903
904

            let originIds = [];
            if (originSubOrders !== undefined && originSubOrders.length > 0) {
              originIds = originSubOrders?.map((item) => {
                return item.id;
              });
            }
905
906
907
908
909
            const curIds = form.getFieldValue('list')?.map((item) => {
              return item.id;
            });
            let diff = originIds.filter((item) => !curIds.includes(item));
            values.deleteSubOrderLists = diff;
zhongnanhuang authored
910
911
            if (optType('edit')) {
PurelzMgnead authored
912
913
914
              values.province = province;
              values.city = city;
              values.district = district;
915
916
              res = await postServiceOrderUpdateOrder({ data: values });
            }
917
918
            values.applyType = orderOptType;
919
            if (optType('after-sales')) {
920
921
922
923
924
              values.filePaths = values.filePaths?.map((file) => {
                return { url: file.response.data[0] };
              });
              res = await postServiceOrderApplyAfterSales({ data: values });
            }
925
926
927
928
929
930
931

            if (optType('order-change-normal')) {
              values.filePaths = values.filePaths?.map((file) => {
                return { url: file.response.data[0] };
              });
              res = await postServiceOrderApplyModify({ data: values });
            }
932
          }
933
934
935
936
937
          if (res.result === RESPONSE_CODE.SUCCESS) {
            message.success(res.message);
            // 不返回不会关闭弹框
            onClose(true);
zhongnanhuang authored
938
939

            //判断保存的数据是否是本地草稿,是的话将草稿删除
940
941
            let isLocalData = form.getFieldValue('isLocalData');
            if (isLocalData) {
zhongnanhuang authored
942
943
944
945
              removeLocalFormData();
              checkHasLocalData();
            }
946
947
            return true;
          }
948
949

          setSubmitBtnLoading(false);
950
951
952
        }}
        onOpenChange={(val) => {
          return !val && onClose();
zhongnanhuang authored
953
        }}
954
      >
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
        {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') },
              }}
            />
          </>
        ) : (
          ''
        )}
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
        <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);
          }}
1018
          disabled={optType('after-sales-check')}
1019
1020
1021
1022
1023
1024
        />
        <ProFormText
          key="erpCustomerName"
          name="erpCustomerName"
          hidden
        ></ProFormText>
zhongnanhuang authored
1025
1026
1027
1028
1029
        <ProFormText
          key="customerNameString"
          name="customerNameString"
          hidden
        ></ProFormText>
1030
1031
1032
1033
1034
1035
1036

        <ProFormText
          key="contactAddress"
          name="contactAddress"
          hidden
        ></ProFormText>
        <ProFormSelect
zhongnanhuang authored
1037
1038
          key="customerName"
          label="收货人"
1039
1040
          width="lg"
          showSearch
zhongnanhuang authored
1041
1042
1043
          name="customerName"
          placeholder="请选择收货人"
          rules={[{ required: true, message: '收货人必填' }]}
1044
          onChange={(_, option) => {
zhongnanhuang authored
1045
            autoFillCustomerInfo(option);
1046
1047
          }}
          fieldProps={{
zhongnanhuang authored
1048
1049
1050
            filterOption() {
              return true;
            },
zhongnanhuang authored
1051
            optionItemRender(item: any) {
1052
1053
1054
1055
1056
1057
1058
1059
1060
              if (item.type === 'add') {
                return (
                  <div title={item.name + '(新增客户)'}>
                    <span style={{ color: '#333333' }}>{item.name}</span>
                    {' | '}
                    <span style={{ color: 'orange' }}>自定义</span>
                  </div>
                );
              }
zhongnanhuang authored
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071

              let title = '';
              let realName = item.realName;
              let phone = item.phone;
              let province = item.province;
              let city = item.city;
              let district = item.district;
              let detail = item.detail;
              let institution = item.institution;
              let institutionContactName = item.institutionContactName;
zhongnanhuang authored
1072
              let address =
zhongnanhuang authored
1073
1074
1075
1076
1077
                getDefaultString(province) +
                getDefaultString(city) +
                getDefaultString(district) +
                getDefaultString(detail);
zhongnanhuang authored
1078
              title =
zhongnanhuang authored
1079
1080
1081
1082
1083
1084
                getDefaultString(realName) +
                '|' +
                getDefaultString(phone) +
                '|' +
                getDefaultString(institution) +
                '|' +
zhongnanhuang authored
1085
1086
1087
1088
                getDefaultString(institutionContactName) +
                '|' +
                address;
zhongnanhuang authored
1089
              return (
zhongnanhuang authored
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
                <div title={title} className="whitespace-normal">
                  <span style={{ color: '#333333' }}>
                    {getDefaultString(realName)}
                  </span>
                  |
                  <span className="text-sky-600">
                    {getDefaultString(phone)}
                  </span>
                  |
                  <span style={{ color: '#333333' }}>
                    {getDefaultString(institution)}
                  </span>
                  |
                  <span style={{ color: '#333333' }}>
                    {getDefaultString(institutionContactName)}
                  </span>
                  |<span className="text-orange-400">{address}</span>
zhongnanhuang authored
1107
1108
                </div>
              );
1109
1110
1111
            },
          }}
          debounceTime={1000}
1112
          request={async (value, {}) => {
1113
            const keywords = value.keyWords;
1114
1115
1116
            if (keywords === '') {
              return [];
            }
zhongnanhuang authored
1117
1118
            const res = await postCanrdApiUserAddressList({
              data: { keywords: keywords },
1119
            });
zhongnanhuang authored
1120
            let options = res?.data?.map((c: any) => {
1121
1122
1123
1124
1125
1126
1127
              return {
                ...c,
                label: c.name,
                value: c.id,
                key: c.id,
              };
            });
PurelzMgnead authored
1128
1129
1130
1131
1132
1133
            console.log(form.getFieldValue('customerShippingAddress'));
            console.log(form.getFieldValue('id'));
            if (form.getFieldValue('id') !== undefined) {
              const resp = await postDistrictSelOrderProvince({
                data: form.getFieldValue('id'),
              });
PurelzMgnead authored
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
              if (resp && resp.data) {
                if (resp.data.province) {
                  setProvince(resp.data.province);
                  form.setFieldValue('province', resp.data.province);
                }
                if (resp.data.city) {
                  setCity(resp.data.city);
                  form.setFieldValue('city', resp.data.city);
                }
                if (resp.data.district) {
                  setDistrict(resp.data.district);
                  form.setFieldValue('district', resp.data.district);
                }
              }
PurelzMgnead authored
1148
1149
              console.log(form.getFieldsValue());
            }
zhongnanhuang authored
1150
            //判断如果是在修改或者复制,那么第一次请求的时候,默认生成当前收货人信息的option
PurelzMgnead authored
1151
zhongnanhuang authored
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
            let realName = form.getFieldValue('customerName');
            let detail = form.getFieldValue('customerShippingAddress');
            let institution = form.getFieldValue('institution');
            let institutionContactName = form.getFieldValue(
              'institutionContactNam',
            );
            if (customerRequestCount === 0) {
              setCustomerRequestCount(1);
              options.push({
                label: realName,
                value: realName,
                key: realName,
                realName: realName,
                detail: detail,
                institution: institution,
                institutionContactName: institutionContactName,
              });
            }
1170
1171
1172
1173
1174
1175
1176
1177
1178
            //第一个商品默认为要新增客户
            if (keywords.trim() !== '') {
              options.unshift({
                name: keywords,
                type: 'add',
                label: keywords,
                value: 3.1415926,
                key: keywords,
              });
zhongnanhuang authored
1179
            }
zhongnanhuang authored
1180
1181
1182
1183
            return options;
          }}
        />
zhongnanhuang authored
1184
1185
        <ProFormText
zhongnanhuang authored
1186
          width="lg"
1187
1188
1189
1190
          key="customerContactNumber"
          name="customerContactNumber"
          label="联系方式"
          placeholder="请输入联系方式"
1191
1192
1193
1194
1195
          fieldProps={{
            onBlur: (v) => {
              loadAccountOptions(v.target.value);
            },
          }}
1196
1197
1198
1199
          rules={[
            { required: true, message: '联系方式必填' },
            { validator: validateContactNumber },
          ]}
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
        />
        <ProFormText
          width="lg"
          key="institution"
          name="institution"
          label="单位"
          placeholder="请输入单位"
          rules={[{ required: true, message: '单位必填' }]}
        />
        <ProFormText
          width="lg"
          key="institutionContactName"
          name="institutionContactName"
          label="课题组"
          placeholder="请输入课题组"
          rules={[{ required: true, message: '课题组必填' }]}
1216
        />
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
        {/*<ProFormSelect
            key={'institutionContactName'}
            width="md"
            showSearch
            name="institutionContactName"
            rules={[{ required: true, message: '请输入课题组名称!' }]}
            request={async (value) => {
              const keywords = value.keyWords;
              const res = await postResearchGroupsNameSet({
                data: {
                  groupName: keywords,
                },
              });
              let options = res?.data?.map((c: any) => {
                return {
                  label: c,
                  value: c,
                  key: c,
                };
              });
              return options;
            }}
            fieldProps={{
              filterOption() {
                return true;
              },
            }}
            debounceTime={1000}
            label="课题组名称"
            placeholder="请输入名称"
        />*/}
PurelzMgnead authored
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
        <div
          style={{
            display: 'flex',
            justifyContent: 'space-between',
            width: 340,
          }}
        >
          <ProFormSelect
            name="province"
            key="province"
            width={100}
            label="省"
PurelzMgnead authored
1260
            allowClear={false}
PurelzMgnead authored
1261
1262
1263
1264
            fieldProps={{
              labelInValue: true,
            }}
            onChange={(value) => {
PurelzMgnead authored
1265
1266
              console.log(value);
PurelzMgnead authored
1267
              if (value !== undefined || value !== null) {
PurelzMgnead authored
1268
1269
                console.log('setProvince');
PurelzMgnead authored
1270
1271
                setProvince(value?.value);
              }
PurelzMgnead authored
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
            }}
            placeholder="请选择"
            rules={[
              {
                required: true,
                message: '请选择!',
              },
            ]}
            request={async () => {
              let province = [];
              let res = await postDistrictSelectByLevel({ data: 1 });
              if (res) {
                res.data.forEach((item) => {
                  province.push({ value: item.district, label: item.district });
                });
              }
              return province;
            }}
          />
          <ProFormSelect
            key={province}
            name="city"
            width={100}
            label="市"
PurelzMgnead authored
1296
            allowClear={false}
PurelzMgnead authored
1297
1298
1299
1300
1301
1302
            disabled={province === ''}
            fieldProps={{
              labelInValue: true,
            }}
            placeholder="请选择"
            onChange={(value) => {
PurelzMgnead authored
1303
1304
1305
              if (value !== undefined || value !== null) {
                setCity(value?.value);
              }
PurelzMgnead authored
1306
1307
1308
1309
1310
1311
1312
1313
            }}
            rules={[
              {
                required: true,
                message: '请选择!',
              },
            ]}
            request={async () => {
PurelzMgnead authored
1314
1315
1316
1317
1318
1319
              let cityOptions = [];
              console.log(form.getFieldValue('id'));
              if (form.getFieldValue('id')) {
                const resp = await postDistrictSelOrderProvince({
                  data: form.getFieldValue('id'),
                });
PurelzMgnead authored
1320
1321
1322
1323
1324
                if (
                  resp.data.province !== null &&
                  resp.data.province !== undefined
                ) {
                  console.log('province is ok');
PurelzMgnead authored
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
                  let res = await postDistrictSelectByNameAndLevel({
                    data: { district: resp.data.province, level: 1 },
                  });
                  if (res && res.data) {
                    cityOptions = res.data.map((item) => ({
                      value: item.district,
                      label: item.district,
                    }));
                  }
                }
              }
PurelzMgnead authored
1336
              if (province !== '') {
PurelzMgnead authored
1337
1338
                console.log(province);
                console.log('province is okk');
PurelzMgnead authored
1339
1340
                let res = await postDistrictSelectByNameAndLevel({
                  data: { district: province, level: 1 },
PurelzMgnead authored
1341
1342
1343
1344
1345
1346
1347
1348
                });
                if (res && res.data) {
                  cityOptions = res.data.map((item) => ({
                    value: item.district,
                    label: item.district,
                  }));
                }
              }
PurelzMgnead authored
1349
              return cityOptions;
PurelzMgnead authored
1350
1351
1352
1353
1354
1355
1356
            }}
          />
          <ProFormSelect
            key={city ? city.toString() : 'district'}
            name="district"
            width={100}
            label="区"
PurelzMgnead authored
1357
            allowClear={false}
PurelzMgnead authored
1358
            onChange={(value) => {
PurelzMgnead authored
1359
1360
1361
              if (value !== undefined || value !== null) {
                setDistrict(value?.value);
              }
PurelzMgnead authored
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
            }}
            disabled={city === ''}
            fieldProps={{
              labelInValue: true,
            }}
            placeholder="请选择"
            rules={[
              {
                required: true,
                message: '请选择!',
              },
            ]}
            request={async () => {
PurelzMgnead authored
1375
1376
1377
1378
1379
              let districtOptions = [];
              if (form.getFieldValue('id')) {
                const resp = await postDistrictSelOrderProvince({
                  data: form.getFieldValue('id'),
                });
PurelzMgnead authored
1380
                if (resp.data.city !== null && resp.data.city !== undefined) {
PurelzMgnead authored
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
                  let res = await postDistrictSelectByNameAndLevel({
                    data: { district: resp.data.city, level: 2 },
                  });
                  if (res && res.data) {
                    districtOptions = res.data.map((item) => ({
                      value: item.district,
                      label: item.district,
                    }));
                  }
                }
              }
PurelzMgnead authored
1392
              if (city !== '') {
PurelzMgnead authored
1393
1394
1395
                let res = await postDistrictSelectByNameAndLevel({
                  data: { district: city, level: 2 },
                });
PurelzMgnead authored
1396
1397
1398
1399
1400
1401
1402
                if (res && res.data) {
                  districtOptions = res.data.map((item) => ({
                    value: item.district,
                    label: item.district,
                  }));
                }
              }
PurelzMgnead authored
1403
              return districtOptions;
PurelzMgnead authored
1404
1405
1406
            }}
          />
        </div>
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
        <ProFormTextArea
          width="lg"
          key="customerShippingAddress"
          name="customerShippingAddress"
          label="收货地址"
          placeholder="请输入收货地址"
          rules={[{ required: true, message: '收货地址必填' }]}
        />
        <div id="total-payment">
          <ProFormDigit
            name="totalPayment"
            width="lg"
            key="totalPayment"
            label="支付总额(¥)"
1421
1422
            rules={[
              { required: true, message: '支付总额必填' },
1423
1424
              {
                validator: (_, value) => {
1425
1426
1427
1428
1429
1430
                  let paymentMethod = form.getFieldValue('paymentMethod');
                  if (
                    value <= 0 &&
                    paymentMethod &&
                    paymentMethod === 'WITHHOLDING_ADVANCE_DEPOSIT'
                  ) {
1431
1432
1433
1434
1435
1436
1437
1438
1439
                    return Promise.reject(
                      new Error(
                        '支付总额必须大于0 (扣预存的订单现在也必须填写实际金额)',
                      ),
                    );
                  }
                  return Promise.resolve();
                },
              },
1440
            ]}
1441
1442
1443
1444
1445
1446
            tooltip="点击计算,合计所有子订单金额"
            fieldProps={{
              addonAfter: (
                <Button
                  className="rounded-l-none"
                  type="primary"
1447
                  disabled={optType('after-sales-check')}
1448
1449
1450
1451
1452
                  onClick={computeTotalPayment}
                >
                  计算
                </Button>
              ),
1453
1454
1455
              onChange: (value: any) => {
                totalPaymentChange(value);
              },
1456
            }}
1457
            disabled={optType('after-sales-check')}
1458
1459
          />
        </div>
1460
1461
1462
1463
        <ProFormSelect
          placeholder="请输入支付渠道"
          name="paymentChannel"
zhongnanhuang authored
1464
          width="lg"
1465
1466
1467
1468
          key="paymentChannel"
          label="支付渠道"
          options={enumToSelect(PAYMENT_CHANNEL_OPTIONS)}
          rules={[{ required: true, message: '支付渠道必填' }]}
1469
          disabled={optType('after-sales-check')}
1470
1471
1472
1473
1474
1475
1476
        />
        <ProFormSelect
          placeholder="请输入支付方式"
          name="paymentMethod"
          width="lg"
          key="paymentMethod"
          label="支付方式"
zhongnanhuang authored
1477
1478
1479
          onChange={(val: any) => {
            setPaymentMethod(val);
          }}
1480
1481
          options={enumToSelect(PAYMENT_METHOD_OPTIONS)}
          rules={[{ required: true, message: '支付方式必填' }]}
1482
          disabled={optType('after-sales-check')}
1483
1484
        />
        <ProFormSelect
zhongnanhuang authored
1485
1486
1487
1488
1489
1490
          name="prepaidUid"
          key="prepaidUid"
          width="lg"
          hidden={paymentMethod !== 'WITHHOLDING_ADVANCE_DEPOSIT'}
          showSearch
          label="预存账号"
1491
1492
1493
1494
1495
1496
1497
1498
1499
          onChange={(value: any) => {
            //检查用户额度
            let valid = checkAccountMoney(
              value,
              form.getFieldValue('totalPayment'),
            );
            if (!valid) {
              form.setFieldValue('prepaidUid', undefined);
            }
zhongnanhuang authored
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
          }}
          placeholder="请选择预存账号"
          rules={[
            {
              required: paymentMethod === 'WITHHOLDING_ADVANCE_DEPOSIT',
              message: '支付方式为扣预存时,预存账号必填',
            },
          ]}
          fieldProps={{
            filterOption() {
              return true;
            },
            optionItemRender(item) {
              let name =
                item.label +
                ' | ' +
                item.institution +
                ' | ' +
                item.nowMoney +
                '¥' +
                ' | ' +
                item.phone;
              return (
                <div title={name}>
                  <span style={{ color: '#333333' }}>{name}</span>
                </div>
              );
            },
          }}
          debounceTime={1000}
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
          // request={async (value, {}) => {
          //   const keywords = value.keyWords;
          //   const res = await postCanrdApiUserList({
          //     data: { keywords: keywords, pageSize: 50 },
          //   });
          //   let options = res?.data?.data?.map((c: any) => {
          //     return {
          //       ...c,
          //       label: c.realName,
          //       value: c.uid,
          //       key: c.uid,
          //     };
          //   });
          //   return options;
          // }}
          options={accountOptions}
zhongnanhuang authored
1546
1547
        />
        <ProFormSelect
1548
1549
1550
1551
1552
1553
          placeholder="选择是否需要开票"
          name="invoicingStatus"
          width="lg"
          key="invoicingStatus"
          label="是否需要开票"
          options={getInvoicingSelect()}
1554
          disabled={optType('after-sales-check')}
1555
1556
1557
1558
1559
1560
          onChange={(_, option) => {
            setInvoicingStatus(option.value);
            if (option.value === 'UN_INVOICE') {
              form.setFieldValue('invoiceIdentificationNumber', undefined);
              form.setFieldValue('bank', undefined);
              form.setFieldValue('bankAccountNumber', undefined);
1561
              form.setFieldValue('invoiceFirst', false);
1562
            }
zhongnanhuang authored
1563
          }}
1564
1565
          rules={[{ required: true, message: '是否需要开票必填' }]}
        />
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
        <ProFormSelect
          placeholder="是否开票后发货"
          name="invoiceFirst"
          width="lg"
          key="invoiceFirst"
          label="是否开票后发货"
          disabled={optType('after-sales-check')}
          hidden={invoicingStatus === 'UN_INVOICE'}
          options={[
            {
              value: true,
              label: '是',
            },
            {
              value: false,
              label: '否',
            },
          ]}
        />
1585
1586

        <ProFormSelect
zhongnanhuang authored
1587
          placeholder="收款单位"
1588
1589
1590
          name="receivingCompany"
          width="lg"
          key="receivingCompany"
zhongnanhuang authored
1591
1592
          showSearch
          label="开票收款单位"
1593
          tooltip="财务开票将依据这个字段,选择对应的公司开票"
zhongnanhuang authored
1594
          options={enumToSelect(PAYEE_OPTIONS)}
1595
1596
1597
1598
          disabled={optType('after-sales-check')}
          hidden={invoicingStatus === 'UN_INVOICE'}
        />
zhongnanhuang authored
1599
        <ProFormTextArea
1600
1601
1602
1603
          width="lg"
          name="invoiceIdentificationNumber"
          label="开票信息"
          key="invoiceIdentificationNumber"
1604
          disabled={optType('after-sales-check')}
1605
1606
1607
1608
1609
1610
1611
1612
          hidden={invoicingStatus === 'UN_INVOICE'}
          placeholder="请输入开票信息"
          rules={[
            {
              required: invoicingStatus === 'UN_INVOICE' ? false : true,
              message: '开票信息必填',
            },
          ]}
zhongnanhuang authored
1613
        />
1614
1615
1616
1617
1618
1619
        {getUserInfo().roleSmallVO?.code === 'admin' ? (
          <ProFormDateTimePicker
            width="lg"
            key="invoicingTime"
            name="invoicingTime"
1620
            disabled={optType('after-sales-check')}
1621
1622
1623
1624
1625
1626
1627
1628
            hidden={invoicingStatus === 'UN_INVOICE'}
            label="开票时间"
            placeholder="请输入开票时间"
          />
        ) : (
          ''
        )}
        <ProFormText
zhongnanhuang authored
1629
          width="lg"
1630
1631
1632
          name="bank"
          key="bank"
          label="开户银行"
1633
          disabled={optType('after-sales-check')}
zhongnanhuang authored
1634
          hidden={invoicingStatus === 'UN_INVOICE'}
1635
          placeholder="请输入开户银行"
zhongnanhuang authored
1636
        />
1637
1638
1639
1640
1641
1642
        <ProFormText
          width="lg"
          key="bankAccountNumber"
          name="bankAccountNumber"
          hidden={invoicingStatus === 'UN_INVOICE'}
          label="银行账号"
1643
          disabled={optType('after-sales-check')}
1644
1645
1646
1647
1648
1649
1650
          placeholder="请输入银行账号"
        />
        <ProFormTextArea
          width="lg"
          name="notes"
          label="备注"
          key="notes"
1651
          disabled={optType('after-sales-check')}
1652
1653
1654
          placeholder="请输入备注"
          rules={[
            {
1655
1656
              max: 1000, // 最大长度为1000个字符
              message: '备注不能超过1000个字符',
1657
            },
1658
1659
1660
1661
1662
            {
              validator: (rule, value) => {
                let totalPayment = form.getFieldValue('totalPayment');
                let list = form.getFieldValue('list');
                let reduce = list.reduce(
曾国涛 authored
1663
                  (sum, item) => FloatAdd(sum, item.subOrderPayment),
1664
1665
1666
1667
1668
1669
1670
1671
                  0,
                );
                if (reduce === totalPayment || value) {
                  return Promise.resolve();
                }
                return Promise.reject(new Error('请填写订单金额不一致的原因'));
              },
            },
1672
          ]}
zhongnanhuang authored
1673
        />
1674
1675
1676
        <h2>商品信息</h2>
        <ProFormList
1677
1678
          creatorButtonProps={{ disabled: optType('after-sales-check') }}
          deleteIconProps={!optType('after-sales-check')}
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
          name="list"
          label=""
          copyIconProps={false} //复制按钮不显示
          initialValue={[
            {
              productCode: '',
              productName: '',
              quantity: '',
              productPrice: '',
              parameters: '',
              subOrderPayment: '',
            },
          ]}
          actionGuard={{
1693
            beforeRemoveRow: async () => {
1694
              return new Promise((resolve) => {
1695
1696
1697
                let list = form.getFieldValue('list');
                if (list && list.length === 1) {
                  message.error('至少需要保留一个商品');
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
                  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"
1741
                    disabled={optType('after-sales-check')}
1742
                    placeholder="请搜索商品"
zhongnanhuang authored
1743
                    tooltip="空格将作为或条件。例如输入[极片 电池],那么查找出来的将是包含[极片]或者包含[电池]的搜索结果"
1744
1745
1746
1747
1748
1749
1750
1751
1752
                    rules={[{ required: true, message: '商品名称必填' }]}
                    onChange={(_, option) => {
                      autoFillProductInfo(option, listMeta, listMeta.index);
                    }}
                    initialValue={{
                      label: listMeta?.record?.productName,
                      value: listMeta?.record?.materialId,
                    }}
                    fieldProps={{
zhongnanhuang authored
1753
1754
1755
                      filterOption() {
                        return true;
                      },
1756
1757
1758
                      optionItemRender(item) {
                        if (item.type === 'add') {
                          return (
1759
                            <div title={item.name + '(新增商品信息)'}>
1760
                              <span style={{ color: '#333333' }}>
zhongnanhuang authored
1761
                                {item.label}
1762
1763
1764
1765
1766
1767
                              </span>
                              {' | '}
                              <span style={{ color: 'orange' }}>新增商品</span>
                            </div>
                          );
                        }
zhongnanhuang authored
1768
                        return (
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
                          <div
                            title={
                              item.label +
                              ' | ' +
                              (item.model === undefined
                                ? '无参数'
                                : item.model) +
                              ' | ' +
                              item.base_unit_name
                            }
                          >
zhongnanhuang authored
1780
                            <span style={{ color: '#333333' }}>
1781
                              {item.label}
zhongnanhuang authored
1782
1783
                            </span>
                            {' | '}
1784
1785
                            <span style={{ color: '#339999' }}>
                              {item.model === undefined ? '无参数' : item.model}
zhongnanhuang authored
1786
1787
                            </span>
                            {' | '}
1788
1789
1790
1791
1792
                            <span style={{ color: '#666666' }}>
                              {item.base_unit_name === undefined
                                ? '无单位'
                                : item.base_unit_name}
                            </span>
zhongnanhuang authored
1793
1794
                          </div>
                        );
1795
1796
1797
1798
1799
1800
1801
                      },
                    }}
                    debounceTime={1000}
                    request={async (value) => {
                      const keywords = value.keyWords;
                      const res = await postKingdeeRepMaterial({
                        data: { search: keywords },
zhongnanhuang authored
1802
                      });
PurelzMgnead authored
1803
1804
                      console.log(res.customerShippingAddress);
1805
1806
1807
1808
1809
1810
1811
                      let options = res?.rows?.map((p: any) => {
                        return {
                          ...p,
                          label: p.name,
                          value: p.id + '|' + p.name,
                          key: p.id,
                        };
zhongnanhuang authored
1812
                      });
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
                      //第一个商品默认为要新增的商品
                      if (keywords.trim() !== '') {
                        options.unshift({
                          productName: keywords,
                          type: 'add',
                          label: keywords,
                          value: 13 + '|' + keywords,
                          key: keywords,
                        });
                      }
                      return options;
                    }}
                  />,
                  <ProFormText
1828
1829
1830
1831
1832
1833
1834
1835
1836
                    key="orderStatus"
                    name="orderStatus"
                    width="lg"
                    disabled
                    label="orderStatus"
                    placeholder="orderStatus"
                    hidden
                  />,
                  <ProFormText
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
                    key={'productCode' + listMeta.index}
                    width="lg"
                    name="productCode"
                    disabled
                    label={
                      <>
                        <span>商品编码</span>
                        <span className="pl-2 text-xs text-gray-400">
                          新增商品时,商品编码由系统自动生成
                        </span>
                      </>
zhongnanhuang authored
1848
                    }
1849
                    placeholder="未输入商品名称"
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
                  />,
                  // <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="请输入商品参数"
zhongnanhuang authored
1865
1866
                    disabled={
                      productParametersDisabledFlagList[listMeta.index] !==
1867
                        false || optType('after-sales-check')
zhongnanhuang authored
1868
                    }
1869
1870
1871
1872
1873
1874
                  />,
                  <ProFormDigit
                    key={'quantity' + listMeta.index}
                    width="lg"
                    name="quantity"
                    label="商品数量"
zhongnanhuang authored
1875
                    fieldProps={{
1876
                      onChange: (value) => {
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
                        // 确保变更后的值为整数
                        const intValue = parseInt(value, 10);
                        if (!isNaN(intValue)) {
                          listMeta.record.quantity = intValue;
                          computeSubOrderPayment(listMeta);
                        }
                      },
                      parser: (value) => {
                        // 将输入的值转换为整数,如果不是合法数字则返回空字符串触发校验错误
                        return value ? parseInt(value, 10) : '';
                      },
                      formatter: (value) => {
                        // 在显示时始终将其格式化为不带小数部分的整数字符串
                        return value ? value.toString() : '';
1891
                      },
zhongnanhuang authored
1892
                    }}
1893
                    placeholder="请输入商品数量"
1894
                    disabled={optType('after-sales-check')}
1895
1896
1897
1898
1899
1900
1901
                    rules={[{ required: true, message: '商品数量必填' }]}
                  />,
                  <ProFormDigit
                    key={'productPrice' + listMeta.index}
                    width="lg"
                    name="productPrice"
                    label="商品单价"
zhongnanhuang authored
1902
                    fieldProps={{
1903
1904
1905
1906
                      onChange: (value) => {
                        listMeta.record.productPrice = value;
                        computeSubOrderPayment(listMeta);
                      },
zhongnanhuang authored
1907
                    }}
1908
                    placeholder="请输入商品单价"
1909
                    disabled={optType('after-sales-check')}
1910
1911
1912
1913
1914
1915
1916
1917
                    rules={[{ required: true, message: '商品单价必填' }]}
                  />,
                  <ProFormText
                    key={'unit' + listMeta.index}
                    width="lg"
                    name="unit"
                    label="商品单位"
                    placeholder="请输入商品单位"
1918
1919
                    disabled={
                      productParametersDisabledFlagList[listMeta.index] !==
1920
                        false || optType('after-sales-check')
1921
                    }
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
                    rules={[{ required: true, message: '商品单位必填' }]}
                  />,

                  <ProFormDigit
                    width="lg"
                    key={'subOrderPayment' + listMeta.index}
                    name="subOrderPayment"
                    label="子订单金额"
                    placeholder="请输入子订单金额"
                    tooltip="商品数量和单价变化后会自动计算子订单金额"
1932
                    disabled={optType('after-sales-check')}
1933
1934
1935
1936
1937
1938
1939
1940
1941
                    rules={[{ required: true, message: '子订单金额必填' }]}
                  />,
                  <ProFormSelect
                    key={'productBelongBusiness' + listMeta.index}
                    placeholder="请输入所属事业部"
                    name="productBelongBusiness"
                    width="lg"
                    label="所属事业部"
                    options={enumToSelect(PRODUCT_BELONG_DEPARTMENT_OPTIONS)}
zhongnanhuang authored
1942
1943
1944
                    onChange={(val: any) => {
                      productBelongBusinessChange(val, listMeta.index);
                    }}
1945
1946
                    initialValue={'EXPERIMENTAL_CONSUMABLES'}
                    rules={[{ required: true, message: '所属事业部必填' }]}
1947
                    disabled={optType('after-sales-check')}
1948
                  />,
zhongnanhuang authored
1949
1950
1951
1952
1953
1954
1955
1956
1957
                  <ProFormSelect
                    key={'shippingWarehouse' + listMeta.index}
                    placeholder="请选择发货仓库"
                    name="shippingWarehouse"
                    width="lg"
                    label="发货仓库"
                    options={enumToSelect(SHIPPING_WAREHOUSE_OPTIONS)}
                    disabled={optType('after-sales-check')}
                  />,
1958
1959
1960
1961
                  <ProFormTextArea
                    key={'notes' + listMeta.index}
                    width="lg"
                    name="notes"
1962
                    disabled={optType('after-sales-check')}
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
                    label={
                      <div>
                        <span>备注</span>
                        <span className="pl-2 text-xs text-gray-400">
                          备注将体现在出货单上,请将需要仓管看见的信息写在备注上,例如需要开收据等信息。
                        </span>
                      </div>
                    }
                    placeholder="请输入备注"
                    rules={[
                      {
zhongnanhuang authored
1974
1975
                        max: 1000, // 最大长度为1000个字符
                        message: '备注不能超过1000个字符',
1976
1977
1978
1979
1980
1981
1982
1983
1984
                      },
                    ]}
                  />,
                  <>
                    <ProFormUploadDragger
                      key={'filePaths' + listMeta.index}
                      label="附件"
                      name="filePaths"
                      action="/api/service/order/fileProcess"
1985
                      disabled={optType('after-sales-check')}
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
                      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
2013
2014
  );
};