import React, { useEffect, useState } from "react"; import { Modal, Form, InputNumber, Select, message, Radio, Divider } from "antd"; import { useStore } from "../index"; import { savePlatformMobile } from "../api"; import { CompanyCategoryTypeEnum, ExpireRepayRuleObj } from "@/pages/finance/entitys"; import { RadioChangeEvent } from "antd/lib/radio"; import InputX from "@/pages/finance/SpecialAccount/FinancingCompany/components/InputX"; const FormItem = Form.Item; const { Option } = Select; export default function CreateModal() { const { visible, current, setCurrent, setVisible, fcList, accountList, setLoading, dealerId, brandList, type } = useStore(); const [form] = Form.useForm(); const [saveLoading, setSaveLoading] = useState(false); useEffect(() => { if (visible) { form.setFieldsValue({ ...current, 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: (

{`往来单位:${current.compName}`}

调整前

{`原最大授信额度:${current.maxCreditQuota!.toFixed(2)}元`}

{`原保证金:${current.depositValue!.toFixed(2)}${current.depositType == 1 ? "元" : "%"}`}

调整后

{`最大授信额度:${fieldValue.maxCreditQuota.toFixed(2)}元`}

{`保证金:${fieldValue.depositValue.toFixed(2)}${fieldValue.depositType == 1 ? "元" : "%"}`}

), onOk: () => { submit(fieldValue); }, }); } else { submit(fieldValue); } } function submit(fieldValue: any) { if (fieldValue.depositAccount.value === fieldValue.account.value) { message.error("还款保证金账户、一般账户请勿配置为同一一账户", 1.5); return; } 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, }; setSaveLoading(true); savePlatformMobile(param) .then((res) => { message.success("保存成功"); setVisible(false); setLoading(true); }) .catch((err) => { message.error(err.message); }) .finally(() => { setSaveLoading(false); }); } function onCancel() { setVisible(false); } return ( { setCurrent({}); form.resetFields(); }} maskClosable={false} width="48%" >
prevValues.compCategory != currentValues.compCategory} > {({ getFieldValue }): any => { const category = getFieldValue("compCategory"); return category ? ( ) : null; }} 前期一次性支付 每张票支付 `${value} 元`} /> { form.setFieldsValue({ depositValue: undefined }); return e.target.value; }} > 固定 比例 prevValues.depositType != currentValues.depositType} > {({ getFieldValue }): any => { return ( `${value} ${getFieldValue("depositType") == 1 ? "元" : "%"}`} /> ); }} `${value} %`} /> {/* 清票划扣账户类型:1 一般户;2 保证金户;3 一般户,保证金户(See: 清票划扣账户类型) */} 一般户 保证金户 一般户,保证金户 `${value} 个月`} /> `${value} 天`} /> prevValues.toLoan != currentValues.toLoan}> {({ getFieldValue }): any => { const category = getFieldValue("toLoan"); return category ? ( <> `${value} %`} /> 每月 `${value} 天`} /> ) : null; }} prevValues.loan != currentValues.loan}> {({ getFieldValue }): any => { const category = getFieldValue("loan"); return category ? ( <> `${value} %`} /> 每月 `${value} 天`} /> ) : null; }} {ExpireRepayRuleObj.map((item) => ( {item.label} ))}
); }