Blame view

src/pages/Invoice/components/InvoiceRecordDetailModal.tsx 11.5 KB
曾国涛 authored
1
2
3
4
5
6
7
8
9
10
11
12
13
import { RESPONSE_CODE } from '@/constants/enum';
import InvoiceDetailTable from '@/pages/Invoice/components/InvoiceDetailTable';
import {
  postServiceConstGetPayeeEnum,
  postServiceConstInvoiceType,
  postServiceConstInvoicingType,
  postServiceInvoiceGetInvoiceRecord,
  postServiceInvoiceModifyRecord,
} from '@/services';
import { enumToSelect } from '@/utils';
import {
  ModalForm,
  ProForm,
曾国涛 authored
14
  ProFormFieldSet,
曾国涛 authored
15
16
17
18
19
  ProFormInstance,
  ProFormSelect,
  ProFormText,
  ProFormTextArea,
} from '@ant-design/pro-components';
曾国涛 authored
20
import { Button, Divider, Form, Space, message } from 'antd';
曾国涛 authored
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { useEffect, useRef, useState } from 'react';

export default ({ id }) => {
  const [readOnly, setReadOnly] = useState(true);
  const [visible, setVisible] = useState(false);
  const [initialValues, setInitialValues] = useState({});
  const [detailTableData, setDetailTableData] = useState([]);
  const [payees, setPayees] = useState([]);
  const [payeeNameOptions, setPayeeNameOptions] = useState([]);
  const formRef = useRef<ProFormInstance>();
  const [form] = Form.useForm();

  useEffect(() => {
    const getPayees = async () => {
      let res = await postServiceConstGetPayeeEnum();
      setPayees(res.data);
      let payeeNameOptions = res.data.map((item) => {
        return {
          label: item.payeeName,
          value: item.payeeName,
        };
      });
      setPayeeNameOptions(payeeNameOptions);
    };
    getPayees();
  }, []);
曾国涛 authored
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
  const getRecord = async (id) => {
    let ret = await postServiceInvoiceGetInvoiceRecord({
      query: {
        id: id,
      },
    });
    const updatedInvoiceDetails = ret.data.invoiceDetails?.map(
      (item, index) => ({
        ...item, // 保留原有属性
        tid: index + 1, // 添加tid属性,这里以T开头,后面跟索引+1,仅作示例,实际可根据需求生成tid
      }),
    );
    setDetailTableData(updatedInvoiceDetails);
    setInitialValues(ret.data);
  };
曾国涛 authored
62
63
  useEffect(() => {
    if (!visible) {
曾国涛 authored
64
      getRecord(id);
曾国涛 authored
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
    }
  }, [visible]);

  const updateDetails = (values) => {
    setDetailTableData(values);
  };
  return (
    <>
      <Space>
        <a
          type="primary"
          onClick={() => {
            setVisible(true);
          }}
        >
          详情
        </a>
        {visible && (
          <ModalForm
            open
            onOpenChange={setVisible}
            title="新建表单"
            formRef={formRef}
            initialValues={initialValues}
            submitter={{
              render: () => {
                return [
                  <Button
                    type={readOnly ? 'primary' : 'default'}
                    key="ok"
                    onClick={() => {
                      setReadOnly(!readOnly);
                    }}
                  >
                    {readOnly ? '编辑' : '取消编辑'}
                  </Button>,
                  <>
                    {!readOnly && (
                      <Button
                        type="primary"
                        key="submit"
                        onClick={async () => {
                          const result = await postServiceInvoiceModifyRecord({
                            data: {
                              ...form.getFieldsValue(),
                              invoiceDetails: [...detailTableData],
                            },
                          });
                          if (result.result === RESPONSE_CODE.SUCCESS) {
                            message.success('提交成功');
                          }
                          setVisible(false);
                          return true;
                        }}
                      >
                        提交
                      </Button>
                    )}
                  </>,
                  /*<Button
曾国涛 authored
125
126
127
128
129
130
131
132
                                                      type={'default'}
                                                      key="ok"
                                                      onClick={() => {
                                                          setVisible(false)
                                                      }}
                                                  >
                                                      取消
                                                  </Button>,*/
曾国涛 authored
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
                ];
              },
            }}
            width={1200}
            form={form}
            autoFocusFirstInput
            modalProps={{
              destroyOnClose: true,
            }}
            submitTimeout={2000}
            onFinish={async (values) => {
              const result = await postServiceInvoiceModifyRecord({
                data: {
                  ...values,
                  invoiceDetails: {
                    ...detailTableData,
                  },
                },
              });
              if (result.result === RESPONSE_CODE.SUCCESS) {
                message.success('提交成功');
              }
              setVisible(false);
              return true;
            }}
          >
            基础信息
            <hr />
            <ProForm.Group>
              <ProFormText
                readonly
                name="id"
                label="订单批号"
                tooltip="最长为 24 位"
                placeholder="请输入名称"
              />

              <ProFormText
                readonly
                width="md"
                name="createByName"
                label="销售代表"
                placeholder="请输入名称"
              />
              <ProFormText
                readonly
                width="md"
                name="createTime"
                label="申请时间"
                placeholder="请输入名称"
              />
              <ProFormSelect
                name="type"
                label="发票类型"
                readonly={readOnly}
                request={async () => {
                  let invoiceTypeRet = await postServiceConstInvoiceType();
                  return enumToSelect(invoiceTypeRet.data);
                }}
                placeholder="Please select a country"
                rules={[
                  { required: true, message: 'Please select your country!' },
                ]}
              />
              <ProFormSelect
                name="invoicingType"
                readonly={readOnly}
                label="开具类型"
                request={async () => {
                  let invoicingTypeRet = await postServiceConstInvoicingType();
                  let options = enumToSelect(invoicingTypeRet.data);
                  return options;
                }}
                placeholder="Please select a country"
                rules={[
                  { required: true, message: 'Please select your country!' },
                ]}
              />
曾国涛 authored
211
212
              <ProFormFieldSet
                name="list"
曾国涛 authored
213
                label="子订单号"
曾国涛 authored
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
                transform={(value: any) => ({
                  list: value,
                  startTime: value[0],
                  endTime: value[1],
                })}
              >
                {initialValues?.subOrderIds?.map((item) => {
                  return (
                    <>
                      <Button
                        className="pl-1 pr-0"
                        type="link"
                        target="_blank"
                        href={'/order?subOrderId=' + item}
                      >
                        {item}
                      </Button>
                      <Divider type="vertical" />
                    </>
                  );
                })}
              </ProFormFieldSet>
曾国涛 authored
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
            </ProForm.Group>
            购方信息
            <hr />
            <ProForm.Group>
              <ProFormText
                readonly={readOnly}
                width="md"
                name="partyAName"
                label="购方名称"
                placeholder="请输入名称"
              />
              <ProFormText
                readonly={readOnly}
                width="md"
                name="partyATaxid"
                label="购方税号"
                placeholder="请输入名称"
              />
              <ProFormText
                readonly={readOnly}
                width="md"
                label="开户银行"
                name={'partyAOpenBank'}
                placeholder="请输入名称"
              />
              <ProFormText
                readonly={readOnly}
                width="md"
                name="partyABankAccount"
                label="银行账号"
                placeholder="请输入名称"
              />
              <ProFormText
                readonly={readOnly}
                width="md"
                name="partyAAddress"
                label="购方地址"
                placeholder="请输入名称"
              />
              <ProFormText
                readonly={readOnly}
                width="md"
                name="partyAPhoneNumber"
                label="电话"
                placeholder="请输入名称"
              />
            </ProForm.Group>
            销方信息
            <hr />
            <ProForm.Group>
              <ProFormSelect
                readonly={readOnly}
                width="md"
                name="partyBName"
                options={payeeNameOptions}
                onChange={(value: any) => {
                  let payee = payees.find((item: any) => {
                    return item.payeeName === value;
                  });
                  console.log(JSON.stringify(payee));
                  form.setFieldsValue({
                    partyBTaxid: payee.taxId,
                    partyBBankAccount: payee.bankAccount,
                    partyBOpenBank: payee.openBank,
                    partyBAddress: payee.address,
                    partyBPhoneNumber: payee.phoneNumber,
                  });
                }}
                label="销方名称"
                placeholder="请输入名称"
              />

              <ProFormText
                readonly
                width="md"
                name="partyBTaxid"
                label="销方税号"
                placeholder="请输入名称"
              />
              <ProFormText
                readonly
                width="md"
                name="partyBOpenBank"
                label="开户银行"
                placeholder="请输入名称"
              />
              <ProFormText
                readonly
                width="md"
                name="partyBBankAccount"
                label="银行账号"
                placeholder="请输入名称"
              />
              <ProFormText
                readonly
                width="md"
                name="partyBAddress"
                label="销方地址"
                placeholder="请输入名称"
              />
              <ProFormText
                readonly
                width="md"
                name="partyBPhoneNumber"
                label="电话"
                placeholder="请输入名称"
              />
            </ProForm.Group>
            订单信息
            <hr />
            <InvoiceDetailTable
曾国涛 authored
347
              recordId={id}
曾国涛 authored
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
              details={detailTableData}
              updateDetails={updateDetails}
              readOnly={readOnly}
            />
            <ProFormTextArea
              readonly={readOnly}
              name="comment"
              label="备注"
              placeholder="请输入备注"
            />
          </ModalForm>
        )}
      </Space>
    </>
  );
};