<template>
    <div class="container">
        <img class="topBox" src="../assets/矩形@3x (1).png" alt="" />

        <div class="top center-content">
            <div class="title1">嗨! 我们是第九空间</div>
            <div class="title2">全球领先的游戏数字藏品NFT集结地</div>
            <div class="btnCon" @click="$router.push('/collection')"><span>立即探索</span></div>
        </div>

        <!-- <swiper class="mySwiper el-image" ref="mySwiper" :options="swiperOptions">
                <swiper-slide>
                    <el-image :src="getImg(banners[0].pic, '', 800)" />
                </swiper-slide>
            </swiper> -->
        <img class="title-img" :src="titleImg" alt="" style="object-fit: cover" />

        <div class="hot1">铸造者</div>
        <div class="introduce center-content">
            <router-link
                class="introduce2"
                :class="{ active: index === showCreator }"
                v-for="(item, index) in creators"
                :key="item.id"
                :to="{
                    path: '/castingDetail',
                    query: {
                        id: item.id
                    }
                }"
            >
                <div
                    class="introduce-content"
                    @mouseenter="(showCreator = index), (initChange = false)"
                    @mouseleave="initChange = true"
                >
                    <el-image class="img1" :src="item.avatar" fit="cover" />
                    <div class="">
                        <div class="name">本期推荐：{{ item.nickname }}</div>
                        <div class="name name1">作者简介</div>
                        <div class="name2">
                            {{ item.intro || '该作者什么都没留下～' }}
                        </div>
                    </div>
                </div>
            </router-link>
        </div>
        <more-title path="/Casting"></more-title>
        <div class="content">
            <div class="center-content">
                <div class="hot">最HOT收藏品</div>
                <div class="list">
                    <collection-info
                        v-for="(item, index) in products"
                        :key="index"
                        :info.sync="products[index]"
                    ></collection-info>
                </div>
                <more-title path="/collection"></more-title>
            </div>
        </div>
        <div class="content1 center-content">
            <div class="hot">官方活动</div>
            <swiper class="mySwiper" ref="mySwiper" :options="swiperOptions">
                <swiper-slide v-for="(item, index) in bannersList" :key="index">
                    <el-image @click="goNext(item)" :src="item.pic" fit="cover" :lazy="true"></el-image>
                </swiper-slide>
            </swiper>
            <more-title path="/collection"></more-title>
            <div class="describe">
                <div class="box">
                    <div class="box1">
                        <div class="text1">发现</div>
                        <div class="text2">和你一起探索，全球最有才华的开发者铸造开创性NFT数字游戏藏品</div>
                    </div>
                </div>
                <div class="box">
                    <div class="box1">
                        <div class="text1">交易</div>
                        <div class="text2">方便快捷-无需数字钱包，人民币支付即可购买和出售游戏资产收藏品</div>
                    </div>
                </div>
            </div>
            <div class="describe">
                <div class="box">
                    <div class="box1">
                        <div class="text1">收集</div>
                        <div class="text2">用稀有和独特的数字宝藏增加库存，成为全球首批游戏数字资产收藏家</div>
                    </div>
                </div>
                <div class="box">
                    <div class="box1">
                        <div class="text1">使命</div>
                        <div class="text2">
                            让每个游戏资产都能获得“电子身份证”，让每位收藏家都能获得区块链“数字指纹”
                        </div>
                    </div>
                </div>
            </div>
            <div class="space">为什么叫第九空间</div>
            <div class="space2">
                一切数据皆可复制的时代，第九空间NFT让你拥有一份独家数字藏品，让你拥有一份唯一游戏权益
            </div>
            <div class="th">
                <div>
                    <div class="words1">我们始终坚信</div>
                    <div class="words2">未来的虚拟世界将演变成同具价值的数字世界</div>
                </div>
                <div class="border"></div>
                <div>
                    <div class="words1">我们非常确定</div>
                    <div class="words2">我们能让你更容易创造和体验未来的数字世界</div>
                </div>
                <div class="border"></div>
                <div>
                    <div class="words1">我们不会放弃</div>
                    <div class="words2">与收藏夹们共建链上游戏生态的数字现实时间</div>
                </div>
                <div class="border"></div>
                <div class="word-item">
                    <div class="words1 words3">此为，第九空间</div>
                    <more-title>了解更多</more-title>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import CollectionInfo from '../components/CollectionInfo.vue';
