Blame view

src/pages/Order/components/ApplyForInvoicingModal.tsx 5.36 KB
zhongnanhuang authored
1
import { RESPONSE_CODE } from '@/constants/enum';
zhongnanhuang authored
2
3
import { postServiceOrderApplyInvoicing } from '@/services';
import { FloatAdd, enumToSelect, getAliYunOSSFileNameFromUrl } from '@/utils';
zhongnanhuang authored
4
5
import {
  ModalForm,
6
  ProFormDatePicker,
7
  ProFormSelect,
zhongnanhuang authored
8
9
10
11
  ProFormTextArea,
  ProFormUploadDragger,
} from '@ant-design/pro-components';
import { Form, message } from 'antd';
zhongnanhuang authored
12
import { useEffect, useState } from 'react';
zhongnanhuang authored
13
import { PAYEE_OPTIONS } from '../constant';
zhongnanhuang authored
14
15
16
17
18
19
20
export default ({
  setCheckVisible,
  isEdit,
  subOrders,
  isMainOrder,
  onClose,
}) => {
21
  const [isUrgent, setIsUrgent] = useState('');
22
23
  let sumPrice = 0;
zhongnanhuang authored
24
25
26
27
  let ids = subOrders?.map((item) => {
    sumPrice = FloatAdd(item.subOrderPayment, sumPrice);
    return item.id;
  });
28
zhongnanhuang authored
29
30
31
32
33
34
  let mainIdSet = new Set();
  subOrders?.forEach((item: { mainOrderId: unknown }) => {
    mainIdSet.add(item.mainOrderId);
  });

  let mainIds = Array.from(mainIdSet).join(',');
zhongnanhuang authored
35
36
37
38
  let newListAnnex = [];

  //回显,子订单可以编辑备注跟附件
39
  if (isEdit) {
zhongnanhuang authored
40
    newListAnnex = subOrders.afterAnnexList?.map((path) => {
41
42
43
44
45
46
47
48
49
      let i = 0;
      return {
        uid: i++,
        name: getAliYunOSSFileNameFromUrl(path),
        status: 'uploaded',
        url: path,
        response: { data: [path] },
      };
    });
zhongnanhuang authored
50
    subOrders.filePaths = newListAnnex;
51
  }
zhongnanhuang authored
52
zhongnanhuang authored
53
54
55
56
  const [form] = Form.useForm<{
    applyInvoicingNotes: string;
    filePaths: any;
    subIds: any[];
zhongnanhuang authored
57
    afterInvoicingUpdate: boolean;
58
    receivingCompany: string;
59
60
    isUrgent: boolean;
    deadline: string;
zhongnanhuang authored
61
62
  }>();
zhongnanhuang authored
63
64
65
66
  useEffect(() => {
    //显示拼接的主订单id
    form.setFieldValue('applyInvoicingNotes', mainIds);
  }, []);
67
zhongnanhuang authored
68
69
70
71
72
  return (
    <ModalForm<{
      applyInvoicingNotes: string;
      filePaths: any;
      subIds: any[];
zhongnanhuang authored
73
      afterInvoicingUpdate: boolean;
zhongnanhuang authored
74
75
76
    }>
      width={500}
      open
zhongnanhuang authored
77
      title={isEdit ? '修改信息' : '申请开票'}
zhongnanhuang authored
78
      initialValues={subOrders}
zhongnanhuang authored
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
      form={form}
      autoFocusFirstInput
      modalProps={{
        okText: '确认',
        cancelText: '取消',
        destroyOnClose: true,
        onCancel: () => {
          setCheckVisible(false);
        },
      }}
      submitter={{
        render: (props, defaultDoms) => {
          return defaultDoms;
        },
      }}
      submitTimeout={2000}
      onFinish={async (values) => {
96
        values.subIds = ids;
zhongnanhuang authored
97
98
99
100
101
        //附件处理
        values.filePaths = values.filePaths?.map((item) => {
          return { url: item.response.data[0] };
        });
zhongnanhuang authored
102
103
        if (isEdit) {
          values.afterInvoicingUpdate = true;
zhongnanhuang authored
104
        } else {
zhongnanhuang authored
105
106
          values.afterInvoicingUpdate = false;
        }
zhongnanhuang authored
107
zhongnanhuang authored
108
        const res = await postServiceOrderApplyInvoicing({ data: values });
109
zhongnanhuang authored
110
111
112
        if (res.result === RESPONSE_CODE.SUCCESS) {
          message.success(res.message);
          onClose();
zhongnanhuang authored
113
114
115
116
        }
      }}
      onOpenChange={setCheckVisible}
    >
117
118
      {isMainOrder ? (
        <div className="mb-[24px]">
zhongnanhuang authored
119
          <span>选中子订单金额之和:</span>
120
121
122
123
124
125
          <span className="text-red-500">{sumPrice}¥</span>
        </div>
      ) : (
        ''
      )}
zhongnanhuang authored
126
127
128
      <div className="mb-1">
        如果需要合并订单,请将需要合并的订单id写在备注中,id之间用英文逗号隔开。
      </div>
zhongnanhuang authored
129
130
131
      <ProFormTextArea
        width="lg"
        name="applyInvoicingNotes"
zhongnanhuang authored
132
        key="applyInvoicingNotes"
zhongnanhuang authored
133
        placeholder="请输入备注"
zhongnanhuang authored
134
135
136
137
138
139
140
141
        onMetaChange={(val) => {
          console.log(val);
        }}
        proFieldProps={{
          onchange: () => {
            message.info('change');
          },
        }}
zhongnanhuang authored
142
      />
143
      <ProFormSelect
zhongnanhuang authored
144
        placeholder="选择收款单位"
145
146
147
148
149
        name="receivingCompany"
        width="lg"
        key="receivingCompany"
        label={
          <div>
zhongnanhuang authored
150
            <span>开票收款单位</span>
151
            <span className="pl-2 text-xs text-gray-400">
zhongnanhuang authored
152
              财务开票将依据这个字段,选择对应的公司开票(若对[收款单位]没有要求,请任意选择一个)
153
154
155
            </span>
          </div>
        }
zhongnanhuang authored
156
157
        options={enumToSelect(PAYEE_OPTIONS)}
        rules={[{ required: true, message: '开票收款单位必填' }]}
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
      <ProFormSelect
        placeholder="选择是否加急"
        name="isUrgent"
        width="lg"
        key="isUrgent"
        label="是否加急"
        options={[
          { label: '是', value: 'true' },
          { label: '否', value: 'false' },
        ]}
        rules={[{ required: true, message: '是否加急必填' }]}
        onChange={(val: any) => {
          setIsUrgent(val);
        }}
      />

      <ProFormDatePicker
        key="deadline"
        label="期望开票时间"
        name="deadline"
        rules={[{ required: isUrgent === 'true', message: '期望开票时间必填' }]}
        hidden={isUrgent !== 'true'}
      />
zhongnanhuang authored
183
184
      <ProFormUploadDragger
        key="2"
zhongnanhuang authored
185
186
187
188
189
190
191
192
        label={
          <div>
            <span>开票明细确认表</span>
            <span className="pl-2 text-xs text-gray-400">
              如果开票信息有变更,如开票内容跟下单内容不一致、下单抬头和付款抬头不一致,请上传开票明细确认表。
            </span>
          </div>
        }
zhongnanhuang authored
193
194
195
196
197
198
199
200
201
        name="filePaths"
        action="/api/service/order/fileProcess"
        fieldProps={{
          headers: { Authorization: localStorage.getItem('token') },
        }}
      />
    </ModalForm>
  );
};