<template>
  <div>
    <div class="col-md-5">
      <div class="product-title">{{cniyvMsg.title}}</div>
      <!-- <div class="price-container">
        <div>
          <span class="price-text">价 格</span>
          <span class="price-icon">￥</span>
          <span class="price">{{cniyvMsg.price}}</span>
        </div>
      </div> -->
    </div>
    <div class="col-md-8">
      <div class="swiper-container swiperTop">
        <div class="swiper-wrapper">
          <div class="swiper-slide" v-for="(item, index) in cniyvMsg.imgs" :key="index">
            <img :src="item" loading="lazy" :data-src="item" alt="">
          </div>
        </div>
        <!-- <div class="swiper-button-next swiper-button-white"></div>
        <div class="swiper-button-prev swiper-button-white"></div> -->
      </div>
      <div class="swiperThumbs-container">
        <div class="swiper-container swiperThumbs">
          <div class="swiper-wrapper">
            <div class="swiper-slide" v-for="(item, index) in cniyvMsg.imgs" :key="index">
              <img :src="item" loading="lazy" :data-src="item" alt="">
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="col-md-12 content">
      <el-card class="box-card" shadow="never">
        <div slot="header" class="clearfix">
          <span class="title">产品介绍</span>
        </div>
        <div v-html="toHtml(cniyvMsg.content)"></div>
        <div v-html="toHtml(cniyvMsg.content1)"></div>
        <div v-html="toHtml(cniyvMsg.content2)"></div>
        <div v-html="toHtml(cniyvMsg.content3)"></div>
      </el-card>
    </div>
  </div>
</template>

<script>
import { mapGetters, mapActions } from 'vuex'
import Swiper from 'swiper'
import 'swiper/css/swiper.min.css'

export default {
  data() {
    return {
      productId: '',
      imageList: [
        'https://shadow.elemecdn.com/app/element/hamburger.9cf7b091-55e9-11e9-a976-7f4d0b07eef6.png',
        'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
        'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg'
      ],
      swiper: '',
      imgUrl: 'https://shadow.elemecdn.com/app/element/hamburger.9cf7b091-55e9-11e9-a976-7f4d0b07eef6.png'
    }
  },
  computed: {
    ...mapGetters([
      'cniyvMsg',
    ]),
  },
  created() {
    this.productId = this.$route.params.id
    // console.log(this.productId, '产品ID')
    this.getProductDetail()
  },
  mounted() {
    this.$nextTick(() => {
      this.initSwiper()
    })
  },

  updated() {
    this.initSwiper()
  },

  methods: {
    ...mapActions({
      getCniyvMsg: 'cniyv/getCniyvMsg'
    }),

    initSwiper() {
      const swiperThumbs = new Swiper('.swiperThumbs', {
        slidesPerView: 4,
        spaceBetween: 10,
        watchSlidesProgress: true
      })

      const swiperTop = new Swiper('.swiperTop', {
        autoplay: true,
        spaceBetween: 10,
        watchSlidesProgress: true,
        slideThumbActiveClass: 'my-slide-thumb-active',
        // navigation: {
        //   nextEl: '.swiper-button-next',
        //   prevEl: '.swiper-button-prev',
        // },
        thumbs: {
          swiper: swiperThumbs
        }
      })
    },

    getProductDetail() {
      this.getCniyvMsg(this.productId)
    },

    toHtml(content) {
      if (!content) return ''
      return content.replace(/&lt;/g, "<")
        .replace(/&gt;/g, ">")
        .replace(/&amp;/g, "&")
        .replace(/&quot;/g, '"')
        .replace(/&apos;/g, "'");
    }
  }
}
</script>


<style scoped>
.swiperTop img {
  /* height: auto; */
  width: auto;
  object-fit: contain;
}

.swiperTop .swiper-slide {
  text-align: center;
}

.swiperThumbs-container {
  margin-top: 20px;
  border: 1px solid #ddd;
  padding: 5px;
}

.swiperThumbs img {
  height: 75px;
  object-fit: contain;
}

.swiperThumbs img:hover {
  transform: scale(0.95);
}

.swiperThumbs .swiper-slide {
  opacity: .5;
}

.swiperThumbs .swiper-slide-thumb-active {
  opacity: 1;
}

.bottom-img {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
:deep(.el-card__header) {
  padding: 5px 0;
  background-color: #3884c0;
}

.box-card .title {
  color: #fff;
  font-weight: 600;
  margin-left: 10px;
}

.content {
  margin-top: 20px;
}

.product-title {
  font: 700 18px Arial,"microsoft yahei";
  color: #606060;
  padding: 5px 0;
  line-height: 28px;
  margin-bottom: 5px;
}

.price-container {
  padding: 10px 0;
  background: #f3f3f3;
}

.price-container .price-text {
  padding-left: 10px;
  font-family: simsun;
  color: #999;
  line-height: 22px;
}

.price-container .price-icon {
  color: #e4393c;
  font-family: "microsoft yahei";
  margin-right: 5px;
  margin-left: 10px;
  vertical-align: middle;
}

.price-container .price {
  font-size: 24px;
  color: #e01222;
  font-family: arial;
  margin-right: 2px;
  line-height: 1;
  display: inline-block;
  min-width: 50px;
}
</style>

