<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="6" :xs="24">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>个人信息</span>
          </div>
          <div>
            <div class="text-center">
              <userAvatar :user="user" />
            </div>
            <ul class="list-group list-group-striped">
              <li class="list-group-item">
                <svg-icon icon-class="user" />登录名
                <el-tooltip placement="top">
                  <div slot="content">{{ user.userName }}</div>
                  <div class="pulll-right">{{ user.userName }}</div>
                </el-tooltip>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="email" />用户邮箱
                <el-tooltip placement="top">
                  <div slot="content">{{ user.email }}</div>
                  <div class="pulll-right">{{ user.email }}</div>
                </el-tooltip>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="company" />所属企业
                <el-tooltip placement="top">
                  <div slot="content">{{ company.scyName }}</div>
                  <div class="pulll-right">{{ company.scyName }}</div>
                </el-tooltip>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="tree" />所属部门
                <el-tooltip placement="top" v-if="user.dept">
                  <div slot="content" >{{ user.dept.deptName }}</div>
                  <div class="pulll-right">{{ user.dept.deptName }}</div>
                </el-tooltip>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="peoples" />所属角色
                <!-- <div class="pull-right" :show-overflow-tooltip="true" width="50" ></div> -->
                <el-tooltip placement="top">
                  <div slot="content">{{ roleGroup }}</div>
                  <div class="pulll-right">{{ roleGroup }}</div>
                </el-tooltip>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="date" />创建日期
                <el-tooltip placement="top">
                  <div slot="content">{{ user.createTime }}</div>
                  <div class="pull-right">{{ user.createTime }}</div>
                </el-tooltip>
              </li>
            </ul>
          </div>
        </el-card>
      </el-col>
      <el-col :span="18" :xs="24">
        <el-card>
          <div slot="header" class="clearfix">
            <span>基本资料</span>
          </div>
          <el-tabs v-model="activeTab">
            <el-tab-pane label="基本资料" name="userinfo">
              <userInfo :user="user" />
            </el-tab-pane>
            <el-tab-pane label="修改密码" name="resetPwd">
              <resetPwd :user="user" />
            </el-tab-pane>
            <!-- <el-tab-pane label="解除绑定" name="bindOff">
              <bindOff/>
            </el-tab-pane> -->
          </el-tabs>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import userAvatar from "./userAvatar";
import userInfo from "./userInfo";
import resetPwd from "./resetPwd";
import bindOff from "./bindOff";
import { getUserProfile } from "@/api/system/user";

export default {
  name: "Profile",
  components: { userAvatar, userInfo, resetPwd, bindOff },
  data() {
    return {
      user: {},
      company: {},
      roleGroup: '',
      activeTab: "userinfo"
    };
  },
  created() {
    this.getUser();
  },
  methods: {
    getUser() {
      var sscDomain = document.location.hostname;
      getUserProfile(sscDomain).then(response => {
        debugger
        this.user = response.data;
        this.company = response.company;
        var roles = response.roleGroup.roles;
        for (var i = 0; i < roles.length; i ++) {
          this.roleGroup += roles[i];
          if (i != roles.length - 1) {
            this.roleGroup += ',';
          }
        }
      });
    }
  }
};
</script>
