index.vue 44 KB

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