index.vue 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375
  1. <template>
  2. <div class="payment">
  3. <!-- 选择支付方式 -->
  4. <template v-if="step === 1">
  5. <div class="moneyInfo">
  6. <div class="tips">You Neet to Pay</div>
  7. <div class="money" v-if="salePlans">
  8. <FontZoom width="300" :unColor="true" v-if="salePlans && salePlans.price">
  9. <template v-if="salePlans && salePlans.currencyCode && salePlans.currencyCode !== 'USD'">
  10. <template v-if="salePlans.price.length + salePlans.currencyInfo.tokenSymbol.length >= 30">
  11. <div style="text-align:center">
  12. <div><img class="icon" :src="salePlans.currencyInfo.iconPath" /> {{ salePlans.price | floatPrice(4) }}</div>
  13. <div>{{ salePlans.currencyInfo.tokenSymbol }} (${{salePlans.usdPrice | floatPrice(2)}})</div>
  14. </div>
  15. </template>
  16. <template v-else>
  17. <img class="icon" :src="salePlans.currencyInfo.iconPath" /> {{ salePlans.price | floatPrice(4) }} {{ salePlans.currencyInfo.tokenSymbol }} (${{salePlans.usdPrice | floatPrice(2)}})
  18. </template>
  19. </template>
  20. <template v-else>
  21. <span class="info usd">${{salePlans.usdPrice | floatPrice(2)}}</span>
  22. </template>
  23. </FontZoom>
  24. </div>
  25. </div>
  26. <div class="payList">
  27. <div class="detail" v-if="salePlans && salePlans.currencyCode && salePlans.currencyCode !== 'USD'">
  28. <div class="title">Crypto Wallet</div>
  29. <div class="item denet" @click="deNetPay">
  30. <div>
  31. <img src="../../static/payment/icon_wallet.png" />
  32. <span>DeNet Pay</span>
  33. </div>
  34. <div class="wallet">
  35. <FontZoom width="300" :unColor="true">
  36. Balance:{{currencyInfoData.balance | floatPrice(4)}} {{currencyInfoData.tokenSymbol}}
  37. </FontZoom>
  38. </div>
  39. </div>
  40. <div
  41. v-if="ifShowMetaMask"
  42. class="item"
  43. @click="maskPay">
  44. <a class="maskLink" :href="maskUrlLink" v-if="Number(usdAmountData.rechargeAmountValue) > 0"></a>
  45. <img src="../../static/payment/icon_meta_mask.png" />
  46. <span>MetaMask</span>
  47. </div>
  48. </div>
  49. <div class="detail" v-if="salePlans && salePlans.currencyCode && salePlans.currencyCode === 'USD'">
  50. <div class="title">Credit/Debit Card</div>
  51. <div class="item denet" @click="deNetPay">
  52. <div>
  53. <img src="../../static/payment/icon_wallet.png" />
  54. <span>DeNet Pay</span>
  55. </div>
  56. <div class="wallet">
  57. Balance:{{currencyInfoData.balance | floatPrice(2)}} {{currencyInfoData.tokenSymbol}}
  58. </div>
  59. </div>
  60. <div
  61. v-if="ifShowAch"
  62. class="item"
  63. @click="achPay(true, Report.objectType.mastercardPayButton)">
  64. <img src="../../static/payment/icon_master_card.png" />
  65. <span>MasterCard</span>
  66. </div>
  67. <div
  68. v-if="ifShowAch"
  69. class="item"
  70. @click="achPay(true, Report.objectType.visaPayButton)">
  71. <img src="../../static/payment/icon_visa.png" />
  72. <span>VISA</span>
  73. </div>
  74. </div>
  75. <div class="detail">
  76. <div class="title">Redemption Code</div>
  77. <div class="item" @click="showRedeem">
  78. <img src="../../static/payment/icon_enter_code.png" />
  79. <span>Enter Code</span>
  80. </div>
  81. </div>
  82. </div>
  83. </template>
  84. <!-- 余额足够 -->
  85. <template v-else-if="step === 2">
  86. <div class="balanceTop">
  87. <img class="balance" src="../../static/img/icon_balance.svg" />
  88. <div class="text">Balance</div>
  89. <div class="money">
  90. <FontZoom width="300" :unColor="true">
  91. <template v-if="salePlans.currencyCode === 'USD'">
  92. <img class="icon" :src="currencyInfoData.iconPath" /> {{ currencyInfoData.balance | floatPrice(2) }} {{currencyInfoData.tokenSymbol}}
  93. </template>
  94. <template v-else>
  95. <img class="icon" :src="currencyInfoData.iconPath" /> {{ currencyInfoData.balance | floatPrice(4) }} {{currencyInfoData.tokenSymbol}}
  96. </template>
  97. </FontZoom>
  98. </div>
  99. <template v-if="waitRefresh">
  100. <div class="waitFont">It may take some time to credit the funds into your account.</div>
  101. <div
  102. @click="checkWaitInfo"
  103. class="waitBtn">
  104. <img :class="{ 'icon-refresh-rotate': refreshRotate }" src="../../static/img/icon_refresh.svg" />
  105. </div>
  106. </template>
  107. </div>
  108. <div class="balanceBot">
  109. <div class="l">
  110. <div class="neet">You Neet to Pay</div>
  111. <div class="money">
  112. <FontZoom width="190" :unColor="true">
  113. <span class="text">
  114. <template v-if="salePlans.currencyCode === 'USD'">
  115. {{ salePlans.price | floatPrice(2) }} {{ salePlans.currencyInfo.tokenSymbol }}
  116. </template>
  117. <template v-else>
  118. {{ salePlans.price | floatPrice(4) }} {{ salePlans.currencyInfo.tokenSymbol }}
  119. </template>
  120. </span>
  121. </FontZoom>
  122. </div>
  123. </div>
  124. <div>
  125. <div
  126. class="btn"
  127. :class="{ disable: (Number(usdAmountData.rechargeAmountValue) > 0) || payDisabled }"
  128. @click="pay">
  129. Pay Now
  130. </div>
  131. </div>
  132. </div>
  133. </template>
  134. <!-- 余额不足 -->
  135. <template v-else-if="step === 3">
  136. <template v-if="salePlans && salePlans.currencyCode && salePlans.currencyCode !== 'USD'">
  137. <div class="balanceInfo">
  138. <div class="top">
  139. <div class="item title">
  140. <img src="../../static/img/icon_deposit.png" />
  141. <span>Deposit to Buy</span>
  142. </div>
  143. <div class="item column">
  144. <div class="l">Deposit</div>
  145. <div class="r">
  146. <FontZoom width="260" :unColor="true">
  147. <img :src="currencyInfoData.iconPath" />
  148. <span><span v-if="Number(usdAmountData.rechargeAmountValue) > 0">{{ usdAmountData.rechargeAmountValue | floatPrice(4) }} </span>{{currencyInfoData.tokenSymbol}}</span>
  149. </FontZoom>
  150. </div>
  151. </div>
  152. <div class="item column">
  153. <div class="l">Network</div>
  154. <div class="r">
  155. <FontZoom width="260" :unColor="true">
  156. <img :src="currencyInfoData.chainInfo.iconPath" />
  157. <span>{{ currencyInfoData.chainInfo.chainName }}</span>
  158. </FontZoom>
  159. </div>
  160. </div>
  161. <div class="address">
  162. <div class="title">Address</div>
  163. <QrCode :tokenChain="currencyInfoData.tokenChain" :rechargeAddress="rechargeAddress" @copy="copyErCode"></QrCode>
  164. </div>
  165. <div class="notice">
  166. <div class="icon"><img src="../../static/img/icon_warning.svg" /></div>
  167. <div class="text">Make sure you also selected <Br/><strong>{{ currencyInfoData.chainInfo.chainName }}</strong> <br/>as the Network on the platform where you are withdrawing funds for this deposit. Otherwise, you'll lose your assets.</div>
  168. </div>
  169. </div>
  170. <div class="line"></div>
  171. <div class="balance">
  172. <div class="icon">
  173. <img src="../../static/img/icon_balance_blue.svg" />
  174. </div>
  175. <div class="text">
  176. <FontZoom width="260" :unColor="true">
  177. <span>Balance: {{ currencyInfoData.balance | floatPrice(4) }} {{ currencyInfoData.tokenSymbol }}</span>
  178. </FontZoom>
  179. </div>
  180. <div
  181. class="refresh"
  182. @click="checkCurrencyInfo">
  183. <img :class="{ 'icon-refresh-rotate': refreshRotate }" src="../../static/img/icon_refresh.svg" />
  184. </div>
  185. </div>
  186. </div>
  187. <div class="balanceBot">
  188. <div class="l">
  189. <div class="neet">You Neet to Pay</div>
  190. <div class="money">
  191. <FontZoomMobile width="220" :unColor="true">
  192. {{salePlans.price | floatPrice(4)}} {{ salePlans.currencyInfo.tokenSymbol }}
  193. </FontZoomMobile>
  194. </div>
  195. </div>
  196. <div>
  197. <div
  198. class="btn"
  199. :class="{ disable: (Number(usdAmountData.rechargeAmountValue) > 0) || payDisabled }"
  200. @click="payToken">
  201. Pay Now
  202. </div>
  203. </div>
  204. </div>
  205. </template>
  206. <template v-if="salePlans && salePlans.currencyCode && salePlans.currencyCode === 'USD'">
  207. <div class="balanceInfo">
  208. <div class="top">
  209. <div class="item usd">
  210. <div class="l">Payment amount</div>
  211. <div class="r fontPayment">${{ usdAmountData.orderAmountValue | floatPrice(2) }}</div>
  212. </div>
  213. <div class="item usd">
  214. <div class="l">Balance</div>
  215. <div class="r font">${{ usdAmountData.balance | floatPrice(2) }}</div>
  216. </div>
  217. <div class="item usd" v-if="Number(usdAmountData.rechargeAmountValue) > 0">
  218. <div class="l">{{ usdAmountData.feeDesc }}</div>
  219. <div class="r font">${{ usdAmountData.feeAmountValue | floatPrice(2) }}</div>
  220. </div>
  221. <div class="item usd" v-if="Number(usdAmountData.rechargeAmountValue) > 0">
  222. <div class="l">Deposit Amount</div>
  223. <div class="r fontDeposit">${{ usdAmountData.rechargeAmountValue }}</div>
  224. </div>
  225. <div class="deposit" @click="achPay(false, '')">Deposit</div>
  226. </div>
  227. <div class="line"></div>
  228. <div class="balance">
  229. <div class="icon">
  230. <img src="../../static/img/icon_balance_blue.svg" />
  231. </div>
  232. <div class="text">Balance: ${{currencyInfoData.balance | floatPrice(2)}}</div>
  233. <div
  234. class="refresh"
  235. @click="checkUsdCurrencyInfo">
  236. <img :class="{ 'icon-refresh-rotate': refreshRotate }" src="../../static/img/icon_refresh.svg" />
  237. </div>
  238. </div>
  239. </div>
  240. <div class="balanceBot">
  241. <div class="l">
  242. <div class="neet">You Neet to Pay</div>
  243. <div class="money">
  244. <FontZoomMobile width="220" :unColor="true">
  245. {{ Number(usdAmountData.rechargeAmountValue) > 0 ? usdAmountData.rechargeAmountValue : usdAmountData.orderAmountValue }} {{ salePlans.currencyInfo.tokenSymbol }}
  246. </FontZoomMobile>
  247. </div>
  248. </div>
  249. <div>
  250. <div
  251. class="btn"
  252. :class="{ disable: (Number(usdAmountData.rechargeAmountValue) > 0) || payDisabled }"
  253. @click="payUSD">
  254. Pay Now
  255. </div>
  256. </div>
  257. </div>
  258. </template>
  259. </template>
  260. <!-- 成功支付 -->
  261. <template v-else-if="step === 4">
  262. <div class="payInfo">
  263. <div class="picShow" v-if="buyData">
  264. <div class="tip">Wow, NFT in the Mystery box is</div>
  265. <img class="pic" :src="buyData.imagePath" />
  266. <div class="name">{{buyData.nftItemName}}</div>
  267. </div>
  268. </div>
  269. <div class="payBtn">
  270. <button class="btn" @click="goNext">Done</button>
  271. </div>
  272. </template>
  273. <!-- loading -->
  274. <div class="loading" v-if="loading">
  275. <van-loading color="#1D9BF0"></van-loading>
  276. </div>
  277. <div class="loadingBg" v-if="loading"></div>
  278. <!-- redeem -->
  279. <van-popup
  280. round
  281. v-model="redeemLayer"
  282. position="bottom">
  283. <div class="redeem">
  284. <div class="tips">Enter Redemption Code</div>
  285. <div class="footer">
  286. <div class="input">
  287. <input
  288. type="text"
  289. ref="input"
  290. v-model="redeemStr"
  291. @input="textInput"
  292. @blur="textBlur"
  293. @focus="textFocus"
  294. @keydown.enter="redeemPayment" />
  295. </div>
  296. <button
  297. class="enter"
  298. :class="{ disable: !redeemNext }"
  299. @click="redeemPayment">
  300. Redeem
  301. </button>
  302. </div>
  303. </div>
  304. </van-popup>
  305. </div>
  306. </template>
  307. <script>
  308. import FontZoom from '../../components/FontZoom.vue';
  309. import FontZoomMobile from '../../components/FontZoomMobile.vue';
  310. import QrCode from '../../components/qrcode.vue';
  311. import { postRequest } from '../../http/index';
  312. import { maskUrl, setStorage, storageKey, OSDetect } from '../../utils/help';
  313. import { Dialog } from 'vant';
  314. import Api from '../../http/api';
  315. import Report from '../../log-center/log';
  316. export default {
  317. name: 'payment',
  318. data() {
  319. return {
  320. step: 1, // 1: 支付方式列表 2: 余额支付 3: 充值支付 4: 支付完成
  321. loading: true,
  322. salePlans: null,
  323. rechargeAddress: '',
  324. redeemStr: '',
  325. redeemNext: false,
  326. redeemLayer: false,
  327. buyData: {},
  328. payDisabled: false,
  329. waitRefresh: false,
  330. refreshRotate: false,
  331. currencyInfoData: {},
  332. currencyTimer: 0,
  333. achTimer: 0,
  334. maskUrlLink: ``,
  335. usdAmountData: {},
  336. Report: Report,
  337. ifShowMetaMask: false,
  338. ifShowAch: false,
  339. }
  340. },
  341. head() {
  342. return {
  343. title: 'Buy NFT Mystery Box',
  344. }
  345. },
  346. components: {
  347. QrCode,
  348. FontZoom,
  349. FontZoomMobile,
  350. },
  351. mounted() {
  352. this.saleInfo()
  353. this.showMetaMask()
  354. this.reportView(Report.pageSource.nftPaymentPage)
  355. },
  356. beforeDestroy() {
  357. clearTimeout(this.currencyTimer);
  358. },
  359. filters: {
  360. floatPrice(price, num) {
  361. if (!price) return;
  362. if (price.indexOf('.') >= 0) {
  363. let reg = new RegExp(`^\\D*(\\d*(?:\\.\\d{0,${num}})?).*$`, "g");
  364. price = price.replace(reg, '$1');
  365. }
  366. return price;
  367. }
  368. },
  369. methods : {
  370. saleInfo () {
  371. postRequest(Api.getNftMysteryBoxSaleInfo, {
  372. params: {
  373. nftProjectId: this.$route.query.nftProjectId
  374. }
  375. }).then(res => {
  376. let { code, data } = res;
  377. if (code === 0) {
  378. this.salePlans = data.salePlans[0];
  379. this.getCurrencyInfoByCode();
  380. // 获取充值地址
  381. if (this.rechargeAddress === '') {
  382. this.getAddress()
  383. }
  384. }
  385. }).finally(() => {
  386. setTimeout(() => {
  387. this.loading = false;
  388. }, 600)
  389. })
  390. },
  391. showMetaMask() {
  392. if (OSDetect() === 'ios') {
  393. this.ifShowMetaMask = true;
  394. }
  395. },
  396. getCurrencyInfoByCode() {
  397. let where = this.salePlans && this.salePlans.currencyCode;
  398. if (!where) return;
  399. postRequest(Api.getCurrencyInfoByCode, {
  400. params: {
  401. currencyCode: this.salePlans.currencyCode
  402. }
  403. }).then(res => {
  404. let { code, data } = res;
  405. if (code === 0) {
  406. this.currencyInfoData = data;
  407. }
  408. })
  409. // 计算金额
  410. postRequest(Api.calcRechargePayAmount, {
  411. params: {
  412. currencyCode: this.salePlans.currencyCode,
  413. orderAmountValue: this.salePlans.price,
  414. payChannel: 'ach'
  415. }
  416. }).then(res => {
  417. let { code, data } = res;
  418. if (code === 0) {
  419. this.usdAmountData = data;
  420. }
  421. })
  422. },
  423. getTokenRechargeRecord() {
  424. postRequest(Api.syncChainTokenRechargeRecord, {
  425. params: {
  426. currencyCode: this.salePlans.currencyCode
  427. }
  428. }).then(res => {
  429. let { code, data } = res;
  430. if (code === 0) {
  431. if (data.length > 0) {
  432. let currencyInfo = data[0];
  433. if (currencyInfo.currencyCode == this.currencyInfoData.currencyCode) {
  434. this.currencyInfoData.balance = currencyInfo.balance;
  435. }
  436. } else {
  437. this.currencyInfoData.balance = 0
  438. }
  439. }
  440. })
  441. },
  442. currencyInfoTimer() {
  443. clearTimeout(this.currencyTimer);
  444. this.currencyTimer = setTimeout(() => {
  445. this.currencyInfoTimer()
  446. this.getCurrencyInfoByCode()
  447. }, 10000);
  448. },
  449. checkUsdCurrencyInfo() {
  450. if (!this.refreshRotate) {
  451. this.refreshRotate = true;
  452. this.getCurrencyInfoByCode()
  453. setTimeout(() => {
  454. this.refreshRotate = false;
  455. }, 1000)
  456. // report
  457. this.reportDepositCashPageClick(Report.objectType.refreshBalanceButton)
  458. }
  459. },
  460. checkCurrencyInfo() {
  461. if (!this.refreshRotate) {
  462. this.refreshRotate = true;
  463. this.getTokenRechargeRecord()
  464. setTimeout(() => {
  465. this.refreshRotate = false;
  466. }, 1000)
  467. // report
  468. this.reportDepositTokenPageClick(Report.objectType.refreshBalanceButton)
  469. }
  470. },
  471. checkWaitInfo(isReport = true) {
  472. if (!this.refreshRotate) {
  473. this.refreshRotate = true;
  474. this.getCurrencyInfoByCode();
  475. setTimeout(() => {
  476. this.refreshRotate = false;
  477. }, 1000)
  478. }
  479. if (isReport) {
  480. this.reportBalanceRefresh()
  481. }
  482. },
  483. showRedeem() {
  484. this.redeemStr = '';
  485. this.redeemNext = false;
  486. this.redeemLayer = true;
  487. this.$nextTick(() => {
  488. this.$refs.input.focus();
  489. })
  490. this.reportView(Report.pageSource.nftRedeemPage)
  491. this.reportPaymentBtnClick(Report.objectType.redeemButton)
  492. },
  493. textInput(e) {
  494. let len = 16
  495. let str = this.redeemStr.replace(/[^a-zA-Z0-9]/g, '')
  496. str = str.toUpperCase();
  497. str = str.slice(0, len);
  498. // set
  499. this.redeemStr = str;
  500. this.redeemNext = str !== '' && str.length === len;
  501. },
  502. textBlur(e) {
  503. let isiOS = !!window.navigator.userAgent.match(/\(i\[^;]+;( U;)? CPU.+Mac OS X/)
  504. if (isiOS) {
  505. setTimeout(() => {
  506. const scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0
  507. window.scrollTo(0, Math.max(scrollHeight - 1, 0))
  508. }, 100)
  509. }
  510. },
  511. textFocus(e) {
  512. let isiOS = !!window.navigator.userAgent.match(/\(i\[^;]+;( U;)? CPU.+Mac OS X/)
  513. if (isiOS) {
  514. setTimeout(() => {
  515. const scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0
  516. window.scrollTo(0, Math.max(scrollHeight - 1, 0))
  517. }, 100)
  518. }
  519. },
  520. redeemPayment() {
  521. if (!this.redeemNext) return;
  522. let params = {
  523. redeemCode: this.redeemStr,
  524. nftProjectId: this.$route.query.nftProjectId,
  525. }
  526. this.redeemNext = false;
  527. postRequest(Api.redeemNft, {
  528. params
  529. }).then(res => {
  530. let { code, data } = res;
  531. if (code === 0) {
  532. this.redeemLayer = false;
  533. if (data.length > 0) {
  534. this.buyData = data[0];
  535. }
  536. // 购买成功
  537. this.step = 4;
  538. this.reportSuccessView();
  539. } else {
  540. this.payError(code)
  541. }
  542. }).finally(() => {
  543. this.redeemNext = true;
  544. })
  545. this.reportRedeemBtnClick()
  546. },
  547. getAddress() {
  548. let where = this.salePlans && this.salePlans.currencyInfo && this.salePlans.currencyInfo.tokenChain;
  549. if (!where) return;
  550. postRequest(Api.getTokenRechargeAddress, {
  551. params: {
  552. tokenChain: this.salePlans.currencyInfo?.tokenChain
  553. }
  554. }).then(res => {
  555. let { code, data } = res;
  556. if (code === 0) {
  557. this.rechargeAddress = data.rechargeAddress
  558. this.maskUrlToLink()
  559. }
  560. })
  561. },
  562. maskUrlToLink() {
  563. // MetaMask Link
  564. let url;
  565. let price = this.usdAmountData.rechargeAmountValue;
  566. if (this.salePlans.currencyInfo?.contractAddress) {
  567. // 代币
  568. url = maskUrl({
  569. target_address: this.salePlans.currencyInfo.contractAddress,
  570. parameters: {
  571. address: this.rechargeAddress,
  572. uint256: `${price}e${this.salePlans.currencyInfo?.decimalLength || 18}`
  573. }
  574. }, false)
  575. } else {
  576. // 主币
  577. url = maskUrl({
  578. target_address: this.rechargeAddress,
  579. parameters: {
  580. value: `${price}e${this.salePlans.currencyInfo?.decimalLength || 18}`
  581. }
  582. })
  583. }
  584. this.maskUrlLink = url;
  585. },
  586. goNext() {
  587. this.reportSuccessClick()
  588. setTimeout(() => {
  589. this.$router.push({
  590. path: `/nft/${this.$route.query.nftProjectId}/${this.$route.query.account}/show`,
  591. })
  592. }, 300)
  593. },
  594. pay(isReport = true) {
  595. if (this.payDisabled || Number(this.usdAmountData.rechargeAmountValue) > 0) return;
  596. this.payDisabled = true;
  597. postRequest(Api.payNftMysteryBoxWithBalance, {
  598. params: {
  599. nftProjectId: this.$route.query.nftProjectId,
  600. salePlanId: this.salePlans.salePlanId,
  601. }
  602. }).then(res => {
  603. let { code, data } = res;
  604. if (code == 0) {
  605. if (data && data.buyItems.length > 0) {
  606. this.buyData = data.buyItems[0];
  607. }
  608. // 购买成功
  609. this.step = 4;
  610. this.reportSuccessView();
  611. } else {
  612. this.payError(code)
  613. }
  614. }).finally(() => {
  615. this.payDisabled = false;
  616. })
  617. // report
  618. if (isReport) {
  619. this.reportBalanceBuy()
  620. }
  621. },
  622. payUSD() {
  623. if (Number(this.usdAmountData.rechargeAmountValue) <= 0) {
  624. this.pay(false)
  625. this.reportDepositCashPageClick(Report.objectType.purchaseNftButton)
  626. }
  627. },
  628. payToken() {
  629. if (Number(this.currencyInfoData.balance) >= Number(this.salePlans.price)) {
  630. this.pay(false)
  631. this.reportDepositTokenPageClick(Report.objectType.purchaseNftButton)
  632. }
  633. },
  634. payError(code) {
  635. let msg;
  636. switch (code.toString()) {
  637. case '5001':
  638. msg = 'nft project not exist'
  639. break;
  640. case '5002':
  641. msg = 'nft project not available'
  642. break
  643. case '5101':
  644. msg = 'nft sale plan not exist'
  645. break
  646. case '5102':
  647. msg = 'nft sold out'
  648. break
  649. case '5103':
  650. msg = 'Purchase limit reached'
  651. break
  652. case '5104':
  653. case '5105':
  654. case '5106':
  655. msg = 'Invalid redemption code'
  656. break;
  657. default:
  658. msg = 'Payment failed, please try again'
  659. break;
  660. }
  661. // Dialog
  662. Dialog({
  663. message: msg,
  664. confirmButtonText: 'OK',
  665. confirmButtonColor: '#1D9BF0',
  666. });
  667. },
  668. deNetPay() {
  669. if (!this.salePlans) return;
  670. let pageSource;
  671. if (this.salePlans.currencyCode === 'USD') {
  672. pageSource = Report.pageSource.nftDepositCashPage
  673. } else {
  674. pageSource = Report.pageSource.nftDepositTokenPage
  675. }
  676. if (Number(this.usdAmountData.rechargeAmountValue) > 0) {
  677. // 余额不够
  678. this.step = 3;
  679. this.currencyInfoTimer();
  680. // Report
  681. this.reportView(pageSource);
  682. } else {
  683. // 余额足够
  684. this.step = 2;
  685. this.reportView(Report.pageSource.nftBalancePage);
  686. }
  687. this.reportPaymentBtnClick(Report.objectType.denetPayButton)
  688. },
  689. maskPay() {
  690. if (Number(this.usdAmountData.rechargeAmountValue) > 0) {
  691. this.step = 2;
  692. this.waitRefresh = true;
  693. this.currencyInfoTimer();
  694. Dialog({
  695. message: `Was the pament successful?`,
  696. showCancelButton: true,
  697. confirmButtonText: 'YES',
  698. confirmButtonColor: '#1D9BF0',
  699. cancelButtonText: 'NO',
  700. cancelButtonColor: '#1D9BF0',
  701. }).then(() => {
  702. this.checkWaitInfo(false)
  703. }).catch(() => {
  704. this.checkWaitInfo(false)
  705. });
  706. this.reportView(Report.pageSource.nftPaymentBalancePage);
  707. } else {
  708. this.step = 2;
  709. this.reportView(Report.pageSource.nftBalancePage);
  710. }
  711. this.reportPaymentBtnClick(Report.objectType.metamaskPayButton)
  712. },
  713. achPay(modifyStep = true, objectType = '') {
  714. if (Number(this.usdAmountData.rechargeAmountValue) > 0) {
  715. if (modifyStep) {
  716. this.step = 2;
  717. this.reportView(Report.pageSource.nftPaymentBalancePage);
  718. }
  719. this.waitRefresh = true;
  720. this.currencyInfoTimer();
  721. Dialog({
  722. message: `Was the pament successful?`,
  723. showCancelButton: true,
  724. confirmButtonText: 'YES',
  725. confirmButtonColor: '#1D9BF0',
  726. cancelButtonText: 'NO',
  727. cancelButtonColor: '#1D9BF0',
  728. }).then(() => {
  729. this.checkWaitInfo(false)
  730. }).catch(() => {
  731. this.checkWaitInfo(false)
  732. });
  733. // setUrl
  734. setStorage(storageKey.paymentUrl, window.location.href)
  735. this.$nextTick(() => {
  736. let win = window.open();
  737. win.opener = null;
  738. win.location.href = `${location.protocol}//${location.host}/payment_ach/${this.usdAmountData.rechargeAmountValue}`;
  739. this.achTimer = setInterval(() => {
  740. console.log('pay')
  741. if (win && win.closed) {
  742. console.log('done')
  743. clearInterval(this.achTimer);
  744. }
  745. }, 500);
  746. })
  747. } else {
  748. if (modifyStep) {
  749. this.step = 2;
  750. this.reportView(Report.pageSource.nftBalancePage);
  751. }
  752. }
  753. if (objectType !== '') {
  754. this.reportPaymentBtnClick(objectType)
  755. } else {
  756. this.reportDepositCashPageClick(Report.objectType.depositButtion)
  757. }
  758. },
  759. copyErCode() {
  760. this.reportDepositTokenPageClick(Report.objectType.copyButtion)
  761. },
  762. reportView(pageSource) {
  763. Report.log({
  764. pageSource,
  765. params: {
  766. eventData: {
  767. businessType: Report.businessType.pageView,
  768. },
  769. extParams: {
  770. userAgent: window.navigator.userAgent,
  771. }
  772. }
  773. })
  774. },
  775. reportPaymentBtnClick(objectType) {
  776. Report.log({
  777. pageSource: Report.pageSource.nftPaymentPage,
  778. params: {
  779. eventData: {
  780. objectType,
  781. businessType: Report.businessType.buttonClick,
  782. },
  783. extParams: {
  784. userAgent: window.navigator.userAgent,
  785. }
  786. }
  787. })
  788. },
  789. reportRedeemBtnClick() {
  790. Report.log({
  791. pageSource: Report.pageSource.nftRedeemPage,
  792. params: {
  793. eventData: {
  794. objectType: Report.objectType.redeemButton,
  795. businessType: Report.businessType.buttonClick,
  796. },
  797. extParams: {
  798. userAgent: window.navigator.userAgent,
  799. }
  800. }
  801. })
  802. },
  803. reportDepositCashPageClick(objectType) {
  804. Report.log({
  805. pageSource: Report.pageSource.nftDepositCashPage,
  806. params: {
  807. eventData: {
  808. objectType,
  809. businessType: Report.businessType.buttonClick,
  810. },
  811. extParams: {
  812. userAgent: window.navigator.userAgent,
  813. }
  814. }
  815. })
  816. },
  817. reportDepositTokenPageClick(objectType) {
  818. Report.log({
  819. pageSource: Report.pageSource.nftDepositTokenPage,
  820. params: {
  821. eventData: {
  822. objectType,
  823. businessType: Report.businessType.buttonClick,
  824. },
  825. extParams: {
  826. userAgent: window.navigator.userAgent,
  827. }
  828. }
  829. })
  830. },
  831. reportBalanceRefresh() {
  832. let pageSource = this.waitRefresh ? Report.pageSource.nftPaymentBalancePage : Report.pageSource.nftBalancePage;
  833. Report.log({
  834. pageSource: pageSource,
  835. params: {
  836. eventData: {
  837. objectType: Report.objectType.refreshBalanceButton,
  838. businessType: Report.businessType.buttonClick,
  839. },
  840. extParams: {
  841. userAgent: window.navigator.userAgent,
  842. }
  843. }
  844. })
  845. },
  846. reportBalanceBuy() {
  847. let pageSource = this.waitRefresh ? Report.pageSource.nftPaymentBalancePage : Report.pageSource.nftBalancePage;
  848. Report.log({
  849. pageSource: pageSource,
  850. params: {
  851. eventData: {
  852. objectType: Report.objectType.purchaseNftButton,
  853. businessType: Report.businessType.buttonClick,
  854. },
  855. extParams: {
  856. userAgent: window.navigator.userAgent,
  857. }
  858. }
  859. })
  860. },
  861. reportSuccessView() {
  862. Report.log({
  863. pageSource: Report.pageSource.nftPurchaseSuccessPage,
  864. params: {
  865. eventData: {
  866. businessType: Report.businessType.pageView,
  867. },
  868. extParams: {
  869. userAgent: window.navigator.userAgent,
  870. }
  871. }
  872. })
  873. },
  874. reportSuccessClick() {
  875. Report.log({
  876. pageSource: Report.pageSource.nftPurchaseSuccessPage,
  877. params: {
  878. eventData: {
  879. businessType: Report.businessType.buttonClick,
  880. objectType: Report.objectType.finishPurchaseButton,
  881. },
  882. extParams: {
  883. userAgent: window.navigator.userAgent,
  884. }
  885. }
  886. })
  887. },
  888. }
  889. }
  890. </script>
  891. <style lang="scss">
  892. html,
  893. body,
  894. #__nuxt,
  895. #__layout {
  896. width: 100%;
  897. height: 100%;
  898. padding: 0;
  899. margin: 0;
  900. overflow: hidden;
  901. }
  902. .payment {
  903. width: 100%;
  904. height: 100%;
  905. }
  906. .moneyInfo {
  907. display: flex;
  908. align-items: center;
  909. justify-content: center;
  910. flex-direction: column;
  911. height: 90px;
  912. border-bottom: solid 8px rgba($color: #f5f5f5, $alpha: .6);
  913. .tips {
  914. font-size: 12px;
  915. font-weight: 500;
  916. }
  917. .money {
  918. display: flex;
  919. align-items: center;
  920. justify-content: center;
  921. margin-top: 10px;
  922. color: #000;
  923. font-size: 20px;
  924. font-weight: 700;
  925. .icon {
  926. overflow: hidden;
  927. width: 26px;
  928. height: 26px;
  929. border-radius: 50%;
  930. margin-right: 10px;
  931. vertical-align: middle;
  932. background-color: #f5f5f5;
  933. }
  934. .info {
  935. &.usd {
  936. margin-top: -5px;
  937. }
  938. }
  939. }
  940. }
  941. .payList {
  942. overflow-y: auto;
  943. height: calc(100% - 90px);
  944. .detail {
  945. padding: 18px 16px;
  946. .title {
  947. color: #ADADAD;
  948. height: 26px;
  949. font-size: 12px;
  950. font-weight: 500;
  951. }
  952. .item {
  953. position: relative;
  954. display: flex;
  955. align-items: center;
  956. justify-content: center;
  957. font-weight: 500;
  958. font-size: 16px;
  959. height: 50px;
  960. margin-bottom: 14px;
  961. border-radius: 100px;
  962. border: 1px solid #ECECEC;
  963. &:last-child {
  964. margin-bottom: 0;
  965. }
  966. img {
  967. width: 24px;
  968. height: 24px;
  969. margin-right: 4px;
  970. }
  971. &.denet {
  972. flex-direction: column;
  973. img {
  974. margin-top: -6px;
  975. }
  976. }
  977. .wallet {
  978. width: 100%;
  979. overflow: hidden;
  980. color: #ADADAD;
  981. font-size: 11px;
  982. text-align: center;
  983. margin-top: -2px;
  984. }
  985. .maskLink {
  986. position: absolute;
  987. z-index: 10;
  988. width: 100%;
  989. height: 100%;
  990. }
  991. }
  992. }
  993. }
  994. .loading {
  995. position: absolute;
  996. z-index: 3;
  997. display: flex;
  998. align-items: center;
  999. justify-content: center;
  1000. top: 0;
  1001. left: 0;
  1002. width: 100%;
  1003. height: 100%;
  1004. }
  1005. .loadingBg {
  1006. position: absolute;
  1007. z-index: 2;
  1008. top: 0;
  1009. left: 0;
  1010. width: 100%;
  1011. height: 100%;
  1012. background-color: rgba($color: #000, $alpha: .1);
  1013. }
  1014. .redeem {
  1015. padding: 18px 16px 38px;
  1016. .tips {
  1017. height: 31px;
  1018. font-size: 15px;
  1019. font-weight: 500;
  1020. }
  1021. .footer {
  1022. display: flex;
  1023. justify-content: space-between;
  1024. .input {
  1025. display: flex;
  1026. align-items: center;
  1027. justify-content: center;
  1028. width: calc(100% - 93px);
  1029. height: 45px;
  1030. border-radius: 5px;
  1031. border: 1px solid #E0E0E0;
  1032. input {
  1033. width: 94%;
  1034. border: 0;
  1035. outline: 0;
  1036. }
  1037. }
  1038. .enter {
  1039. width: 83px;
  1040. height: 45px;
  1041. border: 0;
  1042. padding: 0;
  1043. color: #ffffff;
  1044. font-size: 17px;
  1045. font-weight: 500;
  1046. border-radius: 5px;
  1047. background: #1D9BF0;
  1048. &.disable {
  1049. background: #DEDEDE;
  1050. }
  1051. }
  1052. }
  1053. }
  1054. .payInfo {
  1055. width: 100%;
  1056. height: calc(100% - 88px);
  1057. .picShow {
  1058. padding: 54px 48px;
  1059. .tip {
  1060. height: 44px;
  1061. font-size: 18px;
  1062. font-weight: 600;
  1063. text-align: center;
  1064. }
  1065. .pic {
  1066. display: block;
  1067. margin: auto;
  1068. width: 280px;
  1069. height: 280px;
  1070. border-radius: 3px;
  1071. margin-bottom: 20px;
  1072. }
  1073. .name {
  1074. font-size: 18px;
  1075. font-weight: 600;
  1076. line-height: 21px;
  1077. text-align: center;
  1078. }
  1079. }
  1080. }
  1081. .payBtn {
  1082. padding: 0 16px 38px;
  1083. .btn {
  1084. width: 100%;
  1085. height: 50px;
  1086. color: #FFFFFF;
  1087. font-size: 18px;
  1088. font-weight: 700;
  1089. border-radius: 50px;
  1090. background: #1D9BF0;
  1091. }
  1092. }
  1093. .balanceTop {
  1094. display: flex;
  1095. align-items: center;
  1096. justify-content: center;
  1097. flex-direction: column;
  1098. height: calc(100% - 100px);
  1099. background-color: #f5f5f5;
  1100. .balance {
  1101. width: 66px;
  1102. height: 66px;
  1103. margin-bottom: 6px;
  1104. }
  1105. .text {
  1106. font-size: 15px;
  1107. font-weight: 500;
  1108. line-height: 18px;
  1109. color: #9D9D9D;
  1110. }
  1111. .money {
  1112. font-size: 22px;
  1113. font-weight: 700;
  1114. line-height: 26px;
  1115. margin-top: 6px;
  1116. .icon {
  1117. width: 22px;
  1118. height: 22px;
  1119. margin-right: 6px;
  1120. }
  1121. .font {
  1122. color: #000;
  1123. }
  1124. }
  1125. }
  1126. .balanceInfo {
  1127. overflow-y: auto;
  1128. height: calc(100% - 100px);
  1129. background-color: #f5f5f5;
  1130. .top {
  1131. padding: 0 16px 17px 16px;
  1132. background-color: #ffffff;
  1133. .item {
  1134. display: flex;
  1135. align-items: center;
  1136. height: 54px;
  1137. border-bottom: solid 1px #F2F2F2;
  1138. &.title {
  1139. font-size: 16px;
  1140. font-weight: 600;
  1141. line-height: 19px;
  1142. img {
  1143. width: 26px;
  1144. height: 26px;
  1145. margin-right: 6px;
  1146. }
  1147. }
  1148. &.column {
  1149. color: rgba($color: #5E5E5E, $alpha: .7);
  1150. font-size: 14px;
  1151. font-weight: 400;
  1152. .l {
  1153. width: 70px;
  1154. }
  1155. .r {
  1156. img {
  1157. width: 21px;
  1158. height: 21px;
  1159. margin-right: 4px;
  1160. }
  1161. span {
  1162. color: rgba($color: #5E5E5E, $alpha: .7);
  1163. }
  1164. }
  1165. }
  1166. &.usd {
  1167. font-size: 14px;
  1168. font-weight: 500;
  1169. justify-content: space-between;
  1170. .fontPayment {
  1171. font-size: 18px;
  1172. font-weight: 600;
  1173. }
  1174. .font {
  1175. color: #9A9A9A;
  1176. font-size: 16px;
  1177. font-weight: 500;
  1178. }
  1179. .fontDeposit {
  1180. color: #1D9BF0;
  1181. font-size: 18px;
  1182. font-weight: 600;
  1183. }
  1184. }
  1185. }
  1186. .deposit {
  1187. display: flex;
  1188. align-items: center;
  1189. justify-content: center;
  1190. height: 54px;
  1191. color: #ffffff;
  1192. font-weight: 600;
  1193. font-size: 18px;
  1194. margin-top: 16px;
  1195. border-radius: 54px;
  1196. background: #1D9BF0;
  1197. }
  1198. .address {
  1199. color: rgba($color: #5E5E5E, $alpha: .7);
  1200. .title {
  1201. height: 42px;
  1202. font-size: 14px;
  1203. font-weight: 400;
  1204. line-height: 42px;
  1205. }
  1206. }
  1207. .notice {
  1208. display: flex;
  1209. justify-content: space-between;
  1210. padding: 10px;
  1211. margin-top: 12px;
  1212. border-radius: 8px;
  1213. background: #F9F6EE;
  1214. .icon {
  1215. width: 20px;
  1216. margin-right: 10px;
  1217. img {
  1218. width: 20px;
  1219. height: 20px;
  1220. }
  1221. }
  1222. .text {
  1223. flex: 1;
  1224. color: rgba($color: #5E5E5E, $alpha: .7);
  1225. font-size: 14px;
  1226. font-weight: 400;
  1227. line-height: 19px;
  1228. word-break: break-all;
  1229. strong {
  1230. color: #FF0000;
  1231. font-weight: bold;
  1232. }
  1233. }
  1234. }
  1235. }
  1236. .line {
  1237. height: 8px;
  1238. }
  1239. .balance {
  1240. display: flex;
  1241. align-items: center;
  1242. padding: 0 16px;
  1243. height: 54px;
  1244. background-color: #ffffff;
  1245. .icon {
  1246. width: 24px;
  1247. margin-right: 6px;
  1248. img {
  1249. width: 24px;
  1250. }
  1251. }
  1252. .text {
  1253. flex: 1;
  1254. font-size: 14px;
  1255. font-weight: 500;
  1256. line-height: 17px;
  1257. span {
  1258. color: #000;
  1259. margin-right: auto;
  1260. }
  1261. }
  1262. .refresh {
  1263. width: 24px;
  1264. height: 24px;
  1265. img {
  1266. width: 24px;
  1267. transform-origin: center center;
  1268. }
  1269. }
  1270. }
  1271. }
  1272. .balanceBot {
  1273. display: flex;
  1274. justify-content: space-between;
  1275. width: 100%;
  1276. padding: 17px 16px 38px;
  1277. border-top: solid 1px #ECECEC;
  1278. .l {
  1279. display: flex;
  1280. flex-direction: column;
  1281. justify-content: center;
  1282. }
  1283. .neet {
  1284. font-size: 12px;
  1285. font-weight: 500;
  1286. line-height: 14px;
  1287. }
  1288. .money {
  1289. height: 22px;
  1290. line-height: 22px;
  1291. font-size: 18px;
  1292. font-weight: 700;
  1293. margin-top: 4px;
  1294. .text {
  1295. margin-right: auto;
  1296. }
  1297. }
  1298. .btn {
  1299. display: flex;
  1300. align-items: center;
  1301. justify-content: center;
  1302. width: 110px;
  1303. height: 46px;
  1304. color: #ffffff;
  1305. font-size: 18px;
  1306. font-weight: 700;
  1307. line-height: 21px;
  1308. border-radius: 46px;
  1309. background: #1D9BF0;
  1310. &.disable {
  1311. background: #D2D2D2;
  1312. }
  1313. }
  1314. }
  1315. .waitFont {
  1316. margin-top: 16px;
  1317. padding: 0 20px;
  1318. font-size: 14px;
  1319. font-weight: 500;
  1320. line-height: 17px;
  1321. text-align: center;
  1322. }
  1323. .waitBtn {
  1324. display: flex;
  1325. align-items: center;
  1326. justify-content: center;
  1327. width: 50px;
  1328. height: 50px;
  1329. margin: 50px auto 0;
  1330. border-radius: 50%;
  1331. background-color: #ffffff;
  1332. img {
  1333. width: 24px;
  1334. height: 24px;
  1335. }
  1336. }
  1337. .icon-refresh-rotate {
  1338. transform: rotate(360deg);
  1339. transition-duration: 1s;
  1340. }
  1341. </style>