MobileBuyNft.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. <template>
  2. <div class="page">
  3. <template v-if="data === null">
  4. <img class="loading" src="../static/svg/icon-loading.svg" />
  5. </template>
  6. <template v-else>
  7. <div class="swipe" v-if="curItem">
  8. <div class="show">
  9. <img :src="curItem.imagePath" />
  10. </div>
  11. <div class="list">
  12. <div
  13. class="item"
  14. :class="{ on: curItem.nftItemId === item.nftItemId }"
  15. :key="index"
  16. @click="select(item)"
  17. v-for="(item, index) in listData">
  18. <img :src="item.imagePath" />
  19. </div>
  20. </div>
  21. </div>
  22. <div class="desc line" v-if="nftMetaData.description">
  23. <div class="title">Description</div>
  24. <div class="desc-content" v-html="nftMetaData.description"></div>
  25. </div>
  26. <div class="prop line" v-if="nftMetaData.properties && nftMetaData.properties.length">
  27. <div class="title">Properties</div>
  28. <div class="prop-content">
  29. <div
  30. class="prop-item"
  31. v-for="(filedValueItem, filedValueIndex) in nftMetaData.properties"
  32. :key="filedValueIndex"
  33. >
  34. {{ filedValueItem.name }}
  35. <div class="prop-name">
  36. {{ filedValueItem.value }}
  37. </div>
  38. {{ filedValueItem.description }}
  39. </div>
  40. </div>
  41. </div>
  42. <div class="about line" v-if="nftMetaData.about">
  43. <div class="title">About</div>
  44. <div class="about-content" v-html="nftMetaData.about"></div>
  45. </div>
  46. <div style="height:150px"></div>
  47. <div class="buy">
  48. <div class="random">
  49. <img src="../static/img/icon_nft_random.png" />
  50. <span>Randomly Get Different Styles of NFTs</span>
  51. </div>
  52. <template v-if="data.salePlans.length">
  53. <div v-for="(item, index) in data.salePlans" :key="index">
  54. <template v-if="item.itemCount == 1">
  55. <template v-if="purchaseStatus !== 0">
  56. <div
  57. class="btn"
  58. :class="{ disable: !((data.perUserBuyLimit - data.userBuyCount) >= 1 && (data.itemTotalCount - data.itemSoldCount) >= 1) }"
  59. @click="goBuy(((data.perUserBuyLimit - data.userBuyCount) >= 1 && (data.itemTotalCount - data.itemSoldCount) >= 1))">
  60. <div class="l">BUY {{item.itemCount}}</div>
  61. <FontZoom width="210">
  62. <template v-if="item.currencyCode !== 'USD'">
  63. <template v-if="item.price.length + item.currencyInfo.tokenSymbol.length >= 30">
  64. <div class="tr">
  65. <div><img class="icon" :src="item.currencyInfo.iconPath" /> {{ item.price | floatPrice(4) }}</div>
  66. <div>{{ item.currencyInfo.tokenSymbol }} (${{item.usdPrice | floatPrice(2)}})</div>
  67. </div>
  68. </template>
  69. <template v-else>
  70. <img class="icon" :src="item.currencyInfo.iconPath" /> {{ item.price | floatPrice(4) }} {{ item.currencyInfo.tokenSymbol }} (${{item.usdPrice | floatPrice(2)}})
  71. </template>
  72. </template>
  73. <template v-else>
  74. ${{item.usdPrice | floatPrice(2)}}
  75. </template>
  76. </FontZoom>
  77. </div>
  78. </template>
  79. <template v-else>
  80. <div
  81. class="btn disable">
  82. <div class="l">BUY {{item.itemCount}}</div>
  83. <FontZoom width="210">
  84. <template v-if="item.currencyCode !== 'USD'">
  85. <img class="icon" :src="item.currencyInfo.iconPath" /> {{ item.price | floatPrice(4) }} {{ item.currencyInfo.tokenSymbol }} (${{item.usdPrice | floatPrice(2)}})
  86. </template>
  87. <template v-else>
  88. ${{item.usdPrice | floatPrice(2)}}
  89. </template>
  90. </FontZoom>
  91. </div>
  92. </template>
  93. </template>
  94. </div>
  95. </template>
  96. <template v-else>
  97. <template v-if="purchaseStatus !== 0">
  98. <div
  99. class="btn"
  100. @click="goBuy()">
  101. BUY 1
  102. </div>
  103. </template>
  104. <template v-else>
  105. <div
  106. class="btn disable">
  107. BUY 1
  108. </div>
  109. </template>
  110. </template>
  111. <div class="sale">
  112. <div class="l">SOLD: {{ data.itemSoldCount || 0 }}/{{ data.itemTotalCount }}</div>
  113. <div class="r" v-if="data.perUserBuyLimit < data.itemTotalCount">Buy Limit: {{ data.userBuyCount || 0 }}/{{ data.perUserBuyLimit }}</div>
  114. </div>
  115. </div>
  116. </template>
  117. <van-popup
  118. round
  119. v-model="loginLayer"
  120. position="bottom">
  121. <div class="login">
  122. <div class="title">In order to purchase the NFT, you need to</div>
  123. <div class="btn" @click="login">
  124. <button-login
  125. @success="loginSuccess"
  126. @error="loginError">
  127. </button-login>
  128. <div class="text">Login Twitter</div>
  129. </div>
  130. </div>
  131. </van-popup>
  132. <!-- loading -->
  133. <div class="loginLoading" v-if="loading">
  134. <van-loading color="#1D9BF0"></van-loading>
  135. </div>
  136. <div class="loginLoadingBg" v-if="loading"></div>
  137. </div>
  138. </template>
  139. <script>
  140. import Api from '../http/api';
  141. import FontZoom from './FontZoom';
  142. import ButtonLogin from './buttonLogin';
  143. import Report from './../log-center/log';
  144. import { Toast } from 'vant';
  145. import { postRequest } from '../http';
  146. import { getStorage, storageKey } from '../utils/help';
  147. export default {
  148. name: 'mobileBuyNft',
  149. components: {
  150. FontZoom,
  151. ButtonLogin,
  152. },
  153. data() {
  154. return {
  155. data: null,
  156. curItem: null,
  157. listData: [],
  158. nftMetaData: {},
  159. loading: false,
  160. loginLayer: false,
  161. }
  162. },
  163. props: {
  164. purchaseStatus: {
  165. type: Number,
  166. default: 0
  167. }
  168. },
  169. filters: {
  170. floatPrice(price, num) {
  171. if (price.indexOf('.') >= 0) {
  172. let reg = new RegExp(`^\\D*(\\d*(?:\\.\\d{0,${num}})?).*$`, "g");
  173. price = price.replace(reg, '$1');
  174. }
  175. return price;
  176. }
  177. },
  178. created() {
  179. this.getSaleInfo()
  180. // report
  181. Report.log({
  182. pageSource: Report.pageSource.nftPurchasePage,
  183. params: {
  184. eventData: {
  185. businessType: Report.businessType.pageView,
  186. },
  187. extParams: {
  188. userAgent: window.navigator.userAgent,
  189. }
  190. }
  191. })
  192. },
  193. methods: {
  194. select(item) {
  195. this.curItem = item;
  196. this.nftMetaData = JSON.parse(item['metadata']);
  197. },
  198. getSaleInfo() {
  199. postRequest(Api.getNftMysteryBoxSaleInfo, {
  200. params: {
  201. nftProjectId: this.$route.params.id
  202. },
  203. }).then(res => {
  204. let { code, data } = res;
  205. if (code === 0) {
  206. this.data = data;
  207. this.listData = data.showItems;
  208. this.curItem = data.showItems[0];
  209. this.nftMetaData = JSON.parse(data.showItems[0]['metadata']);
  210. // set title
  211. document.title = data['nftProjectName'] + ` NFT`;
  212. }
  213. })
  214. },
  215. goBuy(isNext = true) {
  216. if (isNext === false) return;
  217. let userInfo = getStorage(storageKey.userInfo)
  218. if (!!userInfo) {
  219. this.loginSuccess(userInfo, false)
  220. } else {
  221. this.loginLayer = true;
  222. // report
  223. Report.log({
  224. pageSource: Report.pageSource.nftLoginPage,
  225. params: {
  226. eventData: {
  227. businessType: Report.businessType.pageView,
  228. },
  229. extParams: {
  230. userAgent: window.navigator.userAgent,
  231. }
  232. }
  233. })
  234. }
  235. // report
  236. Report.log({
  237. pageSource: Report.pageSource.nftPurchasePage,
  238. params: {
  239. eventData: {
  240. businessType: Report.businessType.buttonClick,
  241. objectType: Report.objectType.buyNftButton,
  242. },
  243. extParams: {
  244. userAgent: window.navigator.userAgent,
  245. }
  246. }
  247. })
  248. },
  249. login() {
  250. this.loading = true;
  251. Report.log({
  252. pageSource: Report.pageSource.nftLoginPage,
  253. params: {
  254. eventData: {
  255. businessType: Report.businessType.buttonClick,
  256. objectType: Report.objectType.loginTwitterButton,
  257. },
  258. extParams: {
  259. userAgent: window.navigator.userAgent,
  260. }
  261. }
  262. })
  263. },
  264. loginSuccess(userInfo, isReport = true) {
  265. this.$router.push({
  266. name: 'Payment',
  267. query: {
  268. nftProjectId: this.$route.params.id,
  269. account: this.$route.params.account,
  270. }
  271. });
  272. if (isReport) {
  273. Report.log({
  274. pageSource: Report.pageSource.nftLoginPage,
  275. params: {
  276. eventData: {
  277. businessType: Report.businessType.buttonClick,
  278. objectType: Report.objectType.loginTwitterButton,
  279. },
  280. extParams: {
  281. 'login-result': 'sucess',
  282. userAgent: window.navigator.userAgent,
  283. }
  284. }
  285. })
  286. }
  287. },
  288. loginError() {
  289. Toast('login fail');
  290. this.loading = false;
  291. Report.log({
  292. pageSource: Report.pageSource.nftLoginPage,
  293. params: {
  294. eventData: {
  295. businessType: Report.businessType.buttonClick,
  296. objectType: Report.objectType.loginTwitterButton,
  297. },
  298. extParams: {
  299. 'login-result': 'fail',
  300. userAgent: window.navigator.userAgent,
  301. }
  302. }
  303. })
  304. }
  305. }
  306. }
  307. </script>
  308. <style lang="scss" scoped>
  309. .page {
  310. width: 100%;
  311. height: 100%;
  312. background-color: #fff;
  313. .loading {
  314. position: absolute;
  315. transform: translate(-50%, -50%);
  316. top: 50%;
  317. left: 50%;
  318. margin: auto;
  319. width: 40px;
  320. border-radius: 50%;
  321. }
  322. }
  323. .swipe {
  324. .show {
  325. overflow: hidden;
  326. width: 18rem;
  327. height: 18rem;
  328. margin: 1rem auto;
  329. border-radius: 6px;
  330. background-color: #efefef;
  331. img {
  332. width: 100%;
  333. height: 100%;
  334. }
  335. }
  336. .list {
  337. height: 64px;
  338. margin: 0 16px;
  339. font-size: 0;
  340. overflow-x: auto;
  341. white-space: nowrap;
  342. &::-webkit-scrollbar {
  343. display: none;
  344. }
  345. .item {
  346. display: inline-block;
  347. overflow: hidden;
  348. opacity: .2;
  349. width: 58px;
  350. height: 58px;
  351. margin: 0 3px;
  352. border-radius: 4px;
  353. background-color: #efefef;
  354. img {
  355. width: 100%;
  356. height: 100%;
  357. }
  358. &:first-child {
  359. margin-left: 0;
  360. }
  361. &:last-child {
  362. margin-right: 0;
  363. }
  364. &.on {
  365. opacity: 1;
  366. }
  367. }
  368. }
  369. }
  370. .line {
  371. border: 1px solid #e3e3e3;
  372. border-radius: 10px;
  373. padding: 14px;
  374. margin: 0 16px 12px 16px;
  375. box-sizing: border-box;
  376. .title {
  377. font-weight: 600;
  378. font-size: 14px;
  379. }
  380. }
  381. .desc {
  382. margin-top: 10px;
  383. .desc-content {
  384. font-weight: 500;
  385. font-size: 14px;
  386. color: #929292;
  387. span {
  388. color: #1d9bf0;
  389. }
  390. }
  391. }
  392. .prop {
  393. .prop-content {
  394. display: flex;
  395. flex-wrap: wrap;
  396. margin-top: 12px;
  397. .prop-item {
  398. width: 48%;
  399. min-height: 88px;
  400. background: #f8f8f8;
  401. border-radius: 10px;
  402. display: flex;
  403. flex-direction: column;
  404. justify-content: center;
  405. padding: 8px;
  406. box-sizing: border-box;
  407. align-items: center;
  408. font-weight: 500;
  409. font-size: 12px;
  410. color: #929292;
  411. margin-bottom: 10px;
  412. .prop-name {
  413. font-weight: 700;
  414. font-size: 17px;
  415. margin-top: 6px;
  416. margin-bottom: 8px;
  417. color: #000;
  418. word-break: break-all;
  419. }
  420. }
  421. .prop-item:nth-child(odd) {
  422. margin-right: 8px;
  423. }
  424. }
  425. }
  426. .about-content {
  427. margin-top: 22px;
  428. .section {
  429. font-weight: 400;
  430. font-size: 14px;
  431. margin-bottom: 20px;
  432. }
  433. }
  434. .buy {
  435. position: fixed;
  436. left: 0;
  437. bottom: 0;
  438. width: 100%;
  439. box-sizing: border-box;
  440. background-color: #fff;
  441. padding: 10px 16px 25px 16px;
  442. border-top: solid 1px #E3E3E3;
  443. .random {
  444. color: #8C7D43;
  445. font-size: 14px;
  446. height: 30px;
  447. img {
  448. width: 20px;
  449. height: 20px;
  450. vertical-align: middle;
  451. }
  452. }
  453. .btn {
  454. display: flex;
  455. font-size: 16px;
  456. color: #ffffff;
  457. align-items: center;
  458. justify-content: space-between;
  459. width: 100%;
  460. height: 50px;
  461. padding: 0 14px;
  462. font-weight: 700;
  463. border-radius: 50px;
  464. background: #1D9BF0;
  465. &.disable {
  466. background: #CDCDCD;
  467. cursor: not-allowed;
  468. }
  469. .icon {
  470. width: 22px;
  471. margin-right: 5px;
  472. }
  473. .l {
  474. white-space: nowrap;
  475. }
  476. }
  477. .sale {
  478. display: flex;
  479. justify-content: space-between;
  480. color: #868686;
  481. font-size: 12px;
  482. line-height: 14px;
  483. padding: 10px 0;
  484. letter-spacing: 0.3px;
  485. }
  486. .tr {
  487. text-align: right;
  488. }
  489. }
  490. .login {
  491. box-sizing: border-box;
  492. padding: 38px 16px;
  493. width: 100%;
  494. .title {
  495. font-size: 16px;
  496. font-weight: 500;
  497. margin-bottom: 20px;
  498. }
  499. .btn {
  500. position: relative;
  501. display: flex;
  502. align-items: center;
  503. justify-content: center;
  504. height: 50px;
  505. border-radius: 50px;
  506. background: #1D9BF0;
  507. .text {
  508. font-size: 18px;
  509. font-weight: 700;
  510. color: #ffffff;
  511. }
  512. }
  513. }
  514. .loginLoading {
  515. position: absolute;
  516. z-index: 9991;
  517. display: flex;
  518. align-items: center;
  519. justify-content: center;
  520. top: 0;
  521. left: 0;
  522. width: 100%;
  523. height: 100%;
  524. }
  525. .loginLoadingBg {
  526. position: absolute;
  527. z-index: 9990;
  528. top: 0;
  529. left: 0;
  530. width: 100%;
  531. height: 100%;
  532. background-color: rgba($color: #000, $alpha: .1);
  533. }
  534. </style>