<template>
  <div class="imgcon">
    <div class="swiper-container" :class="keyid" >
    <ul  class="swiper-wrapper imgul">
      <li  class="swiper-slide img" v-for="(pic, picii) in list" :key="picii" :style="{ backgroundImage: `url(${pic})` }"></li>
    </ul>
    <ul class="pagination">
      <li :class="{active:picii==current}" v-for="(pic, picii) in list" :key="picii"></li>
    </ul>
  </div>
  </div>
</template>

<script setup>
import { ref, watch, defineEmits, computed, onMounted, nextTick, defineProps } from "vue";

const current = ref(0)

const props = defineProps({
  list: {
    type: Array,
    default: [],
  },
  keyid:{
    type: String,
    default: 'keyid',
  }
});
const initScroll = () => {
  nextTick(() => {
    let t = setTimeout(() => {
      clearTimeout(t);
      new Swiper(`.${props.keyid}`, {
        on: {
          touchMove(swiper, e) {
            e.stopPropagation();
            e.preventDefault();
          },
          slideChange() {
            current.value = this.activeIndex;
          },
        },
      });
    }, 100);
  });
};

onMounted(() => {
  initScroll();
});
</script>

<style lang="scss" scoped>
.imgcon{
    min-height: 34vh;

.swiper-container {
  position: relative;
  .imgul {
    .img {
      height: 34vh;
      width: 100%;
      background-size: auto 100%;
      background-position: center;
    }
  }

  .pagination{
    position: absolute;
    left: 50%;
    bottom: 10px;
    transform: translateX(-50%);
    z-index: 99;
    >li{
      width: 8px;
      height: 8px;
      margin: 0 4px;
      display: inline-block;
      border-radius: 50%;
      background-color: rgba(0, 0, 0, 0.2);
      &.active{
      background-color: var(--editor-main-color);

      }
    }
  }
}
}
</style>
