<template>
    <swiper
        :style="{
            '--swiper-navigation-color': '#fff',
            '--swiper-pagination-color': '#fff'
        }"
        :speed="600"
        :parallax="true"
        :slidesPerView="'auto'"
        class="mySwiper"
        :class="{ horizontal: !isVertical, windowHorizontal: !windowVertical }"
        :direction="isVertical ? 'horizontal' : 'vertical'"
    >
        <div class="top"></div>
        <div class="bottom" @click="isVertical = !isVertical">
            <div class="btn">
                <img src="../assets/icon-qiehuanhengping.png" alt="" />
                <span>切换{{ isVertical || windowVertical ? '横屏' : '竖屏' }}</span>
            </div>
        </div>
        <div class="parallax-bg" data-swiper-parallax="-50%">
            <div
                class="parallax-bg-img"
                :style="{
                    'background-image': `url(${require('../assets/zhanguan-shu.jpg')})`
                }"
            ></div>
        </div>
        <swiper-slide class="user">
            <div class="icon" data-swiper-parallax="-300">
                <van-image
                    src="https://nanjingnft.oss-cn-hangzhou.aliyuncs.com/font/2022-02-07-01-15-56Liekxwjf.jpg"
                    :width="isVertical && windowVertical ? 110 : 120"
                    :height="isVertical && windowVertical ? 110 : 120"
                    fit="coevr"
                    radius="8"
                />
            </div>
            <div data-swiper-parallax="-200">
                <div class="name">
                    <div>奶盖</div>
                    <div>的展馆</div>
                </div>
            </div>
            <div class="sub-box" data-swiper-parallax="-100">
                <div class="sub">介绍一下展馆主题吧</div>
            </div>
        </swiper-slide>
        <swiper-slide class="imgs" v-for="i in 10" :key="i">
            <div class="icon" data-swiper-parallax="-20">
                <van-image
                    src="https://nanjingnft.oss-cn-hangzhou.aliyuncs.com/font/2022-02-07-01-15-56Liekxwjf.jpg"
                    :width="isVertical && windowVertical ? 110 : 120"
                    :height="isVertical && windowVertical ? 110 : 120"
                    fit="coevr"
                    radius="8"
                />
            </div>
            <div class="icon" data-swiper-parallax="-40">
                <van-image
                    src="https://nanjingnft.oss-cn-hangzhou.aliyuncs.com/font/2022-02-07-01-15-56Liekxwjf.jpg"
                    :width="isVertical && windowVertical ? 110 : 120"
                    :height="isVertical && windowVertical ? 110 : 120"
                    fit="coevr"
                    radius="8"
                />
            </div>
            <div class="icon" data-swiper-parallax="-100">
                <van-image
                    src="https://nanjingnft.oss-cn-hangzhou.aliyuncs.com/font/2022-02-07-01-15-56Liekxwjf.jpg"
                    :width="isVertical && windowVertical ? 110 : 120"
                    :height="isVertical && windowVertical ? 110 : 120"
                    fit="coevr"
                    radius="8"
                />
            </div>
            <div class="icon" data-swiper-parallax="-200">
                <van-image
                    src="https://nanjingnft.oss-cn-hangzhou.aliyuncs.com/font/2022-02-07-01-15-56Liekxwjf.jpg"
                    :width="isVertical && windowVertical ? 110 : 120"
                    :height="isVertical && windowVertical ? 110 : 120"
                    fit="coevr"
                    radius="8"
                />
            </div>
        </swiper-slide>
    </swiper>
</template>

<script>
import { Swiper, SwiperSlide } from 'swiper/vue';

import 'swiper/swiper.min.css';
import 'swiper/swiper-bundle.min.css';
// import required modules
import SwiperCore, { Pagination, Parallax, Navigation } from 'swiper';
SwiperCore.use([Pagination, Parallax, Navigation]);
import { watch, ref, computed } from 'vue';
import { useWindowSize } from '@vant/use';
export default {
    components: {
        Swiper,
        SwiperSlide
    },
    setup() {
        const { width, height } = useWindowSize();

        console.log(width.value); // -> 窗口宽度
        console.log(height.value); // -> 窗口高度

        const windowVertical = computed(() => {
            if (width.value > height.value) {
                return false;
            } else {
                return true;
            }
        });

        return { windowVertical };
    },
    data() {
        return {
            isVertical: true
        };
    }
};
</script>

