<template>
  <div v-if="listData.length">
    <div class="recommend-content">
      <div class="titles">
        <div class="line"></div>
        <div class="text">相关推荐</div>
      </div>
      <ul class="list-box">
        <li v-for="(item, index) in listData" :key="index">
          <app-link :data="item" :to="`/news/hot/${item.id}`">
            <img :src="item.web_img_uri" />
            <div class="dec">{{ item.title }}</div>
          </app-link>
        </li>
      </ul>
    </div>
    <div class="more-btn" @click="$router.push({ path: '/news/hot' })">查看更多</div>
  </div>
</template>
<script>
import AppLink from '@/components/Link'
export default {
  components: { AppLink },
  data() {
    return {
      data: {},
      listData: []
    }
  },
  async fetch() {
    const params = {
      project_id: import.meta.env.VITE_PROJECT_ID,
      type_tag: 'article_news_hot',
      is_recommend: 1,
      page: 1,
      limit: 3
    }
    this.listData = await this.$axios.get('/api/cms/api/v1/articles', { params }).then(res => {
      return res.data.data
    })
  },
  methods: {
    goPage(item) {
      if (item.source) {
        window.open(item.source)
      } else {
        this.$router.push({ name: 'news-hot-id', params: { id: item.id } })
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.recommend-content {
  border-top: 1px solid #e6e6e6;
  padding-top: 37px;
  .titles {
    display: flex;
    align-items: center;
    .line {
      width: 6px;
      height: 22px;
      background: #aa1941;
    }
    .text {
      font-size: 22px;
      color: #333333;
      margin-left: 10px;
    }
  }
  .list-box {
    margin-top: 50px;
    display: flex;
    justify-content: space-between;
    li {
      width: 280px;
      img {
        width: 280px;
        height: 184px;
        display: block;
      }
      .dec {
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
        font-size: 16px;
        line-height: 26px;
        color: #333333;
        margin-top: 10px;
      }
    }
  }
}
.more-btn {
  position: relative;
  z-index: 999;
  width: 164px;
  height: 40px;
  border: 1px solid #d3d3d3;
  border-radius: 8px;
  line-height: 40px;
  text-align: center;
  font-size: 16px;
  color: #999999;
  margin: 50px auto 0;
  cursor: pointer;
}
</style>
