<template>
  <div class="class-content">
    <div class="title-content">
      <div class="left-title">
        <div class="line"></div>
        <div class="text">{{ $t('home.case.title') }}</div>
      </div>
      <div class="right-text" @click="$router.push({ path: '/services/college', query: { type: '2' } })">
        {{ $t('viewMore') }}
      </div>
    </div>
    <div class="swiper-content" @mouseenter="swiperStop" @mouseleave="swiperStart">
      <div v-swiper:mySwiper="swiperOption" ref="mySwiper">
        <div class="swiper-wrapper">
          <div class="swiper-slide" v-for="(item, index) in listData" :key="index">
            <app-link :item="{ news: { data: item, path: '/about/news' } }">
              <img :src="item.web_img_uri" />
              <div class="pop-txt-box">{{ item.title }}</div>
            </app-link>
          </div>
        </div>
      </div>
      <div class="prev-button"></div>
      <div class="next-button"></div>
    </div>
  </div>
</template>
<script>
import appLink from '@/components/Link'
export default {
  components: {
    appLink
  },
  data() {
    return {
      listData: [],
      swiperOption: {
        speed: 400,
        // autoplay: true,
        delay: 3000,
        observer: true,
        loop: true,
        observerParent: true,
        autoHeight: true,
        navigation: {
          nextEl: '.next-button',
          prevEl: '.prev-button'
        }
      }
    }
  },
  async fetch() {
    const params = {
      project_id: process.env.projectId,
      type_tag: 'service_case'
    }
    this.listData = await this.$axios.get('/api/cms/api/v1/articles', { params }).then(res => {
      return res.data.data
    })
  },
  computed: {
    swiper() {
      return this.$refs.mySwiper.swiper
    }
  },
  methods: {
    swiperStop() {
      this.swiper.autoplay.stop()
    },
    swiperStart() {
      this.swiper.autoplay.start()
    }
  }
}
</script>
<style lang="scss" scoped>
.class-content {
  padding-top: 87px;
  width: 1200px;
  margin: 0 auto;
  .title-content {
    display: flex;
    .left-title {
      display: flex;
      .line {
        width: 6px;
        height: 34px;
        background: #aa1941;
      }
      .text {
        font-size: 34px;
        font-weight: bold;
        line-height: 34px;
        color: #424242;
        margin-left: 9px;
      }
    }
    .right-text {
      margin-left: auto;
      margin-top: 18px;
      font-size: 16px;
      font-weight: 300;
      line-height: 34px;
      color: #9b9b9b;
      cursor: pointer;
      // transform: translateY(-34px);
    }
  }
  .swiper-content {
    padding-top: 20px;
    position: relative;
    .swiper-slide {
      position: relative;
      img {
        width: 100%;
        height:600px;
        display: block;
      }
      .pop-txt-box {
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.6);
        height: 76px;
        padding-left: 33px;
        line-height: 76px;
        font-size: 24px;
        color: #ffffff;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
    .prev-button {
      position: absolute;
      top: 50%;
      left: 30px;
      width: 20px;
      height: 35px;
      background: url(https://zws-imgs-pub.ezijing.com/static/public/881f563105c3a04eb30e57094639eb33.png);
      background-size: 100% 100%;
      z-index: 999;
      cursor: pointer;
      transform: translateY(-50%);
    }
    .next-button {
      position: absolute;
      top: 50%;
      right: 30px;
      width: 20px;
      height: 35px;
      background: url(https://zws-imgs-pub.ezijing.com/static/public/87a93f0d579074213dc9014c9887ed38.png);
      background-size: 100% 100%;
      z-index: 999;
      cursor: pointer;
      transform: translateY(-50%);
    }
  }
}
</style>
