<style>
  .q-page-container {
    /* padding-top: 30px !important; */
    padding-bottom: 30px !important;
  }

  .goBackTop {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    /* background-color: #027be3; */
    position: fixed;
    right: 20px;
    bottom: 20px;
    color: #fff;
    text-align: center;
    line-height: 56px;
    z-index: 999;
    opacity: 0;
    transition: opacity 2s linear;
  }

  .showGoback {
    opacity: 100;
  }

</style>
<template>
  <q-layout view="hHh lpr fFf">
    <hor-big-one :base-data="baseinfo" :dataList="dataList" ref="webhead"></hor-big-one>
    <!-- <hor-big-two v-if="headType==2" :base-data="baseinfo" ref="webhead"></hor-big-two> -->
    <q-page-container>
      <div class="flex justify-between" v-if="showUserInfo" style="width: 1200px; margin: 0 auto">
       <navs></navs>
      <router-view />
      </div>
      <router-view v-else />
    </q-page-container>
    <div class="goBackTop bg-primary" :class="{'showGoback':isShowTop}" @click="hangleGoUp">
      <i class="iconfont iconarrow-top"></i>
    </div>
    <q-footer elevated class="bg-grey-8 text-white" style="position: unset;">
      <subscriber></subscriber>
      <horBtm :dataList="dataList"></horBtm>
    </q-footer>
  </q-layout>
</template>

<script>
  import horBigOne from "../components/navs/hor-big-one";
  import horBigTwo from "../components/navs/hor-big-tow";
  import horBtm from "../components/navs/hor-btm";
  import subscriber from "../components/navs/subscriber";
import Navs from 'src/pages/usercenter/components/navs.vue';
  export default {
    components: {
      horBigOne,
      horBigTwo,
      horBtm,
      subscriber,
      Navs
    },
    data() {
      return {
        showUserInfo: false,
        leftDrawerOpen: false,
        baseinfo: {
          logo: "",
          name: "",
          nav: {
            bg: "",
            color: "#222",
            navs: []
          },
          desc: ""
        },
        headType: 1,
        dataList: {},
        //集团编号
        RB_Group_Id: 0,
        //当天
        ToDay: "",
        isShowTop: false
      };
    },
    watch: {
      '$route': function() {
      this.showUserInfo = Boolean(this.$route.meta.isUserCenter)
      }
    },
    created() {
      this.showUserInfo = Boolean(this.$route.meta.isUserCenter)
      var nowDay = this.formatDate2(new Date());
      this.ToDay = nowDay.CYear + "-" + nowDay.CMonth + "-" + nowDay.CDay;
      this.$root.$on('change-head-style', param => {
        this.changeHeadHandler(param);
      })
    },
    mounted() {
      window.addEventListener('scroll', this.getScrollHeight, false);
      //判断是不是同一天
      if (localStorage.ToDay) {
        if (localStorage.ToDay != this.ToDay) {
          localStorage.removeItem("groupinfo");
          localStorage.ToDay = this.ToDay;
        }
      } else {
        localStorage.removeItem("groupinfo");
        localStorage.ToDay = this.ToDay;
      }

      //删除基础配置
      //localStorage.removeItem("baseifo");
      //获取集团数据
      if (localStorage.groupinfo) {
        var jObj = JSON.parse(window.localStorage.getItem('groupinfo'));
        this.RB_Group_Id = jObj.GroupId;
        this.getConfigData();
      } else {
        this.getGroupData();
        //获取网站基础配置
        if (localStorage.baseifo) {
          var jObj = JSON.parse(window.localStorage.getItem('baseifo'));
          this.baseinfo.logo = jObj.Config.Logo;
          this.baseinfo.name = jObj.Config.Name;
          this.baseinfo.nav.navs = jObj.HeaderList;
          this.baseinfo.nav.bg = jObj.Config.BgColor;
          this.dataList = jObj;
        } else {
          this.getConfigData();
        }
      }
    },
    methods: {
      //点击回到顶部
      hangleGoUp() {
        let nowTop = document.body.scrollTop || document.documentElement.scrollTop; // 获取当前滚动条位置
        if (nowTop > 0) {
          window.requestAnimationFrame(this.hangleGoUp);
          window.scrollTo(0, nowTop - (nowTop / 5));
        }
      },
      //监测滚动条位置
      getScrollHeight() {
        let nowTop = document.body.scrollTop || document.documentElement.scrollTop; // 获取当前滚动条位置
        if (nowTop > 200) {
          this.isShowTop = true;
        } else {
          this.isShowTop = false;
        }
      },
      changeHeadHandler(t) {
        this.headType = t;
      },
      //获取集团数据
      getGroupData() {
        let locationName = this.GetDomain();
        var msg = {
          GroupId: 0,
          B2BDomain: locationName,
          IsGetConfigSite:1,
        };
        this.apipost(
          "admin_get_GetGroupDomain", msg,
          res => {
            if (res.data.resultCode == 1) {
              this.RB_Group_Id = res.data.data.GroupId;
              var jsonData = JSON.stringify(res.data.data);
              window.localStorage.setItem("groupinfo", jsonData);
            }
          },
          err => {}
        );
      },
      //获取网站配置数据
      getConfigData() {
        let locationName =this.GetDomain();
        this.apipost(
          "ws_get_GetWebSiteConfig", {
            RB_Group_Id: this.RB_Group_Id,
            B2BDomain: locationName
          },
          res => {
            if (res.data.resultCode == 1) {
              this.dataList = res.data.data;
              if (this.dataList) {
                var jsonData = JSON.stringify(res.data.data);
                window.localStorage.setItem("baseifo", jsonData);
                this.baseinfo.logo = this.dataList.Config.Logo;
                this.baseinfo.name = this.dataList.Config
                  .Name;
                this.baseinfo.nav.navs = this.dataList.HeaderList;
                this.baseinfo.nav.bg = this.dataList
                  .Config.BgColor;
                this.baseinfo.AreaList = this.dataList.AreaList
              }
            }
          },
          err => {}
        );
      },
    },
  };

</script>
