Blame view

src/pages/Order/components/ApplyForInvoicingModal.tsx 4.21 KB
zhongnanhuang authored
1
import { RESPONSE_CODE } from '@/constants/enum';
2
3
4
5
import {
  postServiceOrderApplyInvoicing,
  postServiceOrderMergeApplyInvoicing,
} from '@/services';
zhongnanhuang authored
6
import { getAliYunOSSFileNameFromUrl } from '@/utils';
zhongnanhuang authored
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
export default ({
  setCheckVisible,
  isEdit,
  data,
  subOrders,
  isMainOrder,
  onClose,
}) => {
  let ids = [];
  let newSubOrder = {};
24
25
26
27
28
29
  let sumPrice = 0;

  for (let order of subOrders) {
    sumPrice += parseFloat(order.totalPayment);
  }
zhongnanhuang authored
30
31
32
33
34
  if (isMainOrder) {
    ids = data;
  } else {
    newSubOrder = cloneDeep(subOrders[0]);
    ids = subOrders?.map((item) => {
35
      sumPrice += parseFloat(item.totalPayment);
zhongnanhuang authored
36
37
38
39
      return item.id;
    });
  }
40
41
42
43
44
  let newListAnnex = [];

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

  return (
    <ModalForm<{
      applyInvoicingNotes: string;
      filePaths: any;
      subIds: any[];
zhongnanhuang authored
78
      afterInvoicingUpdate: boolean;
zhongnanhuang authored
79
80
81
    }>
      width={500}
      open
zhongnanhuang authored
82
      title={isEdit ? '修改信息' : '申请开票'}
zhongnanhuang authored
83
      initialValues={newSubOrder}
zhongnanhuang authored
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
      form={form}
      autoFocusFirstInput
      modalProps={{
        okText: '确认',
        cancelText: '取消',
        destroyOnClose: true,
        onCancel: () => {
          setCheckVisible(false);
        },
      }}
      submitter={{
        render: (props, defaultDoms) => {
          return defaultDoms;
        },
      }}
      submitTimeout={2000}
      onFinish={async (values) => {
101
        values.subIds = ids;
zhongnanhuang authored
102
103
104
105
106
        //附件处理
        values.filePaths = values.filePaths?.map((item) => {
          return { url: item.response.data[0] };
        });
107
108
109
110
111
112
113
114
115
116
117
        if (isMainOrder) {
          const res = await postServiceOrderMergeApplyInvoicing({
            data: {
              ...values,
              mainOrderIds: ids,
            },
          });
          if (res.result === RESPONSE_CODE.SUCCESS) {
            message.success(res.message);
            onClose();
          }
zhongnanhuang authored
118
        } else {
119
120
121
122
123
          if (isEdit) {
            values.afterInvoicingUpdate = true;
          } else {
            values.afterInvoicingUpdate = false;
          }
zhongnanhuang authored
124
125
          const res = await postServiceOrderApplyInvoicing({ data: values });
126
127
128
129
130
          if (res.result === RESPONSE_CODE.SUCCESS) {
            message.success(res.message);
            onClose();
          }
zhongnanhuang authored
131
132
133
134
        }
      }}
      onOpenChange={setCheckVisible}
    >
135
136
137
138
139
140
141
142
143
      {isMainOrder ? (
        <div className="mb-[24px]">
          <span>总订单金额:</span>
          <span className="text-red-500">{sumPrice}¥</span>
        </div>
      ) : (
        ''
      )}
zhongnanhuang authored
144
145
146
      <div className="mb-1">
        如果需要合并订单,请将需要合并的订单id写在备注中,id之间用英文逗号隔开。
      </div>
zhongnanhuang authored
147
148
149
150
151
152
153
      <ProFormTextArea
        width="lg"
        name="applyInvoicingNotes"
        placeholder="请输入备注"
      />
      <ProFormUploadDragger
        key="2"
zhongnanhuang authored
154
155
156
157
158
159
160
161
        label={
          <div>
            <span>开票明细确认表</span>
            <span className="pl-2 text-xs text-gray-400">
              如果开票信息有变更,如开票内容跟下单内容不一致、下单抬头和付款抬头不一致,请上传开票明细确认表。
            </span>
          </div>
        }
zhongnanhuang authored
162
163
164
165
166
167
168
169
170
        name="filePaths"
        action="/api/service/order/fileProcess"
        fieldProps={{
          headers: { Authorization: localStorage.getItem('token') },
        }}
      />
    </ModalForm>
  );
};