MobileBuyNft.vue 15 KB

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