MobileBuyNft.vue 13 KB

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