<style lang="less" scoped>
.user {
    width: 128px;
    padding: 6.3vh 100px 0 30px;
    .icon {
        .van-image {
            transition: transform ease-in-out 0.3s;
        }
    }

    .name {
        font-size: 24px;
        font-weight: bold;
        color: #ffffff;
        line-height: 30px;
        padding-top: 6px;
    }
    .sub {
        padding-top: 20px;
        font-size: 12px;
        color: rgba(255, 255, 255, 0.6);
        line-height: 17px;
    }
}

.swiper {
    width: 100%;
    height: 100%;
    background: #000;
}

.parallax-bg {
    position: absolute;
    left: 0;
    top: 0;
    width: 500%;
    height: 100%;
    .parallax-bg-img {
        width: 100%;
        height: 100%;
        -webkit-background-size: contain;
        background-size: contain;
        transition: transform ease-in-out 0.3s;
    }
}

.imgs {
    width: 100vw;
    height: calc(25.2vh + 230px);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    .icon {
        padding: 6.3vh 0;
        img {
            width: 110px;
            height: 110px;
            display: block;
        }
        .van-image {
            transition: transform ease-in-out 0.3s;
        }
    }
}

.bottom {
    position: absolute;
    bottom: 120px;
    left: 30px;
    z-index: 20;
    .btn {
        transition: transform ease-in-out 0.3s;
    }
    img {
        width: 48px;
        height: 48px;
        display: block;
    }
    span {
        font-size: 12px;
        color: #ffffff;
        line-height: 17px;
        margin-top: 4px;
    }
}

.mySwiper {
    padding-top: 7.72vh;
}
/deep/.swiper-wrapper {
    height: calc(var(--app-height) - 7.72vh);
}

.windowHorizontal {
    padding-top: 7.72vw;
    .user {
        width: 298px;
        height: 120px;
        display: flex;
        flex-direction: row;
        position: relative;
        padding: 6.3vh 60px;

        .sub-box {
            position: absolute;
            bottom: 60px;
            left: 190px;
            .sub {
                padding-top: 0;
            }
        }
        .name {
            margin-left: 10px;
            padding-top: 0;
        }
    }
    .imgs {
        box-sizing: border-box;
        height: calc(12.6vh + 120px);
        .icon {
            padding: 6.3vh;
        }
    }

    /deep/.swiper-wrapper {
        height: calc(var(--app-height) - 7.72vw);
    }

    .bottom {
        bottom: 60px;
        left: 60px;
    }
}

.horizontal {
    padding-top: 0;
    padding-right: 7.72vh;
    .parallax-bg {
        width: 100%;
        height: 600%;
    }
    .parallax-bg-img {
        width: 600vh;
        height: 100vw;
        transform: rotate(90deg) translateX(-100vw);
        transform-origin: left bottom;
    }

    .imgs {
        width: calc(12.6vw + 120px);
        height: var(--app-height);
        box-sizing: border-box;
        .icon {
            padding: 6.3vw;
        }
    }

    .user {
        padding: 60px 6.3vw 0 30px;
        height: 298px;
        width: 120px;
        .van-image {
            transform: rotate(90deg);
        }
        .name {
            width: 168px;
            padding-top: 0;
            transform: rotate(90deg) translate(-50px, -50px);
            transform-origin: left bottom;
        }
        .sub {
            width: 168px;
            padding-top: 0;
            transform-origin: left bottom;
            transform: rotate(90deg) translate(-65px, 0px);
        }
    }

    .imgs {
        justify-content: space-around;
        .van-image {
            transform: rotate(90deg);
        }
    }

    /deep/.swiper-wrapper {
        height: var(--app-height);
        align-items: flex-end;
    }

    .bottom {
        top: 60px;
        left: 49px;
        .btn {
            transform: rotate(90deg) translateX(-10px);
        }
    }
    // .user {
    //     padding: calc(21vw - 110px) 100px 0 30px;
    // }
    // /deep/.swiper-wrapper {
    //     height: calc(100vw - 20vw);
    // }
    // &.mySwiper {
    //     padding-top: 20vw;
    // }
    // .imgs {
    //     height: 50vw;
    // }
}
</style>
