Blame view

src/pages/Order/OrderWarning/components/ReissueModal.tsx 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import { RESPONSE_CODE } from '@/constants/enum';
import {
  postServiceInvoiceFindInvoice,
  postServiceInvoiceReissue,
  postServiceOrderFindServiceOrder,
} from '@/services';
import {
  ModalForm,
  ProFormSelect,
  ProFormText,
  ProFormTextArea,
} from '@ant-design/pro-components';
import { Form } from 'antd';
import { useEffect, useState } from 'react';
曾国涛 authored
16
export default ({ setVisible, subOrders, onClose }) => {
17
18
19
20
21
22
23
24
25
  const [invoiceSelectList, setInvoiceSelectList] = useState([]);
  const [mainOrders, setMainOrders] = useState('');
  const [submitting, setSubmitting] = useState(false);

  const [form] = Form.useForm<{ invoiceId: string; notes: string }>();

  let getInvoiceSelectList = async () => {
    const res = await postServiceInvoiceFindInvoice({
      data: {
曾国涛 authored
26
        subOrderIdIn: subOrders.map((item) => item.id),
27
28
29
30
31
32
33
      },
    });
    setInvoiceSelectList([]);
    if (res && res.result === RESPONSE_CODE.SUCCESS) {
      let temInvoiceSelectList = [];
      res.data.forEach((item) => {
        temInvoiceSelectList.push({
34
          label: item.invoiceNumber,
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
          value: item.id,
        });
      });
      setInvoiceSelectList(temInvoiceSelectList);
    }
  };
  useEffect(() => {
    getInvoiceSelectList();
  }, []);
  return (
    <ModalForm<{
      invoiceId: string;
      notes: string;
    }>
      title="重新开票"
      form={form}
      width={500}
      open
      autoFocusFirstInput
      initialValues={{}}
      modalProps={{
        okText: '确认',
        cancelText: '取消',
        destroyOnClose: true,
        onCancel: () => {
          setVisible(false);
        },
      }}
      submitting={submitting}
      onFinish={async (values) => {
        setSubmitting(true);
        postServiceInvoiceReissue({
67
          data: values,
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
        });
        setVisible(false);
        onClose();
      }}
      submitTimeout={2000}
    >
      <ProFormSelect
        width="lg"
        name="invoiceId"
        label="选择要重新开的发票"
        options={invoiceSelectList}
        onChange={async (value) => {
          console.log(value);
          let result = await postServiceOrderFindServiceOrder({
            data: {
              invoiceId: value,
            },
          });
          if (result && result.result === RESPONSE_CODE.SUCCESS) {
            //对data里面每个元素的id用,进行拼接
            let map = result.data.map((item) => item.id);
            let str = map.join(',');
            setMainOrders(str);
          }
        }}
      />
      <ProFormText
95
96
97
98
99
100
101
102
        width="lg"
        name="purchaser"
        label="抬头名称"
        key="purchaser"
        placeholder="请输入抬头名称"
        rules={[{ required: true, message: '抬头名称必填' }]}
      />
      <ProFormText
103
104
105
106
107
108
109
110
111
        width="md"
        name="关联订单"
        label="发票关联订单号"
        readonly={true}
        value={mainOrders}
      />
      <ProFormTextArea
        width="lg"
        name="notes"
112
113
114
115
116
117
        rules={[
          {
            required: true, // 设置为必填
            message: '必须填写重新开票原因', // 当未填写时显示的提示信息
          },
        ]}
118
119
120
121
122
        placeholder="请填写订单重新开票的原因"
      />
    </ModalForm>
  );
};