|
@@ -1,18 +1,17 @@
|
|
|
import styles from './styles.module.scss';
|
|
import styles from './styles.module.scss';
|
|
|
-import {useState} from "react";
|
|
|
|
|
-const WelfareBtn=({children,...props})=>{
|
|
|
|
|
- const [isPressed, setIsPressed] = useState(false);
|
|
|
|
|
- const handleMouseDown = () => {
|
|
|
|
|
- setIsPressed(true);
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- const handleMouseUp = () => {
|
|
|
|
|
- setIsPressed(false);
|
|
|
|
|
- };
|
|
|
|
|
|
|
+import {useEffect, useState} from "react";
|
|
|
|
|
+import {reqFirstPayConfig, reqProtectCheck} from "@features/api";
|
|
|
|
|
+import {useDispatch, useSelector} from "react-redux";
|
|
|
|
|
+import {getFirstBonus, getOpenRelief, getPopBindPhone, getUserInfo} from "@features/mainSlice";
|
|
|
|
|
+import {APP_WELFARE} from "@constants/app";
|
|
|
|
|
+import {getCurrPayOrder, getOFirstPay} from "@features/paySlice";
|
|
|
|
|
+import {getProtectInfo} from "@features/protectSlice";
|
|
|
|
|
+import {formatCash} from "@utils/helpers";
|
|
|
|
|
+import {useThemeProvider} from "@contexts/themeContext";
|
|
|
|
|
+import {useSidebar} from "@contexts/sidebarContext";
|
|
|
|
|
+const WelfareBtn=({children,open=false,pressDown=false,...props})=>{
|
|
|
return (
|
|
return (
|
|
|
- <button className={`${styles.wlf_btn} ${isPressed?styles.wlf_btn_press:''}`}
|
|
|
|
|
- onMouseDown={handleMouseDown}
|
|
|
|
|
- onMouseUp={handleMouseUp}
|
|
|
|
|
|
|
+ <button className={`${styles.wlf_btn} ${open?styles.wlf_btn_open:styles.wlf_btn_close} ${pressDown?styles.wlf_btn_press:''}`}
|
|
|
{...props}
|
|
{...props}
|
|
|
>
|
|
>
|
|
|
{
|
|
{
|
|
@@ -22,26 +21,151 @@ const WelfareBtn=({children,...props})=>{
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
const WWelfarebar = () => {
|
|
const WWelfarebar = () => {
|
|
|
- return (
|
|
|
|
|
- <div className={styles.container}>
|
|
|
|
|
- <div className={styles.content}>
|
|
|
|
|
- <WelfareBtn key={"protect"} onClick={()=>{
|
|
|
|
|
- global.showProtectReward();
|
|
|
|
|
- }}>
|
|
|
|
|
- <img className={styles.wlf_protect} src={require("@assets/welfare/protect.png")}/>
|
|
|
|
|
- </WelfareBtn>
|
|
|
|
|
- <WelfareBtn key={"first_pay"} onClick={()=>{
|
|
|
|
|
- global.showFirstPay();
|
|
|
|
|
- }}>
|
|
|
|
|
- <img className={styles.wlf_first} src={require("@assets/welfare/first_pay.png")}/>
|
|
|
|
|
- </WelfareBtn>
|
|
|
|
|
- <WelfareBtn key={"bind"} onClick={()=>{
|
|
|
|
|
- global.showBindPhone();
|
|
|
|
|
- }}>
|
|
|
|
|
- <img className={styles.wlf_bind} src={require("@assets/welfare/bind.png")}/>
|
|
|
|
|
- </WelfareBtn>
|
|
|
|
|
|
|
+ const dispatch = useDispatch();
|
|
|
|
|
+ const user=useSelector(getUserInfo);
|
|
|
|
|
+ //0:1,1:1,2:1
|
|
|
|
|
+ // const [openState, setOpenState] = useState({});
|
|
|
|
|
+ const [openProtect,setOpenProtect]=useState(0);
|
|
|
|
|
+ const [openFirst,setOpenFirst]=useState(0);
|
|
|
|
|
+ const [openBind,setOpenBind]=useState(0);
|
|
|
|
|
+ const firstPayConf=useSelector(getOFirstPay);
|
|
|
|
|
+ const popBindPhone=useSelector(getPopBindPhone);
|
|
|
|
|
+ const firstBonus=useSelector(getFirstBonus);
|
|
|
|
|
+ const openRelief=useSelector(getOpenRelief);
|
|
|
|
|
+ const protectInfo=useSelector(getProtectInfo);
|
|
|
|
|
+ const orderInfo=useSelector(getCurrPayOrder);
|
|
|
|
|
+ const {welfTabState,isMobile}=useThemeProvider();
|
|
|
|
|
+ const {open} = useSidebar();
|
|
|
|
|
+ const getWelfTabState=(key)=>{
|
|
|
|
|
+ if (welfTabState===key)return true;
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ const changeNewState=(key,state)=>{
|
|
|
|
|
+ // let newOpenState= Object.assign({},openState);
|
|
|
|
|
+ // newOpenState[key]=state;
|
|
|
|
|
+ // setOpenState(newOpenState);
|
|
|
|
|
+ // state=1;
|
|
|
|
|
+ switch (key){
|
|
|
|
|
+ case APP_WELFARE.PROTECT:
|
|
|
|
|
+ setOpenProtect(state);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case APP_WELFARE.FIRST_PAY:
|
|
|
|
|
+ setOpenFirst(state);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case APP_WELFARE.BIND:
|
|
|
|
|
+ setOpenBind(state);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ const checkProtect=()=>{
|
|
|
|
|
+ let state=0;
|
|
|
|
|
+ if (openRelief){
|
|
|
|
|
+ if (protectInfo!=null){
|
|
|
|
|
+ if (user.UserID>0){
|
|
|
|
|
+ let CurProtectTimes=protectInfo.CurProtectTimes!=null?parseInt(protectInfo.CurProtectTimes):0;
|
|
|
|
|
+ if (CurProtectTimes>0)state=1;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ changeNewState(APP_WELFARE.PROTECT,state);
|
|
|
|
|
+ }
|
|
|
|
|
+ const checkProtectLimit=()=>{
|
|
|
|
|
+ if (protectInfo!=null){
|
|
|
|
|
+ let ProtectLimit=protectInfo.ProtectLimit;
|
|
|
|
|
+ if (ProtectLimit!=null){
|
|
|
|
|
+ ProtectLimit=Number(ProtectLimit);
|
|
|
|
|
+ ProtectLimit=Number(formatCash(ProtectLimit))
|
|
|
|
|
+ let Score=user.Score;
|
|
|
|
|
+ if (Score<=ProtectLimit){
|
|
|
|
|
+ dispatch(reqProtectCheck());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ const checkFirstPay=()=>{
|
|
|
|
|
+ let state=0;
|
|
|
|
|
+ if (firstBonus){
|
|
|
|
|
+ if (user.UserID>0){
|
|
|
|
|
+ if (firstPayConf!=null)state=1;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ changeNewState(APP_WELFARE.FIRST_PAY,state);
|
|
|
|
|
+ }
|
|
|
|
|
+ const checkFirstPayStatus=()=>{
|
|
|
|
|
+ if (orderInfo!=null){
|
|
|
|
|
+ if (orderInfo.status==="success"){
|
|
|
|
|
+ dispatch(reqFirstPayConfig());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ const checkBind=()=>{
|
|
|
|
|
+ let state=0;
|
|
|
|
|
+ if (popBindPhone){
|
|
|
|
|
+ if (user.UserID>0){
|
|
|
|
|
+ if (user.Phone==null||user.Phone===""){
|
|
|
|
|
+ state=1;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ changeNewState(APP_WELFARE.BIND,state);
|
|
|
|
|
+ }
|
|
|
|
|
+ useEffect(()=>{
|
|
|
|
|
+ let UserID=user.UserID;
|
|
|
|
|
+ if (UserID>0){
|
|
|
|
|
+ dispatch(reqProtectCheck());
|
|
|
|
|
+ dispatch(reqFirstPayConfig());
|
|
|
|
|
+ }
|
|
|
|
|
+ },[user.UserID]);
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ checkProtectLimit();
|
|
|
|
|
+ }, [user.Score]);
|
|
|
|
|
+ useEffect(()=>{
|
|
|
|
|
+ checkFirstPay();
|
|
|
|
|
+ },[firstPayConf]);
|
|
|
|
|
+ useEffect(()=>{
|
|
|
|
|
+ checkBind();
|
|
|
|
|
+ },[popBindPhone,user.Phone]);
|
|
|
|
|
+ useEffect(()=>{
|
|
|
|
|
+ checkProtect();
|
|
|
|
|
+ },[protectInfo])
|
|
|
|
|
+ useEffect(()=>{
|
|
|
|
|
+ checkFirstPayStatus();
|
|
|
|
|
+ },[orderInfo])
|
|
|
|
|
+ const renderBar=()=>{
|
|
|
|
|
+ let extra='';
|
|
|
|
|
+ if (!isMobile()){
|
|
|
|
|
+ if (open)extra='sidebar-open';
|
|
|
|
|
+ else extra='sidebar-close';
|
|
|
|
|
+ }
|
|
|
|
|
+ return (
|
|
|
|
|
+ <div className={`${styles.container} ${extra}`}>
|
|
|
|
|
+ <div className={styles.content}>
|
|
|
|
|
+ <WelfareBtn key={"protect"} open={openProtect} pressDown={getWelfTabState(APP_WELFARE.PROTECT)}
|
|
|
|
|
+ onClick={() => {
|
|
|
|
|
+ global.showProtectReward();
|
|
|
|
|
+ }}>
|
|
|
|
|
+ <img className={styles.wlf_protect} src={require("@assets/welfare/protect.png")}/>
|
|
|
|
|
+ </WelfareBtn>
|
|
|
|
|
+ <WelfareBtn key={"first_pay"} open={openFirst} pressDown={getWelfTabState(APP_WELFARE.FIRST_PAY)}
|
|
|
|
|
+ onClick={() => {
|
|
|
|
|
+ global.showFirstPay();
|
|
|
|
|
+ }}>
|
|
|
|
|
+ <img className={styles.wlf_first} src={require("@assets/welfare/first_pay.png")}/>
|
|
|
|
|
+ </WelfareBtn>
|
|
|
|
|
+ <WelfareBtn key={"bind"} open={openBind} pressDown={getWelfTabState(APP_WELFARE.BIND)}
|
|
|
|
|
+ onClick={() => {
|
|
|
|
|
+ global.showBindPhone();
|
|
|
|
|
+ }}>
|
|
|
|
|
+ <img className={styles.wlf_bind} src={require("@assets/welfare/bind.png")}/>
|
|
|
|
|
+ </WelfareBtn>
|
|
|
|
|
+ </div>
|
|
|
</div>
|
|
</div>
|
|
|
- </div>
|
|
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ return (
|
|
|
|
|
+ <>
|
|
|
|
|
+ {renderBar()}
|
|
|
|
|
+ </>
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
export default WWelfarebar;
|
|
export default WWelfarebar;
|