option-withdraw.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  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 'element-plus/es/components/message/style/css'
  95. import { withdrawRequest, getWithdrawConfig } from "@/http/account";
  96. import { withdrawCalcFee } from "@/http/pay";
  97. import { debounce } from "@/uilts/help"
  98. const props = defineProps({
  99. amountValue: {
  100. type: Number,
  101. default: 0,
  102. }
  103. });
  104. let withdraw_info = inject('withdraw_info')
  105. console.log('withdraw_info', withdraw_info)
  106. let requestWithdrawParams = ref({
  107. amountValue: "",
  108. currencyCode: "USD",
  109. withdrawNetwork: 'paypal', // 1: paypal
  110. withdrawReceiveAccount: "",
  111. });
  112. let canWithdrawBalance = ref(withdraw_info.paypal.amount_value);
  113. let showWithdrawError = ref(false);
  114. let showWithdrawIptError = ref(false);
  115. let isSubmit = ref(false);
  116. let withdrawIng = ref(false);
  117. let walletWithdrawConfig = ref({
  118. withdrawPerMinAmount: 1,
  119. withdrawUSDSwitch: "",
  120. withdrawFeeDesc: ''
  121. });
  122. let finalWithdrawalAmount = ref('');
  123. let calcReq = ref(false);
  124. onMounted(() => {
  125. queryWithdrawConfig()
  126. });
  127. /**
  128. * 获取提现配置
  129. */
  130. const queryWithdrawConfig = () => {
  131. getWithdrawConfig({
  132. params: {
  133. currencyCode: withdraw_info.currency_code || 'USD',
  134. withdrawNetwork: 'paypal'
  135. },
  136. }).then((res) => {
  137. if (res.code == 0) {
  138. walletWithdrawConfig.value = res.data;
  139. }
  140. console.log('queryWithdrawConfig',walletWithdrawConfig.value);
  141. });
  142. };
  143. const emits = defineEmits("back");
  144. const back = () => {
  145. if (isSubmit.value) {
  146. isSubmit.value = false;
  147. } else {
  148. emits("back", {});
  149. }
  150. };
  151. const doneWithdraw = () => {
  152. isSubmit.value = false;
  153. emits("back", {});
  154. };
  155. const withdrawalAll = () => {
  156. console.log(canWithdrawBalance.value);
  157. showWithdrawIptError.value = false;
  158. requestWithdrawParams.value.amountValue =
  159. canWithdrawBalance.value;
  160. setWithdrawIptStatus(canWithdrawBalance.value);
  161. withdrawCalcAmount();
  162. };
  163. const withdrawCalcAmount = () => {
  164. calcReq.value = true;
  165. withdrawCalcFee({
  166. params: {
  167. amountValue: requestWithdrawParams.value.amountValue,
  168. currencyCode: requestWithdrawParams.value.currencyCode,
  169. withdrawNetwork: 'paypal'
  170. }
  171. }).then(res => {
  172. calcReq.value = false;
  173. if (res.code == 0) {
  174. finalWithdrawalAmount.value = res.data.finalAmountValue;
  175. }
  176. })
  177. }
  178. const withdrawCalcAmountDebounce = debounce(function () {
  179. withdrawCalcAmount();
  180. }, 1000)
  181. /**
  182. * 提现
  183. */
  184. const withdraw = () => {
  185. console.log("requestWithdrawParams.value", requestWithdrawParams.value);
  186. if (withdrawIng.value) {
  187. return;
  188. }
  189. let params = {
  190. ...requestWithdrawParams.value,
  191. };
  192. if (!params.amountValue || !params.withdrawReceiveAccount) {
  193. return;
  194. }
  195. params.withdrawReceiveAccount = params.withdrawReceiveAccount.replace(/\s*/g, "");
  196. params.amountValue = params.amountValue;
  197. if (parseInt(params.amountValue) > parseInt(canWithdrawBalance.value)) {
  198. // ElMessage({
  199. // message: '大于可提现金额',
  200. // type: 'warning',
  201. // })
  202. return;
  203. }
  204. withdrawIng.value = true;
  205. withdrawRequest({
  206. params,
  207. }).then((res) => {
  208. withdrawIng.value = false;
  209. if (res.code == 0) {
  210. canWithdrawBalance.value =
  211. canWithdrawBalance.value - params.amountValue;
  212. requestWithdrawParams.value = {
  213. amountValue: "",
  214. currencyCode: "USD",
  215. withdrawNetwork: 'paypal', // paypal
  216. withdrawReceiveAccount: "",
  217. };
  218. isSubmit.value = true;
  219. } else {
  220. console.log(res);
  221. }
  222. })
  223. .catch((err) => {
  224. console.log(err);
  225. });
  226. };
  227. const onAmountBlur = () => {
  228. withdrawCalcAmount();
  229. }
  230. const onAmountInput = () => {
  231. //限制输入数字 小数点俩位
  232. let value = requestWithdrawParams.value.amountValue;
  233. value = value
  234. .replace(/[^\d.]/g, "")
  235. .replace(/\.{2,}/g, ".")
  236. .replace(".", "$#$")
  237. .replace(/\./g, "")
  238. .replace("$#$", ".")
  239. .replace(/^(-)*(\d+)\.(\d\d).*$/, "$1$2.$3")
  240. .replace(/^\./g, "");
  241. requestWithdrawParams.value.amountValue = value;
  242. setWithdrawIptStatus(value);
  243. // 输入金额大于可提现金额
  244. if (parseInt(value) > parseInt(canWithdrawBalance.value)) {
  245. if (!showWithdrawError.value) {
  246. showWithdrawIptError.value = true;
  247. }
  248. } else {
  249. showWithdrawIptError.value = false;
  250. }
  251. withdrawCalcAmountDebounce();
  252. return value;
  253. };
  254. const setWithdrawIptStatus = (amount) => {
  255. //显示tips
  256. if (
  257. amount > 0 &&
  258. amount < walletWithdrawConfig.value.withdrawPerMinAmount
  259. ) {
  260. showWithdrawError.value = true;
  261. } else {
  262. showWithdrawError.value = false;
  263. }
  264. }
  265. </script>
  266. <style lang="scss" scoped>
  267. .withdraw-wrapper {
  268. width: 100%;
  269. height: 100%;
  270. position: relative;
  271. overflow: hidden;
  272. .nav-bar {
  273. padding: 14px;
  274. box-sizing: border-box;
  275. display: flex;
  276. align-items: center;
  277. font-weight: 500;
  278. font-size: 13px;
  279. .icon {
  280. width: 16px;
  281. margin-right: 6px;
  282. cursor: pointer;
  283. }
  284. }
  285. .content {
  286. padding: 0 20px;
  287. box-sizing: border-box;
  288. .logo-wrapper {
  289. .title {
  290. margin-top: 13px;
  291. font-size: 14px;
  292. color: #5b5b5b;
  293. }
  294. .icon {
  295. width: 111px;
  296. height: 56px;
  297. margin-bottom: 20px;
  298. }
  299. }
  300. .form-wrapper {
  301. .form-item {
  302. margin-bottom: 30px;
  303. .label {
  304. font-size: 14px;
  305. color: #5b5b5b;
  306. margin-bottom: 8px;
  307. .msg {
  308. font-weight: 400;
  309. font-size: 14px;
  310. color: #FFA621;
  311. }
  312. }
  313. .input-wrapper {
  314. display: flex;
  315. align-items: center;
  316. justify-content: space-between;
  317. border: 1px solid #e8e8e8;
  318. border-radius: 8px;
  319. .withdrawal-all-btn {
  320. font-weight: 500;
  321. font-size: 13px;
  322. color: #389aff;
  323. padding-right: 10px;
  324. cursor: pointer;
  325. }
  326. input {
  327. width: 100%;
  328. height: 48px;
  329. border: none;
  330. border-radius: 8px;
  331. padding: 0 16px;
  332. box-sizing: border-box;
  333. outline: none;
  334. }
  335. }
  336. }
  337. .error-msg {
  338. font-size: 13px;
  339. color: #ff0000;
  340. margin-top: -15px;
  341. height: 38px;
  342. }
  343. }
  344. .bottom-msg {
  345. font-size: 13px;
  346. color: #9d9d9d;
  347. text-align: right;
  348. margin-top: 52px;
  349. .top {
  350. height: 22px;
  351. span {
  352. font-weight: 500;
  353. font-size: 15px;
  354. color: #000000;
  355. }
  356. }
  357. }
  358. }
  359. .withdraw-status {
  360. text-align: center;
  361. img {
  362. margin-top: 40px;
  363. margin-bottom: 34px;
  364. }
  365. .title {
  366. font-weight: 500;
  367. font-size: 20px;
  368. margin-bottom: 10px;
  369. }
  370. .desc {
  371. font-size: 15px;
  372. color: rgba($color: #000000, $alpha: 0.5);
  373. }
  374. }
  375. .confirm-btn {
  376. width: 335px;
  377. height: 60px;
  378. text-align: center;
  379. line-height: 60px;
  380. border-radius: 100px;
  381. background: #389aff;
  382. font-weight: 600;
  383. font-size: 18px;
  384. color: #fff;
  385. position: absolute;
  386. left: 50%;
  387. bottom: 35px;
  388. transform: translateX(-50%);
  389. display: flex;
  390. align-items: center;
  391. justify-content: center;
  392. cursor: pointer;
  393. .icon-loading {
  394. width: 20px;
  395. height: 20px;
  396. margin-right: 3px;
  397. }
  398. }
  399. }
  400. </style>