index.vue 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330
  1. <!-- eslint-disable vue/no-deprecated-filter -->
  2. <template>
  3. <div class="payment">
  4. <!-- 选择支付方式 -->
  5. <template v-if="step === 1">
  6. <div class="moneyInfo">
  7. <div class="tips">You Neet to Pay</div>
  8. <div class="money" v-if="salePlans">
  9. <FontZoom width="300" :unColor="true" v-if="salePlans && salePlans.price">
  10. <template v-if="salePlans && salePlans.currencyCode && salePlans.currencyCode !== 'USD'">
  11. <template v-if="salePlans.price.length + salePlans.currencyInfo.tokenSymbol.length >= 30">
  12. <div style="text-align: center">
  13. <div><img class="icon" :src="salePlans.currencyInfo.iconPath" /> {{ salePlans.price | floatPrice(4) }}</div>
  14. <div>{{ salePlans.currencyInfo.tokenSymbol }} (${{ salePlans.usdPrice | floatPrice(2) }})</div>
  15. </div>
  16. </template>
  17. <template v-else> <img class="icon" :src="salePlans.currencyInfo.iconPath" /> {{ salePlans.price | floatPrice(4) }} {{ salePlans.currencyInfo.tokenSymbol }} (${{ salePlans.usdPrice | floatPrice(2) }}) </template>
  18. </template>
  19. <template v-else>
  20. <span class="info usd">${{ salePlans.usdPrice | floatPrice(2) }}</span>
  21. </template>
  22. </FontZoom>
  23. </div>
  24. </div>
  25. <div class="payList">
  26. <div class="detail" v-if="salePlans && salePlans.currencyCode && salePlans.currencyCode !== 'USD'">
  27. <div class="title">Crypto Wallet</div>
  28. <div class="item denet" @click="deNetPay">
  29. <div>
  30. <img src="../../static/payment/icon_wallet.png" />
  31. <span>DeNet Pay</span>
  32. </div>
  33. <div class="wallet">
  34. <FontZoom width="300" :unColor="true"> Balance:{{ currencyInfoData.balance | floatPrice(4) }} {{ currencyInfoData.tokenSymbol }} </FontZoom>
  35. </div>
  36. </div>
  37. <div v-if="ifShowMetaMask" class="item" @click="maskPay">
  38. <a class="maskLink" :href="maskUrlLink" v-if="Number(usdAmountData.rechargeAmountValue) > 0"></a>
  39. <img src="../../static/payment/icon_meta_mask.png" />
  40. <span>MetaMask</span>
  41. </div>
  42. </div>
  43. <div class="detail" v-if="salePlans && salePlans.currencyCode && salePlans.currencyCode === 'USD'">
  44. <div class="title">Credit/Debit Card</div>
  45. <div class="item denet" @click="deNetPay">
  46. <div>
  47. <img src="../../static/payment/icon_wallet.png" />
  48. <span>DeNet Pay</span>
  49. </div>
  50. <div class="wallet">Balance:{{ currencyInfoData.balance | floatPrice(2) }} {{ currencyInfoData.tokenSymbol }}</div>
  51. </div>
  52. <div v-if="ifShowAch" class="item" @click="achPay(true, Report.objectType.mastercardPayButton)">
  53. <img src="../../static/payment/icon_master_card.png" />
  54. <span>MasterCard</span>
  55. </div>
  56. <div v-if="ifShowAch" class="item" @click="achPay(true, Report.objectType.visaPayButton)">
  57. <img src="../../static/payment/icon_visa.png" />
  58. <span>VISA</span>
  59. </div>
  60. </div>
  61. <div class="detail">
  62. <div class="title">Redemption Code</div>
  63. <div class="item" @click="showRedeem">
  64. <img src="../../static/payment/icon_enter_code.png" />
  65. <span>Enter Code</span>
  66. </div>
  67. </div>
  68. </div>
  69. </template>
  70. <!-- 余额足够 -->
  71. <template v-else-if="step === 2">
  72. <div class="balanceTop">
  73. <img class="balance" src="../../static/img/icon_balance.svg" />
  74. <div class="text">Balance</div>
  75. <div class="money">
  76. <FontZoom width="300" :unColor="true">
  77. <template v-if="salePlans.currencyCode === 'USD'"> <img class="icon" :src="currencyInfoData.iconPath" /> {{ currencyInfoData.balance | floatPrice(2) }} {{ currencyInfoData.tokenSymbol }} </template>
  78. <template v-else> <img class="icon" :src="currencyInfoData.iconPath" /> {{ currencyInfoData.balance | floatPrice(4) }} {{ currencyInfoData.tokenSymbol }} </template>
  79. </FontZoom>
  80. </div>
  81. <template v-if="waitRefresh">
  82. <div class="waitFont">It may take some time to credit the funds into your account.</div>
  83. <div @click="checkWaitInfo" class="waitBtn">
  84. <img :class="{ 'icon-refresh-rotate': refreshRotate }" src="../../static/img/icon_refresh.svg" />
  85. </div>
  86. </template>
  87. </div>
  88. <div class="balanceBot">
  89. <div class="l">
  90. <div class="neet">You Neet to Pay</div>
  91. <div class="money">
  92. <FontZoom width="190" :unColor="true">
  93. <span class="text">
  94. <template v-if="salePlans.currencyCode === 'USD'"> {{ salePlans.price | floatPrice(2) }} {{ salePlans.currencyInfo.tokenSymbol }} </template>
  95. <template v-else> {{ salePlans.price | floatPrice(4) }} {{ salePlans.currencyInfo.tokenSymbol }} </template>
  96. </span>
  97. </FontZoom>
  98. </div>
  99. </div>
  100. <div>
  101. <div class="btn" :class="{ disable: Number(usdAmountData.rechargeAmountValue) > 0 || payDisabled }" @click="pay">Pay Now</div>
  102. </div>
  103. </div>
  104. </template>
  105. <!-- 余额不足 -->
  106. <template v-else-if="step === 3">
  107. <template v-if="salePlans && salePlans.currencyCode && salePlans.currencyCode !== 'USD'">
  108. <div class="balanceInfo">
  109. <div class="top">
  110. <div class="item title">
  111. <img src="../../static/img/icon_deposit.png" />
  112. <span>Deposit to Buy</span>
  113. </div>
  114. <div class="item column">
  115. <div class="l">Deposit</div>
  116. <div class="r">
  117. <FontZoom width="260" :unColor="true">
  118. <img :src="currencyInfoData.iconPath" />
  119. <span
  120. ><span v-if="Number(usdAmountData.rechargeAmountValue) > 0">{{ usdAmountData.rechargeAmountValue | floatPrice(4) }} </span>{{ currencyInfoData.tokenSymbol }}</span
  121. >
  122. </FontZoom>
  123. </div>
  124. </div>
  125. <div class="item column">
  126. <div class="l">Network</div>
  127. <div class="r">
  128. <FontZoom width="260" :unColor="true">
  129. <img :src="currencyInfoData.chainInfo.iconPath" />
  130. <span>{{ currencyInfoData.chainInfo.chainName }}</span>
  131. </FontZoom>
  132. </div>
  133. </div>
  134. <div class="address">
  135. <div class="title">Address</div>
  136. <QrCode :tokenChain="currencyInfoData.tokenChain" :rechargeAddress="rechargeAddress" @copy="copyErCode"></QrCode>
  137. </div>
  138. <div class="notice">
  139. <div class="icon"><img src="../../static/img/icon_warning.svg" /></div>
  140. <div class="text">
  141. 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.
  142. </div>
  143. </div>
  144. </div>
  145. <div class="line"></div>
  146. <div class="balance">
  147. <div class="icon">
  148. <img src="../../static/img/icon_balance_blue.svg" />
  149. </div>
  150. <div class="text">
  151. <FontZoom width="260" :unColor="true">
  152. <span>Balance: {{ currencyInfoData.balance | floatPrice(4) }} {{ currencyInfoData.tokenSymbol }}</span>
  153. </FontZoom>
  154. </div>
  155. <div class="refresh" @click="checkCurrencyInfo">
  156. <img :class="{ 'icon-refresh-rotate': refreshRotate }" src="../../static/img/icon_refresh.svg" />
  157. </div>
  158. </div>
  159. </div>
  160. <div class="balanceBot">
  161. <div class="l">
  162. <div class="neet">You Neet to Pay</div>
  163. <div class="money">
  164. <FontZoomMobile width="220" :unColor="true"> {{ salePlans.price | floatPrice(4) }} {{ salePlans.currencyInfo.tokenSymbol }} </FontZoomMobile>
  165. </div>
  166. </div>
  167. <div>
  168. <div class="btn" :class="{ disable: Number(usdAmountData.rechargeAmountValue) > 0 || payDisabled }" @click="payToken">Pay Now</div>
  169. </div>
  170. </div>
  171. </template>
  172. <template v-if="salePlans && salePlans.currencyCode && salePlans.currencyCode === 'USD'">
  173. <div class="balanceInfo">
  174. <div class="top">
  175. <div class="item usd">
  176. <div class="l">Payment amount</div>
  177. <div class="r fontPayment">${{ usdAmountData.orderAmountValue | floatPrice(2) }}</div>
  178. </div>
  179. <div class="item usd">
  180. <div class="l">Balance</div>
  181. <div class="r font">${{ usdAmountData.balance | floatPrice(2) }}</div>
  182. </div>
  183. <div class="item usd" v-if="Number(usdAmountData.rechargeAmountValue) > 0">
  184. <div class="l">{{ usdAmountData.feeDesc }}</div>
  185. <div class="r font">${{ usdAmountData.feeAmountValue | floatPrice(2) }}</div>
  186. </div>
  187. <div class="item usd" v-if="Number(usdAmountData.rechargeAmountValue) > 0">
  188. <div class="l">Deposit Amount</div>
  189. <div class="r fontDeposit">${{ usdAmountData.rechargeAmountValue }}</div>
  190. </div>
  191. <div class="deposit" @click="achPay(false, '')">Deposit</div>
  192. </div>
  193. <div class="line"></div>
  194. <div class="balance">
  195. <div class="icon">
  196. <img src="../../static/img/icon_balance_blue.svg" />
  197. </div>
  198. <div class="text">Balance: ${{ currencyInfoData.balance | floatPrice(2) }}</div>
  199. <div class="refresh" @click="checkUsdCurrencyInfo">
  200. <img :class="{ 'icon-refresh-rotate': refreshRotate }" src="../../static/img/icon_refresh.svg" />
  201. </div>
  202. </div>
  203. </div>
  204. <div class="balanceBot">
  205. <div class="l">
  206. <div class="neet">You Neet to Pay</div>
  207. <div class="money">
  208. <FontZoomMobile width="220" :unColor="true"> {{ Number(usdAmountData.rechargeAmountValue) > 0 ? usdAmountData.rechargeAmountValue : usdAmountData.orderAmountValue }} {{ salePlans.currencyInfo.tokenSymbol }} </FontZoomMobile>
  209. </div>
  210. </div>
  211. <div>
  212. <div class="btn" :class="{ disable: Number(usdAmountData.rechargeAmountValue) > 0 || payDisabled }" @click="payUSD">Pay Now</div>
  213. </div>
  214. </div>
  215. </template>
  216. </template>
  217. <!-- 成功支付 -->
  218. <template v-else-if="step === 4">
  219. <div class="payInfo">
  220. <div class="picShow" v-if="buyData">
  221. <div class="tip">Wow, NFT in the Mystery box is</div>
  222. <img class="pic" :src="buyData.imagePath" />
  223. <div class="name">{{ buyData.nftItemName }}</div>
  224. </div>
  225. </div>
  226. <div class="payBtn">
  227. <button class="btn" @click="goNext">Done</button>
  228. </div>
  229. </template>
  230. <!-- loading -->
  231. <div class="loading" v-if="loading">
  232. <van-loading color="#1D9BF0"></van-loading>
  233. </div>
  234. <div class="loadingBg" v-if="loading"></div>
  235. <!-- redeem -->
  236. <van-popup round v-model="redeemLayer" position="bottom">
  237. <div class="redeem">
  238. <div class="tips">Enter Redemption Code</div>
  239. <div class="footer">
  240. <div class="input">
  241. <input type="text" ref="input" v-model="redeemStr" @input="textInput" @blur="textBlur" @focus="textFocus" @keydown.enter="redeemPayment" />
  242. </div>
  243. <button class="enter" :class="{ disable: !redeemNext }" @click="redeemPayment">Redeem</button>
  244. </div>
  245. </div>
  246. </van-popup>
  247. </div>
  248. </template>
  249. <script>
  250. import FontZoom from '../../components/FontZoom.vue';
  251. import FontZoomMobile from '../../components/FontZoomMobile.vue';
  252. import QrCode from '../../components/qrcode.vue';
  253. import { postRequest } from '../../http/index';
  254. import { maskUrl, setStorage, storageKey, OSDetect } from '../../utils/help';
  255. import { Dialog } from 'vant';
  256. import Api from '../../http/api';
  257. import Report from '../../log-center/log';
  258. export default {
  259. name: 'payment',
  260. data() {
  261. return {
  262. step: 1, // 1: 支付方式列表 2: 余额支付 3: 充值支付 4: 支付完成
  263. loading: true,
  264. salePlans: null,
  265. rechargeAddress: '',
  266. redeemStr: '',
  267. redeemNext: false,
  268. redeemLayer: false,
  269. buyData: {},
  270. payDisabled: false,
  271. waitRefresh: false,
  272. refreshRotate: false,
  273. currencyInfoData: {},
  274. currencyTimer: 0,
  275. achTimer: 0,
  276. maskUrlLink: ``,
  277. usdAmountData: {},
  278. Report: Report,
  279. ifShowMetaMask: false,
  280. ifShowAch: false,
  281. };
  282. },
  283. head() {
  284. return {
  285. title: 'Buy NFT Mystery Box',
  286. };
  287. },
  288. components: {
  289. QrCode,
  290. FontZoom,
  291. FontZoomMobile,
  292. },
  293. mounted() {
  294. this.saleInfo();
  295. this.showMetaMask();
  296. this.reportView(Report.pageSource.nftPaymentPage);
  297. },
  298. beforeUnmount() {
  299. clearTimeout(this.currencyTimer);
  300. },
  301. filters: {
  302. floatPrice(price, num) {
  303. if (!price) return;
  304. if (price.indexOf('.') >= 0) {
  305. let reg = new RegExp(`^\\D*(\\d*(?:\\.\\d{0,${num}})?).*$`, 'g');
  306. price = price.replace(reg, '$1');
  307. }
  308. return price;
  309. },
  310. },
  311. methods: {
  312. saleInfo() {
  313. postRequest(Api.getNftMysteryBoxSaleInfo, {
  314. params: {
  315. nftProjectId: this.$route.query.nftProjectId,
  316. },
  317. })
  318. .then((res) => {
  319. let { code, data } = res;
  320. if (code === 0) {
  321. this.salePlans = data.salePlans[0];
  322. this.getCurrencyInfoByCode();
  323. // 获取充值地址
  324. if (this.rechargeAddress === '') {
  325. this.getAddress();
  326. }
  327. }
  328. })
  329. .finally(() => {
  330. setTimeout(() => {
  331. this.loading = false;
  332. }, 600);
  333. });
  334. },
  335. showMetaMask() {
  336. if (OSDetect() === 'ios') {
  337. this.ifShowMetaMask = true;
  338. }
  339. },
  340. getCurrencyInfoByCode() {
  341. let where = this.salePlans && this.salePlans.currencyCode;
  342. if (!where) return;
  343. postRequest(Api.getCurrencyInfoByCode, {
  344. params: {
  345. currencyCode: this.salePlans.currencyCode,
  346. },
  347. }).then((res) => {
  348. let { code, data } = res;
  349. if (code === 0) {
  350. this.currencyInfoData = data;
  351. }
  352. });
  353. // 计算金额
  354. postRequest(Api.calcRechargePayAmount, {
  355. params: {
  356. currencyCode: this.salePlans.currencyCode,
  357. orderAmountValue: this.salePlans.price,
  358. payChannel: 'ach',
  359. },
  360. }).then((res) => {
  361. let { code, data } = res;
  362. if (code === 0) {
  363. this.usdAmountData = data;
  364. }
  365. });
  366. },
  367. getTokenRechargeRecord() {
  368. postRequest(Api.syncChainTokenRechargeRecord, {
  369. params: {
  370. currencyCode: this.salePlans.currencyCode,
  371. },
  372. }).then((res) => {
  373. let { code, data } = res;
  374. if (code === 0) {
  375. if (data.length > 0) {
  376. let currencyInfo = data[0];
  377. if (currencyInfo.currencyCode == this.currencyInfoData.currencyCode) {
  378. this.currencyInfoData.balance = currencyInfo.balance;
  379. }
  380. } else {
  381. this.currencyInfoData.balance = 0;
  382. }
  383. }
  384. });
  385. },
  386. currencyInfoTimer() {
  387. clearTimeout(this.currencyTimer);
  388. this.currencyTimer = setTimeout(() => {
  389. this.currencyInfoTimer();
  390. this.getCurrencyInfoByCode();
  391. }, 10000);
  392. },
  393. checkUsdCurrencyInfo() {
  394. if (!this.refreshRotate) {
  395. this.refreshRotate = true;
  396. this.getCurrencyInfoByCode();
  397. setTimeout(() => {
  398. this.refreshRotate = false;
  399. }, 1000);
  400. // report
  401. this.reportDepositCashPageClick(Report.objectType.refreshBalanceButton);
  402. }
  403. },
  404. checkCurrencyInfo() {
  405. if (!this.refreshRotate) {
  406. this.refreshRotate = true;
  407. this.getTokenRechargeRecord();
  408. setTimeout(() => {
  409. this.refreshRotate = false;
  410. }, 1000);
  411. // report
  412. this.reportDepositTokenPageClick(Report.objectType.refreshBalanceButton);
  413. }
  414. },
  415. checkWaitInfo(isReport = true) {
  416. if (!this.refreshRotate) {
  417. this.refreshRotate = true;
  418. this.getCurrencyInfoByCode();
  419. setTimeout(() => {
  420. this.refreshRotate = false;
  421. }, 1000);
  422. }
  423. if (isReport) {
  424. this.reportBalanceRefresh();
  425. }
  426. },
  427. showRedeem() {
  428. this.redeemStr = '';
  429. this.redeemNext = false;
  430. this.redeemLayer = true;
  431. this.$nextTick(() => {
  432. this.$refs.input.focus();
  433. });
  434. this.reportView(Report.pageSource.nftRedeemPage);
  435. this.reportPaymentBtnClick(Report.objectType.redeemButton);
  436. },
  437. textInput() {
  438. let len = 16;
  439. let str = this.redeemStr.replace(/[^a-zA-Z0-9]/g, '');
  440. str = str.toUpperCase();
  441. str = str.slice(0, len);
  442. // set
  443. this.redeemStr = str;
  444. this.redeemNext = str !== '' && str.length === len;
  445. },
  446. textBlur() {
  447. let isiOS = !!window.navigator.userAgent.match(/\(i\[^;]+;( U;)? CPU.+Mac OS X/);
  448. if (isiOS) {
  449. setTimeout(() => {
  450. const scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0;
  451. window.scrollTo(0, Math.max(scrollHeight - 1, 0));
  452. }, 100);
  453. }
  454. },
  455. textFocus() {
  456. let isiOS = !!window.navigator.userAgent.match(/\(i\[^;]+;( U;)? CPU.+Mac OS X/);
  457. if (isiOS) {
  458. setTimeout(() => {
  459. const scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0;
  460. window.scrollTo(0, Math.max(scrollHeight - 1, 0));
  461. }, 100);
  462. }
  463. },
  464. redeemPayment() {
  465. if (!this.redeemNext) return;
  466. let params = {
  467. redeemCode: this.redeemStr,
  468. nftProjectId: this.$route.query.nftProjectId,
  469. };
  470. this.redeemNext = false;
  471. postRequest(Api.redeemNft, {
  472. params,
  473. })
  474. .then((res) => {
  475. let { code, data } = res;
  476. if (code === 0) {
  477. this.redeemLayer = false;
  478. if (data.length > 0) {
  479. this.buyData = data[0];
  480. }
  481. // 购买成功
  482. this.step = 4;
  483. this.reportSuccessView();
  484. } else {
  485. this.payError(code);
  486. }
  487. })
  488. .finally(() => {
  489. this.redeemNext = true;
  490. });
  491. this.reportRedeemBtnClick();
  492. },
  493. getAddress() {
  494. let where = this.salePlans && this.salePlans.currencyInfo && this.salePlans.currencyInfo.tokenChain;
  495. if (!where) return;
  496. postRequest(Api.getTokenRechargeAddress, {
  497. params: {
  498. tokenChain: this.salePlans.currencyInfo?.tokenChain,
  499. },
  500. }).then((res) => {
  501. let { code, data } = res;
  502. if (code === 0) {
  503. this.rechargeAddress = data.rechargeAddress;
  504. this.maskUrlToLink();
  505. }
  506. });
  507. },
  508. maskUrlToLink() {
  509. // MetaMask Link
  510. let url;
  511. let price = this.usdAmountData.rechargeAmountValue;
  512. if (this.salePlans.currencyInfo?.contractAddress) {
  513. // 代币
  514. url = maskUrl(
  515. {
  516. target_address: this.salePlans.currencyInfo.contractAddress,
  517. parameters: {
  518. address: this.rechargeAddress,
  519. uint256: `${price}e${this.salePlans.currencyInfo?.decimalLength || 18}`,
  520. },
  521. },
  522. false
  523. );
  524. } else {
  525. // 主币
  526. url = maskUrl({
  527. target_address: this.rechargeAddress,
  528. parameters: {
  529. value: `${price}e${this.salePlans.currencyInfo?.decimalLength || 18}`,
  530. },
  531. });
  532. }
  533. this.maskUrlLink = url;
  534. },
  535. goNext() {
  536. this.reportSuccessClick();
  537. setTimeout(() => {
  538. this.$router.push({
  539. path: `/nft/${this.$route.query.nftProjectId}/${this.$route.query.account}/show`,
  540. });
  541. }, 300);
  542. },
  543. pay(isReport = true) {
  544. if (this.payDisabled || Number(this.usdAmountData.rechargeAmountValue) > 0) return;
  545. this.payDisabled = true;
  546. postRequest(Api.payNftMysteryBoxWithBalance, {
  547. params: {
  548. nftProjectId: this.$route.query.nftProjectId,
  549. salePlanId: this.salePlans.salePlanId,
  550. },
  551. })
  552. .then((res) => {
  553. let { code, data } = res;
  554. if (code == 0) {
  555. if (data && data.buyItems.length > 0) {
  556. this.buyData = data.buyItems[0];
  557. }
  558. // 购买成功
  559. this.step = 4;
  560. this.reportSuccessView();
  561. } else {
  562. this.payError(code);
  563. }
  564. })
  565. .finally(() => {
  566. this.payDisabled = false;
  567. });
  568. // report
  569. if (isReport) {
  570. this.reportBalanceBuy();
  571. }
  572. },
  573. payUSD() {
  574. if (Number(this.usdAmountData.rechargeAmountValue) <= 0) {
  575. this.pay(false);
  576. this.reportDepositCashPageClick(Report.objectType.purchaseNftButton);
  577. }
  578. },
  579. payToken() {
  580. if (Number(this.currencyInfoData.balance) >= Number(this.salePlans.price)) {
  581. this.pay(false);
  582. this.reportDepositTokenPageClick(Report.objectType.purchaseNftButton);
  583. }
  584. },
  585. payError(code) {
  586. let msg;
  587. switch (code.toString()) {
  588. case '5001':
  589. msg = 'nft project not exist';
  590. break;
  591. case '5002':
  592. msg = 'nft project not available';
  593. break;
  594. case '5101':
  595. msg = 'nft sale plan not exist';
  596. break;
  597. case '5102':
  598. msg = 'nft sold out';
  599. break;
  600. case '5103':
  601. msg = 'Purchase limit reached';
  602. break;
  603. case '5104':
  604. case '5105':
  605. case '5106':
  606. msg = 'Invalid redemption code';
  607. break;
  608. default:
  609. msg = 'Payment failed, please try again';
  610. break;
  611. }
  612. // Dialog
  613. Dialog({
  614. message: msg,
  615. confirmButtonText: 'OK',
  616. confirmButtonColor: '#1D9BF0',
  617. });
  618. },
  619. deNetPay() {
  620. if (!this.salePlans) return;
  621. let pageSource;
  622. if (this.salePlans.currencyCode === 'USD') {
  623. pageSource = Report.pageSource.nftDepositCashPage;
  624. } else {
  625. pageSource = Report.pageSource.nftDepositTokenPage;
  626. }
  627. if (Number(this.usdAmountData.rechargeAmountValue) > 0) {
  628. // 余额不够
  629. this.step = 3;
  630. this.currencyInfoTimer();
  631. // Report
  632. this.reportView(pageSource);
  633. } else {
  634. // 余额足够
  635. this.step = 2;
  636. this.reportView(Report.pageSource.nftBalancePage);
  637. }
  638. this.reportPaymentBtnClick(Report.objectType.denetPayButton);
  639. },
  640. maskPay() {
  641. if (Number(this.usdAmountData.rechargeAmountValue) > 0) {
  642. this.step = 2;
  643. this.waitRefresh = true;
  644. this.currencyInfoTimer();
  645. Dialog({
  646. message: `Was the pament successful?`,
  647. showCancelButton: true,
  648. confirmButtonText: 'YES',
  649. confirmButtonColor: '#1D9BF0',
  650. cancelButtonText: 'NO',
  651. cancelButtonColor: '#1D9BF0',
  652. })
  653. .then(() => {
  654. this.checkWaitInfo(false);
  655. })
  656. .catch(() => {
  657. this.checkWaitInfo(false);
  658. });
  659. this.reportView(Report.pageSource.nftPaymentBalancePage);
  660. } else {
  661. this.step = 2;
  662. this.reportView(Report.pageSource.nftBalancePage);
  663. }
  664. this.reportPaymentBtnClick(Report.objectType.metamaskPayButton);
  665. },
  666. achPay(modifyStep = true, objectType = '') {
  667. if (Number(this.usdAmountData.rechargeAmountValue) > 0) {
  668. if (modifyStep) {
  669. this.step = 2;
  670. this.reportView(Report.pageSource.nftPaymentBalancePage);
  671. }
  672. this.waitRefresh = true;
  673. this.currencyInfoTimer();
  674. Dialog({
  675. message: `Was the pament successful?`,
  676. showCancelButton: true,
  677. confirmButtonText: 'YES',
  678. confirmButtonColor: '#1D9BF0',
  679. cancelButtonText: 'NO',
  680. cancelButtonColor: '#1D9BF0',
  681. })
  682. .then(() => {
  683. this.checkWaitInfo(false);
  684. })
  685. .catch(() => {
  686. this.checkWaitInfo(false);
  687. });
  688. // setUrl
  689. setStorage(storageKey.paymentUrl, window.location.href);
  690. this.$nextTick(() => {
  691. let win = window.open();
  692. win.opener = null;
  693. win.location.href = `${location.protocol}//${location.host}/payment_ach/${this.usdAmountData.rechargeAmountValue}`;
  694. this.achTimer = setInterval(() => {
  695. console.log('pay');
  696. if (win && win.closed) {
  697. console.log('done');
  698. clearInterval(this.achTimer);
  699. }
  700. }, 500);
  701. });
  702. } else {
  703. if (modifyStep) {
  704. this.step = 2;
  705. this.reportView(Report.pageSource.nftBalancePage);
  706. }
  707. }
  708. if (objectType !== '') {
  709. this.reportPaymentBtnClick(objectType);
  710. } else {
  711. this.reportDepositCashPageClick(Report.objectType.depositButtion);
  712. }
  713. },
  714. copyErCode() {
  715. this.reportDepositTokenPageClick(Report.objectType.copyButtion);
  716. },
  717. reportView(pageSource) {
  718. Report.log({
  719. pageSource,
  720. params: {
  721. eventData: {
  722. businessType: Report.businessType.pageView,
  723. },
  724. extParams: {
  725. userAgent: window.navigator.userAgent,
  726. },
  727. },
  728. });
  729. },
  730. reportPaymentBtnClick(objectType) {
  731. Report.log({
  732. pageSource: Report.pageSource.nftPaymentPage,
  733. params: {
  734. eventData: {
  735. objectType,
  736. businessType: Report.businessType.buttonClick,
  737. },
  738. extParams: {
  739. userAgent: window.navigator.userAgent,
  740. },
  741. },
  742. });
  743. },
  744. reportRedeemBtnClick() {
  745. Report.log({
  746. pageSource: Report.pageSource.nftRedeemPage,
  747. params: {
  748. eventData: {
  749. objectType: Report.objectType.redeemButton,
  750. businessType: Report.businessType.buttonClick,
  751. },
  752. extParams: {
  753. userAgent: window.navigator.userAgent,
  754. },
  755. },
  756. });
  757. },
  758. reportDepositCashPageClick(objectType) {
  759. Report.log({
  760. pageSource: Report.pageSource.nftDepositCashPage,
  761. params: {
  762. eventData: {
  763. objectType,
  764. businessType: Report.businessType.buttonClick,
  765. },
  766. extParams: {
  767. userAgent: window.navigator.userAgent,
  768. },
  769. },
  770. });
  771. },
  772. reportDepositTokenPageClick(objectType) {
  773. Report.log({
  774. pageSource: Report.pageSource.nftDepositTokenPage,
  775. params: {
  776. eventData: {
  777. objectType,
  778. businessType: Report.businessType.buttonClick,
  779. },
  780. extParams: {
  781. userAgent: window.navigator.userAgent,
  782. },
  783. },
  784. });
  785. },
  786. reportBalanceRefresh() {
  787. let pageSource = this.waitRefresh ? Report.pageSource.nftPaymentBalancePage : Report.pageSource.nftBalancePage;
  788. Report.log({
  789. pageSource: pageSource,
  790. params: {
  791. eventData: {
  792. objectType: Report.objectType.refreshBalanceButton,
  793. businessType: Report.businessType.buttonClick,
  794. },
  795. extParams: {
  796. userAgent: window.navigator.userAgent,
  797. },
  798. },
  799. });
  800. },
  801. reportBalanceBuy() {
  802. let pageSource = this.waitRefresh ? Report.pageSource.nftPaymentBalancePage : Report.pageSource.nftBalancePage;
  803. Report.log({
  804. pageSource: pageSource,
  805. params: {
  806. eventData: {
  807. objectType: Report.objectType.purchaseNftButton,
  808. businessType: Report.businessType.buttonClick,
  809. },
  810. extParams: {
  811. userAgent: window.navigator.userAgent,
  812. },
  813. },
  814. });
  815. },
  816. reportSuccessView() {
  817. Report.log({
  818. pageSource: Report.pageSource.nftPurchaseSuccessPage,
  819. params: {
  820. eventData: {
  821. businessType: Report.businessType.pageView,
  822. },
  823. extParams: {
  824. userAgent: window.navigator.userAgent,
  825. },
  826. },
  827. });
  828. },
  829. reportSuccessClick() {
  830. Report.log({
  831. pageSource: Report.pageSource.nftPurchaseSuccessPage,
  832. params: {
  833. eventData: {
  834. businessType: Report.businessType.buttonClick,
  835. objectType: Report.objectType.finishPurchaseButton,
  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: 0.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: 0.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: 0.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: 0.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: 0.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: 0.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>