<template>
	<view style="position: relative;">
		<u-avatar
		  @longpress="longpress"
		  @click="click"
		  @onError="errorHandle"
		  :src="getAvatarUrl"
		  :text="avatarText"
		  bgColor="#e5e5e5"
		  :defaultUrl="getDdefaultUrl"
		  :shape="shape"
		  :size="size"
		  mode="aspectFill"
		  font-size="14">
		</u-avatar>
		<slot></slot>
	</view>
  
</template>

<script>
// import defaultGroupIcon from "https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/contact_my_group.png";
// import defaultNotifyIcon from "https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/default_notify_icon.png";
const defaultNotifyIcon = "https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/default_notify_icon.png";
const defaultGroupIcon = "https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/contact_my_group.png";
export default {
  name: "MyAvatar",
  props: {
    src: String,
    shape: {
      type: String,
      default: "square",
    },
    size: {
      type: String,
      default: "46",
    },
    isGroup: {
      type: Boolean,
      default: false,
    },
    isNotify: {
      type: Boolean,
      default: false,
    },

    desc: String,
  },
  data() {
    return {
       avatarText: undefined,
	   defaultFaceIcon: "https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/app/newImages/0d7f54fe8adc4d3689923f9bfc83d4c9.png"
    };
  },
  computed: {
    getAvatarUrl() {
		  if (this.isGroup) {
			 return defaultGroupIcon;
		  }
		  else if (this.isNotify) {
			 return defaultNotifyIcon;
		  }
		  else{
			  if (this.src) {
			      return this.src;
			  }else{
			  	  return this.defaultFaceIcon;
			  }
		  }
		  this.avatarText = this.desc ? this.desc.slice(0, 1) : "未知";
		  return "";
    },
    getDdefaultUrl() {
      return this.isGroup ? defaultGroupIcon : undefined;
    },
  },
  methods: {
    errorHandle() {
      this.avatarText = this.desc ? this.desc.slice(0, 1) : "未知";
    },
    redirectShow() {
      if (this.avatarText) {
        this.avatarText = undefined;
      }
    },
    click() {
      this.$emit("click");
    },
    longpress() {
      this.$emit("longpress");
    },
  },
  watch: {
    src() {
      this.redirectShow();
    },
    desc() {
      this.redirectShow();
    },
  },
};
</script>

<style>
	
	
</style>
