<template>
  <div
    :class="
      istop && isFirstSwiper ? 'top_container' : 'top_container container_bg'
    "
  >
    <img
      class="logo"
      :src="istop && isFirstSwiper ? Logo : isHard ? Logo2 : Logo1"
      alt=""
    />
    <img
      class="fold_icon"
      :src="istop && isFirstSwiper ? Icon : Icon1"
      alt=""
      v-if="!drawer"
      @click="openDrawer"
    />
  </div>
  <div class="modal_drawer" v-if="drawer" @click="hidePanel">
    <img :src="Close" class="close" alt="" @click="drawer = false" />
    <div class="content" id="content_tab">
      <div class="icon_wrap">
        <p class="icon"></p>
      </div>
      <div class="btn_wrap">
        <div class="btn" @click="toPage('/company')">公司简介</div>
        <div class="btn" @click="toPage('/case-show')">案例展示</div>
        <div class="btn" @click="toPage('/contact')">联系我们</div>
        <div class="btn" @click="toPage('/recruit')">招贤纳士</div>
        <div class="btn" @click="toPage('/factory')">工厂展示</div>
        <div class="btn" @click="toPage(`${isHard ? '/' : '/hardware'}`)">
          {{ isHard ? '工业设计' : '软硬件研发' }}
        </div>
        <!-- <div class="btn" @click="toPage('/product')">产品研发</div> -->
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import Close from '@/static/img/banner/x.png'
import Logo from '@/static/img/banner/logo.png'
import Logo2 from '@/static/img/banner/logo3.png'
import Icon from '@/static/img/banner/liebiao.png'
import Icon1 from '@/static/img/banner/liebiao2.png'
import Logo1 from '@/static/img/banner/logo2.png'
import { useRouter, useRoute } from 'vue-router'
const route = useRoute()
const router = useRouter()
const drawer = ref(false)
const props = defineProps({
  isFirstSwiper: {
    type: Boolean,
  },
})

const openDrawer = () => {
  drawer.value = true
}
const toPage = path => {
  const origin = window.location.origin
  const pathname = window.location.pathname
  const p = `${origin}${pathname}#${path}`
  window.location.href = p
}

const hidePanel = event => {
  let dom = document.getElementById('content_tab')
  if (dom) {
    if (!dom.contains(event.target)) {
      //这句是说如果我们点击到了id为child以外的区域
      drawer.value = false
    }
  }
}
const isHard = ref(false)

onMounted(() => {
  window.addEventListener('scroll', scrollToTop)
  if (route.path.indexOf('/hardware') != -1) {
    isHard.value = true
  }
})

const istop = ref(true)

const scrollToTop = () => {
  var scrollTop =
    window.pageYOffset ||
    document.documentElement.scrollTop ||
    document.body.scrollTop
  if (scrollTop == 0) {
    istop.value = true
  } else {
    istop.value = false
  }
}
</script>

<style lang="scss" scoped>
.top_container {
  padding: 14px 18px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: fixed;
  top: 0;
  right: 0;
  width: 100%;
  box-sizing: border-box;
  .logo {
    width: 85px;
    height: 17px;
  }
  .fold_icon {
    width: 18px;
    height: 12px;
  }
}
.modal_drawer {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 999;
  background: rgba(0, 0, 0, 0.67);
  .close {
    position: absolute;
    right: 20px;
    width: 13px;
    height: 13px;
    top: 17px;
  }
  .content {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 348px;
    background: #fff;
    z-index: 999;
    border-top-right-radius: 20px;
    border-top-left-radius: 20px;
    display: flex;
    flex-direction: column;
    .icon_wrap {
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 12px 0 0 0;
      .icon {
        width: 24px;
        height: 2px;
        border-radius: 1px;
        background: #000;
      }
    }
    .btn_wrap {
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: space-evenly;
      .btn {
        font-size: 13px;
        font-family: Alibaba PuHuiTi;
        font-weight: 400;
        color: #000000;
        width: 100vw;
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
      }
    }
  }
}
.container_bg {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(30px);
  transition-property: all;
  transition-duration: 0.7s;
  animation-fill-mode: forwards;
}
</style>
