Blame view

src/pages/Order/components/FinancialDrawer.tsx 5.64 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 { enumToSelect } from '@/utils';
8
9
10
import {
  DrawerForm,
  ProFormDatePicker,
zhongnanhuang authored
11
  ProFormDigit,
zhongnanhuang authored
12
  ProFormSelect,
13
  ProFormText,
zhongnanhuang authored
14
  ProFormTextArea,
15
16
} from '@ant-design/pro-components';
import { Form, message } from 'antd';
zhongnanhuang authored
17
import { useEffect, useState } from 'react';
zhongnanhuang authored
18
import { INVOCING_STATUS_OPTIONS_OLD, PAYEE_OPTIONS } from '../constant';
19
zhongnanhuang authored
20
21
22
23
24
25
26
27
export default ({
  mainOrder,
  subOrders,
  isEdit,
  isMainOrder,
  cancel,
  onClose,
}) => {
zhongnanhuang authored
28
  const [invoicingStatus, setInvoicingStatus] = useState('');
29
  const subIds = subOrders.map((item) => item.id);
zhongnanhuang authored
30
31
32
  useEffect(() => {
    // 在组件挂载或数据变化时,更新组件状态
    if (mainOrder) {
zhongnanhuang authored
33
      setInvoicingStatus(subOrders[0]?.invoicingStatus);
zhongnanhuang authored
34
35
36
    }
  }, [mainOrder]);
zhongnanhuang authored
37
  const [form] = Form.useForm<{ name: string; company: string }>();
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  return (
    <DrawerForm<{
      name: string;
      company: string;
    }>
      open
      title="财务信息"
      resize={{
        onResize() {
          console.log('resize!');
        },
        maxWidth: window.innerWidth * 0.8,
        minWidth: 400,
      }}
zhongnanhuang authored
52
      initialValues={mainOrder}
53
54
55
56
57
58
      form={form}
      autoFocusFirstInput
      drawerProps={{
        destroyOnClose: true,
      }}
      submitTimeout={2000}
59
60
      onFinish={async (values) => {
        console.log(values);
61
        let res;
62
63
64
65
        let body = values;
        body.subIds = subIds;
        body.mainOrderId = mainOrder.id;
        body.mainorderOrSubOrderInvoicing = isMainOrder;
66
67
68
69
70
71
72
73
74
        if (isEdit) {
          res = await postServiceOrderEditOrder({ data: body });
        } else {
          res = await postServiceOrderInvoicing({ data: body });
        }
        if (res.result === RESPONSE_CODE.SUCCESS) {
          message.success(res.message);
          onClose();
        }
75
76
      }}
      onOpenChange={(val) => {
zhongnanhuang authored
77
        return !val && cancel();
78
79
      }}
    >
zhongnanhuang authored
80
81
82
83
84
85
86
87
      {isMainOrder ? (
        <ProFormSelect
          placeholder="选择是否需要开票"
          name="invoicingStatus"
          width="lg"
          label="是否需要开票"
          options={enumToSelect(INVOCING_STATUS_OPTIONS_OLD)}
          onChange={setInvoicingStatus}
zhongnanhuang authored
88
          initialValue={subOrders[0]?.invoicingStatus}
zhongnanhuang authored
89
90
91
92
93
94
95
          // disabled={mainInfoDisbled}
          rules={[{ required: true, message: '是否需要开票必填' }]}
        />
      ) : (
        ''
      )}
96
97
      <ProFormText
        width="lg"
zhongnanhuang authored
98
        name="invoiceIdentificationNumber"
99
100
        label="开票信息"
        placeholder="请输入开票信息"
zhongnanhuang authored
101
        disabled
102
103
104
105
106
107
      />
      <ProFormText
        width="lg"
        name="bank"
        label="开户银行"
        placeholder="请输入开户银行"
zhongnanhuang authored
108
        disabled
109
110
111
112
113
114
      />
      <ProFormText
        width="lg"
        name="bankAccountNumber"
        label="开户银行账号"
        placeholder="请输入开户银行账号"
zhongnanhuang authored
115
        disabled
116
      />
zhongnanhuang authored
117
118
119
120
121
122
123
124
125
126
127
128

      {invoicingStatus !== 'UN_INVOICE'
        ? [
            <ProFormDatePicker
              key="invoicingTime"
              width="lg"
              name="invoicingTime"
              label="开票时间"
              disabled={isEdit}
              rules={[
                { required: !isEdit ? true : false, message: '这是必填项' },
              ]}
zhongnanhuang authored
129
              initialValue={subOrders[0]?.invoicingTime}
zhongnanhuang authored
130
131
            />,
            <ProFormDatePicker
132
133
134
135
136
137
138
              key="financialReceiptIssuanceTime"
              width="lg"
              name="financialReceiptIssuanceTime"
              label="开收据时间"
              initialValue={subOrders[0]?.financialReceiptIssuanceTime}
            />,
            <ProFormDatePicker
zhongnanhuang authored
139
140
141
142
              key="collectMoneyTime"
              width="lg"
              name="collectMoneyTime"
              label="收款时间"
zhongnanhuang authored
143
              initialValue={subOrders[0]?.collectMoneyTime}
zhongnanhuang authored
144
            />,
zhongnanhuang authored
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
            <ProFormText
              width="lg"
              key="invoiceNumber"
              name="invoiceNumber"
              label="发票号码"
              initialValue={subOrders[0]?.invoiceNumber}
              rules={[{ required: true, message: '发票号码必填' }]}
            />,
            <ProFormSelect
              key="payee"
              placeholder="选择收款单位"
              name="payee"
              width="lg"
              label="收款单位"
              options={enumToSelect(PAYEE_OPTIONS)}
              initialValue={subOrders[0]?.payee}
              rules={[{ required: true, message: '收款单位必填' }]}
            />,
163
zhongnanhuang authored
164
165
166
167
168
169
170
            <ProFormDigit
              key="money"
              name="money"
              width="lg"
              label="金额"
              rules={[{ required: true, message: '金额必填' }]}
            />,
zhongnanhuang authored
171
172
          ]
        : ''}
zhongnanhuang authored
173
174
      <ProFormSelect
zhongnanhuang authored
175
        placeholder="是否完全开票"
176
        name="afterInvoicingStatus"
zhongnanhuang authored
177
178
        width="lg"
        label="是否完全开票"
179
180
        options={[
          { label: '完全开票', value: 'COMPLETE_INVOICING' },
181
          { label: '部分开票', value: 'PARTIAL_INVOICING' },
182
        ]}
zhongnanhuang authored
183
        // disabled={mainInfoDisbled}
184
185
        initialValue={
          subOrders[0]?.afterInvoicingStatus === 'APPLY_FOR_INVOICING'
186
            ? 'COMPLETE_INVOICING'
187
188
            : subOrders[0]?.afterInvoicingStatus
        }
189
190
        rules={[{ required: true, message: '是否完全开票必填' }]}
      />
zhongnanhuang authored
191
192
193
194
      <ProFormTextArea
        width="lg"
        name="invoicingNotes"
        label="备注"
zhongnanhuang authored
195
        initialValue={subOrders[0]?.invoicingNotes}
zhongnanhuang authored
196
      />
197
198
199
    </DrawerForm>
  );
};