<template>
  <van-swipe class="my-swipe" :autoplay="5000" indicator-color="white">
    <template v-for="(item, index) in list">
      <van-swipe-item :key="index">
        <template v-if="item.uri">
          <a :href="item.uri" target="_blank">
            <img :src="item.web_img_uri" class="banner-img" />
          </a>
        </template>
        <template v-else>
          <img :src="item.web_img_uri" class="banner-img" />
        </template>
      </van-swipe-item>
    </template>
  </van-swipe>
</template>

<script>
export default {
  data() {
    return {
      list: []
    }
  },
  async fetch() {
    const params = { project_id: process.env.projectId, type_tag: 'ad_banner' }
    this.list = await this.$axios.get('/api/cms/api/v1/advertisements', { params }).then(res => {
      return res.data.data
    })
  }
}
</script>

<style lang="scss" scoped>
.banner-img {
  display: block;
  width: 100%;
  height: 1.51rem;
  object-fit: cover;
}
::v-deep .van-swipe__indicator {
  width: 2px;
  height: 2px;
  background-color: #fff;
  opacity: 1;
}
::v-deep .van-swipe__indicator--active {
  width: 10px;
  border-radius: 2px;
}
</style>
