<template>
  <div class="create-container">
    <div class="create-body" v-loading="loading">
      <el-form :model="user" label-width="12%" class="demo">
        <el-form-item label="用户名称" prop="name">
          <span>{{user.name}}</span>
        </el-form-item>
        <el-form-item label="用户图标" prop="photo">
          <!--          <span  class="badge">{{user.photo}}</span>-->
          <img :src="user.photo" style="width: 50px; height: 50px;"/>
        </el-form-item>
        <el-form-item label="性别" prop="count" v-if="this.gender != null &&  this.gender != ''">
          <span>{{user.gender}}</span>
        </el-form-item>
        <el-form-item label="地址" prop="address">
          <span class="badge">{{user.address}}</span>
        </el-form-item>
        <el-form-item label="接包次数" prop="count">
          <span>{{user.taskCount}}</span>
        </el-form-item>
        <el-form-item>
          <div class="btn btn-medium" @click="back()">返回</div>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
  import Http from '@/js/http.js'
  import Apis from '@/js/api.js'
  import {notify} from '@/constants/index'
  import {getAllReportTypes, storageGet} from '@/js/index'

  export default {
    name: 'UserDetail',
    components: {},
    data() {
      return {
        user: {},
        loading: false,
        id: 0,
        user: {
          name: '',
          photo: '',
          taskCount: '',
          address: '',
          gender: '',
        },
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.init()
      })
    },
    methods: {
      init() {
        this.id = this.$route.params.id
        this.loadData()
      },
      back() {
        this.$router.go(-1);
      },
      loadData() {
        this.showLoading()
        Http.get(Apis.USER.GET_DETAIL.replace('{userId}', this.id)).then((res) => {
          console.log(res)
          this.user.name = res.data.name
          this.user.photo = res.data.photoUrl
          this.user.gender = res.data.gender
          this.user.taskCount = res.data.taskCount
          this.user.address = res.data.address
          this.hideLoading()
        }).catch((error) => {
          this.hideLoading()
          notify('error', '打开详情失败:' + error.data)
        })
      },
      setUserInfo() {
        this.user = storageGet('user')
      },
      showLoading() {
        this.loading = true
      },
      hideLoading() {
        this.loading = false
      }
    },
    watch: {
      userType(val) {
        this.userType = val
      }
    }
  }
</script>

<style>
  .demo {
    font-size: 32px;
  }

  .el-form-item {
    max-height: 120px !important;
  }
</style>
