<template>
    <div class="width-100 bannerImg wow animated fadeInUp" :class="selectIndex == 1 ? 'bannerImg1' : ''">
        <!-- 服务 -->
        <div v-if="selectIndex == 1">
            <div class="servicebg">
                <div class="gallery-container">
                    <div class="gallery">
                        <div class="gallery-item position-relative" v-for="item, index in servicelist" :key="index"
                            @click="index == 1 ? '' : goPage('/service', index > 1 ? index - 1 : index, 'service')">
                            <span class="position-absolute" :class="index == 1 ? 'imgtitle1' : 'imgtitle'">
                                <p class="title">{{ item.title }}</p>
                            </span>
                            <img :src="item.detail" :alt="item.title" loading="lazy" />
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- 新闻 -->
        <swiper :modules="modules" :slides-per-view="per1" :space-between="50" :loop="true" :navigation="true"
            class="service-img" v-else>
            <!-- <swiper-slide v-for="item, index in newslist" :key="index" class="hover-scale"
                @click="goPage1(`/news/${item.title}`)"> -->
            <swiper-slide v-for="item, index in newslist" :key="index" class="hover-scale">
                <div class="case" @click="goPage1(`/news/${item.position}`)">
                    <div class="case-img overflow-hidden position-relative">
                        <img :src="item.detail" :alt="item.title" class="width-100 d-block position-relative"
                            loading="lazy">
                    </div>
                    <div class="project-center-title1">
                        <p class="font-size-12 newsdate">2023-08-17</p>
                        <span class="newstitle font-size-28">{{ item.title }}</span>
                        <p class="font-size-14 newsdate">

                        </p>
                    </div>
                </div>
            </swiper-slide>
        </swiper>
    </div>
</template>

<script setup lang="ts">
import { Pagination, Navigation, Scrollbar, A11y } from 'swiper'
import { Swiper, SwiperSlide } from 'swiper/vue';
import 'swiper/css';

import { ref, onMounted } from 'vue'
import router from '../router';

let modules = [Navigation, Pagination, Scrollbar, A11y]
let per1 = ref<any>(2)
const props = defineProps(['index'])

let selectIndex = props.index

let newslist = ref<any>([
    { detail: new URL("../assets/img/information.jpg", import.meta.url).href, title: 'What can we do for you?', position: 0 },
    { detail: new URL("../assets/img/page02.jpg", import.meta.url).href, title: 'Growth History of MONTIER', position: 1 }
])

let servicelist = ref<any>([
    { detail: new URL('../assets/img/Design.jpg', import.meta.url).href, title: 'Design' },
    { detail: new URL('../assets/img/Service.jpg', import.meta.url).href, title: 'Service' },
    { detail: new URL('../assets/img/After-saleService.jpg', import.meta.url).href, title: 'After -sale Service' },
    { detail: new URL('../assets/img/Manufactrue.jpg', import.meta.url).href, title: 'Manufactrue' },
    { detail: new URL('../assets/img/Installation.jpg', import.meta.url).href, title: 'Installation' },
    { detail: new URL('../assets/img/Quality.jpg', import.meta.url).href, title: 'Quality' },
    { detail: new URL('../assets/img/Logistics.jpg', import.meta.url).href, title: 'Logistics' },
])

const goPage = (url: any, index: any, name: string) => {
    localStorage.setItem('scrollPosition', name)
    document.documentElement.scrollTop = 0
    router.push({
        path: url,
        query: {
            index: index
        }
    })
}
const goPage1 = (url: any) => {
    document.documentElement.scrollTop = 0
    router.push({
        path: url
    })
}

onMounted(() => {
    if (document.body.offsetWidth < 960) {
        per1.value = 1
    } else if (newslist.value.length < 3) {
        per1.value = newslist.value.length
    } else {
        per1.value = 3
    }
    window.addEventListener('resize', function () {
        if (document.body.offsetWidth < 960) {
            per1.value = 1
        } else if (newslist.value.length < 3) {
            per1.value = newslist.value.length
        } else {
            per1.value = 3
        }
    })
})


</script>

<style scoped lang="less">
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
.gallery-container {
    margin: 25rem 0;
    display: grid;
    place-content: center;
    margin-right: 25%;
}

.gallery {
    // --s: 20vw;
    scale: 1.25;
    /* control the size */
    --g: -2px;
    /* control the gap */
    display: grid;

    .gallery-item {
        // position: relative;
        overflow: hidden;
        background: #ffffff;
        display: flex;
        align-items: center;
        justify-content: center;

        .imgtitle1 {
            display: none;
        }

        .imgtitle {
            z-index: 999;
            height: 25%;
            clip-path: polygon(0% 0%, 100% 0%, 82% 100%, 18% 100%);
            width: 70%;
            background: rgba(0, 0, 0, 0.3);
            bottom: 5%;
            color: #fff;
            font-weight: bold;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 18px;
            transition: 0.5s linear;

            .title {
                -webkit-box-reflect: below -5px -webkit-linear-gradient(transparent 40%, #fff 100%);
                overflow: hidden;
            }
        }

        img {
            clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0 50%);
            width: 90%;
            height: 90%;
            transition: 0.5s linear;
        }

        // img:hover{
        //     transform: scale(1.2);
        // }
        .imgtitle:hover {
            bottom: 0;
            transform: scale(1.2);
            background: orange;
        }

        .imgtitle:hover+img {
            transform: scale(1.2);
        }
    }
}

