import './payment.css'; import { Button, ConfigProvider, DatePicker, Divider, Flex, Form, GetProp, Image, Input, InputNumber, message, Radio, Spin, Upload, UploadFile, UploadProps } from "antd"; import { ReloadOutlined } from '@ant-design/icons' import {useEffect, useState} from "react"; import locale from 'antd/locale/zh_CN'; import dayjs from 'dayjs'; import 'dayjs/locale/zh-cn'; import {DevUserId, downloadUrl, get, post, uploadImageUrl} from "../../util/AjaxUtils.ts"; import {UploadOutlined} from "@ant-design/icons"; import useMessage from "antd/es/message/useMessage"; import {errorImage} from "../../util/CommonUtil.ts"; dayjs.locale('zh-cn'); type FileType = Parameters>[0]; type FormFieldType = { thirdParty: string; rechargeMoney: number; orgName: string; orgBank: string; orgNumber: string; rechargeFinalTime: string; rechargeVoucher: string; } type PayType = { accountRechargeId: string; thirdPartyPayUrl: string; } type PaySystemBank = { bankAccountName: string; bankName: string; bankNumber: string; bankRemark: string; bankUnionpayNumber: string; } enum ThirdPartyEnum { WX = '微信', ZFB = '支付宝', DGZZ = '对公转账' } interface IPaymentProps { handleConfirm(): void; handleCancel(): void; } export default function Payment(props: IPaymentProps) { const [form] = Form.useForm(); const [messageApi, messageApiContext] = useMessage(); const [isRechargeMoneyEdit, setIsRechargeMoneyEdit] = useState(false); const [isLoading, setIsLoading] = useState(false); const [rechargeVoucherArray, setRechargeVoucherArray] = useState([]); const [thirdParty, setThirdParty] = useState(''); const [accountRechargeId, setAccountRechargeId] = useState(''); const [thirdPartyPayUrl, setThirdPartyPayUrl] = useState(''); const [paySystemBank, setPaySystemBank] = useState({ bankAccountName: '', bankName: '', bankNumber: '', bankRemark: '', bankUnionpayNumber: '' }); const [countdownTime, setCountdownTime] = useState(''); const [isCountdownTimeout, setIsCountdownTimeout] = useState(false); const moneyRange: number[] = [0.01, 2000]; let countdownInterval: number = -1; /** * 倒计时 */ const countdown = () => { if (countdownInterval > -1) { clearInterval(countdownInterval); } const Time = new Date().getTime(); // 设定计时器的时间为60秒 const countDownDate = new Date(Time + 270 * 1000).getTime(); // 更新计时器的秒数 const updateCountdown = () => { const now = new Date().getTime(); const distance = countDownDate - now; // 将毫秒数转换为分钟和秒数 const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); const seconds = Math.floor((distance % (1000 * 60)) / 1000); // 渲染计时器 setCountdownTime(minutes + ":" + (seconds < 10 ? "0" : "") + seconds); if (distance <= 0) { setCountdownTime('已失效'); setIsCountdownTimeout(true); clearInterval(countdownInterval); } } // 每秒更新一次计时器 countdownInterval = setInterval(() => { updateCountdown(); }, 1000); } const getPay = () => { post({ messageApi, url: '/api/pay/get-pay', body: { rechargeMoney: form.getFieldValue('rechargeMoney'), thirdParty: form.getFieldValue('thirdParty') }, onBefore() { setIsLoading(true); }, onSuccess({data}) { setAccountRechargeId(data.accountRechargeId); setThirdPartyPayUrl(data.thirdPartyPayUrl); clearInterval(countdownInterval); if (thirdParty != ThirdPartyEnum.DGZZ) { countdown(); } }, onFinally() { setIsLoading(false); } }) } const getPaySystemBank = () => { get({ messageApi, url: '/api/pay/get-pay-system-bank', onSuccess({data}) { setPaySystemBank(data); } }) } useEffect(() => { form.setFieldsValue({ thirdParty: ThirdPartyEnum.DGZZ, rechargeMoney: 300 }) setThirdParty(ThirdPartyEnum.DGZZ); getPaySystemBank(); getPay(); }, []); const renderMoney = () => { if (isRechargeMoneyEdit) { return (
) } return (
{form.getFieldValue('rechargeMoney')}
) } const renderPayBody = () => { if (thirdParty == '对公转账') { return ( <>
收款方信息
公司名称 {paySystemBank.bankAccountName}
开户银行 {paySystemBank.bankName}
银行账号 {paySystemBank.bankNumber}
银行联行号 {paySystemBank.bankUnionpayNumber}
打款备注
{paySystemBank.bankRemark}
说明
请打款时必须按照以上备注填写
付款方信息
公司名称 *
开户银行 *
打款时间 * { form.setFieldValue('rechargeFinalTime', dateString); }}/>
打款凭证 * { const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png'; if (!isJpgOrPng) { message.error('只能上传 JPG/PNG 格式文件!'); } return isJpgOrPng; }} onChange={(info) => { if (info.file.status === 'uploading') { setIsLoading(true); return; } if (info.file.status === 'done') { setIsLoading(false); info.file.uid = info.file.response.data.fileId; rechargeVoucherArray.push(info.file.uid); setRechargeVoucherArray([...rechargeVoucherArray]); form.setFieldValue('rechargeVoucher', rechargeVoucherArray.join(',')); return; } }} onRemove={(info) => { console.log((info.uid)) const idArray = rechargeVoucherArray.filter(item => item != info.uid); setRechargeVoucherArray([...idArray]); form.setFieldValue('rechargeVoucher', rechargeVoucherArray.join(',')); }} >
) } return <>
{ isCountdownTimeout ? (
{ getPay() }}> 点击刷新
) : <> }
{countdownTime}
} return ( <>
{ post({ messageApi, url: `/api/pay/pay-account-recharge/${accountRechargeId}`, body: { thirdParty: form.getFieldValue('thirdParty'), rechargeMoney: form.getFieldValue('rechargeMoney'), orgName: thirdParty == ThirdPartyEnum.DGZZ ? form.getFieldValue('orgName') : '', orgBank: thirdParty == ThirdPartyEnum.DGZZ ? form.getFieldValue('orgBank') : '', orgNumber: thirdParty == ThirdPartyEnum.DGZZ ? form.getFieldValue('orgNumber') : '', rechargeFinalTime: thirdParty == ThirdPartyEnum.DGZZ ? form.getFieldValue('rechargeFinalTime') : '', rechargeVoucher: thirdParty == ThirdPartyEnum.DGZZ ? form.getFieldValue('rechargeVoucher') : '', }, onBefore() { setIsLoading(true); }, onSuccess() { props.handleConfirm(); }, onFinally() { setIsLoading(false); } }); }} autoComplete="off" > { form.setFieldValue('thirdParty', e.target.value); setThirdParty(e.target.value); getPay(); }} defaultValue="a"> 微信 支付宝 {/*银联*/} 对公转账 {renderMoney()} {renderPayBody()}
{messageApiContext} ) }