<template>
  <div :style="{backgroundImage:'url('+headerUrl+')'}" class="app-header">
    <img src="../../assets/global_images/appLogo.png" style="display: inline-block;float: left;margin-left: 10px; margin-top: 10px; width:37px;height:40px;"/>
    <h3>{{ title }}</h3>
    <IvrBar v-if="showIvrBar"/>
    <el-dropdown class="avatar-container" trigger="click">
      <div class="avatar-wrapper">
        <span style="line-height:50px;">欢迎您，{{ name }}</span>
        <!--<img :src="avatar+'?imageView2/1/w/80/h/80'" class="user-avatar">-->
        <i class="el-icon-caret-bottom"/>
      </div>
      <el-dropdown-menu slot="dropdown" class="user-dropdown">
        <!--<router-link class="inlineBlock" to="/">-->
        <!--<el-dropdown-item>-->
        <!--主页-->
        <!--</el-dropdown-item>-->
        <!--</router-link>-->
        <el-dropdown-item>
          <span style="display:block;" @click="resetPwd">修改密码</span>
        </el-dropdown-item>
        <el-dropdown-item divided>
          <span style="display:block;" @click="logout">注销</span>
        </el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
    <reset-pwd v-show="showSetPwd" ref="retPwd"/>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import ResetPwd from '@/views/system/user/resetPwd'
import { getProject } from '@/utils/baseConfig'
import IvrBar from './ivr/ivrBar'
import { isReceiver } from '@/utils/permission'
export default {
  name: 'AppHeader',
  components: { IvrBar, ResetPwd },
  data() {
    return {
      title: getProject().title,
      name: this.$store.getters.name,
      showSetPwd: false,
      showIvrBar: this.isReceiver(), // 判断角色是否为受理员，受理员允许有ivr功能
      headerUrl: require('@/assets/global_images/header.png')// 头部图片
    }
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar'
    ])
  },
  methods: {
    toggleSideBar() {
      this.$store.dispatch('ToggleSideBar')
    },
    logout() {
      // 判断签入签出状态，如果已签入提醒先签出
      if (isReceiver() && this.$store.getters.online === '1') {
        this.$message.warning('请先签出！')
      } else {
        this.$store.dispatch('LogOut').then(() => {
          const BASE_API = process.env.BASE_API
          if (BASE_API.search('http://10.18.0.23')) {
            window.location.href = 'http://10.18.0.50:8086/platform-sso-server/logout'
          } else {
            this.$router.replace('/')
          }
        })
      }
    },
    resetPwd() {
      this.showSetPwd = true
      this.$refs.retPwd.initDialog(true)
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .app-header{
    height:60px;
    background-color:#000000;
    background-repeat: no-repeat;
    -webkit-background-size: 100% 100%;
    background-size: 100% 100%;
    color:white;
  }
  h3{
    margin-left:10px;
    display: inline-block;
    float:left;
  }
  .avatar-container {
    height: 50px;
    display: inline-block;
    float: right;
    z-index:500;
    position: fixed;
    top:5px;
    right: 35px;
    .avatar-wrapper {
      color:#d3dce6;
      cursor: pointer;
      margin-top: 5px;
      position: relative;
      line-height: initial;
      .user-avatar {
        width: 40px;
        height: 40px;
        border-radius: 10px;
      }
      .el-icon-caret-bottom {
        font-size: 12px;
      }
    }
  }
</style>
