MobileBuyNft.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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">
  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 { postRequest } from '../http';
  99. import { Toast } from 'vant';
  100. import Api from '../http/api';
  101. import FontZoom from './FontZoom';
  102. import ButtonLogin from './buttonLogin';
  103. import { getStorage, storageKey } from '../utils/help';
  104. export default {
  105. name: 'mobileBuyNft',
  106. components: {
  107. FontZoom,
  108. ButtonLogin,
  109. },
  110. data() {
  111. return {
  112. data: null,
  113. curItem: null,
  114. listData: [],
  115. nftMetaData: {},
  116. loginLayer: false,
  117. }
  118. },
  119. created() {
  120. this.getSaleInfo()
  121. },
  122. methods: {
  123. select(item) {
  124. this.curItem = item;
  125. this.nftMetaData = JSON.parse(item['metadata']);
  126. },
  127. getSaleInfo() {
  128. postRequest(Api.getNftMysteryBoxSaleInfo, {
  129. params: {
  130. nftProjectId: this.$route.params.id
  131. },
  132. }).then(res => {
  133. let { code, data } = res;
  134. if (code === 0) {
  135. this.data = data;
  136. this.listData = data.showItems;
  137. this.curItem = data.showItems[0];
  138. this.nftMetaData = JSON.parse(data.showItems[0]['metadata']);
  139. // set title
  140. document.title = data['nftProjectName'] + ` NFT`;
  141. }
  142. })
  143. },
  144. goBuy(isNext = true) {
  145. if (isNext === false) return;
  146. let userInfo = getStorage(storageKey.userInfo)
  147. if (!!userInfo) {
  148. this.loginSuccess(userInfo)
  149. } else {
  150. this.loginLayer = true;
  151. }
  152. },
  153. loginSuccess(userInfo) {
  154. this.$router.push({
  155. name: 'Payment',
  156. query: {
  157. nftProjectId: this.$route.params.id,
  158. account: this.$route.params.account,
  159. }
  160. });
  161. },
  162. loginError() {
  163. Toast('login fail');
  164. }
  165. }
  166. }
  167. </script>
  168. <style lang="scss" scoped>
  169. .page {
  170. width: 100%;
  171. height: 100%;
  172. background-color: #fff;
  173. .loading {
  174. position: absolute;
  175. transform: translate(-50%, -50%);
  176. top: 50%;
  177. left: 50%;
  178. margin: auto;
  179. width: 40px;
  180. border-radius: 50%;
  181. }
  182. }
  183. .swipe {
  184. .show {
  185. overflow: hidden;
  186. width: 18rem;
  187. height: 18rem;
  188. margin: 1rem auto;
  189. border-radius: 6px;
  190. background-color: #efefef;
  191. img {
  192. width: 100%;
  193. height: 100%;
  194. }
  195. }
  196. .list {
  197. height: 70px;
  198. margin: 0 16px;
  199. font-size: 0;
  200. overflow-x: auto;
  201. text-align: center;
  202. white-space: nowrap;
  203. .item {
  204. display: inline-block;
  205. overflow: hidden;
  206. opacity: .2;
  207. width: 58px;
  208. height: 58px;
  209. margin: 0 3px;
  210. border-radius: 4px;
  211. background-color: #efefef;
  212. img {
  213. width: 100%;
  214. height: 100%;
  215. }
  216. &:first-child {
  217. margin-left: 0;
  218. }
  219. &:last-child {
  220. margin-right: 0;
  221. }
  222. &.on {
  223. opacity: 1;
  224. }
  225. }
  226. }
  227. }
  228. .line {
  229. border: 1px solid #e3e3e3;
  230. border-radius: 10px;
  231. padding: 14px;
  232. margin: 0 16px 12px 16px;
  233. box-sizing: border-box;
  234. .title {
  235. font-weight: 600;
  236. font-size: 14px;
  237. }
  238. }
  239. .desc {
  240. margin-top: 10px;
  241. .desc-content {
  242. font-weight: 500;
  243. font-size: 14px;
  244. color: #929292;
  245. span {
  246. color: #1d9bf0;
  247. }
  248. }
  249. }
  250. .prop {
  251. .prop-content {
  252. display: flex;
  253. flex-wrap: wrap;
  254. margin-top: 12px;
  255. .prop-item {
  256. width: 48%;
  257. min-height: 88px;
  258. background: #f8f8f8;
  259. border-radius: 10px;
  260. display: flex;
  261. flex-direction: column;
  262. justify-content: center;
  263. padding: 8px;
  264. box-sizing: border-box;
  265. align-items: center;
  266. font-weight: 500;
  267. font-size: 12px;
  268. color: #929292;
  269. margin-bottom: 10px;
  270. .prop-name {
  271. font-weight: 700;
  272. font-size: 17px;
  273. margin-top: 6px;
  274. margin-bottom: 8px;
  275. color: #000;
  276. word-break: break-all;
  277. }
  278. }
  279. .prop-item:nth-child(odd) {
  280. margin-right: 8px;
  281. }
  282. }
  283. }
  284. .about-content {
  285. margin-top: 22px;
  286. .section {
  287. font-weight: 400;
  288. font-size: 14px;
  289. margin-bottom: 20px;
  290. }
  291. }
  292. .buy {
  293. position: fixed;
  294. left: 0;
  295. bottom: 0;
  296. width: 100%;
  297. box-sizing: border-box;
  298. background-color: #fff;
  299. padding: 10px 16px 25px 16px;
  300. border-top: solid 1px #E3E3E3;
  301. .random {
  302. color: #8C7D43;
  303. font-size: 14px;
  304. height: 30px;
  305. img {
  306. width: 20px;
  307. height: 20px;
  308. vertical-align: middle;
  309. }
  310. }
  311. .btn {
  312. display: flex;
  313. font-size: 16px;
  314. color: #ffffff;
  315. align-items: center;
  316. justify-content: space-between;
  317. width: 100%;
  318. height: 50px;
  319. padding: 0 20px;
  320. font-weight: 700;
  321. border-radius: 50px;
  322. background: #1D9BF0;
  323. &.disable {
  324. background: #CDCDCD;
  325. cursor: not-allowed;
  326. }
  327. .icon {
  328. width: 22px;
  329. margin-right: 5px;
  330. }
  331. }
  332. .sale {
  333. display: flex;
  334. justify-content: space-between;
  335. color: #868686;
  336. font-size: 12px;
  337. line-height: 14px;
  338. padding: 10px 0;
  339. letter-spacing: 0.3px;
  340. }
  341. }
  342. .login {
  343. box-sizing: border-box;
  344. padding: 38px 16px;
  345. width: 100%;
  346. .title {
  347. font-size: 16px;
  348. font-weight: 500;
  349. margin-bottom: 20px;
  350. }
  351. .btn {
  352. position: relative;
  353. display: flex;
  354. align-items: center;
  355. justify-content: center;
  356. height: 50px;
  357. border-radius: 50px;
  358. background: #1D9BF0;
  359. .text {
  360. font-size: 18px;
  361. font-weight: 700;
  362. color: #ffffff;
  363. }
  364. }
  365. }
  366. </style>