<template>
  <view class="hot-section">
    <view class="hot-top" @click="navigateTo">
      <view class="title">风口概念</view>
      <view class="time">近一个月热门</view>
    </view>
    <view class="tag-box">
      <view v-for="(item, index) in topConceptList_d" :key="index" class="tag">
        {{ item.content }}
      </view>
    </view>
    <view class="tag-content">
      <view class="content" @click="goDetail(oneData)">{{ oneData.title }} </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import { getListByTag } from "@/api/detail";
import { getTopConcept_d } from "@/api/newsInfo";
import { useUserStore } from "@/stores/user";
import { computed, onMounted, ref } from "vue";

const emit = defineEmits(["onShow"]);
const active = ref(0);
const topConceptList = ref([]);
const oneData = ref({});
const userStore = useUserStore();

const topConceptList_d = computed(() => {
  return topConceptList.value.slice(0, 3);
});

const handleClickTag = (index: number, item: any) => {
  active.value = index;
  getList(item);
};

// 热门行业top10
async function getTopConcept_dFn() {
  topConceptList.value = await getTopConcept_d({});
}

async function getList() {
  const name = topConceptList.value[active.value].content;
  // 概念标签
  let { code, data } = await getListByTag({ name });
  if (code == 200) {
    oneData.value = data[0];
  }
}

// 跳转详情
function goDetail(item: any) {
  if (userStore.isLogin) {
    uni.navigateTo({
      url: `/pages/detail/indexNewsInfo?id=${item.id}`,
    });
  } else {
    emit("onShow");
  }
}

// 跳转子页
function navigateTo() {
  if (userStore.isLogin) {
    uni.navigateTo({
      url: `/pages/concept/index`,
    });
  } else {
    emit("onShow");
  }
}

onMounted(async () => {
  // 热门行业top10
  await getTopConcept_dFn();
  await getList();
});
</script>

<style scoped lang="scss">
.hot-section {
  width: 710rpx;
  height: 257rpx;
  margin: 0 20rpx 20rpx;
  padding: 30rpx 30rpx 0 30rpx;
  background-image: url("@/assets/images/page/5_pic@2x.png");
  background-repeat: no-repeat;
  background-size: 100% auto;
  box-sizing: border-box;
}

.hot-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24rpx;

  .title {
    font-family: "AlimamaShuHeiTi, AlimamaShuHeiTi";
    font-weight: bold;
    font-size: 32rpx;
    color: #111111;
    line-height: 45rpx;
  }
  .time {
    font-family: "PingFangSC, PingFang SC";
    font-weight: 400;
    font-size: 24rpx;
    color: #666666;
    line-height: 33rpx;
  }
}

.tag-box {
  display: flex;
  align-items: center;
  gap: 10rpx;
  margin-bottom: 20rpx;

  .tag {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rpx 8rpx;
    border-radius: 4rpx;
    border: 1px solid #bb875d;
    font-size: 22rpx;
    color: #c18252;
    line-height: 30rpx;
    text-align: left;
    font-style: normal;
  }
}

.tag-content {
  width: 100%;

  .content {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: break-all;
    font-family: "PingFangSC, PingFang SC";
    font-weight: 500;
    font-size: 28rpx;
    color: #111111;
    line-height: 40rpx;
  }
}
</style>
