<template>
  <div class="Bottom2">
    <div class="box1">
      <!-- 航拍 -->
      <div>
        <div class="swiper-container" :class="`sww${towAc}`" :key="towAc">
          <div class="swiper-wrapper">
            <div
              class="swiper-slide"
              v-for="(item, index) in swData"
              :key="index"
            >
              <div
                v-for="(val, ind) in item.son"
                :key="ind"
                :class="{
                  active: oneAc === val.id,
                  sm: ind === 0 || ind == item.son.length - 1,
                  big: item.son.length < 6,
                }"
                @click="cutVr(val)"
              >
                <img src="../assets/img/demo.png" alt="" />
                <p>{{ val.name }}</p>
              </div>
            </div>
          </div>
        </div>
        <div class="swiper-button-next swiper-button-next1"></div>
        <div class="swiper-button-prev swiper-button-prev1"></div>
      </div>
    </div>
    <div class="box2">
      <div v-for="(item, index) in data" :key="item.id">
        <div @click="botChange(item)" :class="{ active: towAc === item.id }">
          {{ item.name }}
        </div>
        <img
          src="../assets/img/fenge.png"
          alt=""
          v-if="index < data.length - 1"
        />
      </div>
    </div>
  </div>
</template>

<script>
import { exArr1, exArr2 } from "./zhan";
import Swiper from "@/assets/swiper/swiper.js";
export default {
  name: "Bottom2",
  components: {},
  props: {
    list: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      oneAc: "",
      towAc: 1,
      data: [],
      swData: [],
      Swiper: null,
    };
  },
  computed: {},
  methods: {
    // 点击底部的切换分区
    botChange(item) {
      this.swData=[]
      this.Swiper=null
      this.towAc = item.id;
      this.getSwFu(0, item);
    },
    // 封装一个重新加载轮播图的方法
    getSwFu(bs, obj) {
      // 获取分区里面数据的长度
      let num = Math.ceil(obj.son.length / 6);
      for (let i = 0; i < num; i++) {
        this.swData.push({
          son: obj.son.slice(i * 6, (i + 1) * 6),
        });
      }
      this.$nextTick(() => {
        this.Swiper = new Swiper(`.box1 .sww${this.towAc}`, {
          navigation: {
            nextEl: ".swiper-button-next1",
            prevEl: ".swiper-button-prev1",
          },
          slidesPerView: 1,
          initialSlide: bs,
          spaceBetween: 0,
        });
      });
    },
    // 切换VR
    cutVr(val) {
      this.oneAc = val.id;
      this.$emit("zhanChange", val.code);
    },
  },
  watch: {},
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    if (this.list.bs == 1) this.data = exArr1;
    else this.data = exArr2;
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    let obj = this.data.find((v) => v.id == this.list.id1);
    this.towAc = obj.id;
    let index = this.list.id2.indexOf("_");
    let bs = this.list.id2.substr(index + 1, this.list.id2.length);
    let num = Math.ceil(Number(bs) / 6);
    this.oneAc = this.list.id2;

    this.getSwFu(num - 1, obj);
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang='less' scoped>
@import "../assets/swiper/swiper.css";
.Bottom2 {
  width: 100%;
  height: 100%;
  .box1 {
    position: relative;
    width: 100%;
    height: 152px;
    margin-bottom: 4px;
    background-color: rgba(0, 0, 0, 0.8);
    border-radius: 60px 60px 0 0;
    & > div {
      padding: 8px 50px 5px 50px;
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      width: 100%;
      height: 100%;
    }

    .swiper-container {
      width: 100%;
      height: 100%;
      .swiper-slide {
        display: flex;
        justify-content: center;
        & > div {
          border-radius: 20px;
          overflow: hidden;
          position: relative;
          cursor: pointer;
          margin-right: 12px;
          width: 209px;
          height: 100%;
          &:nth-of-type(6) {
            margin-right: 0;
          }
          & > p {
            transition: all 0.3s;
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 30px;
            line-height: 30px;
            text-align: center;
            background-color: rgba(0, 0, 0, 0.6);
            font-size: 14px;
            color: #fff;
          }
          & > img {
            width: 100%;
            height: 100%;
            object-fit: cover;
          }
          &:hover {
            & > p {
              background-color: rgba(181, 147, 134, 0.8);
            }
          }
        }
        .active {
          pointer-events: none;
          & > p {
            background-color: rgba(181, 147, 134, 0.8);
          }
        }
        .sm {
          width: 170px;
        }
        .big {
          width: 209px;
        }
      }
    }
    .swiper-button-next {
      color: #b59386;
    }
    .swiper-button-prev {
      color: #b59386;
    }
  }
  .box2 {
    background-color: rgba(0, 0, 0, 0.8);
    width: 100%;
    height: 65px;
    display: flex;
    align-items: center;
    justify-content: center;
    & > div {
      display: flex;
      align-items: center;
      & > img {
        margin: 0 26px;
        width: 2px;
        height: 40px;
      }
      & > div {
        cursor: pointer;
        font-size: 20px;
        color: #fff;
        padding-bottom: 5px;
        &:hover {
          padding-top: 2px;
          color: #b59386;
          border-bottom: 2px solid #b59386;
        }
      }
    }
    .active {
      padding-top: 2px;
      pointer-events: none;
      color: #b59386;
      border-bottom: 2px solid #b59386;
    }
  }
}
</style>