<template>
  <div class="btm-menu">
    <img @click.stop="$bus.$emit('changeMenu', 'exhibition')" :src="require(`@/assets/images/proj2022/mobile/menu@2x.png`)" alt="" />
    <ul>
      <li v-for="(item, i) in menu" :key="i">
        <div :class="{ active: (i == 3&&isShowHuDong) || (item.id == 'bgm' && isBgm) }" @click="onClick(item)">
          <img :src="require(`@/assets/images/proj2022/mobile/menu/${item.img}.png`)" alt="" />
          <span>{{ item.name }}</span>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
import { supCount, getsupCount } from "@/config/api";

let menu = [
  {
    id: "xiangmu",
    name: "项目",
    img: "project",
    cp: "zhanxiang",
  },
  {
    id: "daolan",
    name: "导览",
    img: "play",
    cp: "daolan",
  },
  {
    id: "bgm",
    img: "music",
    name: "音乐",
  },
  {
    id: "interaction",
    name: "互动",
    img: "interaction",
    cp: "hudong",
  },
];
export default {
  props: ["tourStatus"],
  data() {
    return {
      menu,
      goodNum: 1099,
      isShowGood: false,
      isBgm: false,
      isShowHuDong: false,
    };
  },
  watch: {
    isBgm: {
      immediate: true,
      handler: function(newVal) {
        this.$bus.$emit("toggleHomeBgm", newVal);
        // !newVal ? this.$refs.vbgm.pause() : this.$refs.vbgm.play();
      },
    },
    isShowHuDong(newVal){
        this.$bus.$emit("changeShowfunc", newVal);
    },
    tourStatus(newVal) {
      if (newVal) {
        this.isBgm = false;
      } else {
        let status = localStorage.getItem("g_bgmstatus");
        if (status === "open") {
          this.isBgm = true;
        }
      }
    },
  },
  methods: {
    onClick(item) {

      if (item.id=='daolan') {
        return
      }
      if (item.id == "xiangmu") {
        this.$bus.$emit("emitShowZX", {
          show: true,
        });
        return;
      }

      if (item.id == "interaction") {
        this.isShowHuDong = !this.isShowHuDong
        return;
      }

      item.path && this.$router.push(item.path);
      item.cp && this.$bus.$emit("opencp", item.cp);
      if (item.id == "bgm") {
        this.isBgm = !this.isBgm;
        localStorage.setItem("g_bgmstatus", this.isBgm ? "open" : "close");
      }
      item.id == "zan" && this.dianzan();
    },
    dianzan() {
      if (this.isShowGood) return;
      getsupCount((res) => {
        this.goodNum = res.data;
        this.isShowGood = true;
        setTimeout(() => {
          this.isShowGood = false;
        }, 2500);
        supCount(() => {});
      });
    },
    toggle() {
      let fn = this.tourStatus ? "stopTour" : "startAndPlay";
      this.$bus.$emit("ifrMessage", {
        events: "toggleTour",
        data: fn,
      });
    },
  },
  mounted() {
    this.isBgm = true;
    localStorage.setItem("g_bgmstatus", this.isBgm ? "open" : "close");
    this.$nextTick(() => {
      this.$bus.$on("toggleBGM", (data) => {
        if (!data) {
          this.isBgm = data;
        } else {
          let status = localStorage.getItem("g_bgmstatus");
          if (status === "open") {
            this.isBgm = data;
          }
        }
      });
    });
  },
};
</script>

<style lang="less" scoped>
.smenu {
  width: 100%;

  .sdaolan,
  .stoptour {
    position: fixed;
    cursor: pointer;
    bottom: 113px;
    width: 45px;
    height: 45px;
    left: 14px;
    border-radius: 50%;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.4);
    &::before {
      backdrop-filter: blur(10px) brightness(60%);
    }
    .daolan {
      position: absolute;
      top: 52%;
      left: 50%;
      transform: translate(-50%, -50%);
      text-align: center;
      > img {
        width: 20px;
      }
    }
  }
  .stoptour {
    .daolan {
      position: absolute;
      top: 54%;
      left: 50%;
      transform: translate(-50%, -50%);
      text-align: center;
      > img {
        width: 24px;
      }
    }
  }

  .btm-menu {
    position: fixed;
    bottom: 0%;
    left: 0%;
    z-index: 999;
    width: 100%;
    height: 103px;
    background-image: url("~@/assets/images/proj2022/mobile/tab@2x.png");
    background-size: 100% auto;
    background-repeat: no-repeat;
    background-position: bottom left;
    > img {
      position: absolute;
      top: -10px;
      left: 10px;
      width: 12%;
    }
    .brightness {
      &::before {
        backdrop-filter: blur(10px) brightness(60%);
      }
    }
    > ul {
      width: 100%;
      height: 50%;
      display: flex;
      justify-content: flex-end;
      align-items: center;
      text-align: center;
      z-index: 9999;
      position: absolute;
      bottom: 10px;
      left: 0;
      > li {
        display: inline-block;
        padding: 0 0;
        width: 10%;
        margin: 0 5%;
        > div {
          > img {
            width: 100%;
            opacity: 0.6;
          }
          > span {
            font-size: 12px;
            color: rgba(255, 255, 255, 0.6);
            transform: scale(0.9) translateY(-10px);
            display: inline-block;
          }
        }
        .active {
          position: relative;
          &::after {
            content: "";
            width: 20px;
            height: 20px;
            display: inline-block;
            position: absolute;
            background-color: #fff;
            border-radius: 50%;
            top: 10%;
            left: 50%;
            transform: translateX(-50%);
            filter: blur(7px);
          }
          > img {
            opacity: 1;
          }
          > span {
            color: rgba(255, 255, 255, 1);
          }
        }
      }
    }
  }
}

.likeAddAnimate-enter-active,
.likeAddAnimate-leave-active {
  transition: all 2.5s ease;
}
.likeAddAnimate-enter,
.likeAddAnimate-leave {
  transform: translate(-50%, 0) scale(0);
  opacity: 0;
}
.likeAddAnimate-enter-to,
.likeAddAnimate-leave-to {
  transform: translate(-50%, -80px) scale(1.2);
  opacity: 1;
}
.good {
  position: fixed;
  bottom: 60px;
  left: 50%;
  display: flex;
  .pic {
    width: 35px;
    > img {
      width: 100%;
      height: 100%;
    }
  }
  .num {
    margin-top: 10px;
    margin-left: 10px;
  }
}

.noshow {
  position: fixed;
  top: -100px;
  left: -100px;
  opacity: 0;
  visibility: hidden;
}
</style>
