123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519 |
- <template>
- <div class="page">
- <template v-if="data === null">
- <img class="loading" src="../static/svg/icon-loading.svg" />
- </template>
- <template v-else>
- <div class="swipe" v-if="curItem">
- <div class="show">
- <img :src="curItem.imagePath" />
- </div>
- <div class="list">
- <div class="item" :class="{ on: curItem.nftItemId === item.nftItemId }" :key="index" @click="select(item)" v-for="(item, index) in listData">
- <img :src="item.imagePath" />
- </div>
- </div>
- </div>
- <div class="desc line" v-if="nftMetaData.description">
- <div class="title">Description</div>
- <div class="desc-content" v-html="nftMetaData.description"></div>
- </div>
- <div class="prop line" v-if="nftMetaData.properties && nftMetaData.properties.length">
- <div class="title">Properties</div>
- <div class="prop-content">
- <div class="prop-item" v-for="(filedValueItem, filedValueIndex) in nftMetaData.properties" :key="filedValueIndex">
- {{ filedValueItem.name }}
- <div class="prop-name">
- {{ filedValueItem.value }}
- </div>
- {{ filedValueItem.description }}
- </div>
- </div>
- </div>
- <div class="about line" v-if="nftMetaData.about">
- <div class="title">About</div>
- <div class="about-content" v-html="nftMetaData.about"></div>
- </div>
- <div style="height: 150px"></div>
- <div class="buy">
- <div class="random">
- <img src="../static/img/icon_nft_random.png" />
- <span>Randomly Get Different Styles of NFTs</span>
- </div>
- <template v-if="data.salePlans.length">
- <div v-for="(item, index) in data.salePlans" :key="index">
- <template v-if="item.itemCount == 1">
- <template v-if="purchaseStatus !== 0">
- <div class="btn" :class="{ disable: !(data.perUserBuyLimit - data.userBuyCount >= 1 && data.itemTotalCount - data.itemSoldCount >= 1) }" @click="goBuy(data.perUserBuyLimit - data.userBuyCount >= 1 && data.itemTotalCount - data.itemSoldCount >= 1)">
- <div class="l">BUY {{ item.itemCount }}</div>
- <FontZoom width="210">
- <template v-if="item.currencyCode !== 'USD'">
- <template v-if="item.price.length + item.currencyInfo.tokenSymbol.length >= 30">
- <div class="tr">
- <div><img class="icon" :src="item.currencyInfo.iconPath" /> {{ item.price | floatPrice(4) }}</div>
- <div>{{ item.currencyInfo.tokenSymbol }} (${{ item.usdPrice | floatPrice(2) }})</div>
- </div>
- </template>
- <template v-else> <img class="icon" :src="item.currencyInfo.iconPath" /> {{ item.price | floatPrice(4) }} {{ item.currencyInfo.tokenSymbol }} (${{ item.usdPrice | floatPrice(2) }}) </template>
- </template>
- <template v-else> ${{ item.usdPrice | floatPrice(2) }} </template>
- </FontZoom>
- </div>
- </template>
- <template v-else>
- <div class="btn disable">
- <div class="l">BUY {{ item.itemCount }}</div>
- <FontZoom width="210">
- <template v-if="item.currencyCode !== 'USD'"> <img class="icon" :src="item.currencyInfo.iconPath" /> {{ item.price | floatPrice(4) }} {{ item.currencyInfo.tokenSymbol }} (${{ item.usdPrice | floatPrice(2) }}) </template>
- <template v-else> ${{ item.usdPrice | floatPrice(2) }} </template>
- </FontZoom>
- </div>
- </template>
- </template>
- </div>
- </template>
- <template v-else>
- <template v-if="purchaseStatus !== 0">
- <div class="btn" @click="goBuy()">BUY 1</div>
- </template>
- <template v-else>
- <div class="btn disable">BUY 1</div>
- </template>
- </template>
- <div class="sale">
- <div class="l">SOLD: {{ data.itemSoldCount || 0 }}/{{ data.itemTotalCount }}</div>
- <div class="r" v-if="data.perUserBuyLimit < data.itemTotalCount">Buy Limit: {{ data.userBuyCount || 0 }}/{{ data.perUserBuyLimit }}</div>
- </div>
- </div>
- </template>
- <van-popup round v-model="loginLayer" position="bottom">
- <div class="login">
- <div class="title">In order to purchase the NFT, you need to</div>
- <div class="btn" @click="login">
- <button-login @success="loginSuccess" @error="loginError"> </button-login>
- <div class="text">Login Twitter</div>
- </div>
- </div>
- </van-popup>
- <!-- loading -->
- <div class="loginLoading" v-if="loading">
- <van-loading color="#1D9BF0"></van-loading>
- </div>
- <div class="loginLoadingBg" v-if="loading"></div>
- </div>
- </template>
- <script>
- import Api from '../http/api';
- import FontZoom from './FontZoom';
- import ButtonLogin from './buttonLogin';
- import Report from './../log-center/log';
- import { Toast } from 'vant';
- import { postRequest } from '../http';
- import { getStorage, storageKey } from '../utils/help';
- export default {
- name: 'mobileBuyNft',
- components: {
- FontZoom,
- ButtonLogin,
- },
- data() {
- return {
- data: null,
- curItem: null,
- listData: [],
- nftMetaData: {},
- loading: false,
- loginLayer: false,
- };
- },
- props: {
- purchaseStatus: {
- type: Number,
- default: 0,
- },
- },
- filters: {
- floatPrice(price, num) {
- if (price.indexOf('.') >= 0) {
- let reg = new RegExp(`^\\D*(\\d*(?:\\.\\d{0,${num}})?).*$`, 'g');
- price = price.replace(reg, '$1');
- }
- return price;
- },
- },
- created() {
- this.getSaleInfo();
- // report
- Report.log({
- pageSource: Report.pageSource.nftPurchasePage,
- params: {
- eventData: {
- businessType: Report.businessType.pageView,
- },
- extParams: {
- userAgent: window.navigator.userAgent,
- },
- },
- });
- },
- methods: {
- select(item) {
- this.curItem = item;
- this.nftMetaData = JSON.parse(item['metadata']);
- },
- getSaleInfo() {
- postRequest(Api.getNftMysteryBoxSaleInfo, {
- params: {
- nftProjectId: this.$route.params.id,
- },
- }).then((res) => {
- let { code, data } = res;
- if (code === 0) {
- this.data = data;
- this.listData = data.showItems;
- this.curItem = data.showItems[0];
- this.nftMetaData = JSON.parse(data.showItems[0]['metadata']);
- // set title
- document.title = data['nftProjectName'] + ` NFT`;
- }
- });
- },
- goBuy(isNext = true) {
- if (isNext === false) return;
- let userInfo = getStorage(storageKey.userInfo);
- if (userInfo) {
- this.loginSuccess(userInfo, false);
- } else {
- this.loginLayer = true;
- // report
- Report.log({
- pageSource: Report.pageSource.nftLoginPage,
- params: {
- eventData: {
- businessType: Report.businessType.pageView,
- },
- extParams: {
- userAgent: window.navigator.userAgent,
- },
- },
- });
- }
- // report
- Report.log({
- pageSource: Report.pageSource.nftPurchasePage,
- params: {
- eventData: {
- businessType: Report.businessType.buttonClick,
- objectType: Report.objectType.buyNftButton,
- },
- extParams: {
- userAgent: window.navigator.userAgent,
- },
- },
- });
- },
- login() {
- this.loading = true;
- Report.log({
- pageSource: Report.pageSource.nftLoginPage,
- params: {
- eventData: {
- businessType: Report.businessType.buttonClick,
- objectType: Report.objectType.loginTwitterButton,
- },
- extParams: {
- userAgent: window.navigator.userAgent,
- },
- },
- });
- },
- loginSuccess(userInfo, isReport = true) {
- this.$router.push({
- name: 'Payment',
- query: {
- nftProjectId: this.$route.params.id,
- account: this.$route.params.account,
- },
- });
- if (isReport) {
- Report.log({
- pageSource: Report.pageSource.nftLoginPage,
- params: {
- eventData: {
- businessType: Report.businessType.buttonClick,
- objectType: Report.objectType.loginTwitterButton,
- },
- extParams: {
- 'login-result': 'sucess',
- userAgent: window.navigator.userAgent,
- },
- },
- });
- }
- },
- loginError() {
- Toast('login fail');
- this.loading = false;
- Report.log({
- pageSource: Report.pageSource.nftLoginPage,
- params: {
- eventData: {
- businessType: Report.businessType.buttonClick,
- objectType: Report.objectType.loginTwitterButton,
- },
- extParams: {
- 'login-result': 'fail',
- userAgent: window.navigator.userAgent,
- },
- },
- });
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .page {
- width: 100%;
- height: 100%;
- background-color: #fff;
- .loading {
- position: absolute;
- transform: translate(-50%, -50%);
- top: 50%;
- left: 50%;
- margin: auto;
- width: 40px;
- border-radius: 50%;
- }
- }
- .swipe {
- .show {
- overflow: hidden;
- width: 18rem;
- height: 18rem;
- margin: 1rem auto;
- border-radius: 6px;
- background-color: #efefef;
- img {
- width: 100%;
- height: 100%;
- }
- }
- .list {
- height: 64px;
- margin: 0 16px;
- font-size: 0;
- overflow-x: auto;
- white-space: nowrap;
- &::-webkit-scrollbar {
- display: none;
- }
- .item {
- display: inline-block;
- overflow: hidden;
- opacity: 0.2;
- width: 58px;
- height: 58px;
- margin: 0 3px;
- border-radius: 4px;
- background-color: #efefef;
- img {
- width: 100%;
- height: 100%;
- }
- &:first-child {
- margin-left: 0;
- }
- &:last-child {
- margin-right: 0;
- }
- &.on {
- opacity: 1;
- }
- }
- }
- }
- .line {
- border: 1px solid #e3e3e3;
- border-radius: 10px;
- padding: 14px;
- margin: 0 16px 12px 16px;
- box-sizing: border-box;
- .title {
- font-weight: 600;
- font-size: 14px;
- }
- }
- .desc {
- margin-top: 10px;
- .desc-content {
- font-weight: 500;
- font-size: 14px;
- color: #929292;
- span {
- color: #1d9bf0;
- }
- }
- }
- .prop {
- .prop-content {
- display: flex;
- flex-wrap: wrap;
- margin-top: 12px;
- .prop-item {
- width: 48%;
- min-height: 88px;
- background: #f8f8f8;
- border-radius: 10px;
- display: flex;
- flex-direction: column;
- justify-content: center;
- padding: 8px;
- box-sizing: border-box;
- align-items: center;
- font-weight: 500;
- font-size: 12px;
- color: #929292;
- margin-bottom: 10px;
- .prop-name {
- font-weight: 700;
- font-size: 17px;
- margin-top: 6px;
- margin-bottom: 8px;
- color: #000;
- word-break: break-all;
- }
- }
- .prop-item:nth-child(odd) {
- margin-right: 8px;
- }
- }
- }
- .about-content {
- margin-top: 22px;
- .section {
- font-weight: 400;
- font-size: 14px;
- margin-bottom: 20px;
- }
- }
- .buy {
- position: fixed;
- left: 0;
- bottom: 0;
- width: 100%;
- box-sizing: border-box;
- background-color: #fff;
- padding: 10px 16px 25px 16px;
- border-top: solid 1px #e3e3e3;
- .random {
- color: #8c7d43;
- font-size: 14px;
- height: 30px;
- img {
- width: 20px;
- height: 20px;
- vertical-align: middle;
- }
- }
- .btn {
- display: flex;
- font-size: 16px;
- color: #ffffff;
- align-items: center;
- justify-content: space-between;
- width: 100%;
- height: 50px;
- padding: 0 14px;
- font-weight: 700;
- border-radius: 50px;
- background: #1d9bf0;
- &.disable {
- background: #cdcdcd;
- cursor: not-allowed;
- }
- .icon {
- width: 22px;
- margin-right: 5px;
- }
- .l {
- white-space: nowrap;
- }
- }
- .sale {
- display: flex;
- justify-content: space-between;
- color: #868686;
- font-size: 12px;
- line-height: 14px;
- padding: 10px 0;
- letter-spacing: 0.3px;
- }
- .tr {
- text-align: right;
- }
- }
- .login {
- box-sizing: border-box;
- padding: 38px 16px;
- width: 100%;
- .title {
- font-size: 16px;
- font-weight: 500;
- margin-bottom: 20px;
- }
- .btn {
- position: relative;
- display: flex;
- align-items: center;
- justify-content: center;
- height: 50px;
- border-radius: 50px;
- background: #1d9bf0;
- .text {
- font-size: 18px;
- font-weight: 700;
- color: #ffffff;
- }
- }
- }
- .loginLoading {
- position: absolute;
- z-index: 9991;
- display: flex;
- align-items: center;
- justify-content: center;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- }
- .loginLoadingBg {
- position: absolute;
- z-index: 9990;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- background-color: rgba($color: #000, $alpha: 0.1);
- }
- </style>
|