index.vue 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330
  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, setStorage, storageKey } 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. // setUrl
  716. setStorage(storageKey.paymentUrl, window.location.href)
  717. this.$nextTick(() => {
  718. let win = window.open();
  719. win.opener = null;
  720. win.location.href = `${location.protocol}//${location.host}/payment_ach/${this.usdAmountData.rechargeAmountValue}`;
  721. this.achTimer = setInterval(() => {
  722. console.log('pay')
  723. if (win && win.closed) {
  724. console.log('done')
  725. clearInterval(this.achTimer);
  726. }
  727. }, 500);
  728. })
  729. } else {
  730. if (modifyStep) {
  731. this.step = 2;
  732. this.reportView(Report.pageSource.nftBalancePage);
  733. }
  734. }
  735. if (objectType !== '') {
  736. this.reportPaymentBtnClick(objectType)
  737. } else {
  738. this.reportDepositCashPageClick(Report.objectType.depositButtion)
  739. }
  740. },
  741. copyErCode() {
  742. this.reportDepositTokenPageClick(Report.objectType.copyButtion)
  743. },
  744. reportView(pageSource) {
  745. Report.log({
  746. pageSource,
  747. params: {
  748. eventData: {
  749. businessType: Report.businessType.pageView,
  750. },
  751. extParams: {
  752. userAgent: window.navigator.userAgent,
  753. }
  754. }
  755. })
  756. },
  757. reportPaymentBtnClick(objectType) {
  758. Report.log({
  759. pageSource: Report.pageSource.nftPaymentPage,
  760. params: {
  761. eventData: {
  762. objectType,
  763. businessType: Report.businessType.buttonClick,
  764. },
  765. extParams: {
  766. userAgent: window.navigator.userAgent,
  767. }
  768. }
  769. })
  770. },
  771. reportRedeemBtnClick() {
  772. Report.log({
  773. pageSource: Report.pageSource.nftRedeemPage,
  774. params: {
  775. eventData: {
  776. objectType: Report.objectType.redeemButton,
  777. businessType: Report.businessType.buttonClick,
  778. },
  779. extParams: {
  780. userAgent: window.navigator.userAgent,
  781. }
  782. }
  783. })
  784. },
  785. reportDepositCashPageClick(objectType) {
  786. Report.log({
  787. pageSource: Report.pageSource.nftDepositCashPage,
  788. params: {
  789. eventData: {
  790. objectType,
  791. businessType: Report.businessType.buttonClick,
  792. },
  793. extParams: {
  794. userAgent: window.navigator.userAgent,
  795. }
  796. }
  797. })
  798. },
  799. reportDepositTokenPageClick(objectType) {
  800. Report.log({
  801. pageSource: Report.pageSource.nftDepositTokenPage,
  802. params: {
  803. eventData: {
  804. objectType,
  805. businessType: Report.businessType.buttonClick,
  806. },
  807. extParams: {
  808. userAgent: window.navigator.userAgent,
  809. }
  810. }
  811. })
  812. },
  813. reportBalanceRefresh() {
  814. let pageSource = this.waitRefresh ? Report.pageSource.nftPaymentBalancePage : Report.pageSource.nftBalancePage;
  815. Report.log({
  816. pageSource: pageSource,
  817. params: {
  818. eventData: {
  819. objectType: Report.objectType.refreshBalanceButton,
  820. businessType: Report.businessType.buttonClick,
  821. },
  822. extParams: {
  823. userAgent: window.navigator.userAgent,
  824. }
  825. }
  826. })
  827. },
  828. reportBalanceBuy() {
  829. let pageSource = this.waitRefresh ? Report.pageSource.nftPaymentBalancePage : Report.pageSource.nftBalancePage;
  830. Report.log({
  831. pageSource: pageSource,
  832. params: {
  833. eventData: {
  834. objectType: Report.objectType.purchaseNftButton,
  835. businessType: Report.businessType.buttonClick,
  836. },
  837. extParams: {
  838. userAgent: window.navigator.userAgent,
  839. }
  840. }
  841. })
  842. },
  843. }
  844. }
  845. </script>
  846. <style lang="scss">
  847. html,
  848. body,
  849. #__nuxt,
  850. #__layout {
  851. width: 100%;
  852. height: 100%;
  853. padding: 0;
  854. margin: 0;
  855. overflow: hidden;
  856. }
  857. .payment {
  858. width: 100%;
  859. height: 100%;
  860. }
  861. .moneyInfo {
  862. display: flex;
  863. align-items: center;
  864. justify-content: center;
  865. flex-direction: column;
  866. height: 90px;
  867. border-bottom: solid 8px rgba($color: #f5f5f5, $alpha: .6);
  868. .tips {
  869. font-size: 12px;
  870. font-weight: 500;
  871. }
  872. .money {
  873. display: flex;
  874. align-items: center;
  875. justify-content: center;
  876. margin-top: 10px;
  877. color: #000;
  878. font-size: 20px;
  879. font-weight: 700;
  880. .icon {
  881. overflow: hidden;
  882. width: 26px;
  883. height: 26px;
  884. border-radius: 50%;
  885. margin-right: 10px;
  886. vertical-align: middle;
  887. background-color: #f5f5f5;
  888. }
  889. .info {
  890. &.usd {
  891. margin-top: -5px;
  892. }
  893. }
  894. }
  895. }
  896. .payList {
  897. overflow-y: auto;
  898. height: calc(100% - 90px);
  899. .detail {
  900. padding: 18px 16px;
  901. .title {
  902. color: #ADADAD;
  903. height: 26px;
  904. font-size: 12px;
  905. font-weight: 500;
  906. }
  907. .item {
  908. position: relative;
  909. display: flex;
  910. align-items: center;
  911. justify-content: center;
  912. font-weight: 500;
  913. font-size: 16px;
  914. height: 50px;
  915. margin-bottom: 14px;
  916. border-radius: 100px;
  917. border: 1px solid #ECECEC;
  918. &:last-child {
  919. margin-bottom: 0;
  920. }
  921. img {
  922. width: 24px;
  923. height: 24px;
  924. margin-right: 4px;
  925. }
  926. &.denet {
  927. flex-direction: column;
  928. img {
  929. margin-top: -6px;
  930. }
  931. }
  932. .wallet {
  933. width: 100%;
  934. overflow: hidden;
  935. color: #ADADAD;
  936. font-size: 11px;
  937. text-align: center;
  938. margin-top: -2px;
  939. }
  940. .maskLink {
  941. position: absolute;
  942. z-index: 10;
  943. width: 100%;
  944. height: 100%;
  945. }
  946. }
  947. }
  948. }
  949. .loading {
  950. position: absolute;
  951. z-index: 3;
  952. display: flex;
  953. align-items: center;
  954. justify-content: center;
  955. top: 0;
  956. left: 0;
  957. width: 100%;
  958. height: 100%;
  959. }
  960. .loadingBg {
  961. position: absolute;
  962. z-index: 2;
  963. top: 0;
  964. left: 0;
  965. width: 100%;
  966. height: 100%;
  967. background-color: rgba($color: #000, $alpha: .1);
  968. }
  969. .redeem {
  970. padding: 18px 16px 38px;
  971. .tips {
  972. height: 31px;
  973. font-size: 15px;
  974. font-weight: 500;
  975. }
  976. .footer {
  977. display: flex;
  978. justify-content: space-between;
  979. .input {
  980. display: flex;
  981. align-items: center;
  982. justify-content: center;
  983. width: calc(100% - 93px);
  984. height: 45px;
  985. border-radius: 5px;
  986. border: 1px solid #E0E0E0;
  987. input {
  988. width: 94%;
  989. border: 0;
  990. outline: 0;
  991. }
  992. }
  993. .enter {
  994. width: 83px;
  995. height: 45px;
  996. border: 0;
  997. padding: 0;
  998. color: #ffffff;
  999. font-size: 17px;
  1000. font-weight: 500;
  1001. border-radius: 5px;
  1002. background: #1D9BF0;
  1003. &.disable {
  1004. background: #DEDEDE;
  1005. }
  1006. }
  1007. }
  1008. }
  1009. .payInfo {
  1010. width: 100%;
  1011. height: calc(100% - 88px);
  1012. .picShow {
  1013. padding: 54px 48px;
  1014. .tip {
  1015. height: 44px;
  1016. font-size: 18px;
  1017. font-weight: 600;
  1018. text-align: center;
  1019. }
  1020. .pic {
  1021. display: block;
  1022. margin: auto;
  1023. width: 280px;
  1024. height: 280px;
  1025. border-radius: 3px;
  1026. margin-bottom: 20px;
  1027. }
  1028. .name {
  1029. font-size: 18px;
  1030. font-weight: 600;
  1031. line-height: 21px;
  1032. text-align: center;
  1033. }
  1034. }
  1035. }
  1036. .payBtn {
  1037. padding: 0 16px 38px;
  1038. .btn {
  1039. width: 100%;
  1040. height: 50px;
  1041. color: #FFFFFF;
  1042. font-size: 18px;
  1043. font-weight: 700;
  1044. border-radius: 50px;
  1045. background: #1D9BF0;
  1046. }
  1047. }
  1048. .balanceTop {
  1049. display: flex;
  1050. align-items: center;
  1051. justify-content: center;
  1052. flex-direction: column;
  1053. height: calc(100% - 100px);
  1054. background-color: #f5f5f5;
  1055. .balance {
  1056. width: 66px;
  1057. height: 66px;
  1058. margin-bottom: 6px;
  1059. }
  1060. .text {
  1061. font-size: 15px;
  1062. font-weight: 500;
  1063. line-height: 18px;
  1064. color: #9D9D9D;
  1065. }
  1066. .money {
  1067. font-size: 22px;
  1068. font-weight: 700;
  1069. line-height: 26px;
  1070. margin-top: 6px;
  1071. .icon {
  1072. width: 22px;
  1073. height: 22px;
  1074. margin-right: 6px;
  1075. }
  1076. .font {
  1077. color: #000;
  1078. }
  1079. }
  1080. }
  1081. .balanceInfo {
  1082. overflow-y: auto;
  1083. height: calc(100% - 100px);
  1084. background-color: #f5f5f5;
  1085. .top {
  1086. padding: 0 16px 17px 16px;
  1087. background-color: #ffffff;
  1088. .item {
  1089. display: flex;
  1090. align-items: center;
  1091. height: 54px;
  1092. border-bottom: solid 1px #F2F2F2;
  1093. &.title {
  1094. font-size: 16px;
  1095. font-weight: 600;
  1096. line-height: 19px;
  1097. img {
  1098. width: 26px;
  1099. height: 26px;
  1100. margin-right: 6px;
  1101. }
  1102. }
  1103. &.column {
  1104. color: rgba($color: #5E5E5E, $alpha: .7);
  1105. font-size: 14px;
  1106. font-weight: 400;
  1107. .l {
  1108. width: 70px;
  1109. }
  1110. .r {
  1111. img {
  1112. width: 21px;
  1113. height: 21px;
  1114. margin-right: 4px;
  1115. }
  1116. span {
  1117. color: rgba($color: #5E5E5E, $alpha: .7);
  1118. }
  1119. }
  1120. }
  1121. &.usd {
  1122. font-size: 14px;
  1123. font-weight: 500;
  1124. justify-content: space-between;
  1125. .fontPayment {
  1126. font-size: 18px;
  1127. font-weight: 600;
  1128. }
  1129. .font {
  1130. color: #9A9A9A;
  1131. font-size: 16px;
  1132. font-weight: 500;
  1133. }
  1134. .fontDeposit {
  1135. color: #1D9BF0;
  1136. font-size: 18px;
  1137. font-weight: 600;
  1138. }
  1139. }
  1140. }
  1141. .deposit {
  1142. display: flex;
  1143. align-items: center;
  1144. justify-content: center;
  1145. height: 54px;
  1146. color: #ffffff;
  1147. font-weight: 600;
  1148. font-size: 18px;
  1149. margin-top: 16px;
  1150. border-radius: 54px;
  1151. background: #1D9BF0;
  1152. }
  1153. .address {
  1154. color: rgba($color: #5E5E5E, $alpha: .7);
  1155. .title {
  1156. height: 42px;
  1157. font-size: 14px;
  1158. font-weight: 400;
  1159. line-height: 42px;
  1160. }
  1161. }
  1162. .notice {
  1163. display: flex;
  1164. justify-content: space-between;
  1165. padding: 10px;
  1166. margin-top: 12px;
  1167. border-radius: 8px;
  1168. background: #F9F6EE;
  1169. .icon {
  1170. width: 20px;
  1171. margin-right: 10px;
  1172. img {
  1173. width: 20px;
  1174. height: 20px;
  1175. }
  1176. }
  1177. .text {
  1178. flex: 1;
  1179. color: rgba($color: #5E5E5E, $alpha: .7);
  1180. font-size: 14px;
  1181. font-weight: 400;
  1182. line-height: 19px;
  1183. word-break: break-all;
  1184. strong {
  1185. color: #FF0000;
  1186. font-weight: bold;
  1187. }
  1188. }
  1189. }
  1190. }
  1191. .line {
  1192. height: 8px;
  1193. }
  1194. .balance {
  1195. display: flex;
  1196. align-items: center;
  1197. padding: 0 16px;
  1198. height: 54px;
  1199. background-color: #ffffff;
  1200. .icon {
  1201. width: 24px;
  1202. margin-right: 6px;
  1203. img {
  1204. width: 24px;
  1205. }
  1206. }
  1207. .text {
  1208. flex: 1;
  1209. font-size: 14px;
  1210. font-weight: 500;
  1211. line-height: 17px;
  1212. span {
  1213. color: #000;
  1214. margin-right: auto;
  1215. }
  1216. }
  1217. .refresh {
  1218. width: 24px;
  1219. height: 24px;
  1220. img {
  1221. width: 24px;
  1222. transform-origin: center center;
  1223. }
  1224. }
  1225. }
  1226. }
  1227. .balanceBot {
  1228. display: flex;
  1229. justify-content: space-between;
  1230. width: 100%;
  1231. padding: 17px 16px 38px;
  1232. border-top: solid 1px #ECECEC;
  1233. .l {
  1234. display: flex;
  1235. flex-direction: column;
  1236. justify-content: center;
  1237. }
  1238. .neet {
  1239. font-size: 12px;
  1240. font-weight: 500;
  1241. line-height: 14px;
  1242. }
  1243. .money {
  1244. height: 22px;
  1245. line-height: 22px;
  1246. font-size: 18px;
  1247. font-weight: 700;
  1248. margin-top: 4px;
  1249. .text {
  1250. margin-right: auto;
  1251. }
  1252. }
  1253. .btn {
  1254. display: flex;
  1255. align-items: center;
  1256. justify-content: center;
  1257. width: 110px;
  1258. height: 46px;
  1259. color: #ffffff;
  1260. font-size: 18px;
  1261. font-weight: 700;
  1262. line-height: 21px;
  1263. border-radius: 46px;
  1264. background: #1D9BF0;
  1265. &.disable {
  1266. background: #D2D2D2;
  1267. }
  1268. }
  1269. }
  1270. .waitFont {
  1271. margin-top: 16px;
  1272. padding: 0 20px;
  1273. font-size: 14px;
  1274. font-weight: 500;
  1275. line-height: 17px;
  1276. text-align: center;
  1277. }
  1278. .waitBtn {
  1279. display: flex;
  1280. align-items: center;
  1281. justify-content: center;
  1282. width: 50px;
  1283. height: 50px;
  1284. margin: 50px auto 0;
  1285. border-radius: 50%;
  1286. background-color: #ffffff;
  1287. img {
  1288. width: 24px;
  1289. height: 24px;
  1290. }
  1291. }
  1292. .icon-refresh-rotate {
  1293. transform: rotate(360deg);
  1294. transition-duration: 1s;
  1295. }
  1296. </style>