<template>
  <div>
    <Swiper :banner-array="carouselList" />
    <div id="hot">
      <div class="content">
        <div class="top"  v-if="display">
          <div id="imgtxt" @click="routerToarticleDetails(hotnews.detail)">
            <img :src="hotnews.img">
            <a class="newsTitle">{{ hotnews.title }}</a>
          </div>
          <div id="hottxt">
            <div id="htitle">
              <a class="tle">热点新闻</a>
              <el-button type="text" @click="routerTo">MORE+</el-button>
            </div>
            <div id="hotList">
              <div class="list" v-for="(item, index) in hotnewsList" :key="index" @click="routerToarticleDetails(item.detail)">
                <img :src="item.img">
                <a>{{ item.title }}</a>
              </div>
            </div>
          </div>
        </div>
        <a :href="gg1.link" target="_blank">
        <div class="bottom" :style="{ backgroundImage: `url(${gg1.img})` }"/>
        </a>
      </div>
    </div>
    <div id="daliay">
      <div class="content">
        <div class="top">
          <el-carousel :interval="4000" type="card" height="200px">
            <el-carousel-item v-for="(item, index) in carvideoList" :key="index">
              <img :src="item.img">
              <a>{{ item.title }}</a>
            </el-carousel-item>
          </el-carousel>
        </div>
        <a :href="gg2.link" target="_blank">
        <div class="bottom" :style="{ backgroundImage: `url(${gg2.img})` }"/>
        </a>
      </div>
    </div>
    <div id="wk">
      <div class="content">
        <div class="htitle">
          <a class="tle">热点新闻</a>
          <el-button type="text" @click="routerTo">MORE+</el-button>
        </div>
        <div id="hotList">
          <div class="list" v-for="(item, index) in carList" :key="index"  @click="routerToarticleDetails(item.detail)">
            <img :src="item.img">
            <div class="txt">
              <a class="title">{{ item.title }}</a>
              <a class="subtitle">{{ item.subtitle }}</a>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import Swiper from '@/components/swiper'
