<template>
  <div class="user-item">
    <div class="left" @click="router.push(`tg?id=${item.id}`)">
      <img :src="item.avatar" alt="" srcset="" />
      <div class="user-name">
        <h4>{{ item.showName }}</h4>
        <p>{{ item.followCount }}人关注</p>
      </div>
    </div>

    <button @click="subAdvisor">已关注</button>
  </div>
</template>

<script setup>
import { defineProps, defineEmits } from "vue";
import { useRouter } from "vue-router";
import { attentionTg } from "@/api/index";
import { showConfirmDialog } from "vant";
const router = useRouter();
const props = defineProps({
  item: {
    type: Object,
    default: () => ({}),
  },
});

const emit = defineEmits(["deleteTg"]);
async function subAdvisor() {
  showConfirmDialog({
    message: "确定不在关注当前投顾吗",
    confirmButtonColor: "#F02E18",
  })
    .then(async () => {
      let ret = await attentionTg({
        advisorId: props.item.id,
        channel: 2,
        option: 2,
      });
      if (ret.code === 0) {
        emit("deleteTg", props.item.id);
      }
    })
    .catch(() => {});
}
</script>
<style scoped lang="scss">
.user-item {
  display: flex;
  text-align: left;
  align-items: center;
  justify-content: space-between;
  padding: 32px 0 24px 0;
  border-bottom: 0.5px solid var(---, #ebeced);
  .left {
    display: flex;
    text-align: left;
    align-items: center;
  }
  img {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    margin-right: 24px;
  }
  .user-name {
    h4 {
      color: rgb(51, 51, 51);
      font-size: 32px;
      font-style: normal;
      font-weight: 400;
      line-height: 56px;
    }
    p {
      color: rgb(153, 153, 153);
      font-size: 24px;
      font-style: normal;
      font-weight: 400;
    }
  }
  button {
    padding: 16px 20px;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    border-radius: 8px;
    border: 0.5px solid rgba(179, 179, 179, 0.5);
    color: rgb(153, 153, 153);
    text-align: center;
    font-size: 24px;
    font-weight: 400;
    background: none;
  }
}
</style>
