<template>
  <el-card style="margin-bottom:20px;">
    <div slot="header" class="clearfix">
      <span>用户资料</span>
    </div>

    <div class="user-profile">
      <div class="box-center" >
        <el-upload
            class="avatar-uploader"
           :file-list="fileList"
           :action="uploadUrl"
           method="post"
           :data="params"
           :limit="1"
           :show-file-list	="false"
           :on-success	="onUploadSuccess"
          >
            <img v-if="imageUrl!=null && imageUrl!=''" :src="imageUrl" class="avatar" />
            <svg-icon icon-class="header" style="height:170px;width:170px;" v-else/>
          </el-upload>

      </div>
      <div class="box-center">
        <div class="user-name text-center">{{ dataForm.realName }}</div>
        <div class="user-role text-center text-muted">{{ dataForm.email }}</div>
      </div>
    </div>

  </el-card>
</template>

<script>
import PanThumb from '@/components/PanThumb'

export default {
  components: { PanThumb },
  emits:['onUploadHeader'],
  props: {
    dataForm: {
      type: Object,
      default:null,
    }
  },
  watch:{
      'dataForm':{
        handler(val){
          if(val==null)return;
          this.imageUrl=val.avatar
        },
        immediate: true,
        deep: true,
      }
  },
  data(){
    return{
      fileList:[],
      uploadUrl:"",
      imageUrl:'',
      params:{
        token:"",
      },
    }
  },
  created(){
    let _this=this;
    _this.uploadUrl=process.env.VUE_APP_BASE_API+"/upload/file";
    _this.params.token=_this.$store.getters.token;
  },
  methods:{
    onUploadSuccess(e){
      let _this=this;
      this.imageUrl=e.data.fileUrl;
      this.$emit("onUploadHeader",e.data.fileUrl)
    },
  }
}
</script>

<style lang="scss" scoped>
.box-center {
  margin: 0 auto;
  display: table;

  .avatar-uploader{
    border:1px solid #CCC;
    width:170px;
    height:170px;
    display:flex;
    justify-content: center;
    align-items: center;
  }
}

.text-muted {
  color: #777;
}

.user-profile {
  .user-name {
    font-weight: bold;
  }

  .box-center {
    padding-top: 10px;
  }

  .user-role {
    padding-top: 10px;
    font-weight: 400;
    font-size: 14px;
  }

  .box-social {
    padding-top: 30px;

    .el-table {
      border-top: 1px solid #dfe6ec;
    }
  }

  .user-follow {
    padding-top: 20px;
  }
}

.user-bio {
  margin-top: 20px;
  color: #606266;

  span {
    padding-left: 4px;
  }

  .user-bio-section {
    font-size: 14px;
    padding: 15px 0;

    .user-bio-section-header {
      border-bottom: 1px solid #dfe6ec;
      padding-bottom: 10px;
      margin-bottom: 10px;
      font-weight: bold;
    }
  }
}

.avatar-uploader .avatar {
  width: 160px;
  height: 160px;
  display: block;
}
.avatar-uploader .el-upload {
  border: 1px dashed var(--el-border-color);
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: var(--el-transition-duration-fast);
}

.avatar-uploader .el-upload:hover {
  border-color: var(--el-color-primary);
}

.el-icon.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  text-align: center;
}
</style>
