index.jsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. import styles from "./styles.module.scss";
  2. import WWheel from "@widgets/WCashWheel/WWheel/WWheel";
  3. import Spring from "@components/Spring";
  4. import cash_2 from "@assets/wheel/cash_2.png";
  5. import coin from "@assets/wheel/pix_2.png";
  6. import {useDispatch, useSelector} from "react-redux";
  7. import {getBonusStatus, getMyRecord, getRecord, getTurnplate} from "@features/turnplateSlice";
  8. import {formatCash, stringFormat} from "@utils/helpers";
  9. import React, {useEffect, useState} from "react";
  10. import {Autoplay, EffectCube,EffectCoverflow} from "swiper";
  11. import {Swiper, SwiperSlide} from "swiper/react";
  12. import styled from 'styled-components/macro';
  13. import CountUp from "react-countup";
  14. import Popup from "@components/Popup";
  15. import WShare from "@widgets/WCashWheel/WShare/WShare";
  16. import {isLogined} from "@features/mainSlice";
  17. import {useNavigate} from "react-router";
  18. import {ROUTE_PATH} from "@constants/routes";
  19. import SmallLoading from "@components/SmallLoading";
  20. import WRetainPop from "@widgets/WCashWheel/WRetainPop/WRetainPop";
  21. import {reqTurnplateBonus} from "@features/api";
  22. import {REQ_STATUS} from "@api/config";
  23. const i18n=global.i18n;
  24. const StyledSwiper=styled(Swiper)`
  25. .swiper-wrapper{
  26. transition-timing-function: cubic-bezier(1.00, 1.00, 0.00, 0.00);
  27. }
  28. `
  29. const WCashWheel=({close})=>{
  30. let turnplate=useSelector(getTurnplate);
  31. // if(turnplate==null)turnplate={collect_amount:0,total_amount:10000};
  32. const record=useSelector(getRecord);
  33. const myrecord=useSelector(getMyRecord);
  34. const [recordIndex,setRecordIndex]=useState(0);
  35. const recordLog=[record,myrecord];
  36. const [swiper, setSwiper] = useState(null);
  37. const [openInfoBox,setOpenInfoBox]=useState(false);
  38. const [openShare,setOpenShare]=useState(false);
  39. const isLogin=useSelector(isLogined);
  40. const navigate=useNavigate();
  41. const dispatch = useDispatch();
  42. const bonusStatus=useSelector(getBonusStatus);
  43. useEffect(() => {
  44. if (swiper) {
  45. swiper.update();
  46. }
  47. }, [swiper]);
  48. useEffect(()=>{
  49. },[recordIndex])
  50. const formatPhone=(phone)=>{
  51. let tstr=phone.substring(1,phone.length-2);
  52. phone=phone.replace(tstr,'*'.repeat(tstr.length));
  53. if (!phone.startsWith("55"))phone="55"+phone;
  54. return phone;
  55. }
  56. const checkClickWD=()=>{
  57. let collect=turnplate.collect_amount;
  58. let total=turnplate.total_amount;
  59. if (collect>=total){
  60. if (bonusStatus!==REQ_STATUS.LOADING){
  61. dispatch(reqTurnplateBonus());
  62. }
  63. }
  64. else
  65. {
  66. setOpenInfoBox(true);
  67. }
  68. }
  69. const renderCashMain=()=>{
  70. let collect=turnplate.collect_amount;
  71. // collect=10000;
  72. let total=turnplate.total_amount;
  73. let left=total-collect;
  74. let isEnableCash=collect>0;
  75. let progress=((collect/total)*100).toFixed(2);
  76. return (
  77. <div className={styles.cash_main_con}>
  78. <div className={styles.cash_main}>
  79. <div className={styles.have_cash}>
  80. <img className={styles.cash_img} src={cash_2}/>
  81. <CountUp
  82. start={0}
  83. end={Number(formatCash(collect))}
  84. duration={1}
  85. separator=" "
  86. decimals={2}
  87. prefix={global.DOLLAR+" "}
  88. startOnMount
  89. >
  90. {({ countUpRef, start }) => {
  91. if (countUpRef.current){
  92. let current=countUpRef.current;
  93. if (current.value!==collect){
  94. start();
  95. current.value=collect;
  96. }
  97. }
  98. return (
  99. <div ref={countUpRef} className={styles.cash_text}/>
  100. )
  101. }}
  102. </CountUp>
  103. {/*<div className={styles.cash_text}>{global.DOLLAR+" "+formatCash(collect)}</div>*/}
  104. <button className={styles.cash_btn} disabled={!isEnableCash} onClick={()=>{
  105. // setOpenInfoBox(true);
  106. checkClickWD();
  107. }}>
  108. {
  109. bonusStatus===REQ_STATUS.LOADING?(<SmallLoading fill={"#fff"}/>):(
  110. <>
  111. <img className={styles.icon} src={coin}/>
  112. {i18n.t("turnplate.cash_btn")}
  113. </>
  114. )
  115. }
  116. </button>
  117. </div>
  118. <div className={styles.progress}>
  119. <div>{progress+"%"}</div>
  120. <div className={styles.bar}>
  121. <span className={styles.dot} style={{width:progress+"%"}}>
  122. <div className={styles.custor}></div>
  123. </span>
  124. </div>
  125. </div>
  126. <div className={styles.need_cash}>
  127. <div>{i18n.t("turnplate.need_tip")}</div>
  128. <div className={styles.need_txt}>{formatCash(left)}</div>
  129. <div>{i18n.t("turnplate.need_tip_1")}</div>
  130. </div>
  131. </div>
  132. </div>
  133. )
  134. }
  135. const renderRecord=()=>{
  136. let list=recordLog[recordIndex];
  137. return (
  138. <div className={styles.record_con}>
  139. <div className={styles.record}>
  140. <div className={styles.record_tab}>
  141. <button disabled={recordIndex===0} onClick={()=>{
  142. setRecordIndex(0);
  143. }}>
  144. {i18n.t("turnplate.record.tab_0")}
  145. </button>
  146. <button disabled={recordIndex===1} onClick={()=>{
  147. setRecordIndex(1);
  148. }}>
  149. {i18n.t("turnplate.record.tab_1")}
  150. </button>
  151. </div>
  152. {
  153. list==null||list.length===0?(<></>):(
  154. <StyledSwiper
  155. className={styles.swiper_list}
  156. onSwiper={setSwiper}
  157. direction={"vertical"}
  158. spaceBetween={0}
  159. slidesPerView={5}
  160. loop={true}
  161. autoplay={{delay: 0, disableOnInteraction: false}}
  162. effect="fade"
  163. fadeEffect={{crossFade: true}}
  164. modules={[Autoplay]}
  165. speed={800}
  166. >
  167. {
  168. list.map((item,index)=>{
  169. let phone=formatPhone(item.phone);
  170. let name=item.name;
  171. let amount=item.amount;
  172. return (
  173. <SwiperSlide key={index}>
  174. <div className={styles.swiper_item}>
  175. <div>{phone}</div>
  176. <div className={styles.name}>{name}</div>
  177. <div className={styles.coins_con}>
  178. {"+"+amount}
  179. <div className={styles.unit}>{global.DOLLAR}</div>
  180. </div>
  181. </div>
  182. </SwiperSlide>
  183. )
  184. })
  185. }
  186. </StyledSwiper>
  187. )
  188. }
  189. </div>
  190. </div>
  191. )
  192. }
  193. const renderHelp=()=>{
  194. let arr=Array.from({ length: 6 }, (_, index) => index+1);
  195. return (
  196. <div className={styles.rule_con}>
  197. <div className={styles.rule}>
  198. <div className={styles.title}>{i18n.t("turnplate.rule.title")}</div>
  199. {
  200. arr.map((item,index)=>{
  201. return (
  202. <div key={index}>{i18n.t("turnplate.rule.rule_"+item)}</div>
  203. )
  204. })
  205. }
  206. </div>
  207. </div>
  208. )
  209. }
  210. const renderInfoBox=()=>{
  211. let collect=turnplate.collect_amount;
  212. // collect=9556;
  213. let total=turnplate.total_amount;
  214. let left=total-collect;
  215. return (
  216. <Popup open={openInfoBox} onClose={()=>{
  217. setOpenInfoBox(false);
  218. }}>
  219. <div className={styles.info_box}>
  220. <div className={styles.title}>{i18n.t("turnplate.info_box.title")}</div>
  221. <div className={styles.content}>
  222. <div className={styles.cash_con}>
  223. <div className={styles.tips}>
  224. {i18n.t("turnplate.info_box.tips")}
  225. </div>
  226. <CountUp
  227. start={openInfoBox?0:Number(formatCash(collect))}
  228. end={Number(formatCash(collect))}
  229. duration={1}
  230. separator=" "
  231. decimals={2}
  232. suffix={" BRL"}
  233. >
  234. {({ countUpRef, start }) => {
  235. return (
  236. <div ref={(ref)=>{
  237. countUpRef.current=ref;
  238. if (openInfoBox)start();
  239. }} className={styles.cash}/>
  240. )
  241. }}
  242. </CountUp>
  243. </div>
  244. <div className={styles.step_con}>
  245. <div>{i18n.t("turnplate.info_box.step_title")}</div>
  246. <div className={styles.step_content}>
  247. <div className={`${styles.step_item} ${collect>0?styles.active:''}`}>{i18n.t("turnplate.info_box.step_0")}</div>
  248. <div className={`${styles.step_item} ${collect>0?styles.active:''}`}>{stringFormat(i18n.t("turnplate.info_box.step_1"),[formatCash(left)])}</div>
  249. <div className={`${styles.step_item} ${collect>=total?styles.active:''}`}>{stringFormat(i18n.t("turnplate.info_box.step_2"),[formatCash(total,0)])}</div>
  250. </div>
  251. </div>
  252. <button className={styles.invite_btn} onClick={()=>{
  253. setOpenInfoBox(false);
  254. checkOpenShare();
  255. }}>
  256. {i18n.t("turnplate.info_box.btn_invite")}
  257. </button>
  258. </div>
  259. </div>
  260. </Popup>
  261. )
  262. }
  263. const renderShare=()=>{
  264. return (
  265. <WShare open={openShare} onClose={()=>{
  266. setOpenShare(false);
  267. }}></WShare>
  268. )
  269. }
  270. const checkOpenShare=()=>{
  271. if (!isLogin){
  272. navigate(ROUTE_PATH.SIGN_IN);
  273. return;
  274. }
  275. setOpenShare(true);
  276. }
  277. const renderMain=()=>{
  278. return (
  279. <Spring type={"slideUp"} className={styles.content}>
  280. {renderCashMain()}
  281. <WWheel openShare={checkOpenShare}></WWheel>
  282. {renderRecord()}
  283. {renderHelp()}
  284. {renderInfoBox()}
  285. {renderShare()}
  286. </Spring>
  287. )
  288. }
  289. return (
  290. <div className={styles.container}>
  291. {
  292. turnplate==null?(<SmallLoading></SmallLoading>):(renderMain())
  293. }
  294. </div>
  295. )
  296. }
  297. export default WCashWheel;