<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" />用户名称
                <div class="pull-right">{{ user.userName }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="phone" />手机号码
                <div class="pull-right">{{ user.phonenumber }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="email" />用户邮箱
                <div class="pull-right">{{ user.email }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="tree" />所属组织
                <div class="pull-right" v-if="user.dept">{{ user.dept.deptName }} / {{ postGroup }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="peoples" />所属角色
                <div class="pull-right">{{ roleGroup }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="date" />创建日期
                <div class="pull-right">{{ user.createTime }}</div>
              </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 />
            </el-tab-pane>
          </el-tabs>
        </el-card>
        <el-card style="margin-top: 16px">
          <div slot="header" class="clearfix">
            <span>数据导出</span>
          </div>
          <skeleton v-if="isSkeleton" style="padding: 16px"></skeleton>
          <div class="table-item">
            <el-table
              class="fixed-table"
              :data="tableData"
              element-loading-text="Loading"
              v-horizontal-scroll="'hover'"
              max-height="640px"
              border
              highlight-current-row
              v-if="tableDataTotal > 0 && !isSkeleton"
            >
              <el-table-column label="序号" width="60" align="left">
                <template slot-scope="scope">{{ (params.pageNum - 1 )* params.pageSize + scope.$index + 1 }}</template>
              </el-table-column>
              <el-table-column label="导出表格名称" align="left" prop="fileName"></el-table-column>
              <el-table-column label="导出时间" align="left" prop="createTime"></el-table-column>
              <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope" align="left">
                  <div v-if="scope.row.status === 0" class="wordprimary" style="text-align: left" @click="getFile(scope.row.url)">下载表格</div>
                  <div v-if="scope.row.status === 2" class="wordprimary" style="text-align: left">生成中...</div>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div class="pagination-box" v-if="tableDataTotal>params.pageSize">
            <el-pagination background :current-page="params.pageNum" :page-size="params.pageSize" :total="tableDataTotal" layout="prev, pager, next, jumper" @current-change="handleCurrentChange" @size-change="handleSizeChange" />
          </div>
          <div class="tables">
          <div class="empty" v-if="tableDataTotal==0 && !isSkeleton">
            <img class="img" src="@/assets/images/project/empty.png">
            <div class="p1">暂无数据展示</div>
          </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import userAvatar from "./userAvatar";
import userInfo from "./userInfo";
import resetPwd from "./resetPwd";
import { getUserProfile,fileList } from "@/api/system/user";
import skeleton from '@/views/project/projectList/component/skeleton'

export default {
  name: "Profile",
  components: { userAvatar, userInfo, resetPwd,skeleton },
  data() {
    return {
      user: {},
      roleGroup: {},
      postGroup: {},
      activeTab: "userinfo",
      isSkeleton:true,
      tableData:[],
      tableDataTotal:0,
      params:{pageNum:1,pageSize:10},
    };
  },
  created() {
    this.getUser();
    this.fileList()
  },
  methods: {
    getUser() {
      getUserProfile().then(response => {
        this.user = response.data.user;
        this.roleGroup = response.data.roleGroup;
        this.postGroup = response.data.postGroup;
      });
    },
    fileList(){
      fileList(this.params).then(res=>{
        if(res.code == 200){
          this.tableData = res.rows
          this.tableDataTotal = res.total
        }else{
          this.tableData = []
          this.tableDataTotal = 0
        }
        this.isSkeleton = false
      })
    },
    handleCurrentChange(val){
      this.params.pageNum = val
      this.fileList()
    },
    handleSizeChange(val){
      this.params.pageNum = 1
      this.params.pageSize = val
      this.fileList()
    },
    getFile(url){
      window.open(url)
    }
  }
};
</script>
<style scoped lang="scss">
  .empty{
    margin: 0 auto;
    height: 300px;
    text-align: center;
    .img{
      width: 108px;
      height: 108px;
      margin-bottom: 24px;
      margin-top: 70px;
    }
    .p1{
      color: #333333;
      font-size: 16px;
    }
  }
</style>
