<template>
  <div>
    <el-dialog
      top="100px"
      width="800px"
      :title="$t('Navigator.View.Personal.Information')"
      append-to-body
      :visible="personalInfoVisible"
      :close-on-click-modal="false"
      @close="closeDialog"
    >
      <el-form v-if="userInfo" :inline="true">
        <el-form-item :label="$t('Navigator.UserName')">
          <div class="item">{{ userInfo.fullname }}</div>
        </el-form-item>

        <el-form-item :label="$t('Navigator.UserAccount')">
          <div class="item">{{ userInfo.account }}</div>
        </el-form-item>

        <el-form-item :label="$t('Navigator.phoneNumber')">
          <div class="item">{{ userInfo.mobile }}</div>
        </el-form-item>

        <el-form-item :label="$t('Navigator.EmailAddress')">
          <div class="item">{{ userInfo.email }}</div>
        </el-form-item>

        <el-form-item :label="$t('Navigator.UserGender')">
          <div class="item">{{ userInfo.sex }}</div>
        </el-form-item>

        <el-form-item :label="$t('Navigator.UserStatus')">
          <div class="item">{{ userInfo.status | getUserStatus }}</div>
        </el-form-item>

        <el-form-item :label="$t('Navigator.HomeAddress')" style="width: 100%">
          <div class="item" style="width: 632px">{{ userInfo.address }}</div>
        </el-form-item>

        <el-form-item style="width: 100%" :label="$t('Navigator.Role')">
          <div v-if="roleInfo.roleName">
            <span v-for="name in roleInfo" :key="name">
              <el-tag type="warning">{{ name }}</el-tag>
            </span>
          </div>
        </el-form-item>

        <el-form-item style="width: 100%" :label="$t('Navigator.Position')">
          <el-tooltip
            v-for="post in postInfo"
            :key="post.postId"
            placement="top"
            :content="post.pathName"
          >
            <el-tag type="success">{{ post.postName }}</el-tag>
          </el-tooltip>
        </el-form-item>

        <el-form-item style="width: 100%" :label="$t('Navigator.Organization')">
          <el-tooltip
            v-for="(org, index) in allOrgInfo"
            :key="index"
            placement="top"
            :content="org.pathName"
          >
            <el-tag>{{ org.orgName }}</el-tag>
          </el-tooltip>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    name: 'PersonalInfo',
    filters: {
      getUserStatus(val) {
        switch (val) {
          case 1:
            return '正常'
          case 0:
            return '禁用'
          case -1:
            return '未激活'
          default:
            return '离职'
        }
      },
    },
    props: {
      accountInfo: {
        type: Object,
        default: null,
      },
      personalInfoVisible: {
        type: Boolean,
        default: false,
      },
    },
    data() {
      return {
        orgInfo: [],
        postInfo: {},
        roleInfo: {},
        userInfo: {},
        allOrgInfo: [],
      }
    },
    watch: {
      personalInfoVisible(val) {
        if (val && this.accountInfo) {
          this.orgInfo = this.accountInfo.org
          this.allOrgInfo = this.accountInfo.allOrgMap
          this.postInfo = this.accountInfo.post
          this.roleInfo = this.accountInfo.role
          this.userInfo = this.accountInfo.user
        }
      },
    },
    methods: {
      closeDialog() {
        this.$emit('update:personalInfoVisible', false)
      },
    },
  }
</script>

<style lang="scss" scoped>
  .el-form-item {
    .item {
      width: 250px;
      height: 32px;
      color: $base-font-color;
      border-bottom: 1px solid $base-border-color;
    }
    &:nth-child(2n + 1) {
      margin-right: 50px;
    }
    ::v-deep .el-tag {
      margin: 0 10px 0 0;
    }
  }
</style>
