<template>
  <div class="Bottom2">
    <div class="box1">
      <div>
        <div
          class="swiper-container"
          :class="`sww${towAc}`"
          :key="towAc + box3Ac"
        >
          <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"
                @click="cutVr(val)"
                :class="{
                  active: oneAc === val.id,
                  sm: ind === 0 || ind == item.son.length - 1,
                  big: item.son.length < 6,
                }"
              >
                <el-tooltip :content="val.name" placement="top">
                  <div>
                    <img
                      v-lazy="
                        `https://4dkk.4dage.com/720yun_fd_manage/${val.code}/preview.jpg`
                      "
                      alt=""
                      v-if="box3Ac < 3"
                    />
                    <img v-lazy="codeChange(val.code, val.id)" alt="" v-else />
                    <p>{{ val.name }}</p>
                  </div>
                </el-tooltip>
              </div>
            </div>
          </div>
        </div>
        <div
          class="swiper-button-next"
          :class="{ none: swIndex === swData.length - 1 }"
        ></div>
        <div class="swiper-button-prev" :class="{ none: swIndex === 0 }"></div>
      </div>
    </div>
    <div class="box2" v-if="box3Ac === 3 || box3Ac === 4">
      <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 class="box3">
      <div v-for="(item, index) in box3Data" :key="item.id">
        <div @click="botChange2(item)" :class="{ active: box3Ac === item.id }">
          {{ item.name }}
        </div>
        <img
          src="../assets/img/fenge.png"
          alt=""
          v-if="index < box3Data.length - 1"
        />
      </div>
    </div>
  </div>
</template>

