|
@@ -1,17 +1,15 @@
|
|
|
"use client";
|
|
|
-import React, {useState} from 'react'
|
|
|
import { ServiceTypes } from "@/api/customservice";
|
|
|
+import { lredPacketApi, redPacketApi } from "@/api/promo";
|
|
|
import { Link } from "@/i18n";
|
|
|
import { useGlobalNoticeStore } from "@/stores/useGlobalNoticeStore";
|
|
|
import { useSocialStore } from "@/stores/useSocials";
|
|
|
-import { Badge } from "antd-mobile";
|
|
|
-import { useTranslations } from "next-intl";
|
|
|
-import { FC, useEffect } from "react";
|
|
|
-import PopupHby from "@/app/[locale]/(TabBar)/(entire)/promo/PopupHby";
|
|
|
-import { redPacketApi,lredPacketApi } from "@/api/promo";
|
|
|
import { getToken } from "@/utils/Cookies";
|
|
|
-import { getUserMoneyApi } from "@/api/user";
|
|
|
import { useRequest } from "ahooks";
|
|
|
+import { Badge } from "antd-mobile";
|
|
|
+import { useTranslations } from "next-intl";
|
|
|
+import { FC, useEffect, useState } from "react";
|
|
|
+import PopupHby from "../../promo/PopupHby";
|
|
|
|
|
|
interface Props {
|
|
|
services: ServiceTypes[];
|
|
@@ -20,7 +18,7 @@ interface Props {
|
|
|
const ServiceWidget: FC<Props> = (props) => {
|
|
|
const token = getToken();
|
|
|
const [isShowRedPacket, setIsShowRedPacket] = useState<any>(false);
|
|
|
- const [isShowRedIcon,setIsShowRedIcon] = useState(false)
|
|
|
+ const [isShowRedIcon, setIsShowRedIcon] = useState(false);
|
|
|
const { services, socials } = props;
|
|
|
const defaultService = services.find((item) => item.is_suspend === 1);
|
|
|
|
|
@@ -36,69 +34,66 @@ const ServiceWidget: FC<Props> = (props) => {
|
|
|
unread: state.unread,
|
|
|
}));
|
|
|
|
|
|
+ const getRedPacketInfo = async () => {
|
|
|
+ try {
|
|
|
+ let redPacketInfo: any;
|
|
|
+ let actList: any = [];
|
|
|
+ if (token) {
|
|
|
+ redPacketInfo = await lredPacketApi();
|
|
|
+ actList = redPacketInfo.data?.red_packets || [];
|
|
|
+ } else {
|
|
|
+ redPacketInfo = await redPacketApi();
|
|
|
+ actList = redPacketInfo.data || [];
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- const getRedPacketInfo =async()=>{
|
|
|
- try{
|
|
|
-
|
|
|
- let redPacketInfo:any
|
|
|
- let actList:any = []
|
|
|
- if(token){
|
|
|
- redPacketInfo =await lredPacketApi()
|
|
|
- actList = redPacketInfo.data?.red_packets || []
|
|
|
- }else{
|
|
|
- redPacketInfo =await redPacketApi()
|
|
|
- actList = redPacketInfo.data || []
|
|
|
+ // 是否有已开始但是没领过的红包
|
|
|
+ let isHasStartAct = actList.filter((aItem: any) => {
|
|
|
+ return !!aItem.is_start && !aItem.is_receive;
|
|
|
+ });
|
|
|
+ let isShowRed = isHasStartAct.length > 0;
|
|
|
+ setIsShowRedIcon(isShowRed);
|
|
|
+ } catch (error) {
|
|
|
+ console.log("redPacketInfo===>error:", error);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- // 是否有已开始但是没领过的红包
|
|
|
- let isHasStartAct = actList.filter((aItem:any)=>{
|
|
|
- return !!aItem.is_start && !aItem.is_receive
|
|
|
- })
|
|
|
- let isShowRed = isHasStartAct.length>0
|
|
|
- setIsShowRedIcon(isShowRed)
|
|
|
-
|
|
|
- }catch(error){
|
|
|
- console.log('redPacketInfo===>error:',error)
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ };
|
|
|
// 红包雨轮询
|
|
|
useRequest(getRedPacketInfo, {
|
|
|
- pollingInterval: 180000,
|
|
|
- pollingErrorRetryCount: 1,
|
|
|
- pollingWhenHidden: false,
|
|
|
- onSuccess: (data) => {
|
|
|
- console.log('data',data)
|
|
|
- },
|
|
|
+ pollingInterval: 180000,
|
|
|
+ pollingErrorRetryCount: 1,
|
|
|
+ pollingWhenHidden: false,
|
|
|
+ onSuccess: (data) => {
|
|
|
+ console.log("data", data);
|
|
|
+ },
|
|
|
});
|
|
|
|
|
|
return (
|
|
|
- <>
|
|
|
- {/* 红包雨icon */}
|
|
|
- {
|
|
|
- isShowRedIcon && (
|
|
|
- <div
|
|
|
- className={
|
|
|
- "flex h-[0.54rem] w-[0.54rem] items-center" +
|
|
|
- " absolute bottom-[2.04rem] right-[0.12rem] z-50 justify-center cursor-pointer"
|
|
|
- }
|
|
|
- >
|
|
|
- <img
|
|
|
- className={"h-[0.3889rem] w-[0.3889rem]"}
|
|
|
- src='/hby/red-icon.png'
|
|
|
- onClick={()=>{setIsShowRedPacket(true)}}
|
|
|
- />
|
|
|
- </div>
|
|
|
- )
|
|
|
- }
|
|
|
-
|
|
|
+ <>
|
|
|
+ {/* 红包雨icon */}
|
|
|
+ {isShowRedIcon && (
|
|
|
+ <div
|
|
|
+ className={
|
|
|
+ "flex h-[0.54rem] w-[0.54rem] items-center" +
|
|
|
+ " absolute bottom-[2.04rem] right-[0.12rem] z-50 cursor-pointer justify-center"
|
|
|
+ }
|
|
|
+ >
|
|
|
+ <img
|
|
|
+ className={"h-[0.3889rem] w-[0.3889rem]"}
|
|
|
+ src="/hby/red-icon.png"
|
|
|
+ onClick={() => {
|
|
|
+ setIsShowRedPacket(true);
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ )}
|
|
|
+
|
|
|
{/* 红包弹窗 */}
|
|
|
- {
|
|
|
- isShowRedPacket && (<PopupHby onClose={()=>{setIsShowRedPacket(false)}} />)
|
|
|
- }
|
|
|
+ {isShowRedPacket && (
|
|
|
+ <PopupHby
|
|
|
+ onClose={() => {
|
|
|
+ setIsShowRedPacket(false);
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ )}
|
|
|
|
|
|
{defaultService && (
|
|
|
<Link
|
|
@@ -160,10 +155,10 @@ const ServiceWidget: FC<Props> = (props) => {
|
|
|
target={"_blank"}
|
|
|
className="bg-white m-[0.05rem] h-[0.3889rem] w-[0.3889rem] rounded"
|
|
|
>
|
|
|
- <img
|
|
|
- className={"h-[0.3889rem] w-[0.3889rem]"}
|
|
|
- src={service.icon_url}
|
|
|
- ></img>
|
|
|
+ <img
|
|
|
+ className={"h-[0.3889rem] w-[0.3889rem]"}
|
|
|
+ src={service.icon_url}
|
|
|
+ ></img>
|
|
|
</Link>
|
|
|
);
|
|
|
})}
|