<template>
  <el-avatar :src="userPhoto" fit="cover">
    <img :src="userPhoto" alt="" />
  </el-avatar>
</template>

<script>
import uc from '@/api/uc.js'
export default {
  data() {
    return {
      userPhoto: window.context.front + '/img/defaultPhoto.jpg'
    }
  },
  created() {
    this.getData()
  },
  mounted() {
    this.$bus.$on('updataUserInfo', () => {
      this.getData()
    })
  },
  methods: {
    getData() {
      let currentUser = sessionStorage.getItem('currentUser')
      let account = JSON.parse(currentUser).account
      if (account) {
        uc.getUser(account).then(res => {
          if (res.user.photo) {
            this.$store
              .dispatch('menu/downloadImg', res.user.photo)
              .then(res => {
                if (res != '') {
                  this.userPhoto = res
                }
              })
          }
        })
      }
    }
  }
}
</script>
