Blame view

src/pages/Order/OrderWarning/components/AfterSalesDrawer.tsx 2.69 KB
zhongnanhuang authored
1
2
3
4
5
6
7
8
import { RESPONSE_CODE } from '@/constants/enum';
import { postServiceOrderApplyAfterSales } from '@/services';
import { enumToSelect } from '@/utils';
import {
  DrawerForm,
  ProFormDigit,
  ProFormSelect,
  ProFormTextArea,
9
  ProFormUploadDragger,
zhongnanhuang authored
10
11
} from '@ant-design/pro-components';
import { Form, message } from 'antd';
boyang authored
12
import { AFTE_SALES_PLAN_OPTIONS } from '../../constant';
zhongnanhuang authored
13
14
15
16
export default ({ setVisible, mainOrder, subOrders, onClose }) => {
  let subOrderIds = subOrders?.map((item: { id: any }) => {
    return item.id;
  });
17
zhongnanhuang authored
18
19
20
21
22
23
  let mainOrderId = mainOrder.id;
  const [form] = Form.useForm<{
    afterSalesNotes: string;
    afterSalesPlan: string;
    ids: [];
    totalPayment: number;
24
    filePaths: any[];
zhongnanhuang authored
25
26
27
28
29
30
31
32
33
  }>();

  return (
    <DrawerForm<{
      afterSalesNotes: string;
      afterSalesPlan: string;
      subOrderIds: [];
      totalPayment: number;
      mainId: number;
34
      filePaths: any[];
zhongnanhuang authored
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
    }>
      title="申请售后"
      open
      resize={{
        onResize() {
          console.log('resize!');
        },
        maxWidth: window.innerWidth * 0.8,
        minWidth: 500,
      }}
      form={form}
      autoFocusFirstInput
      drawerProps={{
        destroyOnClose: true,
        onClose: () => {
          setVisible(false);
        },
      }}
      onFinish={async (values) => {
        values.subOrderIds = subOrderIds;
        values.mainId = mainOrderId;
56
57
58
        values.filePaths = values.filePaths?.map((file) => {
          return { url: file.response.data[0] };
        });
zhongnanhuang authored
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
        let res = await postServiceOrderApplyAfterSales({ data: values });
        if (res?.result === RESPONSE_CODE.SUCCESS) {
          message.success(res.message);
          onClose();
        }
      }}
    >
      <ProFormSelect
        key="key"
        label="售后方案"
        width="lg"
        showSearch
        name="afterSalesPlan"
        options={enumToSelect(AFTE_SALES_PLAN_OPTIONS)}
        placeholder="请搜索"
        rules={[{ required: true, message: '售后方案必填' }]}
      ></ProFormSelect>
      <ProFormDigit
        width="lg"
        name="totalPayment"
        label="总金额调整"
        min={0}
zhongnanhuang authored
81
        initialValue={mainOrder.totalPayment}
zhongnanhuang authored
82
83
84
85
86
87
88
89
        rules={[{ required: true, message: '总金额必填' }]}
      />
      <ProFormTextArea
        width="lg"
        label="售后原因"
        name="afterSalesNotes"
        rules={[{ required: true, message: '售后原因必填' }]}
      />
90
91
92
93
94
95
96
97
98
      <ProFormUploadDragger
        key="filePaths"
        label="附件"
        name="filePaths"
        action="/api/service/order/fileProcess"
        fieldProps={{
          headers: { Authorization: localStorage.getItem('token') },
        }}
      />
zhongnanhuang authored
99
100
101
    </DrawerForm>
  );
};