MobileBuyNft.vue 16 KB

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