<script setup>
import { ref } from "vue";
import { useRoute, useRouter } from "vue-router";
import { interactiveInterface } from "@/api/api.js";

const $route = useRoute();
const $router = useRouter();

function handleShow() {
  getList();
}

const isshow = ref(false);
const list = ref([]);
async function getList() {
  const res = await interactiveInterface.getAllNoticeList();
  if (res.Ret === 200) {
    const arr = res.Data.List || [];
    isshow.value = res.Data.IsShow;
    list.value = arr;
  }
}
getList()
function goDetail(item) {
  // 去到留言管理页面
  if ($route.path === "/ybComment") {
    $router.go(0);
  } else {
    $router.push("/ybComment");
  }
}
</script>
<template>
  <el-popover
    placement="bottom"
    width="404"
    trigger="hover"
    popper-class="question-msg-pop"
    @show="handleShow"
    @hide="handleShow"
    v-if="isshow"
  >
    <div class="question-msg-pop-content">
      <div style="font-size: 16px">待处理消息（{{ list.length }}）</div>
      <div class="list-box">
        <div
          class="item"
          v-for="item in list"
          :key="item.CommentId"
          @click="goDetail(item)"
        >
          <img
            class="avatar"
            :src="
              item.HeadImgUrl
                ? item.HeadImgUrl
                : '~@/assets/img/icons/msg-inner.png'
            "
            alt=""
          />
          <div style="overflow: hidden">
            <div class="title">{{ item.Content }}</div>
            <div class="time">{{ item.CreateTime }}</div>
          </div>
        </div>
      </div>
    </div>
    <template #reference >
      <div class="icon-box-item">
        <img
          src="~@/assets/img/icons/msg2.png"
          alt=""
          style="height: 20px; width: 20px"
        />
        <span
          style="
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background: #f00;
            display: block;
            position: absolute;
            right: 5px;
            top: 3px;
          "
          v-show="list.length > 0"
        ></span>
      </div>
    </template>
  </el-popover>
</template>
<style scoped lang="scss">
.question-msg-pop-content {
  min-width: 404px !important;
  .list-box {
    margin-top: 20px;
    border-top: 1px solid #dcdfe6;
    min-height: 400px;
    max-height: 600px;
    overflow-y: auto;
    .item {
      display: flex;
      margin: 17px 0;
      cursor: pointer;
      align-items: center;
      .avatar {
        width: 40px;
        height: 40px;
        object-fit: cover;
        margin-right: 15px;
      }
      .title {
        font-size: 16px;
        color: #666;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      .time {
        color: #999;
        font-size: 12px;
      }
    }
  }
}
.icon-box-item {
  height: 32px;
  padding: 0 10px;
  border-radius: 4px;
  cursor: pointer;
  margin-right: 30px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  color: #333;
  position: relative;
  &:hover {
    background-color: #eaf3fe;
    color: #409eff;
  }
  svg {
    width: 20px;
    height: 20px;
  }
  img {
    width: 20px;
    height: 20px;
  }
}
</style>
