<template>
  <div v-loading.body.fullscreen="fullscreenLoading" element-loading-background="rgba(255, 255, 255, 0)">
    <van-sticky v-if="!appFlag" class="sticky">
      <div class="header">
        <div class="back">
          <backIcon/>
        </div>
        <!-- 在线客服 -->
        {{ $t('tab.tab11') }}
      </div>
    </van-sticky>
    <LiveChatWidget ref="test" visibility="maximized" :customerName="userInfo.im_name" :customerEmail="userInfo.email" license="16117788"/>
  </div>
</template>
<script>
import { mapGetters } from 'vuex'
import { LiveChatWidget } from '@livechat/widget-vue/v2'
export default {
  components: {
    LiveChatWidget,
  },
  data () {
    return {
      fullscreenLoading: false
    }
  },
  computed: {
    ...mapGetters(['userInfo']),
  },
  activated() {
    window.LiveChatWidget.call("maximize")
  },
  deactivated() {
    window.LiveChatWidget.call("hide")
  },
  beforeDestroy() {
    window.LiveChatWidget.call("destroy")
  },
  mounted() {
    if (!window.LiveChatWidget) {
      return
    }
    this.fullscreenLoading = true
    window.LiveChatWidget.on('ready', this.onReady)
    window.LiveChatWidget.on('visibility_changed', this.onVisibilityChanged)
  },
  methods: {
    onReady() {
      this.fullscreenLoading = false
    },
    onVisibilityChanged(data) {
      if (data.visibility == 'minimized') {
        this.$router.back()
      }
    }
  }
}
</script>
<style lang="less" scoped>
.sticky {
  background-color: var(--bg-);
}
.header {
  height:36px;
  position: relative;
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  padding: 11px 14px 0 9px;
  background-color: var(--bg-);
  .back {
    position: absolute;
    left: 9px;
    top: 7px;
  }
}
</style>