popup-withdraw.vue 12 KB

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