index.vue 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326
  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">
  135. <div class="l">Deposit</div>
  136. <div class="r">
  137. <FontZoom width="260" :unColor="true">
  138. <img :src="currencyInfoData.iconPath" />
  139. <span><span v-if="Number(usdAmountData.rechargeAmountValue) > 0">{{ usdAmountData.rechargeAmountValue | floatPrice(4) }} </span>{{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. this.getCurrencyInfoByCode();
  458. setTimeout(() => {
  459. this.refreshRotate = false;
  460. }, 1000)
  461. }
  462. if (isReport) {
  463. this.reportBalanceRefresh()
  464. }
  465. },
  466. showRedeem() {
  467. this.redeemStr = '';
  468. this.redeemNext = false;
  469. this.redeemLayer = true;
  470. this.$nextTick(() => {
  471. this.$refs.input.focus();
  472. })
  473. this.reportView(Report.pageSource.nftRedeemPage)
  474. this.reportPaymentBtnClick(Report.objectType.redeemButton)
  475. },
  476. textInput(e) {
  477. let len = 16
  478. let str = this.redeemStr.replace(/[^a-zA-Z0-9]/g, '')
  479. str = str.toUpperCase();
  480. str = str.slice(0, len);
  481. // set
  482. this.redeemStr = str;
  483. this.redeemNext = str !== '' && str.length === len;
  484. },
  485. textBlur(e) {
  486. let isiOS = !!window.navigator.userAgent.match(/\(i\[^;]+;( U;)? CPU.+Mac OS X/)
  487. if (isiOS) {
  488. setTimeout(() => {
  489. const scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0
  490. window.scrollTo(0, Math.max(scrollHeight - 1, 0))
  491. }, 100)
  492. }
  493. },
  494. textFocus(e) {
  495. let isiOS = !!window.navigator.userAgent.match(/\(i\[^;]+;( U;)? CPU.+Mac OS X/)
  496. if (isiOS) {
  497. setTimeout(() => {
  498. const scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0
  499. window.scrollTo(0, Math.max(scrollHeight - 1, 0))
  500. }, 100)
  501. }
  502. },
  503. redeemPayment() {
  504. if (!this.redeemNext) return;
  505. let params = {
  506. redeemCode: this.redeemStr,
  507. nftProjectId: this.$route.query.nftProjectId,
  508. }
  509. this.redeemNext = false;
  510. postRequest(Api.redeemNft, {
  511. params
  512. }).then(res => {
  513. let { code, data } = res;
  514. if (code === 0) {
  515. this.redeemLayer = false;
  516. if (data.length > 0) {
  517. this.buyData = data[0];
  518. }
  519. // 购买成功
  520. this.step = 4;
  521. } else {
  522. this.payError(code)
  523. }
  524. }).finally(() => {
  525. this.redeemNext = true;
  526. })
  527. this.reportRedeemBtnClick()
  528. },
  529. getAddress() {
  530. let where = this.salePlans && this.salePlans.currencyInfo && this.salePlans.currencyInfo.tokenChain;
  531. if (!where) return;
  532. postRequest(Api.getTokenRechargeAddress, {
  533. params: {
  534. tokenChain: this.salePlans.currencyInfo?.tokenChain
  535. }
  536. }).then(res => {
  537. let { code, data } = res;
  538. if (code === 0) {
  539. this.rechargeAddress = data.rechargeAddress
  540. this.maskUrlToLink()
  541. }
  542. })
  543. },
  544. maskUrlToLink() {
  545. // MetaMask Link
  546. let url;
  547. let price = this.usdAmountData.rechargeAmountValue;
  548. if (this.salePlans.currencyInfo?.contractAddress) {
  549. // 代币
  550. url = maskUrl({
  551. target_address: this.salePlans.currencyInfo.contractAddress,
  552. parameters: {
  553. address: this.rechargeAddress,
  554. uint256: `${price}e${this.salePlans.currencyInfo?.decimalLength || 18}`
  555. }
  556. }, false)
  557. } else {
  558. // 主币
  559. url = maskUrl({
  560. target_address: this.rechargeAddress,
  561. parameters: {
  562. value: `${price}e${this.salePlans.currencyInfo?.decimalLength || 18}`
  563. }
  564. })
  565. }
  566. this.maskUrlLink = url;
  567. },
  568. goNext() {
  569. this.$router.push({
  570. path: `/nft/${this.$route.query.nftProjectId}/${this.$route.query.account}/show`,
  571. })
  572. },
  573. pay(isReport = true) {
  574. if (this.payDisabled || Number(this.usdAmountData.rechargeAmountValue) > 0) return;
  575. this.payDisabled = true;
  576. postRequest(Api.payNftMysteryBoxWithBalance, {
  577. params: {
  578. nftProjectId: this.$route.query.nftProjectId,
  579. salePlanId: this.salePlans.salePlanId,
  580. }
  581. }).then(res => {
  582. let { code, data } = res;
  583. if (code == 0) {
  584. if (data && data.buyItems.length > 0) {
  585. this.buyData = data.buyItems[0];
  586. }
  587. // 购买成功
  588. this.step = 4;
  589. } else {
  590. this.payError(code)
  591. }
  592. }).finally(() => {
  593. this.payDisabled = false;
  594. })
  595. // report
  596. if (isReport) {
  597. this.reportBalanceBuy()
  598. }
  599. },
  600. payUSD() {
  601. if (Number(this.usdAmountData.rechargeAmountValue) <= 0) {
  602. this.pay(false)
  603. this.reportDepositCashPageClick(Report.objectType.purchaseNftButton)
  604. }
  605. },
  606. payToken() {
  607. if (Number(this.currencyInfoData.balance) >= Number(this.salePlans.price)) {
  608. this.pay(false)
  609. this.reportDepositTokenPageClick(Report.objectType.purchaseNftButton)
  610. }
  611. },
  612. payError(code) {
  613. let msg;
  614. switch (code.toString()) {
  615. case '5001':
  616. msg = 'nft project not exist'
  617. break;
  618. case '5002':
  619. msg = 'nft project not available'
  620. break
  621. case '5101':
  622. msg = 'nft sale plan not exist'
  623. break
  624. case '5102':
  625. msg = 'nft sold out'
  626. break
  627. case '5103':
  628. msg = 'Purchase limit reached'
  629. break
  630. case '5104':
  631. case '5105':
  632. case '5106':
  633. msg = 'Invalid redemption code'
  634. break;
  635. default:
  636. msg = 'Payment failed, please try again'
  637. break;
  638. }
  639. // Dialog
  640. Dialog({
  641. message: msg,
  642. confirmButtonText: 'OK',
  643. confirmButtonColor: '#1D9BF0',
  644. });
  645. },
  646. deNetPay() {
  647. if (!this.salePlans) return;
  648. let pageSource;
  649. if (this.salePlans.currencyCode === 'USD') {
  650. pageSource = Report.pageSource.nftDepositCashPage
  651. } else {
  652. pageSource = Report.pageSource.nftDepositTokenPage
  653. }
  654. if (Number(this.usdAmountData.rechargeAmountValue) > 0) {
  655. // 余额不够
  656. this.step = 3;
  657. this.currencyInfoTimer();
  658. // Report
  659. this.reportView(pageSource);
  660. } else {
  661. // 余额足够
  662. this.step = 2;
  663. this.reportView(Report.pageSource.nftBalancePage);
  664. }
  665. this.reportPaymentBtnClick(Report.objectType.denetPayButton)
  666. },
  667. maskPay() {
  668. if (Number(this.usdAmountData.rechargeAmountValue) > 0) {
  669. this.step = 2;
  670. this.waitRefresh = true;
  671. this.currencyInfoTimer();
  672. Dialog({
  673. message: `Was the pament successful?`,
  674. showCancelButton: true,
  675. confirmButtonText: 'YES',
  676. confirmButtonColor: '#1D9BF0',
  677. cancelButtonText: 'NO',
  678. cancelButtonColor: '#1D9BF0',
  679. }).then(() => {
  680. this.checkWaitInfo(false)
  681. }).catch(() => {
  682. this.checkWaitInfo(false)
  683. });
  684. this.reportView(Report.pageSource.nftPaymentBalancePage);
  685. } else {
  686. this.step = 2;
  687. this.reportView(Report.pageSource.nftBalancePage);
  688. }
  689. this.reportPaymentBtnClick(Report.objectType.metamaskPayButton)
  690. },
  691. achPay(modifyStep = true, objectType = '') {
  692. if (Number(this.usdAmountData.rechargeAmountValue) > 0) {
  693. if (modifyStep) {
  694. this.step = 2;
  695. this.reportView(Report.pageSource.nftPaymentBalancePage);
  696. }
  697. this.waitRefresh = true;
  698. this.currencyInfoTimer();
  699. Dialog({
  700. message: `Was the pament successful?`,
  701. showCancelButton: true,
  702. confirmButtonText: 'YES',
  703. confirmButtonColor: '#1D9BF0',
  704. cancelButtonText: 'NO',
  705. cancelButtonColor: '#1D9BF0',
  706. }).then(() => {
  707. this.checkWaitInfo(false)
  708. }).catch(() => {
  709. this.checkWaitInfo(false)
  710. });
  711. // setUrl
  712. setStorage(storageKey.paymentUrl, window.location.href)
  713. this.$nextTick(() => {
  714. let win = window.open();
  715. win.opener = null;
  716. win.location.href = `${location.protocol}//${location.host}/payment_ach/${this.usdAmountData.rechargeAmountValue}`;
  717. this.achTimer = setInterval(() => {
  718. console.log('pay')
  719. if (win && win.closed) {
  720. console.log('done')
  721. clearInterval(this.achTimer);
  722. }
  723. }, 500);
  724. })
  725. } else {
  726. if (modifyStep) {
  727. this.step = 2;
  728. this.reportView(Report.pageSource.nftBalancePage);
  729. }
  730. }
  731. if (objectType !== '') {
  732. this.reportPaymentBtnClick(objectType)
  733. } else {
  734. this.reportDepositCashPageClick(Report.objectType.depositButtion)
  735. }
  736. },
  737. copyErCode() {
  738. this.reportDepositTokenPageClick(Report.objectType.copyButtion)
  739. },
  740. reportView(pageSource) {
  741. Report.log({
  742. pageSource,
  743. params: {
  744. eventData: {
  745. businessType: Report.businessType.pageView,
  746. },
  747. extParams: {
  748. userAgent: window.navigator.userAgent,
  749. }
  750. }
  751. })
  752. },
  753. reportPaymentBtnClick(objectType) {
  754. Report.log({
  755. pageSource: Report.pageSource.nftPaymentPage,
  756. params: {
  757. eventData: {
  758. objectType,
  759. businessType: Report.businessType.buttonClick,
  760. },
  761. extParams: {
  762. userAgent: window.navigator.userAgent,
  763. }
  764. }
  765. })
  766. },
  767. reportRedeemBtnClick() {
  768. Report.log({
  769. pageSource: Report.pageSource.nftRedeemPage,
  770. params: {
  771. eventData: {
  772. objectType: Report.objectType.redeemButton,
  773. businessType: Report.businessType.buttonClick,
  774. },
  775. extParams: {
  776. userAgent: window.navigator.userAgent,
  777. }
  778. }
  779. })
  780. },
  781. reportDepositCashPageClick(objectType) {
  782. Report.log({
  783. pageSource: Report.pageSource.nftDepositCashPage,
  784. params: {
  785. eventData: {
  786. objectType,
  787. businessType: Report.businessType.buttonClick,
  788. },
  789. extParams: {
  790. userAgent: window.navigator.userAgent,
  791. }
  792. }
  793. })
  794. },
  795. reportDepositTokenPageClick(objectType) {
  796. Report.log({
  797. pageSource: Report.pageSource.nftDepositTokenPage,
  798. params: {
  799. eventData: {
  800. objectType,
  801. businessType: Report.businessType.buttonClick,
  802. },
  803. extParams: {
  804. userAgent: window.navigator.userAgent,
  805. }
  806. }
  807. })
  808. },
  809. reportBalanceRefresh() {
  810. let pageSource = this.waitRefresh ? Report.pageSource.nftPaymentBalancePage : Report.pageSource.nftBalancePage;
  811. Report.log({
  812. pageSource: pageSource,
  813. params: {
  814. eventData: {
  815. objectType: Report.objectType.refreshBalanceButton,
  816. businessType: Report.businessType.buttonClick,
  817. },
  818. extParams: {
  819. userAgent: window.navigator.userAgent,
  820. }
  821. }
  822. })
  823. },
  824. reportBalanceBuy() {
  825. let pageSource = this.waitRefresh ? Report.pageSource.nftPaymentBalancePage : Report.pageSource.nftBalancePage;
  826. Report.log({
  827. pageSource: pageSource,
  828. params: {
  829. eventData: {
  830. objectType: Report.objectType.purchaseNftButton,
  831. businessType: Report.businessType.buttonClick,
  832. },
  833. extParams: {
  834. userAgent: window.navigator.userAgent,
  835. }
  836. }
  837. })
  838. },
  839. }
  840. }
  841. </script>
  842. <style lang="scss">
  843. html,
  844. body,
  845. #__nuxt,
  846. #__layout {
  847. width: 100%;
  848. height: 100%;
  849. padding: 0;
  850. margin: 0;
  851. overflow: hidden;
  852. }
  853. .payment {
  854. width: 100%;
  855. height: 100%;
  856. }
  857. .moneyInfo {
  858. display: flex;
  859. align-items: center;
  860. justify-content: center;
  861. flex-direction: column;
  862. height: 90px;
  863. border-bottom: solid 8px rgba($color: #f5f5f5, $alpha: .6);
  864. .tips {
  865. font-size: 12px;
  866. font-weight: 500;
  867. }
  868. .money {
  869. display: flex;
  870. align-items: center;
  871. justify-content: center;
  872. margin-top: 10px;
  873. color: #000;
  874. font-size: 20px;
  875. font-weight: 700;
  876. .icon {
  877. overflow: hidden;
  878. width: 26px;
  879. height: 26px;
  880. border-radius: 50%;
  881. margin-right: 10px;
  882. vertical-align: middle;
  883. background-color: #f5f5f5;
  884. }
  885. .info {
  886. &.usd {
  887. margin-top: -5px;
  888. }
  889. }
  890. }
  891. }
  892. .payList {
  893. overflow-y: auto;
  894. height: calc(100% - 90px);
  895. .detail {
  896. padding: 18px 16px;
  897. .title {
  898. color: #ADADAD;
  899. height: 26px;
  900. font-size: 12px;
  901. font-weight: 500;
  902. }
  903. .item {
  904. position: relative;
  905. display: flex;
  906. align-items: center;
  907. justify-content: center;
  908. font-weight: 500;
  909. font-size: 16px;
  910. height: 50px;
  911. margin-bottom: 14px;
  912. border-radius: 100px;
  913. border: 1px solid #ECECEC;
  914. &:last-child {
  915. margin-bottom: 0;
  916. }
  917. img {
  918. width: 24px;
  919. height: 24px;
  920. margin-right: 4px;
  921. }
  922. &.denet {
  923. flex-direction: column;
  924. img {
  925. margin-top: -6px;
  926. }
  927. }
  928. .wallet {
  929. width: 100%;
  930. overflow: hidden;
  931. color: #ADADAD;
  932. font-size: 11px;
  933. text-align: center;
  934. margin-top: -2px;
  935. }
  936. .maskLink {
  937. position: absolute;
  938. z-index: 10;
  939. width: 100%;
  940. height: 100%;
  941. }
  942. }
  943. }
  944. }
  945. .loading {
  946. position: absolute;
  947. z-index: 3;
  948. display: flex;
  949. align-items: center;
  950. justify-content: center;
  951. top: 0;
  952. left: 0;
  953. width: 100%;
  954. height: 100%;
  955. }
  956. .loadingBg {
  957. position: absolute;
  958. z-index: 2;
  959. top: 0;
  960. left: 0;
  961. width: 100%;
  962. height: 100%;
  963. background-color: rgba($color: #000, $alpha: .1);
  964. }
  965. .redeem {
  966. padding: 18px 16px 38px;
  967. .tips {
  968. height: 31px;
  969. font-size: 15px;
  970. font-weight: 500;
  971. }
  972. .footer {
  973. display: flex;
  974. justify-content: space-between;
  975. .input {
  976. display: flex;
  977. align-items: center;
  978. justify-content: center;
  979. width: calc(100% - 93px);
  980. height: 45px;
  981. border-radius: 5px;
  982. border: 1px solid #E0E0E0;
  983. input {
  984. width: 94%;
  985. border: 0;
  986. outline: 0;
  987. }
  988. }
  989. .enter {
  990. width: 83px;
  991. height: 45px;
  992. border: 0;
  993. padding: 0;
  994. color: #ffffff;
  995. font-size: 17px;
  996. font-weight: 500;
  997. border-radius: 5px;
  998. background: #1D9BF0;
  999. &.disable {
  1000. background: #DEDEDE;
  1001. }
  1002. }
  1003. }
  1004. }
  1005. .payInfo {
  1006. width: 100%;
  1007. height: calc(100% - 88px);
  1008. .picShow {
  1009. padding: 54px 48px;
  1010. .tip {
  1011. height: 44px;
  1012. font-size: 18px;
  1013. font-weight: 600;
  1014. text-align: center;
  1015. }
  1016. .pic {
  1017. display: block;
  1018. margin: auto;
  1019. width: 280px;
  1020. height: 280px;
  1021. border-radius: 3px;
  1022. margin-bottom: 20px;
  1023. }
  1024. .name {
  1025. font-size: 18px;
  1026. font-weight: 600;
  1027. line-height: 21px;
  1028. text-align: center;
  1029. }
  1030. }
  1031. }
  1032. .payBtn {
  1033. padding: 0 16px 38px;
  1034. .btn {
  1035. width: 100%;
  1036. height: 50px;
  1037. color: #FFFFFF;
  1038. font-size: 18px;
  1039. font-weight: 700;
  1040. border-radius: 50px;
  1041. background: #1D9BF0;
  1042. }
  1043. }
  1044. .balanceTop {
  1045. display: flex;
  1046. align-items: center;
  1047. justify-content: center;
  1048. flex-direction: column;
  1049. height: calc(100% - 100px);
  1050. background-color: #f5f5f5;
  1051. .balance {
  1052. width: 66px;
  1053. height: 66px;
  1054. margin-bottom: 6px;
  1055. }
  1056. .text {
  1057. font-size: 15px;
  1058. font-weight: 500;
  1059. line-height: 18px;
  1060. color: #9D9D9D;
  1061. }
  1062. .money {
  1063. font-size: 22px;
  1064. font-weight: 700;
  1065. line-height: 26px;
  1066. margin-top: 6px;
  1067. .icon {
  1068. width: 22px;
  1069. height: 22px;
  1070. margin-right: 6px;
  1071. }
  1072. .font {
  1073. color: #000;
  1074. }
  1075. }
  1076. }
  1077. .balanceInfo {
  1078. overflow-y: auto;
  1079. height: calc(100% - 100px);
  1080. background-color: #f5f5f5;
  1081. .top {
  1082. padding: 0 16px 17px 16px;
  1083. background-color: #ffffff;
  1084. .item {
  1085. display: flex;
  1086. align-items: center;
  1087. height: 54px;
  1088. border-bottom: solid 1px #F2F2F2;
  1089. &.title {
  1090. font-size: 16px;
  1091. font-weight: 600;
  1092. line-height: 19px;
  1093. img {
  1094. width: 26px;
  1095. height: 26px;
  1096. margin-right: 6px;
  1097. }
  1098. }
  1099. &.column {
  1100. color: rgba($color: #5E5E5E, $alpha: .7);
  1101. font-size: 14px;
  1102. font-weight: 400;
  1103. .l {
  1104. width: 70px;
  1105. }
  1106. .r {
  1107. img {
  1108. width: 21px;
  1109. height: 21px;
  1110. margin-right: 4px;
  1111. }
  1112. span {
  1113. color: rgba($color: #5E5E5E, $alpha: .7);
  1114. }
  1115. }
  1116. }
  1117. &.usd {
  1118. font-size: 14px;
  1119. font-weight: 500;
  1120. justify-content: space-between;
  1121. .fontPayment {
  1122. font-size: 18px;
  1123. font-weight: 600;
  1124. }
  1125. .font {
  1126. color: #9A9A9A;
  1127. font-size: 16px;
  1128. font-weight: 500;
  1129. }
  1130. .fontDeposit {
  1131. color: #1D9BF0;
  1132. font-size: 18px;
  1133. font-weight: 600;
  1134. }
  1135. }
  1136. }
  1137. .deposit {
  1138. display: flex;
  1139. align-items: center;
  1140. justify-content: center;
  1141. height: 54px;
  1142. color: #ffffff;
  1143. font-weight: 600;
  1144. font-size: 18px;
  1145. margin-top: 16px;
  1146. border-radius: 54px;
  1147. background: #1D9BF0;
  1148. }
  1149. .address {
  1150. color: rgba($color: #5E5E5E, $alpha: .7);
  1151. .title {
  1152. height: 42px;
  1153. font-size: 14px;
  1154. font-weight: 400;
  1155. line-height: 42px;
  1156. }
  1157. }
  1158. .notice {
  1159. display: flex;
  1160. justify-content: space-between;
  1161. padding: 10px;
  1162. margin-top: 12px;
  1163. border-radius: 8px;
  1164. background: #F9F6EE;
  1165. .icon {
  1166. width: 20px;
  1167. margin-right: 10px;
  1168. img {
  1169. width: 20px;
  1170. height: 20px;
  1171. }
  1172. }
  1173. .text {
  1174. flex: 1;
  1175. color: rgba($color: #5E5E5E, $alpha: .7);
  1176. font-size: 14px;
  1177. font-weight: 400;
  1178. line-height: 19px;
  1179. word-break: break-all;
  1180. strong {
  1181. color: #FF0000;
  1182. font-weight: bold;
  1183. }
  1184. }
  1185. }
  1186. }
  1187. .line {
  1188. height: 8px;
  1189. }
  1190. .balance {
  1191. display: flex;
  1192. align-items: center;
  1193. padding: 0 16px;
  1194. height: 54px;
  1195. background-color: #ffffff;
  1196. .icon {
  1197. width: 24px;
  1198. margin-right: 6px;
  1199. img {
  1200. width: 24px;
  1201. }
  1202. }
  1203. .text {
  1204. flex: 1;
  1205. font-size: 14px;
  1206. font-weight: 500;
  1207. line-height: 17px;
  1208. span {
  1209. color: #000;
  1210. margin-right: auto;
  1211. }
  1212. }
  1213. .refresh {
  1214. width: 24px;
  1215. height: 24px;
  1216. img {
  1217. width: 24px;
  1218. transform-origin: center center;
  1219. }
  1220. }
  1221. }
  1222. }
  1223. .balanceBot {
  1224. display: flex;
  1225. justify-content: space-between;
  1226. width: 100%;
  1227. padding: 17px 16px 38px;
  1228. border-top: solid 1px #ECECEC;
  1229. .l {
  1230. display: flex;
  1231. flex-direction: column;
  1232. justify-content: center;
  1233. }
  1234. .neet {
  1235. font-size: 12px;
  1236. font-weight: 500;
  1237. line-height: 14px;
  1238. }
  1239. .money {
  1240. height: 22px;
  1241. line-height: 22px;
  1242. font-size: 18px;
  1243. font-weight: 700;
  1244. margin-top: 4px;
  1245. .text {
  1246. margin-right: auto;
  1247. }
  1248. }
  1249. .btn {
  1250. display: flex;
  1251. align-items: center;
  1252. justify-content: center;
  1253. width: 110px;
  1254. height: 46px;
  1255. color: #ffffff;
  1256. font-size: 18px;
  1257. font-weight: 700;
  1258. line-height: 21px;
  1259. border-radius: 46px;
  1260. background: #1D9BF0;
  1261. &.disable {
  1262. background: #D2D2D2;
  1263. }
  1264. }
  1265. }
  1266. .waitFont {
  1267. margin-top: 16px;
  1268. padding: 0 20px;
  1269. font-size: 14px;
  1270. font-weight: 500;
  1271. line-height: 17px;
  1272. text-align: center;
  1273. }
  1274. .waitBtn {
  1275. display: flex;
  1276. align-items: center;
  1277. justify-content: center;
  1278. width: 50px;
  1279. height: 50px;
  1280. margin: 50px auto 0;
  1281. border-radius: 50%;
  1282. background-color: #ffffff;
  1283. img {
  1284. width: 24px;
  1285. height: 24px;
  1286. }
  1287. }
  1288. .icon-refresh-rotate {
  1289. transform: rotate(360deg);
  1290. transition-duration: 1s;
  1291. }
  1292. </style>