<template>
  <div :class="[!isMobile?'wrap-nav':'m-wrap-nav']">
    <template  v-if="isMobile">
    <div class="m-wrap">
      <div class="m-l" :style="{width:isIpad?'27vw':'50vw'}">
        <img @click="$router.push({path:'/',id:'layout'})" :src="`${$cdn}/images/cgaiizh.svg`" alt>
      </div>
      <div class="m-r">
        <div class="m-nav-btn" @click="isAside=!isAside" :class="{'m-active':isAside}">
          <span class="bg-black"></span>
          <span class="bg-black"></span>
          <span class="bg-black"></span>
        </div>
      </div>
    </div>
    <mSubnav :class="[isAside?'m-subNav-active':'m-subNav']" @closeNav="item=>{isAside=false}" :text="text.nav" />
    </template>
    <template v-else>
      <div class="nav-left">
        <vcenter>
          <img @click="$router.push({path:'/',id:'layout'})" :src="`${$cdn}/images/cgaiizh.svg`" class="logo" alt>
        </vcenter>
      </div>
    <div class="nav-right">
      <vcenter>
        <ul class="nav-items">
          <li
            @click="clickHandle(item)"
            class="nav-item"
            :class="{active:item.id===activeIdx}"
            v-for="(item,index) in text.nav"
            :key="index"
          >
            {{item.name}}
            <span class="line"></span>
            <ul class="sub-items">
              <li @click.stop="clickItem(sub)" v-for="(sub,idx) in item.sub" :key="idx">{{sub.name}}</li>
            </ul>
            <img
              v-if="index === text.nav.length-1"
              :src="require('@/assets/images/icon-arrow.png')"
              alt
            >
          </li>
        </ul>
      </vcenter>
    </div>
    </template>
  </div>
</template>

<script>
import vcenter from '@/components/vcenter'
import text from '@/util/text/cn.js'
import browser from '@/util/browser.js'
import mSubnav from './mSubnav'

const wh = { width: window.innerWidth, height: window.innerHeight }

export default {
  components: {
    vcenter,
    mSubnav
  },
  data () {
    return {
      text,
      activeIdx: 'layout',
      isIpad: browser.iPad,
      isAside: false,
      wh
    }
  },
  computed: {
    isMobile () {
      // return (browser.iPad && wh.width < 770) || browser.mobile
      return browser.iPad || browser.mobile
    }
  },
  methods: {
    clickHandle (item) {
      if (item.url) {
        this.activeIdx = item.id
        this.$router.push({
          path: item.url,
          query: {
            id: item.id
          }
        })
      }
    },
    clickItem (item) {
      if (item.parentName) {
        this.$router.push({
          name: item.parentName,
          query: {
            id: item.id
          }
        })
      }
      if (item.lang) {
        this.urlrep(item.url)
      }
    },
    urlrep (lg) {
      location.pathname = lg
    }
  }
}
</script>

<style scoped>
.wrap-nav {
  background: #fff;
  z-index: 6000;
  position: fixed;
  font-size: 40px;
  height: 75px;
  width: 100%;
  border-bottom: 1px solid #ccc;
  min-width: 1024px;
}

.nav-left {
  margin-left: 100px;
  width: auto;
  height: 75px;
  display: inline-block;
}

.logo {
  height: 56px;
  width: auto;
  cursor: pointer;
}

.nav-right {
  float: right;
  font-size: 16px;
  height: 75px;
  line-height: 75px;
  margin-right: 138px;
}

.nav-right .nav-items {
  display: inline-block;
}

.nav-right .nav-items .nav-item {
  display: inline-block;
  font-weight: bold;
  position: relative;
  padding: 0 40px;
  cursor: pointer;
}

.nav-right .nav-items .nav-item:hover > img {
  transform: translateY(-50%) rotate(180deg);
  transition: all 0.3s ease;
}

.nav-right .nav-items .nav-item > img {
  width: 16px;
  height: 16px;
  position: absolute;
  right: 5%;
  top: 50%;
  transform: translateY(-50%);
  transition: all 0.3s ease;
}

.nav-right .nav-items .line {
  width: 0;
  left: 50%;
}

.nav-right .nav-items .active .line {
  background: red;
  height: 5px;
  width: 60%;
  position: absolute;
  bottom: 0;
  left: 20%;
  border-radius: 2px;
  transition: all ease 0.5s;
}

.nav-right .nav-items .nav-item:not(:last-child)::after {
  display: inline-block;
  content: "";
  position: absolute;
  width: 2px;
  height: 16px;
  top: 50%;
  right: 0;
  background: #ccc;
  transform: skewX(-10deg) translateY(-50%);
}

.nav-right .nav-items .nav-item .sub-items {
  max-height: 0;
  overflow: hidden;
  position: absolute;
  left: 0;
}

.nav-right .nav-items .nav-item:hover .sub-items {
  max-height: 300px;
  transition: max-height 0.5s cubic-bezier(0.73, 0.32, 0.34, 1.5);
  list-style: none;
}

.nav-right .nav-items .nav-item .sub-items li {
  margin-bottom: 0;
}

.nav-right .nav-items .nav-item:hover .sub-items li {
  background: rgba(0, 0, 0, 0.3);
  width: 140px;
  height: 50px;
  line-height: 50px;
  text-align: center;
  margin-bottom: 8px;
  transition: margin-bottom 0.5s cubic-bezier(0.73, 0.32, 0.34, 1.5);
  color: #fff;
}

@media screen and (max-width: 1550px) {
  .nav-right .nav-items .nav-item {
    padding: 0 30px;
  }

  .nav-right .nav-items .nav-item > img {
    right: 0;
  }
}

@media screen and (max-width: 1400px) {
  .nav-left{
    margin-left: 20px;
  }
  .logo{
    height: 50px;
  }
  .nav-right {
    margin-right: 30px;
  }

  .nav-right .nav-items .nav-item {
    padding: 0 20px;
  }

   .nav-right .nav-items .nav-item {
    padding: 0 16px;
    font-size: 14px;
  }

  .nav-right .nav-items .nav-item:hover .sub-items li {
    width: 110px;
    font-size: 14px;
  }
}

@media screen and (max-width: 1200px) {
  .nav-right {
    margin-right: 20px;
  }

  .nav-right .nav-items .nav-item .sub-items {
    left: -10px;
  }

  .nav-right .nav-items .nav-item:hover .sub-items li {
    width: 100px;
    font-size: 12px;
    height: 40px;
    line-height: 40px;
  }

  .nav-right .nav-items .nav-item > img {
    right: -5%;
    width: 12px;
    height: 12px;
  }
}
</style>
<style scoped>
@import url('./mheader.css');

</style>
