MobileBuyNft.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  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 }}</div>
  66. <div>{{ item.currencyInfo.tokenSymbol }} (${{item.usdPrice}})</div>
  67. </div>
  68. </template>
  69. <template v-else>
  70. <img class="icon" :src="item.currencyInfo.iconPath" /> {{ item.price }} {{ item.currencyInfo.tokenSymbol }} (${{item.usdPrice}})
  71. </template>
  72. </template>
  73. <template v-else>
  74. ${{item.usdPrice}}
  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 }} {{ item.currencyInfo.tokenSymbol }} (${{item.usdPrice}})
  86. </template>
  87. <template v-else>
  88. ${{item.usdPrice}}
  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. created() {
  170. this.getSaleInfo()
  171. // report
  172. Report.log({
  173. pageSource: Report.pageSource.nftPurchasePage,
  174. params: {
  175. eventData: {
  176. businessType: Report.businessType.pageView,
  177. },
  178. extParams: {
  179. userAgent: window.navigator.userAgent,
  180. }
  181. }
  182. })
  183. },
  184. methods: {
  185. select(item) {
  186. this.curItem = item;
  187. this.nftMetaData = JSON.parse(item['metadata']);
  188. },
  189. getSaleInfo() {
  190. postRequest(Api.getNftMysteryBoxSaleInfo, {
  191. params: {
  192. nftProjectId: this.$route.params.id
  193. },
  194. }).then(res => {
  195. let { code, data } = res;
  196. if (code === 0) {
  197. this.data = data;
  198. this.listData = data.showItems;
  199. this.curItem = data.showItems[0];
  200. this.nftMetaData = JSON.parse(data.showItems[0]['metadata']);
  201. // set title
  202. document.title = data['nftProjectName'] + ` NFT`;
  203. }
  204. })
  205. },
  206. goBuy(isNext = true) {
  207. if (isNext === false) return;
  208. let userInfo = getStorage(storageKey.userInfo)
  209. if (!!userInfo) {
  210. this.loginSuccess(userInfo, false)
  211. } else {
  212. this.loginLayer = true;
  213. // report
  214. Report.log({
  215. pageSource: Report.pageSource.nftLoginPage,
  216. params: {
  217. eventData: {
  218. businessType: Report.businessType.pageView,
  219. },
  220. extParams: {
  221. userAgent: window.navigator.userAgent,
  222. }
  223. }
  224. })
  225. }
  226. // report
  227. Report.log({
  228. pageSource: Report.pageSource.nftPurchasePage,
  229. params: {
  230. eventData: {
  231. businessType: Report.businessType.buttonClick,
  232. objectType: Report.objectType.buyNftButton,
  233. },
  234. extParams: {
  235. userAgent: window.navigator.userAgent,
  236. }
  237. }
  238. })
  239. },
  240. login() {
  241. this.loading = true;
  242. Report.log({
  243. pageSource: Report.pageSource.nftLoginPage,
  244. params: {
  245. eventData: {
  246. businessType: Report.businessType.buttonClick,
  247. objectType: Report.objectType.loginTwitterButton,
  248. },
  249. extParams: {
  250. userAgent: window.navigator.userAgent,
  251. }
  252. }
  253. })
  254. },
  255. loginSuccess(userInfo, isReport = true) {
  256. this.$router.push({
  257. name: 'Payment',
  258. query: {
  259. nftProjectId: this.$route.params.id,
  260. account: this.$route.params.account,
  261. }
  262. });
  263. if (isReport) {
  264. Report.log({
  265. pageSource: Report.pageSource.nftLoginPage,
  266. params: {
  267. eventData: {
  268. businessType: Report.businessType.buttonClick,
  269. objectType: Report.objectType.loginTwitterButton,
  270. },
  271. extParams: {
  272. 'login-result': 'sucess',
  273. userAgent: window.navigator.userAgent,
  274. }
  275. }
  276. })
  277. }
  278. },
  279. loginError() {
  280. Toast('login fail');
  281. this.loading = false;
  282. Report.log({
  283. pageSource: Report.pageSource.nftLoginPage,
  284. params: {
  285. eventData: {
  286. businessType: Report.businessType.buttonClick,
  287. objectType: Report.objectType.loginTwitterButton,
  288. },
  289. extParams: {
  290. 'login-result': 'fail',
  291. userAgent: window.navigator.userAgent,
  292. }
  293. }
  294. })
  295. }
  296. }
  297. }
  298. </script>
  299. <style lang="scss" scoped>
  300. .page {
  301. width: 100%;
  302. height: 100%;
  303. background-color: #fff;
  304. .loading {
  305. position: absolute;
  306. transform: translate(-50%, -50%);
  307. top: 50%;
  308. left: 50%;
  309. margin: auto;
  310. width: 40px;
  311. border-radius: 50%;
  312. }
  313. }
  314. .swipe {
  315. .show {
  316. overflow: hidden;
  317. width: 18rem;
  318. height: 18rem;
  319. margin: 1rem auto;
  320. border-radius: 6px;
  321. background-color: #efefef;
  322. img {
  323. width: 100%;
  324. height: 100%;
  325. }
  326. }
  327. .list {
  328. height: 70px;
  329. margin: 0 16px;
  330. font-size: 0;
  331. overflow-x: auto;
  332. white-space: nowrap;
  333. .item {
  334. display: inline-block;
  335. overflow: hidden;
  336. opacity: .2;
  337. width: 58px;
  338. height: 58px;
  339. margin: 0 3px;
  340. border-radius: 4px;
  341. background-color: #efefef;
  342. img {
  343. width: 100%;
  344. height: 100%;
  345. }
  346. &:first-child {
  347. margin-left: 0;
  348. }
  349. &:last-child {
  350. margin-right: 0;
  351. }
  352. &.on {
  353. opacity: 1;
  354. }
  355. }
  356. }
  357. }
  358. .line {
  359. border: 1px solid #e3e3e3;
  360. border-radius: 10px;
  361. padding: 14px;
  362. margin: 0 16px 12px 16px;
  363. box-sizing: border-box;
  364. .title {
  365. font-weight: 600;
  366. font-size: 14px;
  367. }
  368. }
  369. .desc {
  370. margin-top: 10px;
  371. .desc-content {
  372. font-weight: 500;
  373. font-size: 14px;
  374. color: #929292;
  375. span {
  376. color: #1d9bf0;
  377. }
  378. }
  379. }
  380. .prop {
  381. .prop-content {
  382. display: flex;
  383. flex-wrap: wrap;
  384. margin-top: 12px;
  385. .prop-item {
  386. width: 48%;
  387. min-height: 88px;
  388. background: #f8f8f8;
  389. border-radius: 10px;
  390. display: flex;
  391. flex-direction: column;
  392. justify-content: center;
  393. padding: 8px;
  394. box-sizing: border-box;
  395. align-items: center;
  396. font-weight: 500;
  397. font-size: 12px;
  398. color: #929292;
  399. margin-bottom: 10px;
  400. .prop-name {
  401. font-weight: 700;
  402. font-size: 17px;
  403. margin-top: 6px;
  404. margin-bottom: 8px;
  405. color: #000;
  406. word-break: break-all;
  407. }
  408. }
  409. .prop-item:nth-child(odd) {
  410. margin-right: 8px;
  411. }
  412. }
  413. }
  414. .about-content {
  415. margin-top: 22px;
  416. .section {
  417. font-weight: 400;
  418. font-size: 14px;
  419. margin-bottom: 20px;
  420. }
  421. }
  422. .buy {
  423. position: fixed;
  424. left: 0;
  425. bottom: 0;
  426. width: 100%;
  427. box-sizing: border-box;
  428. background-color: #fff;
  429. padding: 10px 16px 25px 16px;
  430. border-top: solid 1px #E3E3E3;
  431. .random {
  432. color: #8C7D43;
  433. font-size: 14px;
  434. height: 30px;
  435. img {
  436. width: 20px;
  437. height: 20px;
  438. vertical-align: middle;
  439. }
  440. }
  441. .btn {
  442. display: flex;
  443. font-size: 16px;
  444. color: #ffffff;
  445. align-items: center;
  446. justify-content: space-between;
  447. width: 100%;
  448. height: 50px;
  449. padding: 0 14px;
  450. font-weight: 700;
  451. border-radius: 50px;
  452. background: #1D9BF0;
  453. &.disable {
  454. background: #CDCDCD;
  455. cursor: not-allowed;
  456. }
  457. .icon {
  458. width: 22px;
  459. margin-right: 5px;
  460. }
  461. .l {
  462. white-space: nowrap;
  463. }
  464. }
  465. .sale {
  466. display: flex;
  467. justify-content: space-between;
  468. color: #868686;
  469. font-size: 12px;
  470. line-height: 14px;
  471. padding: 10px 0;
  472. letter-spacing: 0.3px;
  473. }
  474. .tr {
  475. text-align: right;
  476. }
  477. }
  478. .login {
  479. box-sizing: border-box;
  480. padding: 38px 16px;
  481. width: 100%;
  482. .title {
  483. font-size: 16px;
  484. font-weight: 500;
  485. margin-bottom: 20px;
  486. }
  487. .btn {
  488. position: relative;
  489. display: flex;
  490. align-items: center;
  491. justify-content: center;
  492. height: 50px;
  493. border-radius: 50px;
  494. background: #1D9BF0;
  495. .text {
  496. font-size: 18px;
  497. font-weight: 700;
  498. color: #ffffff;
  499. }
  500. }
  501. }
  502. .loginLoading {
  503. position: absolute;
  504. z-index: 9991;
  505. display: flex;
  506. align-items: center;
  507. justify-content: center;
  508. top: 0;
  509. left: 0;
  510. width: 100%;
  511. height: 100%;
  512. }
  513. .loginLoadingBg {
  514. position: absolute;
  515. z-index: 9990;
  516. top: 0;
  517. left: 0;
  518. width: 100%;
  519. height: 100%;
  520. background-color: rgba($color: #000, $alpha: .1);
  521. }
  522. </style>