import { lunboList, hotNewsConfig, guanggao, hotlist, videoList } from '@/api/car.js'
export default {
  name: 'information',
  data () {
    return {
      carouselList: [
        // { src: '/car1.png', title: '吉利11月销量再刷新纪录，新能源转型成效凸显', subtitle: '国际汽车企业如果现在一旦脱离了中国市场，再想回来就不可能了。必须了解这个发展的趋势，只有参与才有机会。' },
        // { src: '/car2.png', title: '吉利11月销量再刷新纪录，新能源转型成效凸显', subtitle: '国际汽车企业如果现在一旦脱离了中国市场，再想回来就不可能了。必须了解这个发展的趋势，只有参与才有机会。' }
      ],
      hotnews: {
        title: '这两款产品也将采用“CHN”的模式进行研发',
        img: '/hotnew.png'
      },
      hotnewsList: [],
      carvideoList: [],
      carList: [],
      display: 1,
      gg1: {},
      gg2: {}
    }
  },
  components: {
    Swiper
  },
  mounted () {
    this.gethotnewsConfig()
    this.getlunboList()
    this.getguanggao()
    this.gethotlist()
    this.getvideoList()
  },
  methods: {
    routerToarticleDetails (value) {
      localStorage.setItem('article', value)
      this.$router.push({ path: '/articleDetails' })
    },
    routerTo () {
      this.$router.push({ path: '/articleList' })
    },
    async getlunboList () {
      const { data: { message, data } } = await lunboList()
      if (message === 'success') {
        this.carouselList = data.list
      }
    },
    async gethotnewsConfig () {
      const { data: { message, data: { display } } } = await hotNewsConfig()
      if (message === 'success') {
        this.display = display
      }
    },
    async getguanggao () {
      const { data: { message: ggm1, data: gg1 } } = await guanggao(1)
      const { data: { message: ggm2, data: gg2 } } = await guanggao(2)
      if (ggm1 === 'success' && ggm2 === 'success') {
        this.gg1 = {
          img: gg1.image,
          link: gg1.link
        }
        this.gg2 = {
          img: gg2.image,
          link: gg2.link
        }
      }
    },
    async gethotlist () {
      const { data: { message, data } } = await hotlist()
      if (message === 'success') {
        this.hotnews.title = data.list[0].title
        this.hotnews.img = data.list[0].image
        this.hotnews.detail = data.list[0].detail
        for (let index = 1; index < data.list.length; index++) {
          this.hotnewsList.push({
            title: data.list[index].title,
            img: data.list[index].image,
            subtitle: data.list[index].subTitle,
            detail: data.list[index].detail
          })
          this.carList.push({
            title: data.list[index].title,
            img: data.list[index].image,
            subtitle: data.list[index].subTitle,
            detail: data.list[index].detail
          })
        }
      }
    },
    async getvideoList () {
      const { data: { message, data } } = await videoList()
      if (message === 'success') {
        for (const iter of data.list) {
          this.carvideoList.push({
            title: iter.title,
            img: iter.image
          })
        }
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.el-carousel__item{
  background-size: 100%;
  background-repeat: no-repeat;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  #txt {
    display: flex;
    flex-direction: column;
    margin-bottom: 50px;
    color: #FFFFFF;
    .title {
      font-size: 36px;
      font-weight: bold;
      text-align: center;
      margin-bottom: 15px;

    }
    .subtitle {
      font-size: 16px;
      font-weight: 400;
      opacity: 0.5;
      text-align: center;
    }
  }
}
#hot, #daliay, #wk {
  width: 100%;
  background: #E3E5EA;
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  padding-bottom: 30px;
  .content {
    width: 1200px;
    height: 90%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    .top, .bottom {
      width: 100%;
    }
    .top {
      min-height: 470px;
      background-color: #FFFFFF;
      display: flex;
      #imgtxt {
        width: 560px;
        position: relative;
        display: flex;
        justify-content: center;
        align-items: center;
        img {
          width: 560px;
        }
        .newsTitle{
          position: absolute;
          bottom: 5%;
          left: 5%;
          display: inline-block;
          font-size: 18px;
          font-weight: bold;
          color: #FFFFFF;
          line-height: 48px;
          width: 90%;
          background-color: #0000007e;
        }
      }

      #hottxt {
        display: flex;
        justify-content: space-around;
        flex-direction: column;
        align-items: center;
        flex: 1;
        margin-left: 35px;
        #htitle {
          display: flex;
          justify-content: space-between;
          align-items: center;
          width: 95%;
          .tle {
            z-index: 9;
            font-size: 26px;
            font-weight: bold;
            color: #00161C;
            line-height: 48px;
            display: inline-block;
            position: relative;
            text-decoration: none; /* 移除默认的下划线 */
          }
          .tle::after {
            content: '';
            position: absolute;
            left: -15px;
            bottom: 10px;
            width: 65%;
            height: 6px; /* 横线高度为文字高度的一半 */
            background-color: #07CAAF;; /* 横线颜色与文字颜色相同 */
            z-index: -1;
          }
          .el-button {
            font-size: 16px;
            font-weight: bold;
            color: #07CAAF;
            line-height: 48px;
            cursor: pointer;
            z-index: 9999;
          }
        }
      }
      #hotList {
        height: 76%;
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: center;
        .list {
          z-index: 999;
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: center;
          width: 150px;
          margin-right: 39px;
          img {
            width: 150px;
            height: 112px;
            border-radius: 10px;
          }
          a {
            font-size: 14px;
            font-weight: 400;
            color: #010101;
            margin-top: 14px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            width: 150px;
            // line-height: 48px;
          }
        }
      }
    }
    .bottom {
      min-height: 120px;
      background-image: url('../../assets/bottom.png');
      background-size: 100% 100%;
    }
  }
}
#hot {
  min-height: 100px;
  .content {
    margin-top: 20px;
    .top {
      margin-bottom: 30px;
      background-color: #FFFFFF;
      display: flex;
      background-image: url('../../assets/hotTopLeft.png');
      background-position: 101% 0; /* 调整这些值来改变显示的部分 */
      background-size: 30% 50%; /* 使用 'cover' 或 'contain'，或者设置具体尺寸 */
      background-repeat: no-repeat;
      #imgtxt {
        width: 560px;
        position: relative;
        display: flex;
        justify-content: center;
        align-items: center;
        margin-left: 20px;
        img {
          width: 560px;
        }
        .newsTitle{
          position: absolute;
          bottom: 5%;
          left: 0;
          display: inline-block;
          font-size: 18px;
          font-weight: bold;
          color: #FFFFFF;
          line-height: 48px;
          width: 100%;
          background-color: #0000007e;
        }
      }
    }
  }
}

