MobileBuyNft.vue 12 KB

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