MobileBuyNft.vue 10 KB

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