Blame view

src/pages/Order/components/OrderDrawer.tsx 13.4 KB
zhongnanhuang authored
1
import { RESPONSE_CODE } from '@/constants/enum';
2
3
4
5
import {
  postServiceOrderAddOrder,
  postServiceOrderQueryProductInformation,
} from '@/services';
6
import { enumToSelect } from '@/utils';
sanmu authored
7
8
9
10
import {
  DrawerForm,
  FormListActionType,
  ProCard,
11
  ProFormDateTimePicker,
12
  ProFormDigit,
sanmu authored
13
  ProFormList,
14
  ProFormSelect,
sanmu authored
15
  ProFormText,
16
  ProFormTextArea,
sanmu authored
17
} from '@ant-design/pro-components';
sanmu authored
18
import { Form, message } from 'antd';
sanmu authored
19
import { useEffect, useRef } from 'react';
20
21
22
23
24
25
import {
  INVOCING_STATUS_OPTIONS,
  PAYMENT_CHANNEL_OPTIONS,
  PAYMENT_METHOD_OPTIONS,
  PRODUCT_BELONG_DEPARTMENT_OPTIONS,
} from '../constant';
sanmu authored
26
sanmu authored
27
export default ({ onClose, data }) => {
zhongnanhuang authored
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
  const [form] = Form.useForm<{
    salesCode: '';
    customerName: '';
    customerContactNumber: '';
    institution: '';
    institutionContactName: '';
    customerShippingAddress: '';
    totalPayment: '';
    paymentChannel: '';
    paymentMethod: '';
    productBelongBusiness: '';
    invoicingStatus: '';
    invoiceIdentificationNumber: '';
    invoicingTime: '';
    bank: '';
    bankAccountNumber: '';
    notes: '';
    list: [
      {
        productCode: '';
        productName: '';
        quantity: '';
        productPrice: '';
        parameters: '';
        subOrderPayment: '';
        unit: '';
        serialNumber: '';
        notes: '';
      },
    ];
  }>();
59
60
61
62
63
64
  const actionRef = useRef<
    FormListActionType<{
      name: string;
    }>
  >();
  //作为商品行号
sanmu authored
65
66
67
68
69
70
  const rowNumber = useRef(0);

  useEffect(() => {
    form.setFieldsValue({ ...data });
  }, [data]);
zhongnanhuang authored
71
72
73
74
75
76
77
78
79
80
81
82
  /**
   *
   * @param option 商品名称所对应的商品数据
   * @param currentRowData list中当前行的数据
   */
  function autoFillProductInfo(option: any, currentRowData: any) {
    let copyList = form.getFieldValue('list');
    let currentData = copyList[currentRowData.field.key];
    currentData.productCode = option.productCode;
    currentData.parameters = option.specifications;
    currentData.unit = option.unit;
    form.setFieldValue('list', copyList);
83
84
  }
sanmu authored
85
86
87
88
89
90
  return (
    <DrawerForm<{
      name: string;
      company: string;
    }>
      open
91
      width="35%"
sanmu authored
92
      title="新建订单"
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
      initialValues={{
        customerName: '123',
        customerContactNumber: '123',
        institution: '123',
        institutionContactName: '123',
        customerShippingAddress: '123123',
        totalPayment: '12312',
        paymentChannel: 'BANK_TRANSFER',
        paymentMethod: 'PAYMENT_IN_ADVANCE',
        productBelongBusiness: 'EXPERIMENTAL_CONSUMABLES',
        invoicingStatus: 'INVOICED',
        invoiceIdentificationNumber: '12312',
        invoicingTime: '2023-11-29 23:19:15',
        bank: '123',
        bankAccountNumber: '1231',
        notes: '123',
        list: [
          {
            productCode: 'qweq',
            productName: 'qweqwe',
            quantity: '99',
            productPrice: '12313',
            parameters: 'qweq',
            subOrderPayment: '1231',
            unit: 'qweq',
            serialNumber: 'qwewqe',
            notes: 'qweqw',
          },
          {
            productName: 'asdsda',
            productCode: 'dasda',
            parameters: 'sdasa',
            quantity: '99',
            productPrice: '123',
            unit: '123',
            subOrderPayment: '123',
            serialNumber: 'adadas',
          },
        ],
      }}
sanmu authored
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
      resize={{
        onResize() {
          console.log('resize!');
        },
        maxWidth: window.innerWidth * 0.8,
        minWidth: 400,
      }}
      // layout="horizontal"
      // labelCol={{ span: 8 }}
      form={form}
      autoFocusFirstInput
      drawerProps={{
        destroyOnClose: true,
      }}
      submitTimeout={2000}
      onFinish={async (values) => {
zhongnanhuang authored
149
150
151
152
        const data = await postServiceOrderAddOrder({ data: values });
        if (data.result === RESPONSE_CODE.SUCCESS) {
          message.success(data.message);
        }
sanmu authored
153
        // 不返回不会关闭弹框
154
        onClose();
sanmu authored
155
156
157
        return true;
      }}
      onOpenChange={(val) => {
sanmu authored
158
        return !val && onClose();
sanmu authored
159
160
161
162
      }}
    >
      <h2>订单基本信息</h2>
      <ProFormText
163
        name="salesCode"
164
165
166
167
168
        width="lg"
        disabled
        label="销售代表"
        placeholder="请输入销售代表"
        initialValue="JOJO"
169
170
171
172
173
174
175
176
177
178
      />
      <ProFormText
        name="customerName"
        width="lg"
        label="收货人"
        placeholder="请输入收货人"
      />
      <ProFormText
        width="lg"
        name="customerContactNumber"
179
180
        label="联系方式"
        placeholder="请输入联系方式"
181
182
183
      />
      <ProFormText
        width="lg"
184
185
186
        name="institution"
        label="单位"
        placeholder="请输入单位"
sanmu authored
187
      />
188
189
190
191
192
193
      <ProFormText
        width="lg"
        name="institutionContactName"
        label="单位联系人"
        placeholder="请输入单位联系人"
      />
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
      <ProFormTextArea
        width="lg"
        name="customerShippingAddress"
        label="收货地址"
        placeholder="请输入收货地址"
      />
      <ProFormText name="totalPayment" width="lg" label="支付总额(¥)" />
      <ProFormSelect
        placeholder="请输入支付渠道"
        name="paymentChannel"
        width="lg"
        label="支付渠道"
        options={enumToSelect(PAYMENT_CHANNEL_OPTIONS)}
      />
      <ProFormSelect
        placeholder="请输入支付方式"
        name="paymentMethod"
        width="lg"
        label="支付方式"
        options={enumToSelect(PAYMENT_METHOD_OPTIONS)}
      />
      <ProFormSelect
        placeholder="请输入所属事业部"
        name="productBelongBusiness"
        width="lg"
        label="所属事业部"
        options={enumToSelect(PRODUCT_BELONG_DEPARTMENT_OPTIONS)}
      />
      <ProFormSelect
        placeholder="选择是否要开票"
        name="invoicingStatus"
        width="lg"
        label="是否要开票"
        options={enumToSelect(INVOCING_STATUS_OPTIONS)}
      />
229
230
      <ProFormText
        width="lg"
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
        name="invoiceIdentificationNumber"
        label="开票信息"
        placeholder="请输入开票信息"
      />
      <ProFormDateTimePicker
        width="lg"
        name="invoicingTime"
        label="开票时间"
        placeholder="请输入开票时间"
      />
      <ProFormText
        width="lg"
        name="bank"
        label="开户银行"
        placeholder="请输入开户银行"
      />
      <ProFormText
        width="lg"
        name="bankAccountNumber"
        label="银行账号"
        placeholder="请输入银行账号"
      />
      <ProFormText
        width="lg"
        name="notes"
        label="备注"
        placeholder="请输入备注"
258
259
      />
260
      {/* <h2>商品基本信息</h2>
261
      <ProFormText width="lg" name="totalPayment" label="支付总金额" />
262
263
264
265
      <ProFormSelect
        disabled
        placeholder="请输入物流方式"
        name="logisticsMethod"
266
267
        width="lg"
        label="物流方式"
268
269
270
271
272
        request={async () => {
          // 发送请求获取选项数据
          const { data } = await getServiceOrderProvideLogisticsStatus();
          return enumToSelect(data);
        }}
273
274
275
276
277
278
279
      />
      <ProFormText
        width="lg"
        name="paymentStatus"
        label="支付状态"
        placeholder="请输入支付状态"
      />
280
281
282

      <ProFormSelect
        placeholder="请输入支付方式"
283
        name="paymentMethod"
284
        width="lg"
285
        label="支付方式"
286
287
288
289
290
        request={async () => {
          // 发送请求获取选项数据
          const { data } = await getServiceOrderProvidePaymentMethod();
          return enumToSelect(data);
        }}
291
      />
292
293
      <ProFormSelect
        placeholder="请输入支付渠道"
294
        name="paymentChannel"
295
        width="lg"
296
        label="支付渠道"
297
298
299
300
301
        request={async () => {
          // 发送请求获取选项数据
          const { data } = await getServiceOrderProvidePaymentChannel();
          return enumToSelect(data);
        }}
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
      />
      <ProFormText
        width="lg"
        name="paymentTransactionId"
        label="支付流水号"
        placeholder="请输入支付流水号"
      />
      <ProFormText
        width="lg"
        name="invoiceInformation"
        label="发票信息"
        placeholder="请输入发票信息"
      />
      <ProFormText
        width="lg"
        name="invoicingStatus"
        label="开票状态"
        placeholder="请输入开票状态"
      />
      <ProFormText
        width="lg"
        name="productBelongDepartment"
        label="商品所属部门"
        placeholder="请输入商品所属部门"
      />
      <ProFormText
        width="lg"
        name="waybillNumber"
        label="运单号"
        placeholder="请输入运单号"
      />
      <ProFormText
        width="lg"
        name="notes"
        label="备注"
        placeholder="请输入备注"
      />
      <ProFormText
        width="lg"
        name="examineNotes"
        label="审核备注"
        placeholder="请输入审核备注"
      />
      <ProFormText
        width="lg"
        name="orderStatus"
        label="订单状态"
        placeholder="请输入订单状态"
350
      /> */}
351
352
353

      <h2>商品信息</h2>
      <ProFormList
354
        name="list"
355
        label=""
sanmu authored
356
357
358
359
360
361
362
363
364
365
        initialValue={[
          {
            productCode: '',
            productName: '',
            quantity: '',
            productPrice: '',
            parameters: '',
            subOrderPayment: '',
          },
        ]}
366
        actionGuard={{
zhongnanhuang authored
367
          beforeAddRow: async () => {
368
            return new Promise((resolve) => {
sanmu authored
369
              rowNumber.current = 1;
370
371
372
373
374
375
              setTimeout(() => resolve(true), 1000);
            });
          },
          beforeRemoveRow: async (index) => {
            return new Promise((resolve) => {
              if (index === 0) {
zhongnanhuang authored
376
                message.error('第一行数据不能删除');
377
378
379
                resolve(false);
                return;
              }
sanmu authored
380
              rowNumber.current = 1;
381
382
383
              setTimeout(() => {
                resolve(true);
              }, 1000);
384
385
386
            });
          },
        }}
zhongnanhuang authored
387
        itemRender={(doms, listMeta) => {
388
          // const list = actionRef.current?.getList();
sanmu authored
389
          return (
390
391
            <ProCard
              bordered
zhongnanhuang authored
392
              extra={doms.action}
sanmu authored
393
              title={'商品' + rowNumber.current++}
394
395
396
397
              style={{
                marginBlockEnd: 8,
              }}
            >
zhongnanhuang authored
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
              {[
                <ProFormSelect
                  key={listMeta.field.key}
                  label="商品名称"
                  width="lg"
                  showSearch
                  name="productName"
                  placeholder="请搜索商品"
                  onChange={(_, option) => {
                    autoFillProductInfo(option, listMeta);
                  }}
                  request={async (value) => {
                    const { data } =
                      await postServiceOrderQueryProductInformation({
                        data: { productName: value.keyWords },
                      });
                    return data.map((p: any) => {
                      return { ...p, label: p.productName, value: p.id };
                    });
                  }}
                />,
                doms.listDom,
              ]}
421
            </ProCard>
sanmu authored
422
423
          );
        }}
424
425
        actionRef={actionRef}
      >
zhongnanhuang authored
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
        <ProFormText
          width="lg"
          name="productCode"
          disabled
          label="商品编码"
          placeholder="未输入商品名称"
        />
        <ProFormText
          width="lg"
          disabled
          name="parameters"
          label="商品参数"
          placeholder="请输入商品参数"
        />
        <ProFormText
          width="lg"
          name="quantity"
          label="商品数量"
          placeholder="请输入商品数量"
        />
        <ProFormDigit
          width="lg"
          name="productPrice"
          label="商品单价"
          placeholder="请输入商品单价"
        />
        <ProFormText
          width="lg"
          name="unit"
          disabled
          label="价格单位"
          placeholder="请输入价格单位"
        />
459
zhongnanhuang authored
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
        <ProFormDigit
          width="lg"
          name="subOrderPayment"
          label="子订单金额"
          placeholder="请输入子订单金额"
        />
        <ProFormText
          width="lg"
          name="serialNumber"
          label="物流单号"
          placeholder="请输入物流单号"
        />
        <ProFormText
          width="lg"
          name="notes"
          label="备注"
          placeholder="请输入备注"
        />
sanmu authored
478
479
      </ProFormList>
sanmu authored
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
      {/* <ProFormDateRangePicker name="contractTime" label="合同生效时间" /> */}
      {/* <ProForm.Group>
        <ProFormSelect
          options={[
            {
              value: 'chapter',
              label: '盖章后生效',
            },
          ]}
          width="xs"
          name="useMode"
          label="合同约定生效方式"
        />
        <ProFormSelect
          width="xs"
          options={[
            {
              value: 'time',
              label: '履行完终止',
            },
          ]}
          formItemProps={{
            style: {
              margin: 0,
            },
          }}
          name="unusedMode"
          label="合同约定失效效方式"
        />
      </ProForm.Group>
   */}
    </DrawerForm>
  );
};