#daliay {
  height: 625px;
  .top {
    // justify-content: space-between;
    background-color: #00000000 !important;
    .el-carousel {
      width: 100%;
      height: 100% !important;
      background-color: #00000000 !important;

      :deep .el-carousel__container {
        background-color: #00000000 !important;
        height: 100% !important;
      }
    }
    :deep.el-carousel__mask {
      background-color: #00000000 !important;

    }
    :deep .el-carousel__indicators--outside, .el-carousel__indicators--horizontal {
      display: none;
    }
     .el-carousel__item {
        display: flex;
        flex-direction: column;
        // justify-content: center;
        align-items: center;
        img {
          width: 800px;
          height: 80%;
        }
        a {
          font-size: 24px;
          font-weight: bold;
          color: #00161C;
          line-height: 48px;

        }
     }
  }
}

#wk {
    padding-bottom: 200px;
 .content {
  background-color: #FFFFFF;
  display: flex;
  align-items: center;
  position: relative;

  .htitle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 93%;
    margin-bottom: 20px;
    .tle {
      z-index: 9;
      font-size: 26px;
      font-weight: bold;
      color: #00161C;
      line-height: 48px;
      display: inline-block;
      position: relative;
      text-decoration: none; /* 移除默认的下划线 */
    }
    .tle::after {
      content: '';
      position: absolute;
      left: -15px;
      bottom: 10px;
      width: 65%;
      height: 6px; /* 横线高度为文字高度的一半 */
      background-color: #07CAAF;; /* 横线颜色与文字颜色相同 */
      z-index: -1;
    }
    .el-button {
      font-size: 16px;
      font-weight: bold;
      color: #07CAAF;
      line-height: 48px;
      z-index: 999;
    }
  }
  #hotList {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    .list {
      z-index: 999;
      display: flex;
      justify-content: center;
      width: 500px;
      margin: 0 40px 34px 33px;
      .txt {
        display: flex;
        flex-direction: column;
        margin-left: 22px;
        align-items: center;
        width: 60%;
        .title {
          text-align: left;
          width: 100%;
          font-size: 18px;
          font-weight: bold;
          color: #010101;
        }
        .subtitle{
          display: inline-block;
          text-align: left;
          width: 100%;
          font-size: 14px;
          font-weight: 400;
          color: #000000;
          line-height: 24px;
          margin-top: 10px;
          display: -webkit-box; /* Safari */
            -webkit-line-clamp: 3; /* Safari and Chrome */
            -webkit-box-orient: vertical; /* Safari and Chrome */
            overflow: hidden;
        }
      }
      img {
        width: 200px;
        height: 150px;
        border-radius: 10px;
      }
    }
  }
 }
 .content::after {
    content: '';
    width: 100%;
    height: 100%;
    position: absolute;
    background-image: url('../../assets/cartxt.png');
    background-position: 101% 0; /* 调整这些值来改变显示的部分 */
    background-size: 12% 50%; /* 使用 'cover' 或 'contain'，或者设置具体尺寸 */
    background-repeat: no-repeat;
  }
}
</style>
