import './payment.css'; import { Button, ConfigProvider, DatePicker, Divider, Flex, Form, GetProp, Image, Input, InputNumber, message, Radio, Spin, Upload, UploadProps } from "antd"; import { ReloadOutlined } from '@ant-design/icons' import { useEffect, useRef, useState } from "react"; import locale from 'antd/locale/zh_CN'; import dayjs from 'dayjs'; import 'dayjs/locale/zh-cn'; import { DevUserId, 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 [mask, setMask] = useState(false) 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]; const countdownIntervalRef = useRef(); const [refreshQrCodeCount, setRefreshQrCodeCount] = useState(0); /** * 倒计时 */ const countdown = () => { if (countdownIntervalRef.current) { clearInterval(countdownIntervalRef.current); } // if (thirdParty == ThirdPartyEnum.DGZZ) { // return; // } const Time = new Date().getTime(); // 设定计时器的时间为60秒 const countDownDate = new Date(Time + 270 * 1000).getTime(); // const countDownDate = new Date(Time + 5 * 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(countdownIntervalRef.current); setMask(true) } } // 每秒更新一次计时器 countdownIntervalRef.current = 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); countdown(); }, onFinally() { setIsLoading(false); } }) } const getPaySystemBank = () => { get({ messageApi, url: '/api/pay/get-pay-system-bank', onSuccess({ data }) { setPaySystemBank(data); } }) } useEffect(() => { if (!thirdParty) { getPaySystemBank(); form.setFieldsValue({ thirdParty: ThirdPartyEnum.DGZZ, rechargeMoney: 300 }) setThirdParty(ThirdPartyEnum.DGZZ) return; } getPay(); // countdown() }, [thirdParty, isRechargeMoneyEdit, refreshQrCodeCount]); const renderMoney = () => { console.log(form.getFieldValue('rechargeMoney')) if (isRechargeMoneyEdit) { return (
) } return (
{form.getFieldValue('rechargeMoney')}
) } const renderPayBody = () => { if (thirdParty == '对公转账') { return (
倒计时:{countdownTime}
收款方信息
公司名称 {paySystemBank.bankAccountName}
开户银行 {paySystemBank.bankName}
银行账号 {paySystemBank.bankNumber}
银行联行号 {paySystemBank.bankUnionpayNumber}
打款备注
{paySystemBank.bankRemark}
说明
请打款时必须按照以上备注填写
付款方信息
公司名称 *
开户银行 *
银行账号 *
打款时间 * { form.setFieldValue('rechargeFinalTime', dateString); }} />
打款凭证 * { console.log(e); if (e.file.status === 'done') { rechargeVoucherArray.push(e.file.response.data.fileId); setRechargeVoucherArray(rechargeVoucherArray); } if (e.file.status === 'removed') { const idArray = rechargeVoucherArray.filter(item => item != e.file.response.data.fileId); setRechargeVoucherArray(idArray); } return e.fileList; }} rules={[{ required: true, message: '请上传打款凭证' }]} > { const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png'; if (!isJpgOrPng) { message.error('只能上传 JPG/PNG 格式文件!'); } return isJpgOrPng; }} >
) } return <>
{/* { isCountdownTimeout ? (
{ setRefreshQrCodeCount(refreshQrCodeCount + 1); }}> 点击刷新
) : <> } */}
{countdownTime}
} return (
{ setMask(false) setRefreshQrCodeCount(refreshQrCodeCount + 1); }}>
已失效,点击刷新
{ 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 ? rechargeVoucherArray.join(',') : '', }, onBefore() { setIsLoading(true); }, onSuccess() { props.handleConfirm(); }, onFinally() { setIsLoading(false); } }); }} autoComplete="off" > { form.setFieldValue('thirdParty', e.target.value); setThirdParty(e.target.value); }}> 微信 支付宝 {/*银联*/} 对公转账 {renderMoney()} {renderPayBody()}
{messageApiContext}
) }