<template>
  <div class="main-header">
    <p class="p">区域急危重症救治协同平台</p>
    <div class="div">
      <img src="../../assets/images/user.png" alt="" />
      <span v-if="userInfo.roleId!=2">{{ userInfo.userName }}</span>
      <el-dropdown v-else @command="handleCommand">
        <span class="el-dropdown-link">
          {{ userInfo.userName}}<i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="logout">退出登录</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  computed: {
    ...mapGetters([
      'userInfo'
    ])
  },
  data() {
    return {}
  },
  mounted() {

  },
  methods: {
    handleCommand(command) {
      if (command === 'logout') {
        this.logout()
      }
    },
    logout() {
      // 显示确认对话框
      this.$confirm('确定要退出登录吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        window.location.href = 'https://tymh.whhealth.org.cn/mdxtpt/info'
      }).catch(() => {
        this.$message.info('已取消退出')
      })
    }
  },
}
</script>

<style lang="scss"></style>
