<template>
  <el-link type="primary" @click="handleClick" :disabled="id == null || !isLink">{{name | defaultValue}}</el-link>
</template>

<script>
import { mapGetters } from 'vuex'
import { UserType } from '@/utils/constants'

export default {
  name: 'UserLink',
  props: {
    id: {
      type: String,
      default: null
    },
    name: {
      type: String,
      default: null,
    },
    // 是否可点击的链接
    isLink: {
      type: Boolean,
      default: true
    }
  },
  computed: {
    ...mapGetters(['userType', 'smUserType'])
  },
  methods: {
    handleClick() {
      this.$emit('click');
      if (this.userType === UserType.ADMIN) {
        this.$router.push({path: `/smUser/user/${this.id}`})
      } else if (this.userType === UserType.APP) {
        this.$router.push(`/user/${this.id}`)
      }
    }
  }
}
</script>
