<template>
  <div class="news-content">
    <tab />
    <div class="detail-content-box">
      <div class="back-btn" @click="$router.go(-1)">
        <div class="el-icon-arrow-left"></div>
        <div class="text">返回</div>
      </div>
      <div class="times">{{ formatDate(data.start_time) }}</div>
      <div class="titles">{{ data.title }}</div>
      <div class="article-content" v-html="data.content"></div>
      <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">
            <a :target="item.uri !== '' ? '_blank' : '_self'" :href="item.uri ? item.uri : `/about/news/${item.id}`">
              <img :src="item.web_img_uri" alt="" />
              <div class="dec">{{ item.title }}</div>
            </a>
          </li>
        </ul>
      </div>
      <div class="more-btn" @click="$router.push({ path: '/about/news' })">查看更多</div>
    </div>
  </div>
</template>
<script>
import tab from '@/components/about/tabNav'
export default {
  components: {
    tab
  },
  data() {
    return {
      data: {},
      listData: []
    }
  },
  async fetch() {
    this.data = await this.$axios.get(`/api/cms/api/v1/article/${this.$route.params.id}/detail`).then(res => {
      return res.data
    })
    const params = {
      project_id: process.env.projectId,
      type_tag: 'article_news',
      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
    })
  },
  mounted() {},
  methods: {
    goPage(item) {
      if (item.source === '') {
        // this.$router.push({
        //   path: '/about/news-detail',
        //   query: {
        //     id: item.id
        //   }
        // })
        window.open(`${window.location.origin}/about/news-detail?id=${item.id}`)
      } else {
        window.open(item.source)
      }
    },
    formatDate(value) {
      const date = new Date(value * 1000)
      return date.getFullYear() + '/' + (date.getMonth() + 1) + '/' + date.getDate()
    }
  }
}
</script>
<style lang="scss" scoped>
.news-content {
  width: 1200px;
  margin: 0 auto;
  padding-top: 63px;
  display: flex;
  justify-content: space-between;
}
.detail-content-box {
  width: 1000px;
  background: #fff;
  padding: 50px 50px 94px;
  box-sizing: border-box;
  margin-bottom: 100px;
  .back-btn {
    display: flex;
    align-items: center;
    cursor: pointer;
    .el-icon-arrow-left {
      color: rgba(153, 153, 153, 1);
      font-size: 16px;
    }
    .text {
      font-size: 16px;
      color: #999999;
    }
  }
  .times {
    font-size: 16px;
    line-height: 100%;
    margin: 35px 0 16px;
    color: #999999;
  }
  .titles {
    font-size: 32px;
    font-weight: bold;
    color: #141414;
    // height: 62px;
    border-bottom: 1px solid #e6e6e6;
    // line-height: 100%;
    padding-bottom: 10px;
  }
  .article-content {
    padding-top: 25px;
    font-size: 14px;
    line-height: 28px;
    color: #333333;
    img {
      display: block;
      width: 100%;
      margin-top: 40px;
    }
  }
  .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>
