WRetainPop.jsx 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. import Popup from "@components/Popup";
  2. import styles from "./styles.module.scss";
  3. import CountUp from "react-countup";
  4. import { formatCash, localStorageSet } from "@utils/helpers";
  5. import { useSelector } from "react-redux";
  6. import { LOCAL_WHEEL_RETAIN } from "@constants/localkey";
  7. import { useNavigate } from "react-router";
  8. import { ROUTE_PATH } from "@constants/routes";
  9. import { getMyRecord, getRecord, getTurnplate } from "@features/turnplateSlice";
  10. import React, { useState } from "react";
  11. import styled from 'styled-components/macro';
  12. import { Swiper, SwiperSlide } from "swiper/react";
  13. import { Autoplay, Virtual } from "swiper/modules";
  14. import WITHDRAW_TYPE from "@constants/withdraw_types";
  15. import { Trans } from "react-i18next";
  16. const i18n = global.i18n;
  17. const StyledSwiper = styled(Swiper)`
  18. .swiper-wrapper{
  19. transition-timing-function: cubic-bezier(1.00, 1.00, 0.00, 0.00);
  20. }
  21. `;
  22. const WRetainPop = ({ open, onClose, closeP }) => {
  23. let turnplate = useSelector(getTurnplate);
  24. if (turnplate == null) turnplate = { total_amount: 10000, collect_amount: 0 };
  25. let collect = Number(turnplate.collect_amount) || 0;
  26. let total = Number(turnplate.total_amount) || 0;
  27. let left = Math.max(total - collect, 0);
  28. let isEnableCash = total > 0 && collect >= total;
  29. let progress = (total > 0 ? Math.min(Math.max((collect / total) * 100, 0), 100) : 0).toFixed(2);
  30. const clearRetain = () => {
  31. localStorageSet(LOCAL_WHEEL_RETAIN, Date.now());
  32. };
  33. const renderMain = () => {
  34. return (
  35. <div className={styles.cash_main_con}>
  36. <div className={styles.cash_main}>
  37. <div className={styles.have_cash}>
  38. {/* <img className={styles.cash_img} src={cash_2} /> */}
  39. <CountUp
  40. key={`${open}-${collect}`}
  41. start={!open ? Number(formatCash(collect)) : 0}
  42. end={Number(formatCash(collect))}
  43. duration={1}
  44. separator=" "
  45. decimals={2}
  46. prefix={global.DOLLAR + " "}
  47. startOnMount
  48. >
  49. {({ countUpRef }) => {
  50. return (
  51. <div ref={countUpRef} className={styles.cash_text} />
  52. );
  53. }}
  54. </CountUp>
  55. </div>
  56. <div className={styles.progress}>
  57. <div className={styles.progressTip}>{progress + "%"}</div>
  58. <div className={styles.bar}>
  59. <span className={styles.dot} style={{ width: progress + "%" }}>
  60. <div className={styles.custor}></div>
  61. </span>
  62. </div>
  63. </div>
  64. <div className={styles.need_cash}>
  65. {
  66. isEnableCash ? (
  67. <Trans
  68. i18nKey="cashWheel.retain.withdraw_now"
  69. values={{ amount: `${global.DOLLAR} ${formatCash(collect)}` }}
  70. components={{
  71. line1: <div />,
  72. amount: <div className={styles.need_txt} />,
  73. line3: <div />
  74. }}
  75. />
  76. ) : (
  77. <>
  78. <div>{i18n.t("turnplate.need_tip")}</div>
  79. <div className={styles.need_txt}>$ {formatCash(left)}</div>
  80. <div>{i18n.t("turnplate.need_tip_1")}</div>
  81. </>
  82. )
  83. }
  84. </div>
  85. </div>
  86. </div>
  87. );
  88. };
  89. const navigate = useNavigate();
  90. const renderBtns = () => {
  91. const handleClickShare = (e) => {
  92. if (e) e.stopPropagation();
  93. clearRetain();
  94. if (onClose) onClose();
  95. navigate(ROUTE_PATH.SHARE);
  96. };
  97. const handleClickWithdraw = (e) => {
  98. if (e) e.stopPropagation();
  99. clearRetain();
  100. if (onClose) onClose();
  101. global.openFixedWithdraw && global.openFixedWithdraw({
  102. type: WITHDRAW_TYPE.SHARE,
  103. });
  104. };
  105. return (
  106. <div className={styles.btn_con}>
  107. {
  108. isEnableCash ? (
  109. <>
  110. <button className={styles.share_btn} onClick={handleClickWithdraw}>{i18n.t('cashWheel.withdraw')}</button>
  111. </>
  112. ) : (
  113. <>
  114. <button className={styles.share_btn} onClick={handleClickShare}>{i18n.t("turnplate.retain_pop.btn_share")}</button>
  115. </>
  116. )
  117. }
  118. </div>
  119. );
  120. };
  121. const record = useSelector(getRecord);
  122. const myrecord = useSelector(getMyRecord);
  123. const recordLog = [record, myrecord];
  124. const [recordIndex] = useState(0);
  125. const [, setSwiper] = useState(null);
  126. const formatPhone = (phone) => {
  127. let normalized = String(phone ?? '');
  128. if (!normalized) return '';
  129. let tstr = normalized.substring(1, Math.max(normalized.length - 2, 1));
  130. normalized = normalized.replace(tstr, '*'.repeat(tstr.length));
  131. if (!normalized.startsWith("55")) normalized = "55" + normalized;
  132. return normalized;
  133. };
  134. const renderRecord = () => {
  135. let list = recordLog[recordIndex];
  136. return (
  137. <div className={styles.record_con}>
  138. <div className={styles.record}>
  139. {
  140. !Array.isArray(list) || list.length === 0 ? (<></>) : (
  141. <StyledSwiper
  142. className={styles.swiper_list}
  143. onSwiper={setSwiper}
  144. direction={"vertical"}
  145. spaceBetween={0}
  146. slidesPerView={1}
  147. loop={true}
  148. autoplay={{ delay: 0, disableOnInteraction: false }}
  149. effect="fade"
  150. fadeEffect={{ crossFade: true }}
  151. modules={[Autoplay, Virtual]}
  152. speed={1600}
  153. virtual={true}
  154. >
  155. {
  156. list.map((item, index) => {
  157. let phone = formatPhone(item.phone);
  158. let name = item.name;
  159. let amount = item.amount;
  160. return (
  161. <SwiperSlide key={index} virtualIndex={index}>
  162. <div className={styles.swiper_item}>
  163. <div>{phone}</div>
  164. <div className={styles.name}>{name}</div>
  165. <div className={styles.coins_con}>
  166. {"+" + amount}
  167. <div className={styles.unit}>{global.DOLLAR}</div>
  168. </div>
  169. </div>
  170. </SwiperSlide>
  171. );
  172. })
  173. }
  174. </StyledSwiper>
  175. )
  176. }
  177. </div>
  178. </div>
  179. );
  180. };
  181. const renderTips = () => {
  182. return (
  183. <div className={styles.btTips}>
  184. <Trans
  185. i18nKey="cashWheel.retain.tips"
  186. components={{
  187. br: <br />
  188. }}
  189. />
  190. </div>
  191. );
  192. };
  193. return (
  194. <Popup open={open} onClose={(e) => {
  195. if (e) e.stopPropagation();
  196. clearRetain();
  197. if (onClose) onClose();
  198. if (closeP) closeP();
  199. }}>
  200. <div className={styles.container}>
  201. <div className={styles.title}>{i18n.t("turnplate.retain_pop.title")}</div>
  202. <div className={styles.tips}>{i18n.t("turnplate.retain_pop.tips")}</div>
  203. {renderMain()}
  204. {renderBtns()}
  205. {renderRecord()}
  206. {renderTips()}
  207. </div>
  208. </Popup>
  209. );
  210. };
  211. export default WRetainPop;