MobileBuyNft.vue 15 KB

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