<template>
  <div>
    <Swiper :banner-array="carouselList" />
    <div id="hot">
      <div class="content">
        <HotNews  v-if="display" :list="hotnewsList" :type="1"/>
        <a :href="gg1.link" v-if="gg1.image" @click="bannerCk(gg1)">
            <img class="bottom" :src="gg1.image" alt="">
        </a>
      </div>
    </div>
    <div id="daliay">
      <div class="content">
        <div class="top">
          <el-carousel :interval="4000" type="card" height="490px" arrow="always" v-model="currentIndex" @change="handleChange" ref="carousel">
            <el-carousel-item v-for="(item, index) in carvideoList" :key="index">
              <div class="carvideo" :class="currentIndex === index ? 'carvideoShadow' : ''">
                 <img class="videoImage" :src="item.image" />
                  <img class="play" src="@/assets/play.png" @click="videoPlayer(item)">
              </div>
              <a v-if="currentIndex === index">{{ item.title }}</a>
            </el-carousel-item>
          </el-carousel>
        </div>
      </div>
    </div>
    <a :href="gg2.link" v-if="gg2.image" @click="bannerCk(gg2)">class="banner">
        <img :src="gg2.image" alt="">
    </a>
    <div id="wk">
      <div class="content">
        <div class="htitle">
          <a class="tle">汽车文章</a>
          <el-button type="text" class="more" @click="routerTo">MORE+</el-button>
        </div>
        <div id="hotList">
          <div class="list" v-for="(item, index) in carList" :key="index"  @click="detail(item)">
            <img :src="item.image">
            <div class="txt">
              <a class="title">{{ item.title }}</a>
              <a class="subtitle">{{ item.detailText }}</a>
            </div>
          </div>
        </div>
      </div>
    </div>
    <el-dialog title="" v-if="videoDialogVisible" :visible.sync="videoDialogVisible" :lock-scroll="false" :append-to-body="true" width="50%">
        <VideoDialog :url="videoUrl" :lock-scroll="false" :append-to-body="true"></VideoDialog>
    </el-dialog>
  </div>
</template>
<script>
/* eslint-disable */
import Swiper from '@/components/swiper'
import { lunboList, hotNewsConfig, guanggao, hotlist, videoList, carArticle } from '@/api/car.js'
import VideoDialog from '@/components/video'
import HotNews from '@/components/hotNews'
export default {
  name: 'information',
  data () {
    return {
      carouselList: [],
      hotnews: {},
      hotnewsList: [],
      carvideoList: [],
      carList: [],
      display: 1,
      gg1: {},
      gg2: {},
      videoDialogVisible: '',
      videoUrl: '',
      currentIndex: 0
    }
  },
  components: {
    Swiper,
    VideoDialog,
    HotNews
  },
  mounted () {
    this.gethotnewsConfig()
    this.getlunboList()
    this.getguanggao()
    this.gethotlist()
    this.getvideoList()
    this.getCarArticle()
  },
  methods: {
    handleChange(newIndex) {
        this.currentIndex = newIndex;
    },
    detail (item) {
        this.$router.push({ path: '/articleDetails', query: {id : item.id } })
    },
    routerTo () {
      this.$router.push({ path: '/articleList',  query: {type : 2 } })
    },
    async getlunboList () {
      const { data: { code, data } } = await lunboList()
      if (code === 200) {
        this.carouselList = data.list
      }
    },
    async gethotnewsConfig () {
      const { data: { code, data: { display } } } = await hotNewsConfig()
      if (code === 200) {
        this.display = display
      }
    },
    async getguanggao () {
      const { data: { code: ggm1, data: gg1 } } = await guanggao(1)
      const { data: { code: ggm2, data: gg2 } } = await guanggao(2)
      if (ggm1 === 200 && ggm2 === 200) {
        this.gg1 = gg1
        this.gg2 = gg2
      }
    },
    bannerCk(item) {
        item.newOpen === 1 ? window.open(item.link) : window.location.href = item.link
    },
    async gethotlist () {
      const { data: { code, data } } = await hotlist()
      if (code === 200) {
        this.hotnewsList = data.list
      }
    },
    async getvideoList () {
      const { data: { code, data } } = await videoList()
      if (code === 200) {
        this.carvideoList = data.list
      }
    },
    videoPlayer (item) {
        this.videoUrl = item.link
        this.videoDialogVisible = true
    },
    async getCarArticle() {
        const { data: { code, data } } = await carArticle()
        if (code === 200) {
            this.carList = data.list
        }
    }
  }
}
</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: 410px;
      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: 80px;
          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;
          }
          .more:hover {
            border: 1px solid #088669;
            color: #088669;
          }
        }
      }
      #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;
          }
        }
      }
    }
  }
}
#hot {
  min-height: 100px;
  .content {
    margin-top: 20px;
  }
}

#daliay {
    .content {
        height: 410px;
    }
  .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__indicators--outside, .el-carousel__indicators--horizontal {
      display: none;
    }
    :deep .el-carousel__mask {
      background-color: #00000000 !important;
    }
    :deep .el-carousel__arrow--left {
      left: 280px;
    }
    :deep .el-carousel__arrow--right {
      right: 280px;
    }
    :deep .el-carousel__arrow {
      width: 40px;
      height: 40px;
      border-radius: 0%;
      background-color: #ffffffcc;
      color:#07CAAF;
      font-size: 20px;
      font-weight: bold;
      border-radius: 3px;
      top: 43%;
    }
     .el-carousel__item {
        display: flex;
        flex-direction: column;
        align-items: center;
        .carvideoShadow{
          box-shadow: 0 2px 12px 0 #666;
          margin: 12px;
        }
        .carvideo {
          position: relative;
          position: relative;
            border-radius: 15px;
          .play {
            position: absolute;
            margin: 0 auto;
            top: 50%;
            margin-left: 45%;
            margin-top: -50px;
          }
          .videoImage {
            width: 100%;
            border-radius: 10px;
          }
        }
        a {
          font-size: 24px;
          font-weight: bold;
          color: #00161C;
          line-height: 48px;

        }
     }
  }
}

#wk {
 .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;
  }
}
.banner{
    margin: 0 auto;
    margin-bottom: 30px;
    display: block;
    width: 1200px;
}
</style>
