Blame view

src/pages/finance/SpecialAccount/FinancingCompany/components/CreateModal.tsx 17 KB
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
1
2
3
4
  import React, { useEffect, useState } from "react";
  import { Modal, Form, InputNumber, Select, message, Radio, Divider } from "antd";
  import { useStore } from "../index";
  import { savePlatformMobile } from "../api";
4a1c3b82   zhaofeng   融资公司add票据到期还款推送
5
  import { CompanyCategoryTypeEnum, ExpireRepayRuleObj } from "@/pages/finance/entitys";
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
6
  import { RadioChangeEvent } from "antd/lib/radio";
4a1c3b82   zhaofeng   融资公司add票据到期还款推送
7
  import InputX from "@/pages/finance/SpecialAccount/FinancingCompany/components/InputX";
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
8
9
10
11
12
13
14
15
16
  
  const FormItem = Form.Item;
  const { Option } = Select;
  
  export default function CreateModal() {
    const { visible, current, setCurrent, setVisible, fcList, accountList, setLoading, dealerId, brandList } = useStore();
    const [form] = Form.useForm();
  
    const [saveLoading, setSaveLoading] = useState<boolean>(false);
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
17
18
19
    useEffect(() => {
      if (visible) {
        form.setFieldsValue({
4a1c3b82   zhaofeng   融资公司add票据到期还款推送
20
          ...current,
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
67
68
69
70
71
72
73
74
75
76
77
78
          fcComp: current.compId ? { value: current.compId, label: current.compName } : undefined,
          compCategory: current.compCategory,
          account: current.accountId ? { value: current.accountId, label: current.accountName } : undefined,
          depositAccount: current.depositAccountId
            ? { value: current.depositAccountId, label: current.depositAccountName }
            : undefined,
          maxCreditQuota: current.maxCreditQuota,
          depositType: current.depositType || 1,
          depositValue: current.depositValue,
          billServiceFee: current.billServiceFee,
          billLimitDates: current.billLimitDates,
          billTransferDates: current.billTransferDates,
          billTransferInterest: current.billTransferInterest,
          interestSettleDay: current.interestSettleDay,
          depositPayMethod: current.depositPayMethod || 1,
          brand: current.brandId ? { value: current.brandId, label: current.brandName } : undefined,
          repayAdvanceDays: current.repayAdvanceDays,
          toLoan: current.toLoan ? 1 : 0,
          toLoanDue: current.toLoanDueTime
            ? { number: current.toLoanDueTime, unit: current.toLoanDueTimeType }
            : undefined,
          repayAccount: current.repayAccountId
            ? { value: current.repayAccountId, label: current.repayAccountName }
            : undefined,
          toLoanRepayAdvanceDays: current.toLoanRepayAdvanceDays,
          loan: current.loan ? 1 : 0,
          loanInterest: current.loanInterest,
          loanInterestSettleDay: current.loanInterestSettleDay,
          loanRepayAdvanceDays: current.loanRepayAdvanceDays,
        });
      }
    }, [visible]);
  
    function onCompare(fieldValue: any) {
      if (current.compId && fieldValue.depositPayMethod == 1 && current.depositValue != fieldValue.depositValue) {
        Modal.confirm({
          title: "保证金变更",
          content: (
            <div>
              <p>{`往来单位:${current.compName}`}</p>
              <Divider orientation="left">调整前</Divider>
              <p>{`原最大授信额度:${current.maxCreditQuota!.toFixed(2)}元`}</p>
              <p>{`原保证金:${current.depositValue!.toFixed(2)}${current.depositType == 1 ? "元" : "%"}`}</p>
              <Divider orientation="left">调整后</Divider>
              <p>{`最大授信额度:${fieldValue.maxCreditQuota.toFixed(2)}元`}</p>
              <p>{`保证金:${fieldValue.depositValue.toFixed(2)}${fieldValue.depositType == 1 ? "元" : "%"}`}</p>
            </div>
          ),
          onOk: () => {
            submit(fieldValue);
          },
        });
      } else {
        submit(fieldValue);
      }
    }
  
    function submit(fieldValue: any) {
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
      const param = {
        dealerId,
        ...fieldValue,
        compCategory: fieldValue.compCategory,
        compId: fieldValue.fcComp.value,
        compName: fieldValue.fcComp.label,
        accountId: fieldValue.account.value,
        accountName: fieldValue.account.label,
        depositAccountId: fieldValue.depositAccount && fieldValue.depositAccount.value,
        depositAccountName: fieldValue.depositAccount && fieldValue.depositAccount.label,
        depositValue: fieldValue.depositValue,
        brandId: fieldValue.brand && fieldValue.brand.value,
        brandName: fieldValue.brand && fieldValue.brand.label,
        toLoan: !!fieldValue.toLoan,
        toLoanDueTime: fieldValue.toLoanDue && fieldValue.toLoanDue.number,
        toLoanDueTimeType: fieldValue.toLoanDue && fieldValue.toLoanDue.unit,
        repayAccountId: fieldValue.repayAccount && fieldValue.repayAccount.value,
        repayAccountName: fieldValue.repayAccount && fieldValue.repayAccount.label,
        loan: !!fieldValue.loan,
      };
4a1c3b82   zhaofeng   融资公司add票据到期还款推送
99
      setSaveLoading(true);
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
100
101
102
103
104
      savePlatformMobile(param)
        .then((res) => {
          message.success("保存成功");
          setVisible(false);
          setLoading(true);
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
105
106
        })
        .catch((err) => {
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
107
          message.error(err.message);
4a1c3b82   zhaofeng   融资公司add票据到期还款推送
108
109
110
        })
        .finally(() => {
          setSaveLoading(false);
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
        });
    }
  
    function onCancel() {
      setVisible(false);
    }
  
    return (
      <Modal
        title={`${current.compId ? "编辑" : "新增"}融资账户`}
        visible={visible}
        confirmLoading={saveLoading}
        onOk={form.submit}
        onCancel={onCancel}
        afterClose={() => {
          setCurrent({});
4a1c3b82   zhaofeng   融资公司add票据到期还款推送
127
          form.resetFields();
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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
183
184
185
186
187
188
        }}
        maskClosable={false}
        width="48%"
      >
        <Form form={form} labelCol={{ span: 7 }} wrapperCol={{ span: 15 }} onFinish={onCompare}>
          <FormItem label="账户类别" name="compCategory" rules={[{ required: true, message: "请选择类别" }]}>
            <Select placeholder="请选择类别" disabled={!!current.compId}>
              {[1, 2].map((i) => (
                <Option key={i} value={i}>
                  {CompanyCategoryTypeEnum[i]}
                </Option>
              ))}
            </Select>
          </FormItem>
          <FormItem name="brand" label="品牌" rules={[{ required: true, message: "请选择品牌" }]}>
            <Select labelInValue placeholder="请选择品牌" showSearch optionFilterProp="children">
              {brandList.map((item) => (
                <Option key={item.id} value={item.id}>
                  {item.name}
                </Option>
              ))}
            </Select>
          </FormItem>
          <FormItem
            noStyle
            shouldUpdate={(prevValues, currentValues) => prevValues.compCategory != currentValues.compCategory}
          >
            {({ getFieldValue }): any => {
              const category = getFieldValue("compCategory");
              return category ? (
                <FormItem label="融资公司" name="fcComp" rules={[{ required: true, message: "请选择融资公司" }]}>
                  <Select
                    showSearch
                    labelInValue
                    placeholder="请选择融资公司"
                    optionFilterProp="children"
                    disabled={!!current.compId}
                  >
                    {fcList
                      .filter((list) => list.compCategory == getFieldValue("compCategory"))
                      .map((item) => (
                        <Option key={item.id} value={Number(item.id)}>
                          {item.name}
                        </Option>
                      ))}
                  </Select>
                </FormItem>
              ) : null;
            }}
          </FormItem>
          <FormItem
            name="depositPayMethod"
            label="保证金支付方式"
            rules={[{ required: true, message: "请选择支付方式" }]}
          >
            <Radio.Group>
              <Radio value={1}>前期一次性支付</Radio>
              <Radio value={2}>每张票支付</Radio>
            </Radio.Group>
          </FormItem>
          <FormItem name="depositAccount" label="保证金账户">
84bf1a46   zhaolin   fix
189
            <Select labelInValue placeholder="请选择账户" showSearch optionFilterProp="children" allowClear>
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
190
191
192
193
194
195
196
              {accountList.map((item) => (
                <Option key={item.id} value={item.id}>
                  {item.name}
                </Option>
              ))}
            </Select>
          </FormItem>
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
197
198
199
200
201
202
203
204
205
          <FormItem name="account" label="一般账户" rules={[{ required: true, message: "请选择一般账户" }]}>
            <Select labelInValue placeholder="请选择一般账户">
              {accountList.map((item) => (
                <Option key={item.id} value={item.id}>
                  {item.name}
                </Option>
              ))}
            </Select>
          </FormItem>
10bc879b   张志伟   🔥 创建test分支
206
          <FormItem name="repayAccount" label="还款账户">
84bf1a46   zhaolin   fix
207
            <Select labelInValue placeholder="请选择还款账户" allowClear>
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
              {accountList.map((item) => (
                <Option key={item.id} value={item.id}>
                  {item.name}
                </Option>
              ))}
            </Select>
          </FormItem>
          <FormItem
            name="maxCreditQuota"
            label="最大授信额度"
            rules={[{ required: true, message: "请输入最大授信额度" }]}
          >
            <InputNumber
              style={{ width: "100%" }}
              placeholder="请输入最大授信额度"
              min={0}
              precision={2}
              formatter={(value) => `${value} 元`}
            />
          </FormItem>
          <FormItem
            name="depositType"
            label="保证金类型"
            rules={[{ required: true, message: "请选择保证金类型" }]}
            getValueFromEvent={(e: RadioChangeEvent) => {
              form.setFieldsValue({ depositValue: undefined });
              return e.target.value;
            }}
          >
            <Radio.Group disabled={!!current.compId}>
              <Radio value={1}>固定</Radio>
              <Radio value={2}>比例</Radio>
            </Radio.Group>
          </FormItem>
          <FormItem
            noStyle
            shouldUpdate={(prevValues, currentValues) => prevValues.depositType != currentValues.depositType}
          >
            {({ getFieldValue }): any => {
              return (
                <FormItem label="保证金" name="depositValue" rules={[{ required: true, message: "请输入保证金" }]}>
                  <InputNumber
                    style={{ width: "100%" }}
                    placeholder="请输入保证金"
                    min={0}
                    precision={2}
                    max={getFieldValue("depositType") == 1 ? Infinity : 100}
                    formatter={(value) => `${value} ${getFieldValue("depositType") == 1 ? "元" : "%"}`}
                  />
                </FormItem>
              );
            }}
          </FormItem>
          <FormItem name="billServiceFee" label="出票手续费" rules={[{ required: true, message: "请输入出票手续费" }]}>
            <InputNumber
              style={{ width: "100%" }}
              placeholder="请输入手续费"
              min={0}
              max={100}
              precision={2}
              step={0.01}
              formatter={(value) => `${value} %`}
            />
          </FormItem>
ef9cdd25   zhaofeng   融资公司账户add清票划扣账户
272
273
274
275
276
277
278
279
280
281
282
283
          {/* 清票划扣账户类型:1 一般户;2 保证金户;3 一般户,保证金户(See: 清票划扣账户类型) */}
          <FormItem
            name="deductAccountType"
            label="清票划扣账户"
            rules={[{ required: true, message: "请选择清票划扣账户" }]}
          >
            <Radio.Group>
              <Radio value={1}>一般户</Radio>
              <Radio value={2}>保证金户</Radio>
              <Radio value={3}>一般户,保证金户</Radio>
            </Radio.Group>
          </FormItem>
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
284
285
286
287
288
289
290
291
292
293
          <FormItem name="billLimitDates" label="票据期限" rules={[{ required: true, message: "请输入票据期限" }]}>
            <InputNumber style={{ width: "100%" }} placeholder="请输入票据期限" formatter={(value) => `${value} 个月`} />
          </FormItem>
          <FormItem
            name="repayAdvanceDays"
            label="票据到期提前还款天数"
            rules={[{ required: true, message: "请输入票据到期提前还款天数" }]}
          >
            <InputNumber style={{ width: "100%" }} placeholder="请输入提前天数" formatter={(value) => `${value} 天`} />
          </FormItem>
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
294
295
296
297
298
299
          <FormItem name="toLoan" label="是否支持票转贷" rules={[{ required: true, message: "请选择是否支持票转贷" }]}>
            <Radio.Group>
              <Radio value={1}>是</Radio>
              <Radio value={0}>否</Radio>
            </Radio.Group>
          </FormItem>
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
          <FormItem noStyle shouldUpdate={(prevValues, currentValues) => prevValues.toLoan != currentValues.toLoan}>
            {({ getFieldValue }): any => {
              const category = getFieldValue("toLoan");
              return category ? (
                <>
                  <FormItem
                    name="toLoanDue"
                    label="票转贷最长期限"
                    rules={[{ required: true, message: "请输入票转贷最长期限" }]}
                  >
                    <InputX />
                  </FormItem>
  
                  <FormItem
                    name="billTransferInterest"
                    label="票转贷年利率"
                    rules={[{ required: true, message: "请输入票转贷年利率" }]}
                  >
                    <InputNumber
                      style={{ width: "100%" }}
                      placeholder="请输入票转贷年利率"
                      min={0}
                      max={100}
                      precision={2}
                      step={0.01}
                      formatter={(value) => `${value} %`}
                    />
                  </FormItem>
                  <FormItem label="票转贷结息日期">
                    <span>每月</span>
                    <FormItem
                      name="interestSettleDay"
                      noStyle
                      rules={[{ required: true, message: "请输入票转贷利息结算日期" }]}
                    >
                      <InputNumber
                        style={{ width: "80%", marginRight: 6, marginLeft: 6 }}
                        placeholder="请输入票转贷利息结算日期"
                        min={1}
                        precision={0}
                        max={31}
                      />
                    </FormItem>
                    <span>日</span>
                  </FormItem>
                  <FormItem
                    name="toLoanRepayAdvanceDays"
                    label="票转贷还款提前天数"
                    rules={[{ required: true, message: "请输入票转贷还款提前天数" }]}
                  >
                    <InputNumber
                      style={{ width: "100%" }}
                      placeholder="请输入提前天数"
                      formatter={(value) => `${value} 天`}
                    />
                  </FormItem>
                </>
              ) : null;
            }}
          </FormItem>
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
          <FormItem name="loan" label="是否支持贷款启票" rules={[{ required: true, message: "请选择是否支持贷款启票" }]}>
            <Radio.Group>
              <Radio value={1}>是</Radio>
              <Radio value={0}>否</Radio>
            </Radio.Group>
          </FormItem>
          <FormItem noStyle shouldUpdate={(prevValues, currentValues) => prevValues.loan != currentValues.loan}>
            {({ getFieldValue }): any => {
              const category = getFieldValue("loan");
              return category ? (
                <>
                  <FormItem
                    name="loanInterest"
                    label="贷款启票年利率"
                    rules={[{ required: true, message: "请输入贷款启票年利率" }]}
                  >
                    <InputNumber
                      style={{ width: "100%" }}
                      placeholder="请输入贷款启票年利率"
                      min={0}
                      max={100}
                      precision={2}
                      step={0.01}
                      formatter={(value) => `${value} %`}
                    />
                  </FormItem>
                  <FormItem label="贷款启票结息日">
                    <span>每月</span>
                    <FormItem
                      name="loanRepayAdvanceDays"
                      noStyle
                      rules={[{ required: true, message: "请输入贷款启票结息日" }]}
                    >
                      <InputNumber
                        style={{ width: "80%", marginRight: 6, marginLeft: 6 }}
                        placeholder="请输入贷款启票结息日"
                        min={1}
                        precision={0}
                        max={31}
                      />
                    </FormItem>
                    <span>日</span>
                  </FormItem>
                  <FormItem
                    name="loanInterestSettleDay"
                    label="贷款启票还款提前天数"
                    rules={[{ required: true, message: "请输入贷款启票还款提前天数" }]}
                  >
                    <InputNumber
                      style={{ width: "100%" }}
                      placeholder="请输入提前天数"
                      formatter={(value) => `${value} 天`}
                    />
                  </FormItem>
                </>
              ) : null;
            }}
          </FormItem>
4a1c3b82   zhaofeng   融资公司add票据到期还款推送
418
419
420
421
422
423
424
425
426
427
428
          <FormItem
            name="expireRepayRule"
            label="票据到期还款推送"
            rules={[{ required: true, message: "请选择推送方式" }]}
          >
            <Radio.Group>
              {ExpireRepayRuleObj.map((item) => (
                <Radio value={item.value}>{item.label}</Radio>
              ))}
            </Radio.Group>
          </FormItem>
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
429
430
431
432
        </Form>
      </Modal>
    );
  }