"use client"; import React, { useEffect, useState } from "react"; import { Image, Mask, Toast, Input, TextArea, DotLoading } from "antd-mobile"; import requireAPI from "@/utils/requireAPI"; import { get } from "@/utils/storeInfo"; import { useRouter } from "next/navigation"; import { getStreamerDetailInfo } from "@/api/space"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faCopy } from "@fortawesome/free-solid-svg-icons"; export default function AddWeChat({ visible, closeMask, name, price, streamerMid, avatar, streamerData, }) { const [isMoneyEnough, setIsMoneyEnough] = useState(true); //是否已经解锁微信 const [streamerDetailData, setStreamerDetailData] = useState(null); const [wechat, setWechat] = useState(); //保存用户微信号 const [userWechat, setUserWechat] = useState(""); //保存用户备注 const [remarks, setRemarks] = useState(""); const router = useRouter(); useEffect(() => { console.log("avatar", avatar); if (!streamerMid) return; getStreamerDetailInfo(streamerMid).then((res) => { setStreamerDetailData(res); }); }, [streamerData]); useEffect(() => { console.log("avatar", avatar); if (!streamerDetailData || !streamerDetailData?.is_unlock_wechat) return; requireAPI("POST", "/api/vas/query_wechat", { body: { uid: streamerMid, }, }).then((res) => { setWechat(res.data?.wechat_contact); }); }, [streamerDetailData]); //点击解锁微信按钮 const unlockWechat = async (type) => { //余额不够就显示余额不足前往充值,够就直接购买 //先支付,支付成功后添加解锁关系,再展示解锁界面 //支付金币解锁微信 const account = get("account"); if (account) { try { const userResponse = await requireAPI( "POST", "/api/account/list_by_mid", { body: { mid: account.mid, }, } ); if (userResponse.ret === -1) { Toast.show({ icon: "fail", content: data.msg, position: "top", }); return; } if (userResponse?.data.account?.gold_num >= price) { console.log("余额足够"); if (type) { if (!userWechat) { Alert.alert(null, "请填写您的微信"); return; } //付款函数 const payCoin = async () => { try { //支付金币解锁微信 const unlockData = await requireAPI( "POST", "/api/vas/one_step_unlock", { body: { contact_product_id: "contact_wechat", uid: streamerMid, }, } ); if (unlockData.ret === -1) { Toast.show({ icon: "fail", content: unlockData.msg, position: "top", }); return; } return unlockData.data.order_id; } catch (error) { console.error(error); } }; //提交微信函数 const submitWechat = async (order_id) => { //提交用户微信和备注 try { const submitWechatData = await requireAPI( "POST", "/api/vas/consumer_fill_contact", { body: { order_id: order_id, wechat: userWechat, note: remarks, }, } ); if (submitWechatData.ret === -1) { Toast.show({ icon: "fail", content: submitWechatData.msg, position: "top", }); return; } } catch (error) { console.error(error); } }; //用户未解锁微信情况:先支付,再提交用户微信和备注 if (streamerDetailData.is_unlock_wechat === 1) { //用户已解锁微信情况:直接提交用户微信和备注 await submitWechat(streamerData.wechat_order_id); setStreamerDetailData({ ...streamerData, wechat_order_status: 3, }); } else { const order_id = await payCoin(); if (!order_id) return; await submitWechat(order_id); //展示解锁成功界面 // setIsWechatUnlocked(true); setStreamerDetailData({ ...streamerDetailData,wechat_order_status:3 }) return; } } else { const data = await requireAPI("POST", "/api/vas/one_step_unlock", { body: { contact_product_id: "contact_wechat", uid: streamerMid, }, }); if (data.ret === -1) { Toast.show({ icon: "fail", content: data.msg, position: "top", }); return; } } //展示解锁界面 // setIsWechatUnlocked(true); getStreamerDetailInfo(streamerMid).then((res) => { setStreamerDetailData(res); }); } else { setIsMoneyEnough(false); } } catch (error) { console.error(error); } } }; return (
closeMask(false)}>
{isMoneyEnough ? ( <>

{name}

{streamerData?.streamer_ext?.wechat_lock_type === 0 ? (
{streamerDetailData?.is_unlock_wechat ? wechat : "解锁后展示"} {!!streamerDetailData?.is_unlock_wechat && ( )}

添加时请备注自己“铁粉空间”昵称
若解锁后72小时为通过好友,请联系客服

{(!streamerDetailData?.is_unlock_wechat || streamerDetailData?.wechat_order_status === 2) && (
{!streamerDetailData?.is_unlock_wechat && ( 解锁微信( { streamerDetailData?.streamer_ext ?.wechat_coin_price } 金币) )}
)}
) : (
{streamerDetailData?.is_unlock_wechat && streamerDetailData?.wechat_order_status !== 2 ? (

{(streamerDetailData?.wechat_order_status === 0 || streamerDetailData?.wechat_order_status === 3) && "已成功提交您的微信,请耐心等待"} {(streamerDetailData?.wechat_order_status === 4 || streamerDetailData?.wechat_order_status === 5) && "已确认添加,订单完成"}

) : (

* 您的微信

setUserWechat(value)} value={userWechat} />

备注