|
|
@@ -13,8 +13,16 @@ import time_icon from "@assets/moneyrain/shijian_bai.png";
|
|
|
import star_icon from "@assets/moneyrain/bofang_bai.png";
|
|
|
import rain_bg1 from "@assets/moneyrain/rain_bg1.png";
|
|
|
import rain_bg2 from "@assets/moneyrain/rain_bg2.png";
|
|
|
-import {format2LongChips, stringFormat} from "@utils/helpers";
|
|
|
+import {format2LongChips, formatCash, formatTime, stringFormat} from "@utils/helpers";
|
|
|
import WRainAni from "@widgets/WMoneyRain/WRainAni/WRainAni";
|
|
|
+import {useDispatch, useSelector} from "react-redux";
|
|
|
+import {getReciveStatus, getRedPackConfig, getRedPackInfo, updateAlRecivedStatus} from "@features/redpackSlice";
|
|
|
+import {useEffect, useState} from "react";
|
|
|
+import {reqRedpackCheck, reqRedpackRecive} from "@features/api";
|
|
|
+import {getConfig} from "@features/paySlice";
|
|
|
+import {REQ_STATUS} from "@api/config";
|
|
|
+import SmallLoading from "@components/SmallLoading";
|
|
|
+import CountUp from "react-countup";
|
|
|
const i18n=global.i18n;
|
|
|
const StyledRules=styled.div`
|
|
|
background: url(${rain_bg3});
|
|
|
@@ -30,6 +38,30 @@ const StyledRedOpen=styled.div`
|
|
|
`
|
|
|
|
|
|
const WMoneyRain = ({close}) => {
|
|
|
+ const redpack=useSelector(getRedPackInfo);
|
|
|
+ const config=useSelector(getRedPackConfig);
|
|
|
+ const reciveStatus=useSelector(getReciveStatus);
|
|
|
+ const [open,setOpen]=useState(true);
|
|
|
+ const dispatch=useDispatch();
|
|
|
+ useEffect(()=>{
|
|
|
+ dispatch(reqRedpackCheck());
|
|
|
+ return ()=>{
|
|
|
+
|
|
|
+ }
|
|
|
+ },[]);
|
|
|
+ useEffect(()=>{
|
|
|
+ if (!open){
|
|
|
+ if (redpack&&redpack.status===2){
|
|
|
+ dispatch(updateAlRecivedStatus())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },[open])
|
|
|
+ const getDropMax=()=>{
|
|
|
+ if (redpack==null)return 0;
|
|
|
+ let max=Number(redpack.max);
|
|
|
+ max=max*global.CASH_BASE;
|
|
|
+ return max;
|
|
|
+ }
|
|
|
const getRuleTxt=(totalStr)=>{
|
|
|
let txt=[];
|
|
|
for (let i = 0; i < 4; i++) {
|
|
|
@@ -39,23 +71,47 @@ const WMoneyRain = ({close}) => {
|
|
|
}
|
|
|
return txt;
|
|
|
}
|
|
|
+ const getTimeConfig=()=>{
|
|
|
+ let timeData=[];
|
|
|
+ if (config){
|
|
|
+ for (let i = 0; i < config.length; i++) {
|
|
|
+ let item=config[i];
|
|
|
+ if (item){
|
|
|
+ let str=item.StartTime+"-"+item.EndTime;
|
|
|
+ timeData.push(str);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return timeData;
|
|
|
+ }
|
|
|
+ const onClickCollect=()=>{
|
|
|
+ if (redpack==null)return;
|
|
|
+ if (redpack.status!==1)return;
|
|
|
+ if (reciveStatus===REQ_STATUS.LOADING)return;
|
|
|
+ dispatch(reqRedpackRecive());
|
|
|
+ }
|
|
|
+ const onClose=()=>{
|
|
|
+ setOpen(false);
|
|
|
+ if(close)close();
|
|
|
+ }
|
|
|
const renderRules=()=>{
|
|
|
let toatlNum=10000000;
|
|
|
- let maxNum=777700;
|
|
|
+ let maxNum=getDropMax();
|
|
|
let totalStr=format2LongChips(toatlNum);
|
|
|
let maxStr=format2LongChips(maxNum);
|
|
|
- let timeData=[
|
|
|
- "12:00-12:59",
|
|
|
- "14:00-14:59",
|
|
|
- "18:00-18:59",
|
|
|
- "20:00-20:59"
|
|
|
- ];
|
|
|
+ // let timeData=[
|
|
|
+ // "12:00-12:59",
|
|
|
+ // "14:00-14:59",
|
|
|
+ // "18:00-18:59",
|
|
|
+ // "20:00-20:59"
|
|
|
+ // ];
|
|
|
+ let timeData=getTimeConfig();
|
|
|
let timeLen=timeData.length;
|
|
|
let rules=getRuleTxt(totalStr);
|
|
|
return (
|
|
|
- <Grow in={true} timeout={500}>
|
|
|
+ <Grow in={open} timeout={500}>
|
|
|
<StyledRules className={styles.rule_container}>
|
|
|
- <button className={styles.close} onClick={close}>
|
|
|
+ <button className={styles.close} onClick={onClose}>
|
|
|
<img src={close_bai}/>
|
|
|
</button>
|
|
|
<div className={styles.title}>
|
|
|
@@ -114,13 +170,13 @@ const WMoneyRain = ({close}) => {
|
|
|
}
|
|
|
const renderRedPack=()=>{
|
|
|
let toatlNum=10000000;
|
|
|
- let maxNum=777700;
|
|
|
+ let maxNum=getDropMax();
|
|
|
let totalStr=format2LongChips(toatlNum);
|
|
|
let maxStr=format2LongChips(maxNum);
|
|
|
return (
|
|
|
- <Grow in={true} timeout={500}>
|
|
|
+ <Grow in={open} timeout={500}>
|
|
|
<StyledRedPack className={styles.red_pack_con}>
|
|
|
- <button className={styles.close} onClick={close}>
|
|
|
+ <button className={styles.close} onClick={onClose}>
|
|
|
<img src={close_bai}/>
|
|
|
</button>
|
|
|
<div className={styles.title}>
|
|
|
@@ -137,8 +193,9 @@ const WMoneyRain = ({close}) => {
|
|
|
</div>
|
|
|
</div>
|
|
|
<div className={styles.red_btn_con}>
|
|
|
- <button className={styles.red_btn}>
|
|
|
- {i18n.t("moneyRain.redPack.btn")}
|
|
|
+ <button className={styles.red_btn} onClick={onClickCollect}>
|
|
|
+ {reciveStatus===REQ_STATUS.LOADING?(<SmallLoading fill={"#fff"}></SmallLoading>):(i18n.t("moneyRain.redPack.btn"))}
|
|
|
+ {/*{i18n.t("moneyRain.redPack.btn")}*/}
|
|
|
</button>
|
|
|
</div>
|
|
|
</StyledRedPack>
|
|
|
@@ -146,38 +203,99 @@ const WMoneyRain = ({close}) => {
|
|
|
)
|
|
|
}
|
|
|
const renderRedOpen=()=>{
|
|
|
- let reciveNum=10000;
|
|
|
- let maxNum=777700;
|
|
|
- let maxStr=format2LongChips(maxNum);
|
|
|
- let reciveStr=format2LongChips(reciveNum);
|
|
|
+ let reciveNum=redpack.amount;
|
|
|
+ // reciveNum=34;
|
|
|
+ let maxNum=getDropMax();
|
|
|
+ let maxStr=global.DOLLAR+" "+format2LongChips(maxNum);
|
|
|
+ let reciveStr=global.DOLLAR+" "+format2LongChips(reciveNum);
|
|
|
+ let next_in_seconds=redpack.next_in_seconds;
|
|
|
+ let timeStr=formatTime(next_in_seconds);
|
|
|
+ return (
|
|
|
+ <Fade in={open} timeout={500}>
|
|
|
+ <Grow in={open} timeout={500}>
|
|
|
+ <StyledRedOpen className={styles.red_open_con}>
|
|
|
+ <button className={styles.close} onClick={onClose} style={{right: "0.5rem"}}>
|
|
|
+ <img src={close_icon}/>
|
|
|
+ </button>
|
|
|
+ <div className={styles.red_amount_uint}>{i18n.t("moneyRain.redOpen.max_drop")+maxStr}</div>
|
|
|
+ {/*<div className={styles.red_amount_recive}>{reciveStr}</div>*/}
|
|
|
+ <CountUp
|
|
|
+ start={0}
|
|
|
+ end={Number(formatCash(reciveNum))}
|
|
|
+ duration={1}
|
|
|
+ separator=" "
|
|
|
+ decimals={2}
|
|
|
+ prefix={global.DOLLAR+" "}
|
|
|
+ startOnMount
|
|
|
+ >
|
|
|
+ {({ countUpRef, start }) => {
|
|
|
+ return (
|
|
|
+ <div ref={(ref)=>{
|
|
|
+ countUpRef.current=ref;
|
|
|
+ start();
|
|
|
+ }} className={styles.red_amount_recive}/>
|
|
|
+ )
|
|
|
+ }}
|
|
|
+ </CountUp>
|
|
|
+ {/*<div className={styles.red_open_tips}>*/}
|
|
|
+ {/* <div>{i18n.t("moneyRain.redOpen.time_tips")}</div>*/}
|
|
|
+ {/* <div className={styles.time}>{timeStr}</div>*/}
|
|
|
+ {/*</div>*/}
|
|
|
+ </StyledRedOpen>
|
|
|
+ </Grow>
|
|
|
+ </Fade>
|
|
|
+ )
|
|
|
+ }
|
|
|
+ const renderAlRecived=()=>{
|
|
|
+ let maxNum=getDropMax();
|
|
|
+ let maxStr=global.DOLLAR+" "+format2LongChips(maxNum);
|
|
|
return (
|
|
|
- <Grow in={true} timeout={500}>
|
|
|
+ <Grow in={open} timeout={500}>
|
|
|
<StyledRedOpen className={styles.red_open_con}>
|
|
|
- <button className={styles.close} onClick={close} style={{right: "0.5rem"}}>
|
|
|
+ <button className={styles.close} onClick={onClose} style={{right: "0.5rem"}}>
|
|
|
<img src={close_icon}/>
|
|
|
</button>
|
|
|
- <div className={styles.red_amount_uint}>{i18n.t("moneyRain.redOpen.max_drop")+maxStr}</div>
|
|
|
- <div className={styles.red_amount_recive}>{reciveStr}</div>
|
|
|
- <div className={styles.red_open_tips}>
|
|
|
- <div>{i18n.t("moneyRain.redOpen.time_tips")}</div>
|
|
|
- <div className={styles.time}>12:00:01</div>
|
|
|
- </div>
|
|
|
+ {/*<div className={styles.red_amount_uint}>{i18n.t("moneyRain.redOpen.max_drop")+maxStr}</div>*/}
|
|
|
+ <div className={styles.red_already_recived}>{i18n.t("moneyRain.redOpen.already_collect")}</div>
|
|
|
</StyledRedOpen>
|
|
|
</Grow>
|
|
|
)
|
|
|
}
|
|
|
+ const checkStatusRender=()=>{
|
|
|
+ // return renderAlRecived();
|
|
|
+ // return renderRedOpen();
|
|
|
+ if (redpack===null)return (<></>);
|
|
|
+ let status=redpack.status;
|
|
|
+ //时间未到
|
|
|
+ if (status===0){
|
|
|
+ return renderRules();
|
|
|
+ }
|
|
|
+ //领取
|
|
|
+ else if (status===1){
|
|
|
+ return renderRedPack();
|
|
|
+ }
|
|
|
+ //领取奖励
|
|
|
+ else if (status===2){
|
|
|
+ return renderRedOpen();
|
|
|
+ }
|
|
|
+ else if (status===-1){
|
|
|
+ // return renderAlRecived();
|
|
|
+ return renderRules();
|
|
|
+ }
|
|
|
+ }
|
|
|
const renderMain = () => {
|
|
|
return (
|
|
|
<>
|
|
|
{/*{renderRules()}*/}
|
|
|
{/*{renderRedPack()}*/}
|
|
|
- {renderRedOpen()}
|
|
|
+ {/*{renderRedOpen()}*/}
|
|
|
+ {checkStatusRender()}
|
|
|
</>
|
|
|
)
|
|
|
}
|
|
|
return (
|
|
|
- <Modal open={true} onClose={close} closeAfterTransition>
|
|
|
- <Fade in={true} timeout={500}>
|
|
|
+ <Modal open={open} onClose={onClose} closeAfterTransition>
|
|
|
+ <Fade in={open} timeout={500}>
|
|
|
<div className={styles.container}>
|
|
|
<WRainAni></WRainAni>
|
|
|
<div className={styles.content}>
|