Blame view

src/pages/Order/components/ApplyForInvoicingModal.tsx 3.5 KB
1
import { RESPONSE_CODE } from '@/constants/enum';
2
3
4
5
import {
  postServiceOrderApplyInvoicing,
  postServiceOrderMergeApplyInvoicing,
} from '@/services';
zhongnanhuang authored
6
import { getAliYunOSSFileNameFromUrl } from '@/utils';
7
8
9
10
11
12
import {
  ModalForm,
  ProFormTextArea,
  ProFormUploadDragger,
} from '@ant-design/pro-components';
import { Form, message } from 'antd';
zhongnanhuang authored
13
import { cloneDeep } from 'lodash';
zhongnanhuang authored
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
export default ({
  setCheckVisible,
  isEdit,
  data,
  subOrders,
  isMainOrder,
  onClose,
}) => {
  console.log(subOrders);
  let ids = [];
  let newSubOrder = {};
  if (isMainOrder) {
    ids = data;
  } else {
    newSubOrder = cloneDeep(subOrders[0]);
    ids = subOrders?.map((item) => {
      return item.id;
    });
  }
34
35
36
37
38
  let newListAnnex = [];

  //回显,子订单可以编辑备注跟附件
  if (!isMainOrder) {
    if (isEdit) {
zhongnanhuang authored
39
      newListAnnex = newSubOrder.afterAnnexList?.map((path) => {
40
41
42
43
44
45
46
47
48
        let i = 0;
        return {
          uid: i++,
          name: getAliYunOSSFileNameFromUrl(path),
          status: 'uploaded',
          url: path,
          response: { data: [path] },
        };
      });
zhongnanhuang authored
49
      newSubOrder.filePaths = newListAnnex;
50
51
    }
  }
zhongnanhuang authored
52
53
  //拼接主订单id
zhongnanhuang authored
54
  console.log(isMainOrder);
55
  if (isMainOrder) {
zhongnanhuang authored
56
57
    console.log('in');
    newSubOrder.applyInvoicingNotes = ids.join(',');
58
  }
zhongnanhuang authored
59
60
61
62
63
  const [form] = Form.useForm<{
    applyInvoicingNotes: string;
    filePaths: any;
    subIds: any[];
zhongnanhuang authored
64
    afterInvoicingUpdate: boolean;
65
66
67
68
69
70
71
  }>();

  return (
    <ModalForm<{
      applyInvoicingNotes: string;
      filePaths: any;
      subIds: any[];
zhongnanhuang authored
72
      afterInvoicingUpdate: boolean;
73
74
75
    }>
      width={500}
      open
zhongnanhuang authored
76
      title={isEdit ? '修改信息' : '申请开票'}
zhongnanhuang authored
77
      initialValues={newSubOrder}
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
      form={form}
      autoFocusFirstInput
      modalProps={{
        okText: '确认',
        cancelText: '取消',
        destroyOnClose: true,
        onCancel: () => {
          setCheckVisible(false);
        },
      }}
      submitter={{
        render: (props, defaultDoms) => {
          return defaultDoms;
        },
      }}
      submitTimeout={2000}
      onFinish={async (values) => {
95
        values.subIds = ids;
96
97
98
99
100
        //附件处理
        values.filePaths = values.filePaths?.map((item) => {
          return { url: item.response.data[0] };
        });
101
102
103
104
105
106
107
108
109
110
111
        if (isMainOrder) {
          const res = await postServiceOrderMergeApplyInvoicing({
            data: {
              ...values,
              mainOrderIds: ids,
            },
          });
          if (res.result === RESPONSE_CODE.SUCCESS) {
            message.success(res.message);
            onClose();
          }
zhongnanhuang authored
112
        } else {
113
114
115
116
117
          if (isEdit) {
            values.afterInvoicingUpdate = true;
          } else {
            values.afterInvoicingUpdate = false;
          }
zhongnanhuang authored
118
119
          const res = await postServiceOrderApplyInvoicing({ data: values });
120
121
122
123
124
          if (res.result === RESPONSE_CODE.SUCCESS) {
            message.success(res.message);
            onClose();
          }
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
        }
      }}
      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>
  );
};