index.vue 45 KB

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