Blame view

src/pages/Order/components/ApplyForInvoicingModal.tsx 5.81 KB
zhongnanhuang authored
1
import { RESPONSE_CODE } from '@/constants/enum';
zhongnanhuang authored
2
import { postServiceOrderApplyInvoicing } from '@/services';
zhongnanhuang authored
3
import { enumToSelect, getAliYunOSSFileNameFromUrl } from '@/utils';
zhongnanhuang authored
4
5
import {
  ModalForm,
6
  ProFormSelect,
7
  ProFormText,
zhongnanhuang authored
8
9
10
11
  ProFormTextArea,
  ProFormUploadDragger,
} from '@ant-design/pro-components';
import { Form, message } from 'antd';
zhongnanhuang authored
12
import { useEffect, useState } from 'react';
zhongnanhuang authored
13
import { PAYEE_OPTIONS } from '../constant';
zhongnanhuang authored
14
15
16
17
18
export default ({
  setCheckVisible,
  isEdit,
  subOrders,
  isMainOrder,
zhongnanhuang authored
19
  totalPayment,
zhongnanhuang authored
20
21
  onClose,
}) => {
22
  const [isUrgent, setIsUrgent] = useState('');
zhongnanhuang authored
23
  let sumPrice = totalPayment;
24
zhongnanhuang authored
25
26
27
  let ids = subOrders?.map((item) => {
    return item.id;
  });
28
zhongnanhuang authored
29
30
31
32
33
34
  let mainIdSet = new Set();
  subOrders?.forEach((item: { mainOrderId: unknown }) => {
    mainIdSet.add(item.mainOrderId);
  });

  let mainIds = Array.from(mainIdSet).join(',');
zhongnanhuang authored
35
36
37
38
  let newListAnnex = [];

  //回显,子订单可以编辑备注跟附件
39
  if (isEdit) {
zhongnanhuang authored
40
    newListAnnex = subOrders.afterAnnexList?.map((path) => {
41
42
43
44
45
46
47
48
49
      let i = 0;
      return {
        uid: i++,
        name: getAliYunOSSFileNameFromUrl(path),
        status: 'uploaded',
        url: path,
        response: { data: [path] },
      };
    });
zhongnanhuang authored
50
    subOrders.filePaths = newListAnnex;
51
  }
zhongnanhuang authored
52
zhongnanhuang authored
53
54
55
56
  const [form] = Form.useForm<{
    applyInvoicingNotes: string;
    filePaths: any;
    subIds: any[];
zhongnanhuang authored
57
    afterInvoicingUpdate: boolean;
58
    receivingCompany: string;
59
60
    isUrgent: boolean;
    deadline: string;
zhongnanhuang authored
61
62
  }>();
zhongnanhuang authored
63
64
65
66
  useEffect(() => {
    //显示拼接的主订单id
    form.setFieldValue('applyInvoicingNotes', mainIds);
  }, []);
67
zhongnanhuang authored
68
69
70
71
72
  return (
    <ModalForm<{
      applyInvoicingNotes: string;
      filePaths: any;
      subIds: any[];
zhongnanhuang authored
73
      afterInvoicingUpdate: boolean;
zhongnanhuang authored
74
75
76
    }>
      width={500}
      open
zhongnanhuang authored
77
      title={isEdit ? '修改信息' : '申请开票'}
zhongnanhuang authored
78
      initialValues={subOrders}
zhongnanhuang authored
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
      form={form}
      autoFocusFirstInput
      modalProps={{
        okText: '确认',
        cancelText: '取消',
        destroyOnClose: true,
        onCancel: () => {
          setCheckVisible(false);
        },
      }}
      submitter={{
        render: (props, defaultDoms) => {
          return defaultDoms;
        },
      }}
      submitTimeout={2000}
      onFinish={async (values) => {
96
        values.subIds = ids;
zhongnanhuang authored
97
98
99
100
101
        //附件处理
        values.filePaths = values.filePaths?.map((item) => {
          return { url: item.response.data[0] };
        });
zhongnanhuang authored
102
103
        if (isEdit) {
          values.afterInvoicingUpdate = true;
zhongnanhuang authored
104
        } else {
zhongnanhuang authored
105
106
          values.afterInvoicingUpdate = false;
        }
zhongnanhuang authored
107
zhongnanhuang authored
108
        const res = await postServiceOrderApplyInvoicing({ data: values });
109
zhongnanhuang authored
110
111
112
        if (res.result === RESPONSE_CODE.SUCCESS) {
          message.success(res.message);
          onClose();
zhongnanhuang authored
113
114
115
116
        }
      }}
      onOpenChange={setCheckVisible}
    >
117
118
      {isMainOrder ? (
        <div className="mb-[24px]">
zhongnanhuang authored
119
          <span>选中子订单金额之和:</span>
120
121
122
123
124
125
          <span className="text-red-500">{sumPrice}¥</span>
        </div>
      ) : (
        ''
      )}
zhongnanhuang authored
126
127
128
      <div className="mb-1">
        如果需要合并订单,请将需要合并的订单id写在备注中,id之间用英文逗号隔开。
      </div>
zhongnanhuang authored
129
130
131
      <ProFormTextArea
        width="lg"
        name="applyInvoicingNotes"
zhongnanhuang authored
132
        key="applyInvoicingNotes"
zhongnanhuang authored
133
        placeholder="请输入备注"
zhongnanhuang authored
134
135
136
137
138
139
140
141
        onMetaChange={(val) => {
          console.log(val);
        }}
        proFieldProps={{
          onchange: () => {
            message.info('change');
          },
        }}
zhongnanhuang authored
142
      />
143
144
145
146
147
148
149
150
      <ProFormText
        width="lg"
        name="purchaser"
        label="抬头名称"
        key="purchaser"
        placeholder="请输入抬头名称"
        rules={[{ required: true, message: '抬头名称必填' }]}
      />
151
      <ProFormSelect
zhongnanhuang authored
152
        placeholder="选择收款单位"
153
154
155
156
157
        name="receivingCompany"
        width="lg"
        key="receivingCompany"
        label={
          <div>
zhongnanhuang authored
158
            <span>开票收款单位</span>
159
            <span className="pl-2 text-xs text-gray-400">
zhongnanhuang authored
160
              财务开票将依据这个字段,选择对应的公司开票(若对[收款单位]没有要求,请任意选择一个)
161
162
163
            </span>
          </div>
        }
zhongnanhuang authored
164
165
        options={enumToSelect(PAYEE_OPTIONS)}
        rules={[{ required: true, message: '开票收款单位必填' }]}
166
      />
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
      <ProFormSelect
        placeholder="选择是否加急"
        name="isUrgent"
        width="lg"
        key="isUrgent"
        label="是否加急"
        options={[
          { label: '是', value: 'true' },
          { label: '否', value: 'false' },
        ]}
        rules={[{ required: true, message: '是否加急必填' }]}
        onChange={(val: any) => {
          setIsUrgent(val);
        }}
      />
183
      {/* <ProFormDatePicker
184
185
186
187
188
        key="deadline"
        label="期望开票时间"
        name="deadline"
        rules={[{ required: isUrgent === 'true', message: '期望开票时间必填' }]}
        hidden={isUrgent !== 'true'}
189
      /> */}
190
zhongnanhuang authored
191
192
193
194
195
196
197
198
      <ProFormTextArea
        key="invoicingUrgentCause"
        label="加急开票原因"
        name="invoicingUrgentCause"
        rules={[{ required: isUrgent === 'true', message: '加急开票原因' }]}
        hidden={isUrgent !== 'true'}
      />
zhongnanhuang authored
199
200
      <ProFormUploadDragger
        key="2"
zhongnanhuang authored
201
202
203
204
205
206
207
208
        label={
          <div>
            <span>开票明细确认表</span>
            <span className="pl-2 text-xs text-gray-400">
              如果开票信息有变更,如开票内容跟下单内容不一致、下单抬头和付款抬头不一致,请上传开票明细确认表。
            </span>
          </div>
        }
zhongnanhuang authored
209
210
211
212
213
214
215
216
217
        name="filePaths"
        action="/api/service/order/fileProcess"
        fieldProps={{
          headers: { Authorization: localStorage.getItem('token') },
        }}
      />
    </ModalForm>
  );
};