index.jsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import React, { useEffect, useState } from "react";
  2. import Popup from "@components/Popup";
  3. import styles from "./styles.module.scss";
  4. import lockedImg from "@assets/game/bonus_box.png";
  5. import unlockImg from "@assets/game/bonus_box.png";
  6. import LazyImage from "@components/LazyImage";
  7. import { isLandscape, stringFormat } from "@utils/helpers";
  8. import useFreeWithdraw from "@hooks/useFreeWithdraw";
  9. import { useOrientation } from "react-use";
  10. import MainButton from "@components/Buttons/MainButton";
  11. const i18n = global.i18n;
  12. const WGameWithdrawTips = ({ onLeave, currentAmount, totalAoumt, forceLandscape = false }) => {
  13. const [isShow, setIsShow] = useState(false);
  14. const [viewType, setViewType] = useState(0);
  15. const total = Number(totalAoumt) || 0;
  16. const current = Number(currentAmount) || 0;
  17. const lackMoney = Math.max(total - current, 0).toFixed(2);
  18. const { openWithdrawInGame } = useFreeWithdraw();
  19. const orientation = useOrientation();
  20. // /bindsms {phone,code,password,repassword}
  21. const hide = () => {
  22. setIsShow(false);
  23. global.hideDropCoins?.();
  24. }
  25. const onClose = () => {
  26. hide();
  27. }
  28. const onLeaveClick = () => {
  29. onLeave?.();
  30. hide();
  31. }
  32. const openWithdraw = () => {
  33. hide();
  34. openWithdrawInGame();
  35. // adjust 游戏内点击引导提款弹窗
  36. global.tracker?.trackEvent?.("click_withdraw_panel");
  37. global.tracker?.trackEvent?.("click_withdraw_panel_count");
  38. }
  39. useEffect(() => {
  40. const gameWithdrawTips = {
  41. show: (type) => {
  42. setViewType(type);
  43. setIsShow(true);
  44. },
  45. hide: () => {
  46. setIsShow(false);
  47. global.hideDropCoins?.();
  48. },
  49. };
  50. global.gameWithdrawTips = gameWithdrawTips;
  51. return () => {
  52. if (global.gameWithdrawTips === gameWithdrawTips) delete global.gameWithdrawTips;
  53. }
  54. }, [])
  55. /// 未达到提现条件
  56. const renderLeaveTips = () => {
  57. return (
  58. <div className={styles.container}>
  59. <img className={styles.bonus_box} src={lockedImg} alt={i18n.t("gameLeaveTips.leave_tips.title")} />
  60. <div className={styles.title}>
  61. {stringFormat(i18n.t("gameLeaveTips.leave_tips.title"), [lackMoney])}
  62. </div>
  63. <div className={styles.tips}>
  64. {i18n.t("gameLeaveTips.leave_tips.tips")}
  65. <br />
  66. {i18n.t("gameLeaveTips.leave_tips.tips2")}
  67. </div>
  68. <MainButton onClick={onClose}>
  69. {i18n.t("gameLeaveTips.playMore")}
  70. </MainButton>
  71. <div className={styles.btn_cancel} onClick={onLeaveClick}>
  72. {i18n.t("gameLeaveTips.leave")}
  73. </div>
  74. </div>
  75. );
  76. }
  77. /// 提现未达到要求
  78. const renderNotEnough = () => {
  79. return (
  80. <div className={`${styles.container} ${styles.not_enough}`}>
  81. <img className={styles.bonus_box} src={lockedImg} alt={''} />
  82. <div className={styles.title}>
  83. {i18n.t("gameLeaveTips.not_enough.title")}
  84. </div>
  85. <div className={styles.tips}>
  86. {i18n.t("gameLeaveTips.not_enough.tips")}
  87. <span className={styles.lbl_money}>{`${global.DOLLAR}${lackMoney}`}</span>
  88. {i18n.t("gameLeaveTips.not_enough.tips2")}
  89. </div>
  90. <MainButton onClick={onClose}>
  91. {i18n.t("gameLeaveTips.ok")}
  92. </MainButton>
  93. </div>
  94. );
  95. }
  96. /// 提现已解锁
  97. const renderUnlocked = () => {
  98. return (
  99. <div className={styles.container}>
  100. <LazyImage className={styles.bonus_box} src={unlockImg} alt={i18n.t("gameLeaveTips.withdraw.title")} />
  101. <div className={styles.title_withdraw}>
  102. {i18n.t("gameLeaveTips.withdraw.title")}
  103. </div>
  104. <div className={styles.tips}>
  105. {i18n.t("gameLeaveTips.withdraw.tips")}
  106. <br />
  107. {i18n.t("gameLeaveTips.withdraw.tips2")}
  108. </div>
  109. <MainButton onClick={openWithdraw}>
  110. {i18n.t("gameLeaveTips.withdraw.now")}
  111. </MainButton>
  112. <div className={styles.btn_cancel} onClick={onClose}>
  113. {i18n.t("gameLeaveTips.withdraw.later")}
  114. </div>
  115. </div>
  116. );
  117. }
  118. const renderView = () => {
  119. switch (viewType) {
  120. case 1: return renderLeaveTips();
  121. case 2: return renderNotEnough();
  122. case 3: return renderUnlocked();
  123. default: return <></>
  124. }
  125. }
  126. return (
  127. <>
  128. <Popup
  129. onClose={onClose}
  130. popupClass={isLandscape(orientation) || forceLandscape ? "popup-landscape" : ""}
  131. open={isShow}
  132. zIndex={130}
  133. rootClass={forceLandscape ? "popup-rotate" : ""}
  134. >
  135. {renderView()}
  136. </Popup>
  137. </>
  138. )
  139. }
  140. export default WGameWithdrawTips;