<!-- -->
<template>
  <div class="home-display">
    <div class="title wow animate__animated animate__fadeInUp">展览</div>
    <div class="wrapper wow animate__animated animate__fadeInUp">
      <!-- <div
        class="sliders"
        :style="{
          transform: `translateX(-${currentIndex * sliderItemWidth}px)`,
        }"
      > -->
      <div
        class="sliders"
        :style="{
          transform: `translateX(-${currentIndex * sliderItemWidth}px)`,
        }"
        v-if="list.length > 0"
      >
        <div
          :class="['slide-item', currentIndex == index ? 'active' : '']"
          v-for="(item, index) in list"
          :key="index"
        >
          <div class="content">
            <div class="content-name">{{ item.title }}</div>
            <div class="content-intro">
              {{ item.intro ? item.intro : "" }}
            </div>
            <EntranceIcon color="#fff" />
          </div>
          <div class="img" @click="handleClick(item)">
            <img
              v-if="$getFullUrl(item.faceImagePressUrl)"
              :src="$getFullUrl(item.faceImagePressUrl)"
              alt=""
            />
            <img v-else :src="$getFullUrl(item.faceImageUrl)" alt="" />
            <div class="img-name">{{ item.title }}</div>
          </div>
        </div>
      </div>
      <div class="pagination wow animate__animated animate__fadeInUp">
        <ul>
          <li
            v-for="(item, index) in list"
            :key="index"
            :class="list[currentIndex] == item ? 'active' : ''"
            @click="handleChangePage(item)"
          >
            {{ index + 1 }}
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import { getRecommendDisplay } from "@/api/display";
import EntranceIcon from "@/components/EntranceIcon";
export default {
  name: "Display",
  components: {
    EntranceIcon,
  },
  data() {
    return {
      list: [],
      currentIndex: 0,
      sliderItemWidth: 0,
    };
  },
  mounted() {
    this.loadList();
  },
  methods: {
    async loadList() {
      let res = await getRecommendDisplay();
      this.list = res.data;
      this.getSlideItemWidth();
    },
    handleChangePage(page) {
      let index = this.list.indexOf(page);
      this.currentIndex = index;
      console.log(-this.currentIndex * this.sliderItemWidth);
    },
    handleClick(item) {
      console.log(item);
      const { exhibitionId } = item;
      this.$router.push({
        path: "display/" + exhibitionId,
      });
    },
    getSlideItemWidth() {
      setTimeout(() => {
        let slideItem = document.getElementsByClassName("slide-item");
        if (slideItem[0]) {
          this.sliderItemWidth = slideItem[0].offsetWidth;
        }
      }, 500);
    },
  },
};
</script>

<style lang="scss" scoped>
.home-display {
  background-image: url("@/assets/imgs/home/cr-bg.png");
  background-size: cover;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  padding: 0 13%;
  .title {
    color: #fff;
    margin-top: 70px;
    margin-bottom: 90px;
    font-family: "Alibaba PuHuiTi";
    flex-basis: auto;
    font-size: 22px;
  }

  .wrapper {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    position: relative;
    flex: 1;
    overflow: hidden;
    .sliders {
      display: flex;
      min-width: 100%;
      height: 100%;
      transition: all 0.5s ease;
      .slide-item {
        min-width: 100%;
        position: relative;
        display: flex;
        justify-content: space-between;
        height: 100%;
        padding: 0 10px;
        transition: all 1s ease;

        .content {
          color: #fff;
          font-family: "Alibaba PuHuiTi";
          width: 600px;
          height: 100%;
          .content-name {
            font-size: 20px;
            font-weight: bold;
            margin-bottom: 40px;
          }
          .content-intro {
            font-size: 14px;
            font-weight: 400;
            line-height: 40px;
            margin-bottom: 40px;
          }
        }
        .img {
          margin-top: 240px;
          width: 380px;
          height: 480px;
          cursor: pointer;
          img {
            width: 100%;
          }
          .img-name {
            display: flex;
            justify-content: center;
            font-size: 16px;
            font-family: Microsoft YaHei;
            font-weight: 400;
            color: #88754d;
          }
        }
      }
    }

    .pagination {
      position: absolute;
      bottom: 60px;
      right: 0;
      ul {
        display: flex;
        li {
          width: 22px;
          height: 22px;
          margin-right: 25px;
          color: #999;
          display: flex;
          align-items: center;
          justify-content: center;
          cursor: pointer;
          transition: all 0.5s ease;
        }
        li:hover,
        .active {
          background: #2069c4;
          color: #fff;
        }
      }
    }
  }
}
::v-deep .el-carousel {
  width: 100%;
  height: 100%;
}
::v-deep .el-carousel__container {
  height: 100%;
}
::v-deep .el-carousel-item {
  height: 100%;
  position: relative;
}
::v-deep .el-carousel--horizontal {
  overflow: hidden;
}
</style>
