Blame view

src/pages/Order/components/FinancialDrawer.tsx 7.54 KB
1
// import { PlusOutlined } from '@ant-design/icons';
2
3
4
5
6
import { RESPONSE_CODE } from '@/constants/enum';
import {
  postServiceOrderEditOrder,
  postServiceOrderInvoicing,
} from '@/services';
zhongnanhuang authored
7
import { FloatAdd, enumToSelect, enumValueToLabel } from '@/utils';
zhongnanhuang authored
8
import { getReceivingCompanyOptions } from '@/utils/order';
9
10
11
import {
  DrawerForm,
  ProFormDatePicker,
zhongnanhuang authored
12
  ProFormDigit,
zhongnanhuang authored
13
  ProFormSelect,
14
  ProFormText,
zhongnanhuang authored
15
  ProFormTextArea,
16
} from '@ant-design/pro-components';
zhongnanhuang authored
17
import { Button, Form, message } from 'antd';
zhongnanhuang authored
18
import { useEffect, useState } from 'react';
zhongnanhuang authored
19
import { INVOCING_STATUS_OPTIONS_OLD, PAYEE_OPTIONS } from '../constant';
20
zhongnanhuang authored
21
22
23
24
25
26
27
28
export default ({
  mainOrder,
  subOrders,
  isEdit,
  isMainOrder,
  cancel,
  onClose,
}) => {
zhongnanhuang authored
29
  const [invoicingStatus, setInvoicingStatus] = useState('');
30
  const subIds = subOrders.map((item) => item.id);
zhongnanhuang authored
31
32
33
  useEffect(() => {
    // 在组件挂载或数据变化时,更新组件状态
    if (mainOrder) {
zhongnanhuang authored
34
      setInvoicingStatus(subOrders[0]?.invoicingStatus);
zhongnanhuang authored
35
36
37
    }
  }, [mainOrder]);
zhongnanhuang authored
38
  const [form] = Form.useForm<{ name: string; company: string }>();
zhongnanhuang authored
39
40
41
42
43
44
45
46
47

  /**
   * 自动选择收款公司
   * @param receivingCompany
   */
  function chooseReceivingCompany(receivingCompany: any) {
    form.setFieldValue('payee', receivingCompany);
  }
zhongnanhuang authored
48
49
50
51
52
53
54
55
56
  /**
   * 计算选中子订单的主订单金额之和
   */
  function computeTotalPayment() {
    let distinctMap = new Map();

    subOrders?.forEach((item: any) => {
      distinctMap.set(item.mainOrderId, item.totalPayment);
    });
zhongnanhuang authored
57
zhongnanhuang authored
58
59
60
61
62
63
64
65
    let sum = 0;
    for (let p of distinctMap.values()) {
      sum = FloatAdd(p, sum);
    }

    form.setFieldValue('money', sum);
  }
66
67
68
69
70
71
72
73
74
75
76
77
78
79
  return (
    <DrawerForm<{
      name: string;
      company: string;
    }>
      open
      title="财务信息"
      resize={{
        onResize() {
          console.log('resize!');
        },
        maxWidth: window.innerWidth * 0.8,
        minWidth: 400,
      }}
zhongnanhuang authored
80
      initialValues={mainOrder}
81
82
83
84
85
86
      form={form}
      autoFocusFirstInput
      drawerProps={{
        destroyOnClose: true,
      }}
      submitTimeout={2000}
87
      onFinish={async (values) => {
88
        let res;
89
90
        let body = values;
        body.subIds = subIds;
91
92
93
94
95
96
97
98
99
        if (isEdit) {
          res = await postServiceOrderEditOrder({ data: body });
        } else {
          res = await postServiceOrderInvoicing({ data: body });
        }
        if (res.result === RESPONSE_CODE.SUCCESS) {
          message.success(res.message);
          onClose();
        }
100
101
      }}
      onOpenChange={(val) => {
zhongnanhuang authored
102
        return !val && cancel();
103
104
      }}
    >
zhongnanhuang authored
105
106
107
108
109
110
111
112
      {isMainOrder ? (
        <ProFormSelect
          placeholder="选择是否需要开票"
          name="invoicingStatus"
          width="lg"
          label="是否需要开票"
          options={enumToSelect(INVOCING_STATUS_OPTIONS_OLD)}
          onChange={setInvoicingStatus}
zhongnanhuang authored
113
          initialValue={subOrders[0]?.invoicingStatus}
zhongnanhuang authored
114
115
116
117
118
119
120
          // disabled={mainInfoDisbled}
          rules={[{ required: true, message: '是否需要开票必填' }]}
        />
      ) : (
        ''
      )}
121
      <ProFormTextArea
122
        width="lg"
zhongnanhuang authored
123
        name="invoiceIdentificationNumber"
124
125
        label="开票信息"
        placeholder="请输入开票信息"
zhongnanhuang authored
126
        disabled
127
128
129
130
131
132
      />
      <ProFormText
        width="lg"
        name="bank"
        label="开户银行"
        placeholder="请输入开户银行"
zhongnanhuang authored
133
        disabled
134
135
136
137
138
139
      />
      <ProFormText
        width="lg"
        name="bankAccountNumber"
        label="开户银行账号"
        placeholder="请输入开户银行账号"
zhongnanhuang authored
140
        disabled
141
      />
zhongnanhuang authored
142
143
144
145
146
147
148
149
150
151
152
153

      {invoicingStatus !== 'UN_INVOICE'
        ? [
            <ProFormDatePicker
              key="invoicingTime"
              width="lg"
              name="invoicingTime"
              label="开票时间"
              disabled={isEdit}
              rules={[
                { required: !isEdit ? true : false, message: '这是必填项' },
              ]}
zhongnanhuang authored
154
              initialValue={subOrders[0]?.invoicingTime}
zhongnanhuang authored
155
156
            />,
            <ProFormDatePicker
157
158
159
160
161
162
163
              key="financialReceiptIssuanceTime"
              width="lg"
              name="financialReceiptIssuanceTime"
              label="开收据时间"
              initialValue={subOrders[0]?.financialReceiptIssuanceTime}
            />,
            <ProFormDatePicker
zhongnanhuang authored
164
165
166
167
              key="collectMoneyTime"
              width="lg"
              name="collectMoneyTime"
              label="收款时间"
zhongnanhuang authored
168
              initialValue={subOrders[0]?.collectMoneyTime}
zhongnanhuang authored
169
            />,
zhongnanhuang authored
170
171
172
173
174
175
176
177
            <ProFormText
              width="lg"
              key="invoiceNumber"
              name="invoiceNumber"
              label="发票号码"
              initialValue={subOrders[0]?.invoiceNumber}
              rules={[{ required: true, message: '发票号码必填' }]}
            />,
zhongnanhuang authored
178
179
180
181
182
183
184
185
            <div
              key="salesChooseReceivingCompany"
              hidden={subOrders[0].receivingCompany === null}
            >
              <span className={'pl-2 text-xs text-gray-400'}>
                销售申请开票时选择了:
                {enumValueToLabel(
                  subOrders[0].receivingCompany,
zhongnanhuang authored
186
                  getReceivingCompanyOptions(PAYEE_OPTIONS),
zhongnanhuang authored
187
188
189
190
191
192
193
194
195
196
197
198
199
200
                )}
              </span>
              <span
                hidden={subOrders[0].receivingCompany === 'ANY'}
                className={
                  'pl-2 text-xs text-[#1677ff] cursor-pointer hover:text-[#64abf7]'
                }
                onClick={() => {
                  chooseReceivingCompany(subOrders[0].receivingCompany);
                }}
              >
                选择
              </span>
            </div>,
zhongnanhuang authored
201
202
203
204
205
            <ProFormSelect
              key="payee"
              placeholder="选择收款单位"
              name="payee"
              width="lg"
zhongnanhuang authored
206
              showSearch
zhongnanhuang authored
207
208
209
210
211
              label="收款单位"
              options={enumToSelect(PAYEE_OPTIONS)}
              initialValue={subOrders[0]?.payee}
              rules={[{ required: true, message: '收款单位必填' }]}
            />,
212
zhongnanhuang authored
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
            <div id="total-payment" key="money">
              <ProFormDigit
                key="money"
                name="money"
                width="lg"
                label="金额"
                rules={[{ required: true, message: '金额必填' }]}
                tooltip="点击计算,合计所有子订单对应主订单总额"
                fieldProps={{
                  addonAfter: (
                    <Button
                      className="rounded-l-none"
                      type="primary"
                      onClick={computeTotalPayment}
                    >
                      计算
                    </Button>
                  ),
                }}
              />
            </div>,
zhongnanhuang authored
234
235
          ]
        : ''}
zhongnanhuang authored
236
237
      <ProFormSelect
zhongnanhuang authored
238
        placeholder="是否完全开票"
239
        name="afterInvoicingStatus"
zhongnanhuang authored
240
241
        width="lg"
        label="是否完全开票"
242
243
        options={[
          { label: '完全开票', value: 'COMPLETE_INVOICING' },
244
          { label: '部分开票', value: 'PARTIAL_INVOICING' },
245
        ]}
zhongnanhuang authored
246
        // disabled={mainInfoDisbled}
247
248
        initialValue={
          subOrders[0]?.afterInvoicingStatus === 'APPLY_FOR_INVOICING'
249
            ? 'COMPLETE_INVOICING'
250
251
            : subOrders[0]?.afterInvoicingStatus
        }
252
253
        rules={[{ required: true, message: '是否完全开票必填' }]}
      />
zhongnanhuang authored
254
255
256
257
      <ProFormTextArea
        width="lg"
        name="invoicingNotes"
        label="备注"
zhongnanhuang authored
258
        initialValue={subOrders[0]?.invoicingNotes}
zhongnanhuang authored
259
      />
260
261
262
    </DrawerForm>
  );
};