"use client"; import React, { useState, useEffect } from "react"; import AuthBar from "@/components/AuthBar"; import { Toast } from "antd-mobile"; import { checkAuth } from "@/utils/auth"; import { useRouter } from "next/navigation"; import baseRequest from "@/utils/baseRequest"; import { generateSignature } from "@/utils/crypto"; export default function Purchased() { //如果没登录直接跳转下载页 const router = useRouter(); useEffect(() => { const prepare = async () => { const isLogined = await checkAuth(); if (!isLogined) { router.replace("/auth/login/phonenumlogin"); } }; prepare(); }, []); //获取订单数据 const [data, setData] = useState([]); useEffect(() => { const getData = async () => { try { const base = baseRequest(); const signature = generateSignature({ offset: 0, limit: 99, ...base, }); const detailResponse = await fetch( `/api/vas/h5_get_unlock_wechat_list?signature=${signature}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ offset: 0, limit: 99, ...base, }), } ); const detailData = await detailResponse.json(); if (detailData.ret === -1) { Toast.show({ content: detailData.msg, }); return; } setData(detailData.data.list); } catch (error) { console.error(error); } }; getData(); }, []); const [currentWechat, setCurrentWechat] = useState(""); const getWechat = async (streamerMid) => { // 获取微信 try { const base = baseRequest(); const signature = generateSignature({ uid: streamerMid, ...base, }); const detailResponse = await fetch( `/api/vas/query_wechat?signature=${signature}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ uid: streamerMid, ...base, }), } ); const detailData = await detailResponse.json(); if (detailData.ret === -1) { Toast.show({ content: detailData.msg, }); return; } setCurrentWechat(detailData.data.wechat_contact); } catch (error) { console.error(error); } }; const DirectGetWechatItem = ({ item }) => { //点击查看微信 const handleClick = async () => { await getWechat(item?.account.mid); setTimeout( () => document.getElementById("get_wechat_modal").showModal(), 100 ); }; //点击主播 const handleNavigation = () => { router.push(`../${item?.account.user_id}`); }; let orderLabel; switch (item.order_status) { case 3: orderLabel = item.lock_type === 1 ? `等待${item.account.name}添加您的微信` : "请查看并添加微信"; break; case 4: orderLabel = `${item.account.name}已确认完成添加`; break; case 5: orderLabel = `订单已完成`; break; case 6: orderLabel = `已退款`; break; default: orderLabel = ""; } return (

{item.account?.name}

{orderLabel}

{item.lock_type === 0 && item.order_status !== 6 && ( )}
); }; const GetWechatModal = () => { const handleCopy = () => { navigator.clipboard.writeText(currentWechat); Toast.show({ content: "复制成功", }); }; return (

Ta的微信号:{currentWechat}

); }; const SubmitUserWechatItem = ({ item }) => { const [wechat, setWechat] = useState(""); const [remarks, setRemarks] = useState(""); const [status, setStatus] = useState("pending"); const handleSubmit = async (e) => { e.preventDefault(); if (!wechat) { Toast.show({ content: "请填写微信号", }); return; } //提交用户微信号 try { const base = baseRequest(); const signature = generateSignature({ order_id: item.order_id, wechat: wechat, note: remarks, ...base, }); const detailResponse = await fetch( `/api/vas/consumer_fill_contact?signature=${signature}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ order_id: item.order_id, wechat: wechat, note: remarks, ...base, }), } ); const detailData = await detailResponse.json(); if (detailData.ret === -1) { Toast.show({ content: detailData.msg, }); return; } //提交成功后隐藏form并显示toast setStatus("inprogress"); Toast.show({ content: "提交成功,请留意好友请求", }); } catch (error) { console.error(error); } }; return (

{item.account?.name}

{status === "pending" ? "请填写您的微信等待Ta添加您" : "已提交您的微信,请留意好友请求"}

{status === "pending" && (

您的微信:

setWechat(e.target.value)} className="input input-bordered input-md input-primary w-full max-w-sm" />

备注:

setRemarks(e.target.value)} className="input input-bordered input-md input-primary w-full max-w-sm" />

若超72小时仍未收到Ta的好友申请,请前往APP联系客服退款

)}
); }; return (

已购买

{data.length === 0 && (

若购买成功却未展示订单,请刷新页面

)} {data.map((item) => { if (item.order_status === 2) { return ; } else { return ; } })}
); }