<template>
  <div class="header">
    <div
      class="nav"
      style="background-color: #fff;"
    >
      <ul>
        <div class="logo"><img :src="require('@/assets/images/nav-logo.png')" alt="" /></div>
        <li class="nav-li" :class="{ cur: type === 'home' }" @click="navigation('home')">
          <a>首页</a>
        </li>
        <li class="nav-li" :class="{ cur: type === 'survey' }" @click="navigation('survey')">
          <a>概况</a>
        </li>
        <li class="nav-li" :class="{ cur: type === 'information' }" @click="navigation('information')">
          <a>资讯</a>
        </li>
        <li class="nav-li" :class="{ cur: type === 'exhibition' }" @click="navigation('exhibition')"><a>展览</a></li>
        <li class="nav-li" :class="{ cur: type === 'collection' }" @click="navigation('collection')"><a>典藏</a></li>
        <li class="nav-li" :class="{ cur: type === 'activity' }" @click="navigation('activity')"><a>活动</a></li>
        <li class="nav-li" :class="{ cur: type === 'service' }" @click="navigation('service')"><a>服务</a></li>
      </ul>
    </div>
  </div>
</template>

<script>
export default {
  name: 'mheader',
  data () {
    return {
      type: 'home',
      allType: ['home', 'survey', 'information', 'exhibition', 'collection', 'activity', 'service']
    }
  },
  methods: {
    navigation (type) {
      this.type = type
      this.$router.push({ path: `/${type}` })
    }
  },
  watch: {
    $route (to, from) {
      // console.log('从哪来',from.path);//从哪来
      // console.log('到哪去',to.path);//到哪去
      this.allType.forEach(item => {
        if (to.path.indexOf(item) != -1) this.type = item
      })
    }
  },
  created () {
    // 页面刷新时候
    this.allType.forEach(item => {
      if (window.location.href.split('?')[0].indexOf(item) != -1) this.type = item
    })
  }
}
</script>

<style lang="less" scoped>
.header {
  width: 100%;
  height: 70px;
  box-shadow: 0px 0px 2px 0px;
  margin-bottom:2px ;
  transform: translateZ(10px);
  .nav {
    width: 100%;
    height: 100%;
    background-position: center center;
    background-repeat: no-repeat;
    background-size: 100% 100%;
    color: #fff;
    font-size: 0;
    ul {
      width: 57%;
      margin: 0 auto;
      min-width: 1089px;
      display: flex;
      // justify-content: center;
      .nav-li {
        height: 70px;
        padding: 24px 42px;
        cursor: pointer;
        > a {
          font-size: 16px;
          font-family: Microsoft YaHei;
          font-weight: bold;
          line-height: 21px;
          color: black;
          letter-spacing: 2px;
          opacity: 0.7;
        }
      }
      .logo {
        width: 74px;
        height: 39px;
        margin-top:16px;
        margin-right: 67px;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .cur {
        background: rgba(148, 83, 53, .6);
        a {
          color: #FFFFFF;
          opacity: 1;
        }
      }
    }
  }
}
</style>
