<template>
  <div class="recommend-brand">
    <div v-swiper:mySwiper="swiperOption">
      <div class="swiper-wrapper">
        <div class="swiper-slide" v-for="banner in sliceBanners">
          <a :href="banner.hrefUrl" target="_blank" v-if="banner.hrefUrl">
            <img :src="banner.pictureLink"/>
          </a>
          <span v-if="!banner.hrefUrl">
                <img :src="banner.pictureLink"/>
              </span>
        </div>
        <div class="swiper-button-prev"><i class="iconfont icon-swiper-left"></i></div>
        <div class="swiper-button-next"><i class="iconfont icon-swiper-right"></i></div>
      </div>
      <div class="swiper-pagination swiper-pagination-bullets"></div>
    </div>
    <div class="recommend-area">
      <ul class="recommend-items">
        <li v-for="item in hotBrands.data">
          <a :href="item.detailsLink" target="_blank">
            <img :src="item.pictureLink" alt="">
            <div>
              <p>{{item.title}}</p>
              <span class="brand-application" v-if="item.metadatas.contExp_abstract" :title="item.metadatas.contExp_abstract">应用领域：{{item.metadatas.contExp_abstract | applicationFilter}}</span>
              <span class="brand-introduce" v-if="item.metadatas.contExp_select">品牌介绍：{{item.metadatas.contExp_select | introduceFilter}}</span>
            </div>
          </a>
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
  export default {
    data () {
      return {
        activeSlide: 0,
        swiperOption: {
          autoplay: 6000,
          pagination: '.swiper-pagination',
          paginationClickable: true,
          mousewheelControl: false,
          effect: 'fade',
          lazyLoading: true,
          loop: true,
          prevButton: '.swiper-button-prev',
          nextButton: '.swiper-button-next',
          onTransitionStart: (swiper) => {
            if (this.banners.data && this.banners.data.length && (swiper.activeIndex > this.banners.data.length)) {
              swiper.activeIndex = 1
            }
            if (this.banners.data && this.banners.data.length && swiper.activeIndex <= 0) {
              swiper.activeIndex = this.banners.data.length
            }
          }
        }
      }
    },
    filters: {
      applicationFilter: function (str) {
        return str.split(',').join('|')
      },
      introduceFilter: function (title) {
        if (title === '') {
          return title
        }
        let len = 0
        let index = 0
        for (let i = 0; i < title.length; i++) {
          if (index === 0 && title.charAt(i).charCodeAt(0) > 255) {
            len = len + 2
          } else {
            len++
          }
          if (len > 80) {
            index = i
            break
          }
        }
        if (index > 0) {
          return title.substring(0, index) + '...'
        } else {
          return title
        }
      }
    },
    computed: {
      floors () {
        return this.$store.state.floor.list.data
      },
      hotBrands () {
        return this.$store.state.product.brand.recommends.data
      },
      banners () {
        return this.$store.state.carousel.brandCarousel.data
      },
      sliceBanners () {
        return this.banners && this.banners.data.length ? this.banners.data.slice(0, 3) : []
      }
    }
  }
</script>
<style lang="scss" scoped>
  .recommend-brand {
    width: 1190px;
    margin: 0 auto;
    .swiper-container {
      z-index: 2;
      .swiper-wrapper {
        width: 1190px;
        margin: 0 auto;
        .swiper-slide {
          height: 163px;
          margin: 0 auto;
          display: flex;
          img {
            width: 1190px;
            height: 163px;
            border: 1px solid #ccc;
          }
        }
        .swiper-button-prev i, .swiper-button-next i {
          font-size: 26px;
        }
      }
      .swiper-pagination-bullets {
        .swiper-pagination-bullet {
          width: 10px!important;
          height: 10px!important;
        }
      }
    }
    .recommend-adv {
      margin: 0 auto;
      width: 1190px;
      height: 163px;
      display: block;
      border-radius: 3px;
    }
    .recommend-area {
      margin: 29px auto 0;
      width: 1190px;
      height: 362px;
      background:url("/images/brandCenter/recommend-bg.png") no-repeat;
      .recommend-items {
        padding-top: 80px;
        padding-left: 2px;
        li {
          border-radius: 3px;
          width: 234px;
          height: 127px;
          background: #fff;
          display: inline-block;
          margin-right: 4px;
          vertical-align: middle;
          margin-bottom: 5px;
          text-align: center;
          &:nth-child(5n) {
            margin-right: 0;
          }
          a {
            padding-top: 22px;
            width: 234px;
            height: 127px;
            line-height: 91px;
            display: block;
            position: relative;
            img {
              max-width: 140px;
              max-height: 91px;
            }
            >div {
              display: none;
              position: absolute;
              bottom: 2px;
              border-radius: 3px;
              width: 234px;
              height: 127px;
              background-color: #3a78f4;
              opacity: 0.9;
              top: 0;
              text-align: left;
              padding: 13px 7px;
              p {
                font-size: 15px;
                color: #fff;
                font-weight: bold;
                height: 16px;
                line-height: 16px;
              }
              span {
                color: #fff;
                display: block;
                width: 228px;
                line-height: 18px;
                font-size: 12px;
                &.brand-application {
                  padding-right: 5px;
                  text-overflow: ellipsis;
                  white-space: nowrap;
                  overflow: hidden;
                }
                &.brand-introduce {
                  padding-right: 5px;
                  word-break: break-all;
                }
              }
            }
          }
          &:hover {
            /*position: relative;
            bottom: 5px;*/
            a {
              div {
                display: block;
              }
            }
          }
        }
      }
    }
  }
</style>
