<template>
  <div>
    <v-header @returnScrollTop="returnScrollTop"></v-header>
    <back-top :backTopIsShow="backTopState" @handleBackTop="handleBackTop"></back-top>
    <main class="content-container" ref="container" :class="headFixed == true ? 'marginTop' : ''">
      <nuxt/>
    </main>
    <v-footer></v-footer>
  </div>
</template>

<style>
</style>

<script>
  import VHeader from '~/components/home/header';
  import VFooter from '~/components/home/footer';
  import backTop from '~/components/common/backTop.vue'
  // import {seo} from '~/utils/assist'

  export default {
    components: {
      VHeader,
      backTop,
      VFooter
    },
    data (){
      return {
        headFixed: true,
        maxClientWidth: 980,
        backTopState: true // 返回顶部部分距离顶部的距离
      }
    },
    mounted (){
      // window.addEventListener('scroll',this.handleScroll);
      // seo();
      // var _hmt = _hmt || [];
      // (function() {
      //   var hm = document.createElement("script");
      //   hm.src = "https://hm.baidu.com/hm.js?02736a493e850835a7c343e9edd17e88";
      //   var s = document.getElementsByTagName("script")[0];
      //   s.parentNode.insertBefore(hm, s);
      // })();
    },
    methods: {
      // 返回顶部
      handleBackTop() {
        document.getElementById("backTop").scrollIntoView();
      },
      // 返回距离顶部的距离 从header中获取 其中有一个原生监听sroll
      returnScrollTop(val) {
        this.backTopState = (val !== 0)
        // console.log(this.backTopState,'backTop');
      },
      handleScroll (){
        var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
        var offsetTop = document.querySelector('.h-nav-list').offsetTop;
        if (scrollTop > offsetTop) {
          this.headFixed = true;
        } else {
          this.headFixed = false;
        }
      }
    },
    destroyed (){
      window.removeEventListener('scroll',this.handleScroll)
    }
  }
</script>
