<template>
    <div class="width-100 bannerImg">
        <swiper :modules="modules" :slides-per-View='per' :space-between="50" :loop="true" :navigation="true"
            class="service-img" v-if="selectIndex == 1">
            <swiper-slide v-for="item, index in servicelist" :key="index" class="hover-scale">
                <div>
                    <div class="case-img overflow-hidden position-relative sww" @click="goPage('/service',index)">
                        <img :src="item.detail" alt="information"
                            class="width-100 d-block position-relative">
                        <h3 class="position-absolute color-fff project-center-title">{{ item.title }}</h3>
                    </div>
                </div>
            </swiper-slide>
        </swiper>
        <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 servicelist" :key="index" class="hover-scale">
                <div>
                    <div class="case-img overflow-hidden position-relative">
                        <img src="../assets/img/information.jpg" alt="information"
                            class="width-100 d-block position-relative">
                    </div>
                    <div class="project-center-title1">
                        <div class="font-size-14 newsdate">2023-08-17</div>
                        <h2 class="newstitle">{{ item.title }}</h2>
                    </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 per = ref<any>(5)
let per1 = ref<any>(3)
const props = defineProps(['index'])

let selectIndex = props.index

let servicelist = ref<any>([
    { detail: new URL("../assets/img/page01.png", import.meta.url).href, title: 'Design' },
    { detail: new URL("../assets/img/page02.png", import.meta.url).href, title: 'Procurement & Manufacture' },
    { detail: new URL("../assets/img/page03.png", import.meta.url).href, title: 'Logistic and warehouseing' },
    { detail: new URL("../assets/img/page04.png", import.meta.url).href, title: 'Installation' },
    { detail: new URL("../assets/img/page05.png", import.meta.url).href, title: 'Quality Control' },
])

const goPage = (url: any, index: any) => {
    router.push({
        path: url,
        query: {
            index: index
        }
    })
}

onMounted(() => {
    if (document.body.offsetWidth < 1000) {
        per.value = 2
        per1.value = 1
    } else {
        per.value = 5
        per1.value = 3
    }
    window.addEventListener('resize', function () {
        if (document.body.offsetWidth < 1000) {
            per.value = 2
            per1.value = 1
        } else {
            per.value = 5
            per1.value = 3
        }
    })
})


</script>

<style scoped lang="less">
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.service-img {
    padding: 0 20px;
}

.hover-scale {
    .case-img {
        cursor: pointer;
        img {
            transition: all 0.5s;
        }
    }

}

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


.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;
    }
    .newstitle{
        color: #333333;
    }
}

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

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

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

:deep(.swiper-button-next) {
    color: transparent;
    background: url('../assets/img/right.png') no-repeat;
    background-size: 100%;
    background-position: right;
    width: 2vw;
}

.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 (max-width: 800px) {

    .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: 100vw;

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

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