popup-withdraw.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. <template>
  2. <div class="withdraw-wrapper">
  3. <!-- <div class="nav-bar">
  4. <img
  5. :src="require('@/assets/svg/icon-bar-arrow-left.svg')"
  6. class="icon"
  7. @click="back"
  8. />
  9. Withdraw
  10. </div> -->
  11. <template v-if="!isSubmit">
  12. <div class="content">
  13. <div class="logo-wrapper">
  14. <div class="title">Withdraw to</div>
  15. <img class="icon" :src="
  16. require('@/assets/svg/icon-withdraw-paypal-logo.svg')
  17. " />
  18. </div>
  19. <div class="form-wrapper">
  20. <div class="form-item">
  21. <div class="label">PayPal account</div>
  22. <div class="input-wrapper">
  23. <input type="text" v-model="requestWithdrawParams.withdrawReceiveAccount"
  24. placeholder="Enter PayPal account" />
  25. </div>
  26. </div>
  27. <div class="form-item">
  28. <div class="label">Withdrawal amount<span class="msg">(${{
  29. walletWithdrawConfig.withdrawPerMinAmount
  30. }} minimum)</span></div>
  31. <div class="input-wrapper amount-wrapper">
  32. <input type="text" v-model="requestWithdrawParams.amountValue" placeholder="$0"
  33. style="width: 220px" @input="onAmountInput" />
  34. <div @click="withdrawalAll" class="withdrawal-all-btn">
  35. Withdrawal All
  36. </div>
  37. </div>
  38. </div>
  39. <div class="error-msg">
  40. <template v-if="showWithdrawError">
  41. The minimum withdrawal amount is ${{ walletWithdrawConfig.withdrawPerMinAmount }} USD
  42. </template>
  43. <template v-if="showWithdrawIptError">
  44. The withdrawal amount exceeds the total account balance of ${{ canWithdrawBalance }} USD
  45. </template>
  46. </div>
  47. </div>
  48. <div class="bottom-msg">
  49. <div class="top">
  50. <template v-if="!calcReq">
  51. final amount
  52. <span>${{
  53. finalWithdrawalAmount > 0
  54. ? finalWithdrawalAmount
  55. : 0
  56. }}
  57. </span>
  58. </template>
  59. <template v-else>
  60. calculating
  61. </template>
  62. </div>
  63. <div>{{ walletWithdrawConfig.withdrawFeeDesc }}</div>
  64. </div>
  65. </div>
  66. <div @click="withdraw" class="confirm-btn">
  67. <img class="icon-loading" v-if="withdrawIng" :src="require('@/assets/svg/icon-btn-loading.svg')" />
  68. Confirm
  69. </div>
  70. </template>
  71. <template v-else>
  72. <div class="withdraw-status">
  73. <img :src="require('@/assets/svg/icon-withdraw-status.svg')" alt="" />
  74. <div>
  75. <div class="title">Submitted successfully</div>
  76. <div class="desc">
  77. <!-- Please wait for a while,<br />
  78. then check the balance with paypal -->
  79. Estimate in 24 hours
  80. </div>
  81. </div>
  82. </div>
  83. <div class="confirm-btn" @click="doneWithdraw">
  84. Done
  85. </div>
  86. </template>
  87. </div>
  88. </template>
  89. <script setup>
  90. /* eslint-disable */
  91. import { defineProps, defineEmits, ref, onMounted, watch, computed, inject } from "vue";
  92. import { withdrawRequest, getWithdrawConfig } from "@/http/account";
  93. import { withdrawCalcFee } from "@/http/pay";
  94. import { debounce } from "@/uilts/help"
  95. const props = defineProps({
  96. amountValue: {
  97. type: Number,
  98. default: 0,
  99. }
  100. });
  101. let withdraw_info = inject('withdraw_info')
  102. console.log('withdraw_info', withdraw_info)
  103. let requestWithdrawParams = ref({
  104. amountValue: "",
  105. currencyCode: "USD",
  106. withdrawNetwork: 'paypal', // 1: paypal
  107. withdrawReceiveAccount: "",
  108. });
  109. let canWithdrawBalance = ref(withdraw_info.paypal.amount_value);
  110. let showWithdrawError = ref(false);
  111. let showWithdrawIptError = ref(false);
  112. let isSubmit = ref(false);
  113. let withdrawIng = ref(false);
  114. let walletWithdrawConfig = ref({
  115. withdrawPerMinAmount: 1,
  116. withdrawUSDSwitch: "",
  117. withdrawFeeDesc: ''
  118. });
  119. let finalWithdrawalAmount = ref('');
  120. let calcReq = ref(false);
  121. onMounted(() => {
  122. queryWithdrawConfig()
  123. });
  124. /**
  125. * 获取提现配置
  126. */
  127. const queryWithdrawConfig = () => {
  128. getWithdrawConfig({
  129. params: {
  130. currencyCode: withdraw_info.currency_code || 'USD',
  131. withdrawNetwork: 'paypal'
  132. },
  133. }).then((res) => {
  134. if (res.code == 0) {
  135. walletWithdrawConfig.value = res.data;
  136. }
  137. console.log('queryWithdrawConfig', walletWithdrawConfig.value);
  138. });
  139. };
  140. const emits = defineEmits("back");
  141. const back = () => {
  142. if (isSubmit.value) {
  143. isSubmit.value = false;
  144. } else {
  145. emits("back", {});
  146. }
  147. };
  148. const doneWithdraw = () => {
  149. isSubmit.value = false;
  150. emits("back", {});
  151. };
  152. const withdrawalAll = () => {
  153. console.log(canWithdrawBalance.value);
  154. showWithdrawIptError.value = false;
  155. requestWithdrawParams.value.amountValue =
  156. canWithdrawBalance.value;
  157. setWithdrawIptStatus(canWithdrawBalance.value);
  158. withdrawCalcAmount();
  159. };
  160. const withdrawCalcAmount = () => {
  161. calcReq.value = true;
  162. withdrawCalcFee({
  163. params: {
  164. amountValue: requestWithdrawParams.value.amountValue,
  165. currencyCode: requestWithdrawParams.value.currencyCode,
  166. withdrawNetwork: 'paypal'
  167. }
  168. }).then(res => {
  169. calcReq.value = false;
  170. if (res.code == 0) {
  171. finalWithdrawalAmount.value = res.data.finalAmountValue;
  172. }
  173. }).catch(err => {
  174. calcReq.value = false;
  175. })
  176. }
  177. const withdrawCalcAmountDebounce = debounce(function () {
  178. withdrawCalcAmount();
  179. }, 300)
  180. /**
  181. * 提现
  182. */
  183. const withdraw = () => {
  184. console.log("requestWithdrawParams.value", requestWithdrawParams.value);
  185. if (withdrawIng.value || calcReq.value || showWithdrawError.value || showWithdrawIptError.value) {
  186. return;
  187. }
  188. let params = {
  189. ...requestWithdrawParams.value,
  190. };
  191. if (!params.amountValue || !params.withdrawReceiveAccount) {
  192. return;
  193. }
  194. params.withdrawReceiveAccount = params.withdrawReceiveAccount.replace(/\s*/g, "");
  195. params.amountValue = params.amountValue;
  196. if (+params.amountValue > +canWithdrawBalance.value) {
  197. return;
  198. }
  199. withdrawIng.value = true;
  200. withdrawRequest({
  201. params,
  202. }).then((res) => {
  203. withdrawIng.value = false;
  204. if (res.code == 0) {
  205. canWithdrawBalance.value =
  206. canWithdrawBalance.value - params.amountValue;
  207. requestWithdrawParams.value = {
  208. amountValue: "",
  209. currencyCode: "USD",
  210. withdrawNetwork: 'paypal', // paypal
  211. withdrawReceiveAccount: "",
  212. };
  213. isSubmit.value = true;
  214. } else {
  215. console.log(res);
  216. }
  217. }).catch((err) => {
  218. console.log(err);
  219. });
  220. };
  221. const onAmountBlur = () => {
  222. withdrawCalcAmount();
  223. }
  224. const onAmountInput = () => {
  225. //限制输入数字 小数点俩位
  226. let value = requestWithdrawParams.value.amountValue;
  227. value = value
  228. .replace(/[^\d.]/g, "")
  229. .replace(/\.{2,}/g, ".")
  230. .replace(".", "$#$")
  231. .replace(/\./g, "")
  232. .replace("$#$", ".")
  233. .replace(/^(-)*(\d+)\.(\d\d).*$/, "$1$2.$3")
  234. .replace(/^\./g, "");
  235. requestWithdrawParams.value.amountValue = value;
  236. setWithdrawIptStatus(value);
  237. // 输入金额大于可提现金额
  238. if (+value > +canWithdrawBalance.value) {
  239. if (!showWithdrawError.value) {
  240. showWithdrawIptError.value = true;
  241. }
  242. } else {
  243. showWithdrawIptError.value = false;
  244. }
  245. withdrawCalcAmountDebounce();
  246. return value;
  247. };
  248. const setWithdrawIptStatus = (amount) => {
  249. //显示tips
  250. if (
  251. +amount > 0 &&
  252. +amount < +walletWithdrawConfig.value.withdrawPerMinAmount
  253. ) {
  254. showWithdrawError.value = true;
  255. } else {
  256. showWithdrawError.value = false;
  257. }
  258. }
  259. </script>
  260. <style lang="scss" scoped>
  261. .withdraw-wrapper {
  262. width: 100%;
  263. height: 100%;
  264. position: relative;
  265. overflow: hidden;
  266. .nav-bar {
  267. padding: 14px;
  268. box-sizing: border-box;
  269. display: flex;
  270. align-items: center;
  271. font-weight: 500;
  272. font-size: 13px;
  273. .icon {
  274. width: 16px;
  275. margin-right: 6px;
  276. cursor: pointer;
  277. }
  278. }
  279. .content {
  280. padding: 0 20px;
  281. box-sizing: border-box;
  282. .logo-wrapper {
  283. .title {
  284. margin-top: 13px;
  285. font-size: 14px;
  286. color: #5b5b5b;
  287. }
  288. .icon {
  289. width: 111px;
  290. height: 56px;
  291. margin-bottom: 20px;
  292. }
  293. }
  294. .form-wrapper {
  295. .form-item {
  296. margin-bottom: 30px;
  297. .label {
  298. font-size: 14px;
  299. color: #5b5b5b;
  300. margin-bottom: 8px;
  301. .msg {
  302. font-weight: 400;
  303. font-size: 14px;
  304. color: #FFA621;
  305. }
  306. }
  307. .input-wrapper {
  308. display: flex;
  309. align-items: center;
  310. justify-content: space-between;
  311. border: 1px solid #e8e8e8;
  312. border-radius: 8px;
  313. .withdrawal-all-btn {
  314. font-weight: 500;
  315. font-size: 13px;
  316. color: #1D9BF0;
  317. padding-right: 10px;
  318. cursor: pointer;
  319. }
  320. input {
  321. width: 100%;
  322. height: 48px;
  323. border: none;
  324. border-radius: 8px;
  325. padding: 0 16px;
  326. box-sizing: border-box;
  327. outline: none;
  328. }
  329. }
  330. }
  331. .error-msg {
  332. font-size: 13px;
  333. color: #ff0000;
  334. margin-top: -15px;
  335. height: 38px;
  336. }
  337. }
  338. .bottom-msg {
  339. font-size: 13px;
  340. color: #9d9d9d;
  341. text-align: right;
  342. margin-top: 52px;
  343. .top {
  344. height: 22px;
  345. span {
  346. font-weight: 500;
  347. font-size: 15px;
  348. color: #000000;
  349. }
  350. }
  351. }
  352. }
  353. .withdraw-status {
  354. text-align: center;
  355. img {
  356. margin-top: 40px;
  357. margin-bottom: 34px;
  358. }
  359. .title {
  360. font-weight: 500;
  361. font-size: 20px;
  362. margin-bottom: 10px;
  363. }
  364. .desc {
  365. font-size: 15px;
  366. color: rgba($color: #000000, $alpha: 0.5);
  367. }
  368. }
  369. .confirm-btn {
  370. width: 335px;
  371. height: 60px;
  372. text-align: center;
  373. line-height: 60px;
  374. border-radius: 100px;
  375. background: #1D9BF0;
  376. font-weight: 600;
  377. font-size: 18px;
  378. color: #fff;
  379. position: absolute;
  380. left: 50%;
  381. bottom: 35px;
  382. transform: translateX(-50%);
  383. display: flex;
  384. align-items: center;
  385. justify-content: center;
  386. cursor: pointer;
  387. .icon-loading {
  388. width: 20px;
  389. height: 20px;
  390. margin-right: 3px;
  391. }
  392. }
  393. }
  394. </style>