Blame view

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

      {invoicingStatus !== 'UN_INVOICE'
        ? [
            <ProFormDatePicker
              key="invoicingTime"
              width="lg"
              name="invoicingTime"
              label="开票时间"
              disabled={isEdit}
              rules={[
                { required: !isEdit ? true : false, message: '这是必填项' },
              ]}
zhongnanhuang authored
132
              initialValue={subOrders[0]?.invoicingTime}
zhongnanhuang authored
133
134
135
136
137
138
            />,
            <ProFormDatePicker
              key="collectMoneyTime"
              width="lg"
              name="collectMoneyTime"
              label="收款时间"
zhongnanhuang authored
139
              initialValue={subOrders[0]?.collectMoneyTime}
zhongnanhuang authored
140
141
142
            />,
          ]
        : ''}
zhongnanhuang authored
143
144
      <ProFormSelect
zhongnanhuang authored
145
        placeholder="是否完全开票"
146
        name="afterInvoicingStatus"
zhongnanhuang authored
147
148
        width="lg"
        label="是否完全开票"
149
150
151
152
        options={[
          { label: '部分开票', value: 'PARTIAL_INVOICING' },
          { label: '完全开票', value: 'COMPLETE_INVOICING' },
        ]}
zhongnanhuang authored
153
        // disabled={mainInfoDisbled}
154
        initialValue={subOrders[0]?.afterInvoicingStatus}
155
156
        rules={[{ required: true, message: '是否完全开票必填' }]}
      />
zhongnanhuang authored
157
158
159
160
      <ProFormTextArea
        width="lg"
        name="invoicingNotes"
        label="备注"
zhongnanhuang authored
161
        initialValue={subOrders[0]?.invoicingNotes}
zhongnanhuang authored
162
      />
163
164
165
    </DrawerForm>
  );
};