<!--
 * @Description: 顶部轮播图
 * @Author: 空白格
 * @Date: 2022-08-22 09:14:32
 * @LastEditors: 空白格
 * @LastEditTime: 2022-12-19 10:36:55
 * @FilePath: \veterans_client_web\src\views\Home\components\HeaderBanner.vue
 * @Copyright: Copyright (c) 2016~2022 by 空白格, All Rights Reserved.
-->
<template>
  <div class="home-carousel">
    <el-carousel height="400px" arrow="never">
      <el-carousel-item
        class="home-carousel-item"
        v-for="(item, index) in bannerList"
        :key="index"
      >
        <el-image
          class="image"
          v-if="item.id"
          :src="item.bannerUrl"
          fit="cover"
          @click="jumpPage('/bannerdetails', { id: item.id, type: 4 })"
        >
          <div slot="placeholder" class="image-slot">
            图片加载中<span class="dot">...</span>
          </div>
        </el-image>
        <el-image class="image" :src="item.bannerUrl" v-else fit="cover">
          <div slot="placeholder" class="image-slot">
            图片加载中<span class="dot">...</span>
          </div>
        </el-image>
        <el-image
          class="image-text"
          v-if="item.bannerTxtUrl"
          :src="item.bannerTxtUrl"
          fit="cover"
        >
          <div slot="placeholder" class="image-slot">
            图片加载中<span class="dot">...</span>
          </div>
        </el-image>
      </el-carousel-item>
    </el-carousel>
  </div>
</template>

<script>
import { getBannerList } from "@/api/Home";
export default {
  name: "HeaderBanner",
  data() {
    return {
      bannerList: [
        {
          bannerUrl: require("@/assets/images/banner-1.png")
        },
      ],
    };
  },
  created() {
    this.getBanner();
  },
  methods: {
    /**
     * 获取轮播图
     * @date 2022-08-22
     * @returns {any}
     */
    getBanner() {
      getBannerList({ type: 4 }).then((res) => {
        res.data.length ? (this.bannerList = res.data) : "";
      });
    },
    /**
     * 跳转
     * @date 2022-08-30
     * @param {any} path
     * @param {any} query
     * @returns {any}
     */
    jumpPage(path, query) {
      this.$router.push({
        path,
        query,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.home {
  &-carousel {
    &-item {
      // position: relative;
      cursor: pointer;
      .image-text {
        width: 900px;
        height: 270px;
        position: absolute;
        left: 300px;
        top: 80px;
      }
    }
    .image {
      width: 100%;
      height: 100%;
    }
    .image-slot {
      line-height: 300px;
      text-align: center;
    }
    :deep(.el-carousel__arrow) {
      border: solid 1px rgba($color: #fff, $alpha: 0.7);
    }
    // :deep(.el-carousel__button) {
    //   display: none;
    //   // 指示器按钮
    //   width: 10px;
    //   height: 10px;
    //   border: none;
    //   border-radius: 50%;
    //   background-color: #fff;
    // }
    // :deep(.is-active .el-carousel__button) {
    //   // 指示器激活按钮
    //   width: 18px;
    //   border-radius: 10px;
    // }
    :deep(.el-carousel__button) {
      // 指示器按钮
      width: 10px;
      height: 10px;
      border: none;
      border-radius: 50%;
      background-color: #fff;
    }
    :deep(.is-active .el-carousel__button) {
      // 指示器激活按钮
      width: 24px;
      border-radius: 10px;
      background-color: #f00;
    }
  }
}
</style>