import MoreTitle from '../components/MoreTitle.vue';
import pageableTable from '@/mixins/pageableTable';
import { Swiper, SwiperSlide } from 'vue-awesome-swiper';
import 'swiper/css/swiper.css';
export default {
    components: { CollectionInfo, MoreTitle, Swiper, SwiperSlide },
    mixins: [pageableTable],
    data() {
        return {
            creators: [],
            showCreator: 3,
            initChange: true,
            timer: null,
            products: [],
            banners: [],
            bannersList: [],
            swiperOptions: {
                slidesPerView: 2,
                spaceBetween: 20,
                autoplay: true
            },
            active: '',
            show: false,
            activeName: '',
            lists: ''
        };
    },
    computed: {
        titleImg() {
            return this.getImg((this.banners[0] || {}).pic, '', 1800);
        }
    },
    mounted() {
        this.getCreators();
        this.getProduct('DEFAULT', 'likes,desc;sort,desc;createdAt,desc').then(res => {
            this.products = res;
        });
        this.$http
            .post(
                '/banner/all',
                {
                    query: {
                        type: 'PC_ACT'
                    },
                    sort: 'createdAt,desc'
                },
                { body: 'json' }
            )
            .then(res => {
                this.bannersList = res.content;
            });
        this.$http
            .post(
                '/banner/all',
                {
                    query: {
                        del: false,
                        type: 'PC_TITLE'
                    }
                },
                { body: 'json' }
            )
            .then(res => {
                // console.log(res);
                this.banners = res.content;
            });
    },
    methods: {
        getCreators() {
            this.$http
                .post(
                    '/user/all',
                    {
                        page: 0,
                        query: { hasRole: 'ROLE_MINTER' },
                        size: 4,
                        sort: 'sales,desc'
                    },
                    { body: 'json' }
                )
                .then(res => {
                    this.creators = res.content;
                    this.showCreator = res.content.length - 1;
                    if (res.content.length == 4) {
                        this.autoChange();
                    }
                });
        },
        autoChange() {
            if (this.timer) {
                clearTimeout(this.timer);
            }
            if (!this.initChange) {
                return;
            }
            this.showCreator = (this.showCreator + 1) % this.creators.length;
            this.timer = setTimeout(this.autoChange, 3000);
        },
        getProduct(type = '', sort = 'sort,desc') {
            return this.$http
                .post(
                    '/collection/all',
                    {
                        page: 0,
                        size: 4,
                        query: {
                            type: type,
                            onShelf: true,
                            del: false,
                            source: 'OFFICIAL'
                        },
                        sort: sort
                    },
                    { body: 'json' }
                )
                .then(res => {
                    return Promise.resolve(res.content);
                });
        },
        goNext(info) {
            if (info.link && info.linkType === 'collection') {
                this.$router.push(`/collectionDetail?id=${info.linkContent}`);
            }
        }
    },
    watch: {
        initChange() {
            if (this.initChange) {
                if (this.timer) {
                    clearTimeout(this.timer);
                }
                this.timer = setTimeout(this.autoChange, 3000);
            }
        }
    }
};
</script>
<style lang="less" scoped>
.topBox {
    width: 100%;
    height: 460px;
}
.container {
    position: relative;
    .title-img {
        width: 55%;
        height: 460px;
        display: inline-block;
        position: absolute;
        top: 0;
        right: 0px;
    }

    .top {
        position: absolute;
        width: 100%;
        top: 0;
        left: 0;
        right: 0;
        z-index: 88;
        // justify-content: space-between;

        .title {
            height: 42px;
            font-size: 32px;
            font-weight: 400;
            color: #ffffff;
            line-height: 42px;
            font-family: ZhenyanGB-Regular, ZhenyanGB;
            padding: 130px 0 25px 10px;
        }
        .title1 {
            line-height: 47px;
            font-size: 46px;
            font-weight: 400;
            color: #ffffff;
            font-family: ZhenyanGB-Regular, ZhenyanGB;
            padding: 130px 0 25px 10px;
        }
        .title2 {
            font-size: 20px;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #ffffff;
            padding-left: 10px;
        }
        .btnCon {
            line-height: 44px;
            text-align: center;
            background: transparent;
            margin: 60px 0 0 10px;
            font-size: 20px;
            width: 136px;
            cursor: pointer;
            height: 44px;
            border: 1px solid;
            border-radius: 8px;
            color: #fdfb60;
            border-image: linear-gradient(135deg, rgba(253, 251, 96, 1), rgba(255, 143, 62, 1)) 1 1;
        }
    }
}
.introduce {
    display: flex;
    align-items: center;
    // justify-content: space-between;

    .introduce-content {
        display: inline-flex;
        align-items: center;
        height: 178px;
        width: 220px;
        cursor: pointer;
        overflow: hidden;
        transition: width ease-in-out 0.3s;
        .img1 {
            width: 220px;
            height: 180px;
            border-radius: 8px;
            margin-right: 16px;
            flex-shrink: 0;
            transition: width ease-in-out 0.3s;
        }
        .name {
            font-size: 16px;
            font-weight: bold;
            color: #ffffff;
            line-height: 24px;
            &.name1 {
                margin: 10px 0 4px 0;
            }
        }
        .name2 {
            font-size: 14px;
            font-weight: 400;
            color: #939599;
            line-height: 20px;
            width: 254px;
            height: 100px;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    }
    .introduce2 {
        &.active {
            .introduce-content {
                width: 460px;
                .img1 {
                    width: 180px;
                }
            }
        }
    }
    .introduce2 + .introduce2 {
        margin-left: 30px;
    }

    .active + .introduce2 {
        margin-left: 20px;
    }
}
.hot1 {
    font-size: 24px;
    text-align: center;
    font-weight: 400;
    color: #ffffff;
    line-height: 34px;
    font-family: ZhenyanGB-Regular, ZhenyanGB;
    padding: 80px 0 40px;
}
.content {
    background: #0f1111;
    .hot {
        font-size: 24px;
        text-align: center;
        font-weight: 400;
        color: #ffffff;
        line-height: 34px;
        font-family: ZhenyanGB-Regular, ZhenyanGB;
        padding: 100px 0 50px;
    }
    .all {
        display: flex;
        align-content: center;
        justify-content: center;
        padding-bottom: 40px;
        &.all1 {
            margin-top: 40px;
        }
        .img1 {
            width: 32px;
            height: 24px;
        }
        .name {
            font-size: 16px;
            font-weight: 400;
            color: #ffffff;
            line-height: 24px;
            margin: 0 10px;
            cursor: pointer;
        }

        &:hover {
            .name {
                animation-name: jello;
            }
        }
    }
}
.content1 {
    .hot {
        font-size: 24px;
        text-align: center;
        font-weight: 400;
        color: #ffffff;
        line-height: 34px;
        padding: 60px 0 50px;
        font-family: ZhenyanGB-Regular, ZhenyanGB;
    }
    .imgBox {
        display: flex;
        align-items: center;
        justify-content: space-between;
        .imgBox1 {
            width: 585px;
            height: 260px;
            border-radius: 8px;
        }
    }
    .all {
        display: flex;
        align-content: center;
        justify-content: center;
        margin: 40px 0 60px;
        &.all1 {
            margin: 0;
        }
        .img1 {
            width: 32px;
            height: 24px;
        }
        .name {
            font-size: 16px;
            font-weight: 400;
            color: #ffffff;
            line-height: 24px;
            margin: 0 10px;
        }
    }
    .describe {
        display: flex;
        align-items: center;
        justify-content: space-between;
        .box {
            .line();
            width: 580px;
            height: 114px;
            border: 1px solid;
            margin-bottom: 30px;
            cursor: inherit;
            .box1 {
                margin: 30px 0 0 40px;
                .text1 {
                    font-size: 18px;
                    font-weight: bold;
                    color: #ffffff;
                    line-height: 24px;
                    margin-bottom: 6px;
                }
                .text2 {
                    font-size: 14px;
                    font-weight: 400;
                    color: #939599;
                    line-height: 24px;
                }
            }
        }
    }
    .space {
        height: 34px;
        font-size: 24px;
        text-align: center;
        margin: 100px 0 8px;
        font-weight: 400;
        color: #ffffff;
        font-family: ZhenyanGB-Regular, ZhenyanGB;
        line-height: 34px;
    }
    .space2 {
        font-size: 16px;
        font-weight: 400;
        text-align: center;
        color: #939599;
        line-height: 24px;
        margin-bottom: 30px;
    }
    .th {
        display: flex;
        justify-content: space-between;
        background: #131414;
        border-radius: 8px;
        height: 175px;
        align-items: center;
        padding: 0 50px;
        margin-bottom: 70px;
        .border {
            width: 1px;
            height: 115px;
            background: #494a4d;
        }
        .words1 {
            font-size: 18px;
            font-weight: 400;
            color: #ffffff;
            line-height: 25px;
            // margin: 12px 0;
            &.words3 {
                text-align: center;
            }
        }
        .words2 {
            width: 240px;
            font-size: 16px;
            font-weight: 400;
            color: #939599;
            line-height: 24px;
            margin-top: 12px;
        }
        .th2 {
            display: flex;
            align-content: center;
            .img1 {
                width: 32px;
                height: 24px;
            }
            .name {
                font-size: 16px;
                font-weight: 400;
                color: #ffffff;
                line-height: 24px;
                margin: 0 10px;
            }
        }
    }
}

.list {
    margin: -16px;
    .collect {
        margin: 16px;
    }
}
.word-item {
    .more {
        padding: 0;
    }
}

.mySwiper {
    .el-image {
        width: 100%;
        height: 260px;
        border-radius: 8px;
        cursor: pointer;
    }
}
</style>
