<template>
  <div class="client-details-page">

    <!-- 详情页 -->
    <div class="client-details-box">

      <!--行业资讯详情-->
      <div class="client-details-wrap" :class="{'isRiZhi': infoData.newsClassifyId == 3}">
        <h1>{{infoData.title}}</h1>
        <p class="details-visits-box"><i></i><span>{{infoData.startTime}}</span><i type="visits"></i><span>{{infoData.visits}}</span>
        </p>
        <div class="client-content-box" v-html="infoData.content"></div>
        <div class="client-details-pagination">
          <a v-show="infoData.lastId" :href="`${baseUrl}/news/${infoData.lastId}`">
            <span class="mta-hidden-xs" @click.prevent="changeNews(infoData.lastId)" :title="'上一篇：'+infoData.lastName">上一篇：{{infoData.lastName}}</span>
            <span class="mta-hidden-sm details-phone-btn" @click.prevent="changeNews(infoData.lastId)">上一篇</span>
          </a>
          <a v-show="infoData.nextId" :href="`${baseUrl}/news/${infoData.nextId}`">
            <span class="mta-hidden-xs" @click.prevent="changeNews(infoData.nextId)" :title="'下一篇：'+infoData.nextName">下一篇：{{infoData.nextName}}</span>
            <span class="mta-hidden-sm details-phone-btn" @click.prevent="changeNews(infoData.lastId)">下一篇</span>
          </a>
        </div>
      </div>

      <!-- 最新新闻 -->
      <div class="latest-news-box mta-hidden-xs" v-if="infoData.newsClassifyId != 3">
        <h4>最新新闻</h4>
        <ul class="latest-news-list">
          <li v-for="(item, index) in newestData" :key="index">
            <a :href="`${baseUrl}/news/${item.code}`">
              <span @click.prevent="changeNews(item.code)" :title="item.title">{{item.title}}</span>
            </a>
            <p class="details-visits-box"><i></i><span>{{item.startTime}}</span><i type="visits"></i><span style="margin-right: 0">{{item.visits}}</span>
            </p>
          </li>
        </ul>
      </div>

    </div>
  </div>
</template>

<script>
  import { mapGetters } from 'vuex';

  export default {
    name:     'news_id',
    layout:   'templateB',

    async asyncData({ params, $axios, store }) {
      // 设置选中菜单
      store.commit('setActiveNav', '/news');
      try {
        const url = '/home/news/info';
        const opt = {
          code: params.id,
        };
        const res = await $axios.post(url, opt);
        const url2 = '/home/news/newest';
        const res2 = await $axios.post(url2);
          console.log(res);
        return {
          infoData:   res.data.data,
          newestData: res2.data.data.data,
        };
      } catch (e) {
        return {};
      }
    },
    head(){
      return {
        title: this.infoData.title,
        meta: [
          {
            hid: this.infoData.keyword,
            name: 'description',
            content: this.infoData.intro
          }
        ],
      }
    },
    computed: {
      baseUrl() {
        return this.getBaseUrl;
      },
      ...mapGetters(['getBaseUrl']),
    },
    methods:  {
      changeNews(id) {
        this.$router.push({ name: 'news-id', params: { id } });
      },
    },
  };
</script>
<style lang="scss">
.client-details-page .client-details-wrap.isRiZhi {
  width: 100% !important;
  border-right: none;

  h1 {
    text-align: center;
  }

  .details-visits-box {
    text-align: center;
  }
}
</style>
