<template>
  <div id="app">
    <cr-nav-bar v-if="header" :title="title" left-text="" @click-left="backFun" />
    <div class="app">
      <Weapp v-if="isWeixinBrowser" jump-url="/pages/user/login" />
      <keep-alive>
        <router-view v-if="$route.meta.keepLive" />
      </keep-alive>
      <router-view v-if="!$route.meta.keepLive" />
    </div>
    <div v-if="loading" class="loading-container">
      <cr-loading class="loading" size="24px">加载中...</cr-loading>
    </div>
    <net-error />
    <goods-share ref="gdShare" />
  </div>
</template>
<script>
import { mapState } from 'vuex';
import NetError from '@/components/NetError';
// import { isApp, isWxMp, isWechat } from '@/service/validation.service';
// import store from '@/store';
import Weapp from '@/components/weapp';
import goodsShare from '@/components/groupShare';

export default {
  name: 'App',
  components: {
    NetError,
    Weapp,
    goodsShare
  },
  data() {
    return {};
  },
  computed: {
    ...mapState({
      title: state => state.pay.title,
      header: state => state.pay.header,
      loading: state => state.pay.loading,
      isPrimordialBrowser: state => state.pay.isPrimordialBrowser,
      isWeixinBrowser: state => state.pay.isWeixinBrowser
    })
  },
  watch: {
    header: {
      immediate: true,
      handler(val, oldVal) {
        if (val !== oldVal) {
          document.body.className = val ? 'has-header' : '';
        }
      }
    },
    $route() {
      // store.dispatch('change_show_mini_app_guide', {
      //   bool: !isApp && !isWxMp && !isWechat ? true : false,
      //   pointer: this
      // });
      // store.dispatch('change_is_weixin_browser', !isApp && !isWxMp && isWechat ? true : false);
    }
  },
  methods: {
    backFun() {
      this.$router.go(-1);
    }
  }
};
</script>
<style lang="less">
.app {
  user-select: none;
  height: 100%;
  min-height: 100%;
  position: relative;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

.loading-container {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: 999;
  display: flex;
  justify-content: center;
  align-items: center;
  .loading {
    padding: 6px;
    border-radius: 6px;
    background-color: rgba(0, 0, 0, 0.5);
    color: #fff;
    @{deep} .cr-loading--text {
      color: #fff;
    }
  }
}
</style>
