<template>
  <div>
    <!-- 新闻资讯 PC-->
    <div class="client-news-information mta-hidden-xs" v-if="newsData.length">
      <h4 class="client-title">新闻资讯</h4>
      <div class="client-container">
        <div class="industry-information-box">
          <div class="industry-information-left">
            <img :src="newsData[0].pic" alt="新闻资讯"/>
            <h4 @click="checkInfo(newsData[0])">{{ newsData[0].title }}<i></i></h4>
            <div><b>{{ newsData[0].yyyy }}</b><span>{{ newsData[0].mmdd }}</span></div>
            <p>{{ newsData[0].intro }}</p>
          </div>
          <div class="industry-information-right">
            <ul>
              <li v-for="(item, index) in newsData" v-if="index >= 1">
                <h4 @click="checkInfo(item)">
                  <a style="display: none" :href="`${baseUrl}/news/${item.code}`"></a>
                  <span>{{ item.yyyy }}</span>{{ item.title }}
                </h4>
                <p><span>{{ item.mmdd }}</span>{{ item.intro }}</p>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>

    <!-- 新闻资讯 手机-->

      <div class="client-newsInfo-phone mta-hidden-sm" v-if="newsData.length">
        <div class="client-container">
        <h4 class="client-title">新闻资讯</h4>
        <el-carousel :interval="5000" type="card" height="300px" indicator-position="none" arrow="never">
          <el-carousel-item v-for="(item,index) in newsData" @click.native="checkInfo(item)" :key="index" class="el-row">
            <img :src="item.pic" alt="新闻资讯"/>
            <div class="newsInfo-card-content">
              <a style="display: none" :href="`${baseUrl}/news/${item.code}`"></a>
              <h4>{{ item.title }}<i></i></h4>
              <span>{{ item.yyyy }}-{{ item.mmdd }}</span>
              <p>{{ item.intro }}</p>
            </div>
          </el-carousel-item>
        </el-carousel>

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

</template>

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

export default {
  name: "newsComp",
  props: {
    newsData: {
      type: Array,
      default: () => ([])
    }
  },
  data() {
    return {
      checkIsPc: false,
    }
  },
  computed: {
    baseUrl() {
      return this.getBaseUrl;
    },
    ...mapGetters(['getBaseUrl']),
  },
  methods: {
    isPC() {
      const browserWidth = document.documentElement.clientWidth;
      if (browserWidth <= 768) {

        return false;
      } else {
        return true;
      }
    },
    checkInfo(data) {
      const opt = {
        id: data.code,
      };
      this.$router.push({name: 'news-id', params: opt});
    }
  },
  mounted() {
    this.checkIsPc = this.isPC();
  }
}
</script>

<style lang="scss" scoped>
.client-news-information {
  background: #fafafa;

  .client-title {
    font-size: 30px;
    font-weight: 800;
    color: #333;
    margin-bottom: 70px;
  }

  .industry-information-left {
    img {
      width: 605px;
      height: 180px;
    }
    h4:hover {
      color: #00b96b;
    }
  }
}
</style>
