"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"; export default function WithDrawal() { return (

提现通道1月8号开放,请耐心等待

); 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, }); return; } //todo:查询账户可提现钻石数量 setData({ verificationStatus: verificationData.data.realname_authentication_api_vo.status, }); } 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 handleSubmit = async () => { if (!withdrawalNum || withdrawalNum < 2000) { Toast.show({ content: "提现最低金额为200元(即2000钻石)", }); 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 handleConfirm = async () => { //todo:提交提现申请,如果出错则设置errorMessage,如果成功则跳转成功页面 router.push("/withdrawal/success"); }; 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.单笔最低提现金额为200元(即2000钻石),若提现金额大于2000元(即20000钻石)请联系客服;

4.自助提现渠道每日提现上限为2000元(即20000钻石),若有更多提现需求,请联系客服。

提现金额: ¥{withdrawalNum / 10}

收款人姓名:{payee}

收款支付宝:{alipayAccount}

{errorMessage && (

提现失败:{errorMessage}

)}
); }