pay.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. <template>
  2. <div class="dialog" :style="{'height': dialogStyle.height + 'px'}">
  3. <!-- home -->
  4. <div class="area-title">
  5. <img :src="require('@/assets/svg/icon-back.svg')" @click="clickBack" />
  6. <div class="title">Payment</div>
  7. </div>
  8. <!-- 内容 -->
  9. <div class="area-content">
  10. <div
  11. class="left"
  12. :class="{ auto: tempCurrentCurrencyInfo.currencyCode === 'USD' && Number(finalAmountData.rechargeAmountValue) <= 0 }">
  13. <img :src="require('@/assets/img/img-box5.png')" v-show="pay_info.home.sale_plan.itemCount == 5"
  14. alt="" />
  15. <img :src="require('@/assets/img/img-box1.png')" v-show="pay_info.home.sale_plan.itemCount == 1"
  16. alt="" />
  17. <div class="tip">
  18. <span>Mystery box*{{ pay_info.home.sale_plan.itemCount }}</span>
  19. <div>
  20. <img :src="pay_info.home.sale_plan.currencyInfo.iconPath" alt="" />
  21. <span>{{ pay_info.home.sale_plan.price }}</span>
  22. </div>
  23. </div>
  24. </div>
  25. <div
  26. class="right"
  27. :class="{ none: tempCurrentCurrencyInfo.currencyCode === 'USD' && Number(finalAmountData.rechargeAmountValue) <= 0 }">
  28. <div class="card-content" v-if="tempCurrentCurrencyInfo.currencyCode">
  29. <template v-if="tempCurrentCurrencyInfo.currencyCode !== 'USD'">
  30. <div class="card-title">
  31. <img class="img" :src="require('@/assets/subject/top-01.svg')" />
  32. <div class="font">Deposit to Send Giveaway</div>
  33. </div>
  34. <top-up2 v-if="tempCurrentCurrencyInfo.currencyCode" :asyncIng="asyncIng"
  35. :currentCurrencyInfo="tempCurrentCurrencyInfo" @topUpDone="topUpDone">
  36. </top-up2>
  37. <div class="card-title">
  38. <img class="img" :src="require('@/assets/subject/top-02.svg')" />
  39. <div class="font">Wait for the amount to arrive</div>
  40. </div>
  41. <preview-balance v-if="tempCurrentCurrencyInfo.currencyCode"
  42. :currencyCode="tempCurrentCurrencyInfo.currencyCode"
  43. :tokenSymbol="tempCurrentCurrencyInfo.tokenSymbol" @updateData="updateData">
  44. </preview-balance>
  45. </template>
  46. <template v-else>
  47. <div class="card-title">
  48. <img class="img" :src="require('@/assets/subject/top-01.svg')" />
  49. <div class="font">Deposit to Send Giveaway</div>
  50. </div>
  51. <payment-info-usd
  52. :finalAmountData="finalAmountData">
  53. </payment-info-usd>
  54. </template>
  55. </div>
  56. </div>
  57. </div>
  58. <!-- 底部 -->
  59. <div class="footer" v-if="tempCurrentCurrencyInfo.currencyCode">
  60. <template v-if="tempCurrentCurrencyInfo.currencyCode !== 'USD'">
  61. <div class="buy1" @click="clickPlay" v-if="state.is_btn_grey == false">
  62. <btn-loading :color="'while'" v-if="state.loading.show"></btn-loading>
  63. <template
  64. v-else-if="(pay_info.home.sale_plan.price.length + pay_info.home.sale_plan.currencyInfo.tokenSymbol.length) > 30">
  65. <div class="left">Pay</div>
  66. <div class="right">
  67. <p>{{ pay_info.home.sale_plan.price }}</p>
  68. <p>{{ pay_info.home.sale_plan.currencyInfo.tokenSymbol }}</p>
  69. </div>
  70. </template>
  71. <template v-else>
  72. <div class="left">Pay</div>
  73. <div class="right">
  74. {{ pay_info.home.sale_plan.price }}
  75. {{ pay_info.home.sale_plan.currencyInfo.tokenSymbol }}
  76. </div>
  77. </template>
  78. </div>
  79. <div class="buy1 grey" v-else>
  80. <template
  81. v-if="(pay_info.home.sale_plan.price.length + pay_info.home.sale_plan.currencyInfo.tokenSymbol.length) > 30">
  82. <div class="left">Pay</div>
  83. <div class="right">
  84. <p>{{ pay_info.home.sale_plan.price }}</p>
  85. <p>{{ pay_info.home.sale_plan.currencyInfo.tokenSymbol }}</p>
  86. </div>
  87. </template>
  88. <template v-else>
  89. <div class="left">Pay</div>
  90. <div class="right">
  91. {{ pay_info.home.sale_plan.price }}
  92. {{ pay_info.home.sale_plan.currencyInfo.tokenSymbol }}
  93. </div>
  94. </template>
  95. </div>
  96. </template>
  97. <template v-else>
  98. <!-- Balance -->
  99. <div class="balance">
  100. <img class="icon" src="@/assets/subject/icon-balance.png" />
  101. <div class="con">
  102. <div class="desc">Balance</div>
  103. <div class="price">
  104. $
  105. {{tempCurrentCurrencyInfo.balance}}
  106. </div>
  107. </div>
  108. <img class="refresh"
  109. :class="{ 'icon-refresh-rotate': refreshRotate }"
  110. :src=" require('@/assets/svg/icon-form-refresh.svg')"
  111. @click="updateCurrencyBanlce"/>
  112. </div>
  113. <!-- Play -->
  114. <div class="buy1 usd" @click="clickPayUSD">
  115. <div class="left">Pay</div>
  116. <div class="right">
  117. {{ finalAmountData.rechargeAmountValue > 0 ? finalAmountData.rechargeAmountValue : finalAmountData.orderAmountValue }}
  118. {{ pay_info.home.sale_plan.currencyInfo.tokenSymbol }}
  119. </div>
  120. </div>
  121. </template>
  122. </div>
  123. </div>
  124. <!-- 预览页充值 -->
  125. <message-box
  126. :dialogVisible="showDepositMessageBox"
  127. title="Is the Deposit Completed?"
  128. @cancel="depositAchCancel"
  129. @confirm="depositAchConfirm">
  130. </message-box>
  131. </template>
  132. <script setup >
  133. import Report from "@/log-center/log"
  134. import router from "@/router/buy-nft.js";
  135. import { ref, onMounted, onUnmounted, inject, reactive } from 'vue'
  136. import topUp2 from "@/view/iframe/publish/components/top-up2.vue";
  137. import { getCurrencyInfoByCode } from "@/http/publishApi";
  138. import PreviewBalance from "@/view/components/preview-balance.vue";
  139. import paymentInfoUsd from '@/view/components/payment-info-usd.vue';
  140. import payButton from "@/view/iframe/publish/components/pay-button";
  141. import messageBox from "@/view/components/message-box.vue";
  142. import BtnLoading from '../components/btn-loading.vue'
  143. import { payNftMysteryBoxWithBalance } from "@/http/pay";
  144. import { calcRechargePayAmount } from "@/http/account";
  145. import { getChromeStorage, setChromeStorage } from "@/uilts/chromeExtension"
  146. import { ElMessage } from 'element-plus'
  147. import "element-plus/es/components/message/style/css";
  148. import { sendChromeTabMessage } from '@/uilts/chromeExtension.js';
  149. let pay_info = inject('pay_info');
  150. let postId = inject('post_Id');
  151. let state = reactive({
  152. loading: {
  153. show: false
  154. },
  155. is_btn_grey: true
  156. })
  157. let currentCurrencyInfo = reactive({
  158. currencyCode: "",
  159. currencyName: "",
  160. balance: "",
  161. });
  162. // 真实支付金额数据
  163. let finalAmountData = ref({
  164. currencyCode: '',
  165. feeAmountValue: 0,
  166. finalAmountValue: 0,
  167. requestAmountValue: 0,
  168. });
  169. let showDepositMessageBox = ref(false);
  170. let amountTimer = ref(0);
  171. let dialogStyle = reactive({
  172. height: '800'
  173. })
  174. const calcRechPayAmount = async (params) => {
  175. let res = await calcRechargePayAmount({
  176. params : params
  177. })
  178. if (res.code == 0) {
  179. finalAmountData.value = res.data;
  180. }
  181. return res.data;
  182. }
  183. const depositAchCancel = async () => {
  184. showDepositMessageBox.value = false;
  185. getCurrencyInfo()
  186. }
  187. const depositAchConfirm = async () => {
  188. showDepositMessageBox.value = false;
  189. getCurrencyInfo()
  190. }
  191. const updateData = (obj_data) => {
  192. if (Number(obj_data.balance) >= Number(pay_info.home.sale_plan.price)) {
  193. state.is_btn_grey = false
  194. }
  195. }
  196. const clickBack = () => {
  197. router.back()
  198. }
  199. const clickPlay = () => {
  200. state.loading.show = true
  201. payNftMysteryBoxWithBalance({
  202. params: {
  203. nftProjectId: pay_info.home.nftProjectId,
  204. salePlanId: pay_info.home.sale_plan.salePlanId,
  205. nftGroupId: pay_info.nft_group_Id
  206. }
  207. }).then((res) => {
  208. state.loading.show = false
  209. if (res.code == 0) {
  210. pay_info.buy_items = res.data.buyItems
  211. sendChromeTabMessage({ actionType: "FINISH_GROUP_BANNNER" }, () => { })
  212. router.push({ path: '/open_box' });
  213. Report.reportLog({
  214. pageSource: Report.pageSource.nftShopPage,
  215. businessType: Report.businessType.buttonClick,
  216. objectType: Report.objectType.buy_button,
  217. nftProjectId: pay_info.home.nftProjectId,
  218. postEditorPostId: postId.value,
  219. }, {
  220. 'buy-number': pay_info.home?.sale_plan?.itemCount,
  221. result: 'success'
  222. })
  223. } else {
  224. let msg = ''
  225. switch (res.code.toString()) {
  226. case '5001':
  227. msg = 'nft project not exist'
  228. break;
  229. case '5002':
  230. msg = 'nft project not available'
  231. break
  232. case '5101':
  233. msg = 'nft sale plan not exist'
  234. break
  235. case '5102':
  236. msg = 'nft sold out'
  237. break
  238. case '5103':
  239. msg = 'Purchase limit reached'
  240. break
  241. default:
  242. console.log(res.msg)
  243. }
  244. ElMessage({
  245. message: msg,
  246. grouping: true,
  247. type: 'warning',
  248. offset: -16,
  249. appendTo: document.body
  250. })
  251. Report.reportLog({
  252. pageSource: Report.pageSource.nftShopPage,
  253. businessType: Report.businessType.buttonClick,
  254. objectType: Report.objectType.buy_button,
  255. nftProjectId: pay_info.home.nftProjectId,
  256. postEditorPostId: postId.value,
  257. }, {
  258. 'buy-number': pay_info.home?.sale_plan?.itemCount,
  259. result: 'fail'
  260. })
  261. }
  262. }).catch(() => {
  263. state.loading.show = false
  264. })
  265. // report
  266. Report.reportLog({
  267. pageSource: Report.pageSource.nftPreviewPage,
  268. businessType: Report.businessType.buttonClick,
  269. objectType: Report.objectType.confirmButton,
  270. nftProjectId: pay_info.home.nftProjectId,
  271. postEditorPostId: postId.value,
  272. })
  273. }
  274. const clickPayUSD = () => {
  275. if(Number(finalAmountData.value.rechargeAmountValue) > 0) {
  276. setTimeout(() => {
  277. showDepositMessageBox.value = true;
  278. }, 1000)
  279. chrome.tabs.getCurrent(tab =>{
  280. let achPayInfo = {
  281. amountValue: finalAmountData.value.rechargeAmountValue,
  282. tab: tab
  283. };
  284. let guideUrl = chrome.runtime.getURL('/iframe/ach-cashier.html');
  285. setChromeStorage({ achPayInfo : JSON.stringify(achPayInfo)});
  286. chrome.tabs.create({
  287. url: guideUrl
  288. });
  289. })
  290. } else {
  291. clickPlay()
  292. }
  293. }
  294. // 余额是否同步中
  295. let asyncIng = ref(false);
  296. //临时货币信息
  297. let tempCurrentCurrencyInfo = ref({});
  298. const refreshRotate = ref(false);
  299. const updateCurrencyBanlce = () => {
  300. if(!refreshRotate.value) {
  301. refreshRotate.value = true;
  302. getCurrencyInfo()
  303. setTimeout(() => {
  304. refreshRotate.value = false;
  305. }, 1000)
  306. }
  307. }
  308. const getLocalCurrencyInfoByCode = () => {
  309. if (currentCurrencyInfo.currencyCode) {
  310. getCurrencyInfo();
  311. }
  312. }
  313. const getCurrencyInfo = async () => {
  314. let { accessToken = '' } = await getChromeStorage('userInfo') || {};
  315. if (accessToken) {
  316. getCurrencyInfoByCode({
  317. params: {
  318. currencyCode: currentCurrencyInfo.currencyCode
  319. }
  320. }).then(res => {
  321. if (res.code == 0 && res.data) {
  322. currentCurrencyInfo = res.data;
  323. tempCurrentCurrencyInfo.value = res.data;
  324. }
  325. });
  326. // 处理USD支付
  327. if (currentCurrencyInfo?.currencyCode === 'USD') {
  328. calcRechPayAmount({
  329. currencyCode: currentCurrencyInfo.currencyCode,
  330. orderAmountValue: pay_info.home.sale_plan.price,
  331. payChannel: 'ach'
  332. })
  333. amountInterval()
  334. }
  335. }
  336. }
  337. const amountInterval = () => {
  338. clearTimeout(amountTimer.value);
  339. amountTimer.value = setTimeout(() => {
  340. getCurrencyInfo()
  341. }, 10000)
  342. }
  343. const setDialogStyle = () => {
  344. let clientHeight = window.innerHeight;
  345. if(clientHeight >= 840) {
  346. dialogStyle.height = 800;
  347. } else {
  348. dialogStyle.height = clientHeight - 40;
  349. }
  350. }
  351. onMounted(() => {
  352. currentCurrencyInfo.currencyCode = pay_info.home.sale_plan.currencyCode
  353. let timer = currentCurrencyInfo.currencyCode === 'USD' ? 10000 : 0;
  354. setTimeout(() => {
  355. getLocalCurrencyInfoByCode();
  356. }, timer);
  357. setDialogStyle()
  358. // setParams
  359. if (router.currentRoute.value?.query?.finalAmount) {
  360. finalAmountData.value = JSON.parse(router.currentRoute.value.query.finalAmount);
  361. }
  362. if (router.currentRoute.value?.query?.currentCurrencyInfo) {
  363. tempCurrentCurrencyInfo.value = JSON.parse(router.currentRoute.value.query.currentCurrencyInfo);
  364. }
  365. // report
  366. Report.reportLog({
  367. pageSource: Report.pageSource.nftPreviewPage,
  368. businessType: Report.businessType.pageView,
  369. nftProjectId: pay_info.home.nftProjectId,
  370. postEditorPostId: postId.value,
  371. })
  372. })
  373. onUnmounted(() => {
  374. clearTimeout(amountTimer.value);
  375. })
  376. </script>
  377. <style lang="scss" scoped>
  378. .dialog {
  379. background: #fff;
  380. border-radius: 25px;
  381. max-width: 1000px;
  382. min-width: 1000px;
  383. max-height: 90%;
  384. z-index: 23;
  385. display: flex;
  386. flex-direction: column;
  387. .area-title {
  388. width: 100%;
  389. height: 48px;
  390. display: flex;
  391. align-items: center;
  392. border-bottom: 1px solid #D9D9D9;
  393. font-weight: 500;
  394. font-size: 16px;
  395. letter-spacing: 0.3px;
  396. color: #000000;
  397. img {
  398. width: 24p;
  399. height: 24px;
  400. margin-left: 14px;
  401. margin-right: 12px;
  402. cursor: pointer;
  403. }
  404. }
  405. .area-content {
  406. display: flex;
  407. overflow-y: auto;
  408. flex: 1;
  409. .left {
  410. width: 400px;
  411. margin: 40px 56px 0 56px;
  412. &.auto {
  413. margin: 40px auto 0 auto;
  414. }
  415. img {
  416. max-width: 400px;
  417. max-height: 400px;
  418. width: 100%;
  419. height: auto;
  420. }
  421. p {
  422. margin: 0;
  423. padding: 0;
  424. }
  425. .tip {
  426. margin-top: 15px;
  427. font-size: 16px;
  428. display: flex;
  429. justify-content: space-between;
  430. div {
  431. display: flex;
  432. align-items: center;
  433. }
  434. img {
  435. margin-right: 4px;
  436. width: 14px;
  437. height: 14px;
  438. }
  439. }
  440. }
  441. .right {
  442. width: 400px;
  443. margin: 30px 56px 0px 30px;
  444. &.none {
  445. display: none;
  446. }
  447. .card-content {
  448. float: right;
  449. width: 430px;
  450. padding-bottom: 22px;
  451. .card-title {
  452. margin-bottom: 12px;
  453. display: flex;
  454. align-items: center;
  455. .img {
  456. width: 20px;
  457. height: 20px;
  458. margin-right: 8px;
  459. }
  460. .font {
  461. font-size: 17px;
  462. font-weight: 500;
  463. span {
  464. color: #0091e9;
  465. }
  466. }
  467. }
  468. .card-list {
  469. padding: 20px;
  470. border-radius: 20px;
  471. border: 1px solid #E6E6E6;
  472. .item {
  473. display: flex;
  474. justify-content: space-between;
  475. align-items: center;
  476. height: 47px;
  477. font-size: 14px;
  478. font-weight: 500;
  479. box-shadow: inset 0px -1px 0px #EAEAEA;
  480. }
  481. }
  482. }
  483. }
  484. }
  485. .pay {
  486. width: 200px;
  487. height: 50px;
  488. font-weight: 700;
  489. font-size: 18px;
  490. margin-right: 30px;
  491. color: #FFFFFF;
  492. background: #1D9BF0;
  493. border-radius: 10000px;
  494. text-align: center;
  495. line-height: 50px;
  496. cursor: pointer;
  497. p {
  498. margin: 0;
  499. padding: 0;
  500. }
  501. }
  502. .footer {
  503. border-top: 1px solid #D9D9D9;
  504. height: 80px;
  505. width: 100%;
  506. display: flex;
  507. align-items: center;
  508. justify-content: flex-end;
  509. position: relative;
  510. .sold {
  511. position: absolute;
  512. left: 20px;
  513. }
  514. .limit {
  515. color: #AF934E;
  516. margin-right: 25px;
  517. }
  518. .buy5 {
  519. border: 1px solid #1D9BF0;
  520. background: rgba(29, 155, 240, 0.01);
  521. border-radius: 100px;
  522. color: #1D9BF0;
  523. width: 217px;
  524. height: 50px;
  525. display: flex;
  526. justify-content: space-between;
  527. align-items: center;
  528. padding: 0 15px 0 20px;
  529. font-weight: 700;
  530. font-size: 18px;
  531. cursor: pointer;
  532. margin-right: 12px;
  533. .off {
  534. color: #AF934E;
  535. font-weight: 700;
  536. font-size: 14px;
  537. letter-spacing: 0.3px;
  538. }
  539. .usdt {
  540. color: #1D9BF0;
  541. font-size: 14px;
  542. font-weight: 700;
  543. }
  544. }
  545. .buy1 {
  546. cursor: pointer;
  547. background: #1D9BF0;
  548. color: #fff;
  549. border-radius: 100px;
  550. min-width: 217px;
  551. min-height: 50px;
  552. display: flex;
  553. align-items: center;
  554. font-size: 14px;
  555. font-weight: 700;
  556. justify-content: space-between;
  557. padding: 0 15px 0 20px;
  558. margin-right: 25px;
  559. .left {
  560. margin-right: 20px;
  561. }
  562. .right {
  563. text-align: right;
  564. p {
  565. margin: 0;
  566. padding: 0;
  567. line-height: 17px;
  568. }
  569. }
  570. &.usd {
  571. min-width: auto;
  572. }
  573. }
  574. .grey {
  575. background: #CDCDCD;
  576. cursor: not-allowed;
  577. }
  578. }
  579. }
  580. .balance {
  581. display: flex;
  582. margin-right: 20px;
  583. .icon {
  584. width: 40px;
  585. height: 40px;
  586. }
  587. .con {
  588. padding: 0 5px;
  589. .desc {
  590. color: rgba($color: #000000, $alpha: 0.5);
  591. font-size: 12px;
  592. margin-bottom: 4px;
  593. }
  594. .price {
  595. font-size: 14px;
  596. font-weight: bold;
  597. word-break: break-all;
  598. }
  599. }
  600. .refresh {
  601. width: 40px;
  602. cursor: pointer;
  603. margin-left: -5px;
  604. }
  605. }
  606. .icon-refresh-rotate {
  607. transform: rotate(360deg);
  608. transition-duration: 1s;
  609. }
  610. </style>