<template>
  <div class="" style="margin: 20px;" id="reset-password">
    <div v-if="user">
      <el-row :gutter="20">

        <el-col :span="6" :xs="24">
          <user-card :user="user" />
        </el-col>

        <el-col :span="18" :xs="24">
          <el-card>
            <el-tabs v-model="activeTab">
              <el-tab-pane label="操作日志" name="timeline">
                <timeline />
              </el-tab-pane>
              <el-tab-pane label="信息修改" name="account">
                <account />
              </el-tab-pane>
            </el-tabs>
          </el-card>
        </el-col>

      </el-row>
    </div>
  </div>
</template>

<script>
  import {
    mapGetters
  } from 'vuex'
  import UserCard from './component/UserCard'
  import Timeline from './component/Timeline'
  import Account from './component/Account'

  import {
    getInfo
  } from '@/api/user'

  export default {
    name: 'Profile',
    components: {
      UserCard,
      Timeline,
      Account
    },
    data() {
      return {
        user: {},
        activeTab: 'timeline'
      }
    },
    computed: {
      ...mapGetters([
        'name',
        'avatar',
        'roles'
      ])
    },
    created() {
      this.getUser()
    },
    methods: {
      getUser() {

        getInfo().then(res => {
          this.user = {
            name:res.name,
            username:res.username,
            role: this.roles.join(' | '),
            avatar: this.avatar
          }
        })

      }
    }
  }
</script>
<style lang="scss">
#app:has(#reset-password) {
  .sidebar-container {
    display: none;
  }
}
</style>
