<template>
  <view class="all">
    <PageHeaderView
      :title="type == 0 ? '热门行业池Top10' : '风口概念池Top10'"
    ></PageHeaderView>

    <!-- 类目标签 start -->
    <view class="page_content">
      <view class="tag_list">
        <view
          :class="['tag_item', clickTagIndex == index ? tagClickedClass : '']"
          class="tag_item"
          v-for="(item, index) in tagList"
          :key="index"
          @click="clickTag(index)"
        >
          {{ item.content }}
        </view>
      </view>
    </view>
    <!-- 类目标签 end -->

    <!-- 列表 start -->
    <view class="list">
      <view
        v-for="(item, index) in list"
        :key="index"
        class="news-item"
        @click="goDetail(item)"
      >
        <view class="news-content">
          <text class="news-title">{{ item.title }}</text>
          <text class="news-desc">{{ item.summary }}</text>
          <view class="news-meta">
            <text class="source">{{ item.tag }}</text>
            <text class="time">{{ item.time }}</text>
          </view>
        </view>
      </view>
    </view>
    <!-- 列表 end -->
  </view>
</template>

<script setup>
import { ref, onMounted, onUnmounted, reactive } from "vue";
import PageHeaderView from "@/components/PageHeaderView.vue";
import {
  getindustryCount,
  getConceptCount,
  getTopNews,
  getTopIndustry_d,
  getTopConcept_d,
  getNews_cnt_d,
  newsInfoScore,
} from "@/api/newsInfo";

import { getListByTag, getListByTagIndustry } from "@/api/detail";

import dayjs from "dayjs/esm/index";

const props = defineProps({
  type: {
    type: String,
    default: () => 0,
  },
  index: {
    type: String,
    default: () => 0,
  },
});

const clickTagIndex = ref(0);

const tagList = ref([]);

const listData = ref([
  {
    title: "伊朗考虑报复美国对其核设施的袭击",
    summary:
      "伊朗誓言报复，向以色列发射导弹；特朗普提出伊朗政权更迭的想法；伊朗外长在莫斯科会见普京；伊朗考虑关闭霍尔木兹海峡，影...",
    source: "日-日本经济新闻",
    time: "2025-06-23 10:00",
  },
  {
    title: "刚果延长禁令后，中国钴价和库存飙升",
    summary:
      "刚果民主共和国将钴出口禁令延长至9月，导致全球约四分之三的钴供应受到影响。这一消息引发了中国市场的反应。",
    source: "彭博社", // 原文第二条未显示明确来源，此处留空，可根据实际补充
    time: "", // 原文第二条未显示明确时间，此处留空，可根据实际补充
  },
]);

function clickTag(index) {
  clickTagIndex.value = index;

  getListByTagFn();
}

const industryList = ref([]);
const topConceptList = ref([]);
// 热门行业top10
async function getTopIndustry_dFn() {
  industryList.value = await getTopIndustry_d({});
}

// 风口概念池top10
async function getTopConcept_dFn() {
  topConceptList.value = await getTopConcept_d({});
}

const list = ref([]);
async function getListByTagFn() {
  let id = 0;

  if (props.type == 0) {
    id = industryList.value[clickTagIndex.value].content;
  } else {
    id = topConceptList.value[clickTagIndex.value].content;
  }
  uni.showLoading();
  if (props.type == 1) {
    // id = 1125;

    // 概念标签
    let { code, data } = await getListByTag({ name: id });
    if (code == 200) {
      list.value = data;
    }
  } else {
    // id = 181;
    // 行业
    let { code, data } = await getListByTagIndustry({ name: id });
    if (code == 200) {
      list.value = data;
    }
  }
  uni.hideLoading();
}

function goDetail(item) {
  uni.navigateTo({
    url: "/pages/detail/indexNewsInfo?id=" + item.id,
  });
}

const tagClickedClass = ref("");
onMounted(async () => {
  if (props.type && props.type == 0) {
    // 热门行业池
    tagClickedClass.value = "tag_item_act_blue";
    // 热门行业top10
    await getTopIndustry_dFn();
    tagList.value = industryList.value;
  } else {
    // 风口概念池
    tagClickedClass.value = "tag_item_act_yellow";
    // 风口概念池top10
    await getTopConcept_dFn();
    tagList.value = topConceptList.value;
  }

  if (props.index) {
    clickTagIndex.value = props.index;
  }

  getListByTagFn();
});
</script>

<style scoped lang="scss">
.page_content {
  padding: 0 30rpx;
}

.tag_list {
  display: flex;
  flex-wrap: wrap;
  gap: 15rpx;
  margin-top: 30rpx;

  .tag_item {
    background: #f3f5f8;
    border-radius: 8rpx;
    padding: 15rpx 25rpx;
    border-radius: 10rpx;
    width: calc(50vw - 100rpx);

    font-family: PingFangSC, PingFang SC;
    font-weight: normal;
    font-size: 28rpx;
    color: #333333;
    line-height: 40rpx;
    text-align: center;
    font-style: normal;
  }

  .tag_item_act_blue {
    font-family: PingFangSC, PingFang SC;
    font-weight: bold;
    font-size: 28rpx;
    color: #3f80fa;
    line-height: 40rpx;
    text-align: center;
    font-style: normal;
    background-color: #f5f8fe;
  }

  .tag_item_act_yellow {
    font-family: PingFangSC, PingFang SC;
    font-weight: bold;
    font-size: 28rpx;
    color: #ffa800;
    line-height: 40rpx;
    text-align: center;
    font-style: normal;
    background-color: #fff9ec;
  }
}

.news-item {
  display: flex;
  align-items: flex-start;
  margin-bottom: 15px;
  border-bottom: 1px solid #f2f2f2;
  padding-bottom: 10px;
}

.list {
  padding: 0 30rpx;
  margin-top: 50rpx;
}

.news-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10rpx;
}

.news-title {
  font-size: 16px;
  font-weight: bold;
  color: #333;
  margin-bottom: 5px;
  line-height: 1.2;
}

.news-desc {
  font-family: PingFangSC, PingFang SC;
  font-weight: 400;
  font-size: 24rpx;
  color: #333333;
  text-align: left;
  font-style: normal;

  display: -webkit-box; /* 设置为WebKit内核的弹性盒子模型 */
  -webkit-box-orient: vertical; /* 垂直排列 */
  -webkit-line-clamp: 2; /* 限制显示三行 */
  overflow: hidden; /* 隐藏超出范围的内容 */
  text-overflow: ellipsis; /* 使用省略号 */
}

.news-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #999;
  margin-top: 10rpx;
  width: 100%;
}

.time {
  margin-left: 10rpx;
}

.source,
.time {
  // opacity: 0.8;
  font-family: PingFangSC, PingFang SC;
  font-weight: 400;
  font-size: 22rpx;
  color: #999999;
  line-height: 30rpx;
  text-align: left;
  font-style: normal;
}
</style>
