"use client"; import React, { useState, useEffect } from "react"; import { useSearchParams } from "next/navigation"; import { setCookie, getCookie } from "cookies-next"; import { useRouter } from "next/navigation"; import { Checkbox } from "antd-mobile"; import Link from "next/link"; import baseRequest from "@/utils/baseRequest"; import Divider from "@/components/Divider"; import { Toast } from "antd-mobile"; import { generateSignature } from "@/utils/crypto"; import { JSEncrypt } from "jsencrypt"; export default function WithDrawal() { const router = useRouter(); const searchParams = useSearchParams(); const mid = searchParams.get("mid"); const token = searchParams.get("token"); const mobile_phone = searchParams.get("mobile_phone"); //将searchParams中的mid和token写入cookie,并重定向到没有searchParams的路由 useEffect(() => { if (mid && token && mobile_phone) { setCookie("mid", mid); setCookie("token", token); setCookie("mobile_phone", mobile_phone); router.replace("/withdrawal"); } }, [mid, token, mobile_phone]); //查看主播实名认证情况 const [data, setData] = useState({}); useEffect(() => { const getData = async () => { const mid = getCookie("mid"); if (!mid) return; try { const base = baseRequest(); const signature = generateSignature({ mid: parseInt(mid, 10), ...base, }); const verificationResponse = await fetch( `/api/realname_authentication/list_by_mid?signature=${signature}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ mid: parseInt(mid, 10), ...base, }), } ); const verificationData = await verificationResponse.json(); if (verificationData.ret === -1) { Toast.show({ content: verificationData.msg, }); } const signature2 = generateSignature({ ...base, }); const withdrawalResponse = await fetch( `/api/vas/withdraw_page?signature=${signature2}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ ...base, }), } ); const withdrawalData = await withdrawalResponse.json(); if (withdrawalData.ret === -1) { Toast.show({ content: withdrawalData.msg, }); return; } setData({ verificationStatus: verificationData.data?.realname_authentication_api_vo?.status, withdrawal_diamond: withdrawalData.data.withdraw_diamonds, }); } catch (error) { console.error(error); } }; getData(); }, []); const [withdrawalNum, setWithdrawalNum] = useState(""); const [alipayAccount, setAlipayAccount] = useState(""); const [payee, setPayee] = useState(""); const [maskedMobilePhone, setMaskedMobilePhone] = useState(""); const [veriCode, setVeriCode] = useState(""); //设置checkbox const [checked, setChecked] = useState(false); //从cookie中读取mobile_phone并做脱敏处理 useEffect(() => { const mobilePhoneCache = getCookie("mobile_phone"); const maskedNumber = mobilePhoneCache?.replace( /(\d{3})\d{4}(\d{4})/, "$1****$2" ); setMaskedMobilePhone(maskedNumber); }, []); //这是提现钻石的数量 const handleChangeWithdrawalNum = (e) => { let newValue = parseInt(e.target.value, 10); // 确保输入的值在最小值和最大值范围内 if ( newValue >= 0 && newValue <= Math.min(data?.withdrawal_diamond, 20000) ) { setWithdrawalNum(newValue); } else if (isNaN(newValue)) { setWithdrawalNum(0); } else if (newValue > Math.min(data?.withdrawal_diamond, 20000)) { setWithdrawalNum(Math.min(data?.withdrawal_diamond, 20000)); } }; //重新获取验证码的计时器 const [isCounting, setIsCounting] = useState(false); const [seconds, setSeconds] = useState(60); useEffect(() => { let interval; if (isCounting && seconds > 0) { interval = setInterval(() => { setSeconds(seconds - 1); }, 1000); } else { setIsCounting(false); setSeconds(60); clearInterval(interval); } return () => { clearInterval(interval); }; }, [isCounting, seconds]); //点击获取验证码 const handleVerification = async () => { //开始倒计时 setIsCounting(true); //发送短信验证码 const base = baseRequest(); const signature = generateSignature({ ...base, }); try { await fetch(`/api/vas/withdraw_send_verifycode?signature=${signature}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ ...base, }), }); } catch (error) { console.error(error); } }; //点击提交申请按钮 const handleSubmit = async () => { //维护中 // Toast.show({ // content: "提现功能维护中,预计2月20日开放", // }); // return; if (!withdrawalNum || withdrawalNum < 1000) { Toast.show({ content: "提现最低金额为100元(即1000钻石)", }); return; } if (!alipayAccount || !payee) { Toast.show({ content: "请完善收款信息", }); return; } if (!veriCode) { Toast.show({ content: "请输入验证码", }); return; } if (!checked) { Toast.show({ content: "请先同意《用户提现协议》", }); return; } document.getElementById("comfirm_modal").showModal(); }; //点击二次确认按钮 const [errorMessage, setErrorMessage] = useState(""); const [isSubmitting, setIsSubmitting] = useState(false); const handleConfirm = async () => { try { setIsSubmitting(true); //对支付宝账号和真实姓名进行RSA加密 const encrypt = new JSEncrypt(); encrypt.setPublicKey(process.env.NEXT_PUBLIC_WITHDRAW_RSA_KEY); const auth_alipay_id = encrypt.encrypt(alipayAccount); const auth_alipay_name = encrypt.encrypt(payee); const base = baseRequest(); const signature = generateSignature({ diamonds: parseInt(withdrawalNum, 10), auth_alipay_id: auth_alipay_id, auth_alipay_name: auth_alipay_name, verify_code: veriCode, ...base, }); const applyResponse = await fetch( `/api/vas/withdraw_apply?signature=${signature}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ diamonds: parseInt(withdrawalNum, 10), auth_alipay_id: auth_alipay_id, auth_alipay_name: auth_alipay_name, verify_code: veriCode, ...base, }), } ); const applyData = await applyResponse.json(); if (applyData.ret === -1) { setErrorMessage(applyData.msg); setIsSubmitting(false); return; } router.push("/withdrawal/success"); } catch (error) { console.error(error); } finally { setIsSubmitting(false); } }; return (

可提现钻石:

{data?.withdrawal_diamond}

(新入帐钻石需等待7日才能提现哦)

兑换比例:10钻石=1RMB

*提现数量

预计提现金额:{withdrawalNum ? withdrawalNum / 10 + "元" : "自动计算"}

*支付宝账号

{data?.verificationStatus === 0 ? ( setAlipayAccount(e.target.value)} className="input input-bordered input-md input-primary w-full" /> ) : ( )}

*收款人姓名

{data?.verificationStatus === 0 ? ( setPayee(e.target.value)} className="input input-bordered input-md input-primary w-full" /> ) : ( )}

*绑定手机

{maskedMobilePhone}

*验证码

{data?.verificationStatus === 0 ? (
setVeriCode(e.target.value)} className="input input-bordered input-md input-primary w-full" />
) : ( )}
setChecked(!checked)} >

同意 《用户提现协议》

注意事项:

1.需实名认证后方可提现,详情请点击 “实名认证” ;

2.请确保输入信息准确无误,并且支付宝收款人与实名认证本人保持一致,以防提现失败,由输入错误带来的损失与平台方无关;

3.单笔最低提现金额为100元(即1000钻石),若提现金额大于2000元(即20000钻石)请联系客服;

4.自助提现渠道每日只能提现一次,若有更多提现需求,请联系客服。

提现金额: ¥{withdrawalNum / 10}

收款人姓名:{payee}

收款支付宝:{alipayAccount}

{errorMessage && (

提现失败:{errorMessage}

)}
); }