<template>
  <div id="app">
    <cr-nav-bar v-if="header" :title="title" left-text="" @click-left="backFun" />
    <div class="app">
      <router-view />
    </div>
    <div v-if="loading" class="loading-container">
      <cr-loading class="loading" size="24px">加载中...</cr-loading>
    </div>
    <net-error />
  </div>
</template>
<script>
import { mapState } from 'vuex';
import NetError from '@/components/NetError';
export default {
  name: 'App',
  components: {
    NetError
  },
  data() {
    return {};
  },
  computed: {
    ...mapState({
      title: state => state.pay.title,
      header: state => state.pay.header,
      loading: state => state.pay.loading
    })
  },
  watch: {
    header: {
      immediate: true,
      handler(val, oldVal) {
        if (val !== oldVal) {
          document.body.className = val ? 'has-header' : '';
        }
      }
    }
  },
  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>
