2024-07-06 11:05:19 +08:00
|
|
|
|
"use client";
|
|
|
|
|
|
2024-07-08 20:07:36 +08:00
|
|
|
|
import React, { useEffect, useState } from "react";
|
2024-07-15 16:54:04 +08:00
|
|
|
|
import { Image, Mask, Toast, Input, TextArea, DotLoading } from "antd-mobile";
|
2024-07-22 16:07:41 +08:00
|
|
|
|
import requireAPI from "@/utils/requireAPI";
|
2024-07-06 11:05:19 +08:00
|
|
|
|
import { get } from "@/utils/storeInfo";
|
|
|
|
|
import { useRouter } from "next/navigation";
|
2024-07-15 16:54:04 +08:00
|
|
|
|
import { getStreamerDetailInfo } from "@/api/space";
|
2024-07-30 22:53:41 +08:00
|
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
|
|
|
import { faCopy } from "@fortawesome/free-solid-svg-icons";
|
2024-07-31 15:11:13 +08:00
|
|
|
|
import clipboard from "copy-to-clipboard";
|
2024-07-06 11:05:19 +08:00
|
|
|
|
export default function AddWeChat({
|
|
|
|
|
visible,
|
|
|
|
|
closeMask,
|
|
|
|
|
name,
|
|
|
|
|
price,
|
|
|
|
|
streamerMid,
|
2024-07-08 20:07:36 +08:00
|
|
|
|
avatar,
|
|
|
|
|
streamerData,
|
2024-07-06 11:05:19 +08:00
|
|
|
|
}) {
|
|
|
|
|
const [isMoneyEnough, setIsMoneyEnough] = useState(true);
|
2024-07-15 16:54:04 +08:00
|
|
|
|
//是否已经解锁微信
|
2024-07-08 20:07:36 +08:00
|
|
|
|
const [streamerDetailData, setStreamerDetailData] = useState(null);
|
2024-07-25 19:52:30 +08:00
|
|
|
|
const [wechat, setWechat] = useState(<DotLoading />);
|
2024-07-30 22:53:41 +08:00
|
|
|
|
//保存用户微信号
|
|
|
|
|
const [userWechat, setUserWechat] = useState("");
|
|
|
|
|
//保存用户备注
|
|
|
|
|
const [remarks, setRemarks] = useState("");
|
2024-07-06 11:05:19 +08:00
|
|
|
|
const router = useRouter();
|
2024-07-15 16:54:04 +08:00
|
|
|
|
useEffect(() => {
|
2024-08-05 18:59:30 +08:00
|
|
|
|
// console.log("avatar", avatar);
|
2024-07-15 16:54:04 +08:00
|
|
|
|
if (!streamerMid) return;
|
|
|
|
|
getStreamerDetailInfo(streamerMid).then((res) => {
|
|
|
|
|
setStreamerDetailData(res);
|
|
|
|
|
});
|
|
|
|
|
}, [streamerData]);
|
|
|
|
|
useEffect(() => {
|
2024-08-05 18:59:30 +08:00
|
|
|
|
// console.log("avatar", avatar);
|
2024-07-15 20:00:44 +08:00
|
|
|
|
if (!streamerDetailData || !streamerDetailData?.is_unlock_wechat) return;
|
2024-07-22 16:07:41 +08:00
|
|
|
|
requireAPI("POST", "/api/vas/query_wechat", {
|
2024-07-15 16:54:04 +08:00
|
|
|
|
body: {
|
|
|
|
|
uid: streamerMid,
|
|
|
|
|
},
|
2024-07-25 19:52:30 +08:00
|
|
|
|
}).then((res) => {
|
|
|
|
|
setWechat(res.data?.wechat_contact);
|
|
|
|
|
});
|
2024-07-15 16:54:04 +08:00
|
|
|
|
}, [streamerDetailData]);
|
2024-07-06 11:05:19 +08:00
|
|
|
|
//点击解锁微信按钮
|
2024-07-30 22:53:41 +08:00
|
|
|
|
const unlockWechat = async (type) => {
|
2024-07-06 11:05:19 +08:00
|
|
|
|
//余额不够就显示余额不足前往充值,够就直接购买
|
|
|
|
|
|
|
|
|
|
//先支付,支付成功后添加解锁关系,再展示解锁界面
|
|
|
|
|
//支付金币解锁微信
|
|
|
|
|
const account = get("account");
|
|
|
|
|
if (account) {
|
|
|
|
|
try {
|
2024-07-25 19:52:30 +08:00
|
|
|
|
const userResponse = await requireAPI(
|
|
|
|
|
"POST",
|
|
|
|
|
"/api/account/list_by_mid",
|
|
|
|
|
{
|
|
|
|
|
body: {
|
|
|
|
|
mid: account.mid,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
);
|
2024-07-06 11:05:19 +08:00
|
|
|
|
if (userResponse.ret === -1) {
|
|
|
|
|
Toast.show({
|
|
|
|
|
icon: "fail",
|
|
|
|
|
content: data.msg,
|
|
|
|
|
position: "top",
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (userResponse?.data.account?.gold_num >= price) {
|
2024-08-05 18:59:30 +08:00
|
|
|
|
// console.log("余额足够");
|
2024-07-30 22:53:41 +08:00
|
|
|
|
if (type) {
|
|
|
|
|
if (!userWechat) {
|
2024-07-31 14:46:03 +08:00
|
|
|
|
Toast.show({
|
|
|
|
|
content: "请填写您的微信",
|
|
|
|
|
position: "top",
|
|
|
|
|
});
|
2024-07-30 22:53:41 +08:00
|
|
|
|
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) => {
|
|
|
|
|
//提交用户微信和备注
|
2024-07-31 15:11:13 +08:00
|
|
|
|
|
2024-07-30 22:53:41 +08:00
|
|
|
|
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) {
|
|
|
|
|
//用户已解锁微信情况:直接提交用户微信和备注
|
2024-08-05 18:59:30 +08:00
|
|
|
|
// console.log(
|
|
|
|
|
// "ccccc",
|
|
|
|
|
// streamerDetailData,
|
|
|
|
|
// streamerData.wechat_order_id
|
|
|
|
|
// );
|
2024-07-31 14:46:03 +08:00
|
|
|
|
await submitWechat(streamerDetailData.wechat_order_id);
|
2024-07-30 22:53:41 +08:00
|
|
|
|
setStreamerDetailData({
|
2024-07-31 14:46:03 +08:00
|
|
|
|
...streamerDetailData,
|
2024-07-30 22:53:41 +08:00
|
|
|
|
wechat_order_status: 3,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
2024-08-05 18:59:30 +08:00
|
|
|
|
// console.log(
|
|
|
|
|
// "xxxx",
|
|
|
|
|
// streamerDetailData,
|
|
|
|
|
// streamerData.wechat_order_id
|
|
|
|
|
// );
|
2024-07-30 22:53:41 +08:00
|
|
|
|
const order_id = await payCoin();
|
|
|
|
|
if (!order_id) return;
|
2024-07-31 15:11:13 +08:00
|
|
|
|
|
2024-07-30 22:53:41 +08:00
|
|
|
|
await submitWechat(order_id);
|
|
|
|
|
//展示解锁成功界面
|
|
|
|
|
// setIsWechatUnlocked(true);
|
|
|
|
|
setStreamerDetailData({
|
2024-07-31 14:46:03 +08:00
|
|
|
|
...streamerDetailData,
|
2024-07-31 15:11:13 +08:00
|
|
|
|
wechat_order_status: 3,
|
|
|
|
|
is_unlock_wechat: 1,
|
2024-07-31 14:46:03 +08:00
|
|
|
|
});
|
2024-07-30 22:53:41 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
const data = await requireAPI("POST", "/api/vas/one_step_unlock", {
|
|
|
|
|
body: {
|
|
|
|
|
contact_product_id: "contact_wechat",
|
|
|
|
|
uid: streamerMid,
|
|
|
|
|
},
|
2024-07-06 11:05:19 +08:00
|
|
|
|
});
|
2024-07-30 22:53:41 +08:00
|
|
|
|
if (data.ret === -1) {
|
|
|
|
|
Toast.show({
|
|
|
|
|
icon: "fail",
|
|
|
|
|
content: data.msg,
|
|
|
|
|
position: "top",
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-07-31 14:46:03 +08:00
|
|
|
|
setStreamerDetailData({
|
|
|
|
|
...streamerDetailData,
|
|
|
|
|
wechat_order_status: 3,
|
2024-07-31 15:11:13 +08:00
|
|
|
|
is_unlock_wechat: 1,
|
2024-07-31 14:46:03 +08:00
|
|
|
|
});
|
2024-07-06 11:05:19 +08:00
|
|
|
|
}
|
2024-07-30 22:53:41 +08:00
|
|
|
|
|
2024-07-06 11:05:19 +08:00
|
|
|
|
//展示解锁界面
|
|
|
|
|
// setIsWechatUnlocked(true);
|
2024-07-25 19:52:30 +08:00
|
|
|
|
getStreamerDetailInfo(streamerMid).then((res) => {
|
|
|
|
|
setStreamerDetailData(res);
|
|
|
|
|
});
|
2024-07-06 11:05:19 +08:00
|
|
|
|
} else {
|
|
|
|
|
setIsMoneyEnough(false);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Mask visible={visible}>
|
|
|
|
|
<div className="relative w-screen h-screen">
|
|
|
|
|
<div className="w-full h-full" onClick={() => closeMask(false)}></div>
|
|
|
|
|
<div className="absolute top-1/2 left-1/2 -ml-[35vw] -mt-[35vw] w-[70vw] h-max flex flex-col justify-center items-center p-4 pt-10 bg-[#261e30] rounded-2xl">
|
|
|
|
|
{isMoneyEnough ? (
|
|
|
|
|
<>
|
|
|
|
|
<Image
|
|
|
|
|
src={avatar}
|
|
|
|
|
width={64}
|
|
|
|
|
height={64}
|
|
|
|
|
className="rounded-full absolute -top-8"
|
2024-07-25 19:52:30 +08:00
|
|
|
|
fit="cover"
|
2024-07-06 11:05:19 +08:00
|
|
|
|
/>
|
|
|
|
|
<p className="text-2xl font-bold">{name}</p>
|
2024-07-30 22:53:41 +08:00
|
|
|
|
<div className="mt-2 w-full">
|
2024-07-08 20:07:36 +08:00
|
|
|
|
<div>
|
|
|
|
|
{streamerData?.streamer_ext?.wechat_lock_type === 0 ? (
|
2024-07-30 22:53:41 +08:00
|
|
|
|
<div className="flex flex-col justify-center items-center">
|
2024-07-08 20:07:36 +08:00
|
|
|
|
<div className="my-2 bg-[#FFFFFF1A] px-4 py-2 rounded-lg text-base text-center">
|
2024-07-25 19:52:30 +08:00
|
|
|
|
{streamerDetailData?.is_unlock_wechat
|
|
|
|
|
? wechat
|
|
|
|
|
: "解锁后展示"}
|
2024-07-30 22:53:41 +08:00
|
|
|
|
{!!streamerDetailData?.is_unlock_wechat && (
|
|
|
|
|
<FontAwesomeIcon
|
|
|
|
|
icon={faCopy}
|
|
|
|
|
// size="sm"
|
|
|
|
|
color="#ffffff"
|
|
|
|
|
className="ml-2"
|
2024-07-31 15:11:13 +08:00
|
|
|
|
onClick={() => {
|
|
|
|
|
clipboard(wechat);
|
|
|
|
|
Toast.show({
|
|
|
|
|
icon: "success",
|
|
|
|
|
content: "已复制到剪贴板",
|
|
|
|
|
position: "top",
|
|
|
|
|
});
|
|
|
|
|
}}
|
2024-07-30 22:53:41 +08:00
|
|
|
|
/>
|
|
|
|
|
)}
|
2024-07-08 20:07:36 +08:00
|
|
|
|
</div>
|
|
|
|
|
<p className="text-[red] text-center mb-2">
|
|
|
|
|
添加时请备注自己“铁粉空间”昵称
|
|
|
|
|
<br />
|
|
|
|
|
若解锁后72小时为通过好友,请联系客服
|
|
|
|
|
</p>
|
2024-07-30 22:53:41 +08:00
|
|
|
|
{(!streamerDetailData?.is_unlock_wechat ||
|
|
|
|
|
streamerDetailData?.wechat_order_status === 2) && (
|
|
|
|
|
<div
|
|
|
|
|
className="bg-primary px-4 py-2 rounded-full flex items-center justify-center"
|
2024-07-31 15:11:13 +08:00
|
|
|
|
onClick={() => unlockWechat()}
|
2024-07-30 22:53:41 +08:00
|
|
|
|
>
|
|
|
|
|
{!streamerDetailData?.is_unlock_wechat && (
|
|
|
|
|
<span className="text-[16px] whitespace-nowrap">
|
|
|
|
|
解锁微信(
|
|
|
|
|
{
|
|
|
|
|
streamerDetailData?.streamer_ext
|
|
|
|
|
?.wechat_coin_price
|
|
|
|
|
}
|
|
|
|
|
金币)
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2024-07-08 20:07:36 +08:00
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<div>
|
2024-07-15 16:54:04 +08:00
|
|
|
|
{streamerDetailData?.is_unlock_wechat &&
|
|
|
|
|
streamerDetailData?.wechat_order_status !== 2 ? (
|
|
|
|
|
<p className="text-sm text-center text-white mt-2">
|
2024-07-25 19:52:30 +08:00
|
|
|
|
{(streamerDetailData?.wechat_order_status === 0 ||
|
|
|
|
|
streamerDetailData?.wechat_order_status === 3) &&
|
2024-07-15 16:54:04 +08:00
|
|
|
|
"已成功提交您的微信,请耐心等待"}
|
2024-07-25 19:52:30 +08:00
|
|
|
|
{(streamerDetailData?.wechat_order_status === 4 ||
|
|
|
|
|
streamerDetailData?.wechat_order_status === 5) &&
|
2024-07-15 16:54:04 +08:00
|
|
|
|
"已确认添加,订单完成"}
|
2024-07-08 20:07:36 +08:00
|
|
|
|
</p>
|
2024-07-15 16:54:04 +08:00
|
|
|
|
) : (
|
|
|
|
|
<div>
|
|
|
|
|
<div>
|
|
|
|
|
<p>
|
|
|
|
|
<span className="text-[#F53030]">*</span>
|
|
|
|
|
您的微信
|
|
|
|
|
</p>
|
|
|
|
|
<div className="text-white text-sm border border-[#2c2b2f] rounded-xl p-2 my-1 w-full">
|
|
|
|
|
<Input
|
|
|
|
|
placeholder="填写您的微信,以便Ta主动联系您"
|
2024-08-05 18:59:30 +08:00
|
|
|
|
style={{"--font-size": "16px"}}
|
2024-07-30 22:53:41 +08:00
|
|
|
|
onChange={(value) => setUserWechat(value)}
|
|
|
|
|
value={userWechat}
|
2024-07-15 16:54:04 +08:00
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="mt-2">
|
|
|
|
|
<p>备注</p>
|
|
|
|
|
<div className="text-white border border-[#2c2b2f] rounded-xl p-2 my-1 w-full">
|
|
|
|
|
<TextArea
|
|
|
|
|
placeholder="如添加好友需填写验证信息,请将相应答案填写在此处"
|
2024-08-05 18:59:30 +08:00
|
|
|
|
style={{"--font-size": "16px"}}
|
2024-07-30 22:53:41 +08:00
|
|
|
|
onChange={(value) => setRemarks(value)}
|
|
|
|
|
value={remarks}
|
2024-07-15 16:54:04 +08:00
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-07-08 20:07:36 +08:00
|
|
|
|
</div>
|
2024-07-15 16:54:04 +08:00
|
|
|
|
)}
|
|
|
|
|
<p className="text-xs text-center text-[#F53030] font-medium my-2">
|
2024-07-08 20:07:36 +08:00
|
|
|
|
若解锁后72小时未通过好友,请联系客服
|
|
|
|
|
</p>
|
2024-07-30 22:53:41 +08:00
|
|
|
|
{(!streamerDetailData?.is_unlock_wechat ||
|
|
|
|
|
streamerDetailData?.wechat_order_status === 2) && (
|
|
|
|
|
<div
|
|
|
|
|
className="bg-primary px-4 py-2 rounded-full flex items-center justify-center"
|
|
|
|
|
onClick={() => unlockWechat("sendWechat")}
|
|
|
|
|
>
|
|
|
|
|
{/* {!streamerDetailData?.is_unlock_wechat && (
|
2024-07-15 16:54:04 +08:00
|
|
|
|
<span className="text-[16px] whitespace-nowrap">
|
|
|
|
|
解锁微信(
|
|
|
|
|
{streamerDetailData?.streamer_ext?.wechat_coin_price}
|
|
|
|
|
金币)
|
|
|
|
|
</span>
|
2024-07-30 22:53:41 +08:00
|
|
|
|
)} */}
|
|
|
|
|
{!streamerDetailData?.is_unlock_wechat && (
|
|
|
|
|
<span className="text-[16px] whitespace-nowrap">
|
|
|
|
|
提交并支付(
|
|
|
|
|
{
|
|
|
|
|
streamerDetailData?.streamer_ext
|
|
|
|
|
?.wechat_coin_price
|
|
|
|
|
}
|
|
|
|
|
金币)
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
{streamerDetailData?.wechat_order_status === 2 && (
|
|
|
|
|
<span className="text-white text-base font-medium px-4 whitespace-nowrap">
|
|
|
|
|
提交微信
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2024-07-15 16:54:04 +08:00
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2024-07-08 20:07:36 +08:00
|
|
|
|
</div>
|
2024-07-06 11:05:19 +08:00
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<>
|
2024-07-08 20:07:36 +08:00
|
|
|
|
<p className="text-2xl text-white font-medium mb-4">余额不足</p>
|
2024-07-06 11:05:19 +08:00
|
|
|
|
<div
|
|
|
|
|
onClick={() => {
|
|
|
|
|
router.push("/my/wallet");
|
|
|
|
|
closeMask(false);
|
|
|
|
|
setIsMoneyEnough(true);
|
|
|
|
|
}}
|
|
|
|
|
className="px-4 py-2 bg-[#FF669E] rounded-full items-center justify-center"
|
|
|
|
|
>
|
|
|
|
|
<span className="text-white text-base">前往充值</span>
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Mask>
|
|
|
|
|
);
|
|
|
|
|
}
|