<script>
import { exArr1, exArr2, exArr3, exArr4 } from "./zhan";
import Swiper from "@/assets/swiper/swiper.js";
export default {
  name: "Bottom2",
  components: {},
  data() {
    return {
      oneAc: "",
      towAc: "1",
      box3Ac: 1,
      data: [],
      swData: [],
      Swiper: null,
      swIndex: 0,
      box3Data: [
        { id: 1, name: "航拍", code: "" },
        { id: 2, name: "地面全景", code: "" },
        { id: 3, name: "第一展厅", code: "" },
        { id: 4, name: "第二展厅", code: "" },
      ],
    };
  },
  computed: {},
  methods: {
    // 处理链接
    codeChange(code, id) {
      let index = code.indexOf("&");
      let url = code.substr(0, index);
      if (index > 0) {
        let arr = [
          "4-3_7",
          "4-3_8",
          "4-3_12",
          "4-3_12",
          "4-3_14",
          "4-3_15",
          "4-3_16",
          "4-3_17",
          "4-3_19",
          "4-3_20",
          "4-3_21",
          "4-3_22",
          "4-3_23",
          "4-3_24",
          "4-5_7",
          "4-5_8",
          "4-5_9",
          "4-6_2",
          "4-6_3",
          "4-6_4",
          "4-6_5",
          "4-6_6",
          "4-6_7",
          "4-6_8",
          "4-6_9",
          "4-6_10",
        ];
        if (arr.find((v) => v === id)) return `img/${id}.jpg`;
        else
          return `https://4dkk.4dage.com/scene_view_data/${url}/user/thumb-2k.jpg`;
      } else
        return `https://4dkk.4dage.com/scene_view_data/${code}/user/thumb-2k.jpg`;
    },
    // 点击底部的切换分区
    botChange(item) {
      // console.log('--------',item.id);
      // this.$emit('changeMap',)

      this.towAc = "1";
      this.towAc = item.id;
      if (this.box3Ac === 3) this.data = [...exArr3];
      else this.data = [...exArr4];
      this.getSwFu(item.id + "", "1_1", true);
    },
    botChange2(item) {
      this.$emit("zhanShowFu");
      if (this.box3Ac === item.id) return;
      this.towAc = "1";
      this.box3Ac = item.id;
      if (item.id === 1) this.data = [...exArr1];
      else if (item.id === 2) this.data = [...exArr2];
      else if (item.id === 3) this.data = [...exArr3];
      else this.data = [...exArr4];
      this.getSwFu("1", "1_1", true);

      // 给父组件传递信息
      this.$emit("gaoduChange", this.box3Ac);
      // this.$emit("zhanChange", this.box3Ac, item.code);
    },
    // 封装一个重新加载轮播图的方法
    getSwFu(id1, id2, flag) {
      this.$nextTick(() => {
        this.swData = [];
        this.Swiper = null;

        let obj = this.data.find((v) => v.id == id1);
        this.towAc = obj.id;
        let index = id2.indexOf("_");
        let bs = id2.substr(index + 1, id2.length);
        let num1 = Math.ceil(Number(bs) / 6);
        num1 -= 1;
        if (!flag) {
          this.oneAc = id2;
        }
        // 获取分区里面数据的长度
        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),
          });
        }

        setTimeout(() => {
          this.Swiper = new Swiper(`.box1 .sww${this.towAc}`, {
            navigation: {
              nextEl: ".swiper-button-next",
              prevEl: ".swiper-button-prev",
            },
            slidesPerView: 1,
            initialSlide: num1,
            spaceBetween: 0,
          });
        }, 300);
      });
    },
    // 切换VR
    cutVr(val) {
      if (this.oneAc === val.id) return;
      if (val.code === "") return this.$message.warning("数据计算中，敬请期待");
      this.oneAc = val.id;
      this.$emit("zhanChange", val.code);
    },

    // 进来页面的方法
    baseList(bs) {
      if (bs == 3) this.data = [...exArr3];
      else if (bs == 4) this.data = [...exArr4];
      else this.data = exArr1;
    },
  },
  watch: {
    "Swiper.activeIndex"(val) {
      this.swIndex = val;
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.baseList(1);
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    this.getSwFu("1", "1_1", true);
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang='less' scoped>
@import "../assets/swiper/swiper.css";
.Bottom2 {
  width: 100%;
  height: 100%;
  position: relative;
  .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%;
          /deep/.el-tooltip {
            width: 100%;
            height: 100%;
          }
          &:nth-of-type(6) {
            margin-right: 0;
          }
          p {
            opacity: 0.8;
            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.8);
            font-size: 14px;
            color: #fff;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            padding: 0 6px;
            border-radius: 0 0 20px 20px;
          }
          img {
            width: 100%;
            height: 100%;
            object-fit: cover;
          }
          &:hover {
            p {
              opacity: 1;
              background-color: rgba(181, 147, 134, 0.8);
            }
          }
        }
        .active {
          p {
            opacity: 1;
            background-color: rgba(181, 147, 134, 0.8);
          }
        }
        .sm {
          width: 170px;
        }
        .big {
          width: 209px;
        }
      }
    }
    .swiper-button-next {
      opacity: 1;
      pointer-events: auto;
      cursor: pointer;
      color: #c48871;
    }
    .swiper-button-prev {
      pointer-events: auto;
      opacity: 1;
      cursor: pointer;
      color: #c48871;
    }
    .none {
      opacity: 0.35;
      pointer-events: none;
    }
  }
  .box2 {
    background-color: rgba(0, 0, 0, 0.8);
    width: 100%;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-bottom: 2px;
    & > div {
      display: flex;
      align-items: center;
      & > img {
        margin: 0 26px;
        width: 2px;
        height: 40px;
      }
      & > div {
        cursor: pointer;
        font-size: 16px;
        color: #fff;
        padding-bottom: 5px;
        opacity: 0.8;
        &:hover {
          opacity: 1;
          padding-top: 2px;
          color: #c48871;
          border-bottom: 2px solid #c48871;
        }
      }
    }
    .active {
      opacity: 1;
      padding-top: 2px;
      pointer-events: none;
      color: #c48871;
      border-bottom: 2px solid #c48871;
    }
  }
  .box3 {
    margin-top: 5px;
    background-color: rgba(0, 0, 0, 0.8);
    width: 100%;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-bottom: 2px;
    & > 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;
        opacity: 0.8;
        &:hover {
          opacity: 1;
          padding-top: 2px;
          color: #c48871;
          border-bottom: 2px solid #c48871;
        }
      }
    }
    .active {
      opacity: 1;
      padding-top: 2px;
      // pointer-events: none;
      color: #c48871;
      border-bottom: 2px solid #c48871;
    }
  }
}
</style>