Blame view

src/pages/Order/components/ApplyForInvoicingModal.tsx 2.63 KB
1
2
import { RESPONSE_CODE } from '@/constants/enum';
import { postServiceOrderApplyInvoicing } from '@/services';
zhongnanhuang authored
3
import { getAliYunOSSFileNameFromUrl } from '@/utils';
4
5
6
7
8
9
import {
  ModalForm,
  ProFormTextArea,
  ProFormUploadDragger,
} from '@ant-design/pro-components';
import { Form, message } from 'antd';
zhongnanhuang authored
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { cloneDeep } from 'lodash';
export default ({ setCheckVisible, isEdit, subOrders, onClose }) => {
  const subOrder = cloneDeep(subOrders[0]);
  let newListAnnex = subOrder.afterAnnexList?.map((path) => {
    let i = 0;
    return {
      uid: i++,
      name: getAliYunOSSFileNameFromUrl(path),
      status: 'uploaded',
      url: path,
      response: { data: [path] },
    };
  });

  subOrder.filePaths = newListAnnex;
26
27
28
29
  const [form] = Form.useForm<{
    applyInvoicingNotes: string;
    filePaths: any;
    subIds: any[];
zhongnanhuang authored
30
    afterInvoicingUpdate: boolean;
31
32
33
34
35
36
37
38
  }>();
  let subOrderIds = subOrders?.map((subOrder) => subOrder.id);

  return (
    <ModalForm<{
      applyInvoicingNotes: string;
      filePaths: any;
      subIds: any[];
zhongnanhuang authored
39
      afterInvoicingUpdate: boolean;
40
41
42
    }>
      width={500}
      open
zhongnanhuang authored
43
44
      title={isEdit ? '修改信息' : '申请开票'}
      initialValues={subOrder}
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
      form={form}
      autoFocusFirstInput
      modalProps={{
        okText: '确认',
        cancelText: '取消',
        destroyOnClose: true,
        onCancel: () => {
          setCheckVisible(false);
        },
      }}
      submitter={{
        render: (props, defaultDoms) => {
          return defaultDoms;
        },
      }}
      submitTimeout={2000}
      onFinish={async (values) => {
        values.subIds = subOrderIds;
        //附件处理
        values.filePaths = values.filePaths?.map((item) => {
          return { url: item.response.data[0] };
        });
zhongnanhuang authored
68
69
70
71
72
73
        if (isEdit) {
          values.afterInvoicingUpdate = true;
        } else {
          values.afterInvoicingUpdate = false;
        }
74
        const res = await postServiceOrderApplyInvoicing({ data: values });
75
76

        if (res.result === RESPONSE_CODE.SUCCESS) {
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
          message.success(res.message);
          onClose();
        }
      }}
      onOpenChange={setCheckVisible}
    >
      <div>如果需要合并订单,请将需要合并的订单id写在备注中。</div>
      <ProFormTextArea
        width="lg"
        name="applyInvoicingNotes"
        placeholder="请输入备注"
      />
      <ProFormUploadDragger
        key="2"
        label="附件"
        name="filePaths"
        action="/api/service/order/fileProcess"
        fieldProps={{
          headers: { Authorization: localStorage.getItem('token') },
        }}
      />
    </ModalForm>
  );
};