<template>
  <a :class="userClass" :target="target" :href="userUrl">
    <div class="img-wrap">
      <p class="head_img_url" v-if="data.head_img_url">
        <WlPic :src="data.head_img_url" />
      </p>
      <div :class="`user-icon ${type}`" v-if="show_type">
        <i :class="`icon-card-${type} iconfont icon`"></i>
      </div>
    </div>
    <p class="user-name" v-if="(data.nick_name && !is_trial) || (is_trial && data.userid_third)">
      <WlStaffName :name="data.nick_name" type="userName" :openid="data.userid_third" :is_trial="is_trial" />
    </p>
  </a>
</template>

<script>
import { isEmpty } from "@packages/utils/index";
import WlPic from "@packages/components/Common/WlPic/src/index.vue";
import WlStaffName from "@packages/components/Common/WlStaffName/src/index.vue";
export default {
  name: "WlUser",
  components: { WlPic, WlStaffName },
  props: {
    data: {
      type: Object,
      default: () => {
        return {};
      },
    },
    size: {
      type: String,
      default: "normal",
    },
    target: {
      type: String,
      default: "_self",
    },
    type: {
      type: String,
      default: "",
    },
    is_trial: {
      type: Boolean,
      default: false,
    },
    inline: {
      type: Boolean,
      default: false,
    },
  },
  computed: {
    userUrl() {
      return this.data.href || "javascript:void(0)";
    },
    userClass() {
      return {
        "user-wrap": true,
        [this.size]: true,
        "inline": this.inline,
        cursor: !isEmpty(this.data.href),
      };
    },
    show_type() {
      return ['weixin', 'wxwork'].includes(this.type)
    }
  },
};
</script>

<style lang="scss" scoped>
.img-wrap {
  position: relative;

  .head_img_url {
    flex-shrink: 0;
    width: j(16);
    height: j(16);
    border-radius: 50%;
    overflow: hidden;
  }

  .user-icon {
    position: absolute;
    width: j(17px);
    height: j(17px);
    border-radius: 50%;
    border: j(2px) solid white;
    bottom: 0;
    right: 0;
    transform: translate(3px, 3px);
    color: white;
    @extend %flex-middle-center;

    .icon {
      font-size: j(12px);
      transform: scale(0.7);
    }
  }

  .weixin {
    background-color: #74d178;
  }

  .wxwork {
    background-color: #5bbaff;
  }
}

.user-name {
  font-size: j(12);
  font-weight: 500;
  padding-left: 5px;
  color: $disabled-color;
  color: rgba(41, 80, 184, 1);
}

.user-wrap {
  &:not(.inline) {
    @extend %flex-middle;
    text-decoration: none;

    .user-name {
      @include textEllipsis(1);
    }
  }

  &.inline {
    display: inline;

    .img-wrap {
      display: inline-block;
      vertical-align: text-bottom;
    }

    .user-name {
      display: inline;
    }
  }

  &.normal {
    .head_img_url {
      width: 22px;
      height: 22px;
    }

    .user-name {
      font-size: j(15);
    }
  }

  &.medium {
    .head_img_url {
      width: 20px;
      height: 20px;
    }

    .user-name {
      font-size: j(13);
    }
  }

  &.small {
    .head_img_url {
      width: 16px;
      height: 16px;
    }

    .user-name {
      font-size: j(12);
    }
  }

  &.cursor {
    cursor: pointer;

    .user-name {
      color: #2950b8;
    }
  }
}
</style>
