index.vue 45 KB

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