.gallery>div {
    grid-area: 1/1;
    /* 规定从第一行第一列开始显示项目 */
    // width: var(--s);
    aspect-ratio: 1.15;
    /* 宽高比例缩放 */
    object-fit: cover;
    /* 保持图片原有比例, 会有剪切*/
    clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0 50%);
    transform: translate(var(--_x, 0), var(--_y, 0)) scale(var(--_t, 1));
    /* 对图片进行移动和缩放 */
    cursor: pointer;
    /* 灰度滤镜 */
    // transition: 0.2s linear;
    /* 过渡效果 */
}


.gallery>div:nth-child(1) {
    --_y: calc(-100% - var(--g));
}

.gallery>div:nth-child(7) {
    --_y: calc(100% + var(--g));
}

.gallery>div:nth-child(3),
.gallery>div:nth-child(5) {
    --_x: calc(-75% - 0.87 * var(--g));
}

.gallery>div:nth-child(4),
.gallery>div:nth-child(6) {
    --_x: calc(75% + 0.87 * var(--g));
}

.gallery>div:nth-child(3),
.gallery>div:nth-child(4) {
    --_y: calc(-50% - 0.5 * var(--g));
}

.gallery>div:nth-child(5),
.gallery>div:nth-child(6) {
    --_y: calc(50% + 0.5 * var(--g));
}

.service-img {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    // padding: 0 20px;
}

.hover-scale {
    .case {
        width: 70%;
        position: relative;
        left: 50%;
        transform: translateX(-50%);

        .case-img {
            cursor: pointer;

            img {
                width: 100%;
                height: 100%;
                transition: all 1s;
            }
        }
    }

    .project-center-title1 {
        .newstitle {
            transition: all 0.5s;
        }
    }
}

.hover-scale:hover .case-img img {
    transform: scale(1.1);
}

.hover-scale:hover .project-center-title1 .newstitle {
    color: #F56C6C;
}


.project-center-title {
    bottom: 0;
    left: 0;
    text-align: center;
    background: rgba(0, 0, 0, 0.5);
    width: 100%;
    padding: 10px 5px;
}

.project-center-title1 {
    cursor: pointer;
    width: 100%;
    padding: 10px 5px;

    .newsdate {
        color: #999;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        display: -moz-box;
        -moz-line-clamp: 2;
        -moz-box-orient: vertical;
        word-wrap: break-word;
        word-break: break-all;
        white-space: normal;
    }

    .newstitle {
        margin: 10px 0;
        color: #333333;
    }
}

// :deep(.swiper-button-prev:after) {
//     display: none;
// }

// :deep(.swiper-button-next:after) {
//     display: none;
// }

/*自定义样式*/
:deep(.swiper-button-prev) {
    background: rgba(0, 0, 0, 0.2);
    // color: transparent;
    // background: url('../assets/img/left.png') no-repeat;
    // background-size: 100%;
    // background-position: left;
    // width: 2vw;
}

:deep(.swiper-button-next) {
    background: rgba(0, 0, 0, 0.2);
    // color: transparent;
    // background: url('../assets/img/right.png') no-repeat;
    // background-size: 100%;
    // background-position: right;
    // width: 2vw;
}
.bannerImg1{
    width: 100% !important;
    background: url('../assets/img/servicebg.jpg') no-repeat;
    background-size: 150%;
    background-position: center;
}
.bannerImg {
    width: 80vw;
    margin: 0 auto 10px;

    :deep(.swiper-button-prev:after) {
        color: #fff;
        font-size: 30px;
    }

    :deep(.swiper-button-next:after) {
        color: #fff;
        font-size: 30px;
    }
}

@media screen and (max-width: 1000px) {
    .gallery-container {
        scale: 0.35;
        margin: 0 0 10vw 0;
    }

    .sww {
        width: 35vw;
        height: 35vw;

        img {
            width: 35vw;
            height: 35vw;
        }
    }

    .project-center-title {
        font-size: 8px;
        white-space: nowrap;
    }


    :deep(.swiper-button-prev:after) {
        display: inline-block;
    }

    :deep(.swiper-button-next:after) {
        display: inline-block;
    }

    :deep(.swiper-button-prev) {
        background: transparent;
        background-color: rgba(0, 0, 0, 0.5);
    }

    :deep(.swiper-button-next) {
        background: transparent;
        background-color: rgba(0, 0, 0, 0.5);
    }

    .bannerImg {
        margin-top: 50px;
        width: 100%;

        :deep(.swiper-button-prev) {
            width: 40px;
        }

        :deep(.swiper-button-next) {
            width: 40px;
        }
    }
}
</style>
