<template>
  <div class="mainContent">
    <div class="canvasContent" ref="canvasContent" :style="{ width: `${canvasWidth}rpx`, height: `${canvasHeight}rpx` }"
      v-if="interactionDiagramDetailData.interactionDiagramImage">
      <img class="img-bg" ref="canvasBgContent" :src="interactionDiagramDetailData.interactionDiagramImage" />

      <div class="drap-container-item" v-for="(point, index) in pointList" :key="index"
        :style="{ top: `${canvasHeight * point.pointY}rpx`, left: `${canvasWidth * point.pointX}rpx` }"
        @click="handleClick(point, index)">

        <div :class="showPoint == point ? 'point_source_active' : 'point_source'"  />
        <div class="product-detail" @click="toProductDetail" v-if="showPoint == point && (point.product && point.product.productName)">
          <div class="product-name">{{ (point.product && point.product.productName) ? point.product.productName : '' }}</div>
          <div class="product-price">￥{{ (point.product && point.product.price) ? point.product.price : '' }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      interactionDiagramDetailData:{},
      showPoint: {},
      pointList: [],
      canvasWidth: 0,
      canvasHeight: 0
    }
  },
  methods: {
    toProductDetail () {
      this.$emit('clickProductDetail', {
        productId: this.productData.productId
      })
    },
	// 点击元素获取组件配置
	    handleClick(row, index) {
	      console.log("handleClick");
	      if(this.showPoint == row){
	        this.showPoint = null
	      }else{
	        this.showPoint = row
	      }
	    },
    setParams (data, pointList) {
      this.interactionDiagramDetailData = data
      this.pointList = pointList
      
      const position = {
          height: 750,
          width: 750
        }

        // 图片的原始宽度
        var naturalWidth = this.interactionDiagramDetailData.imageWidth;
        var naturalHeight = this.interactionDiagramDetailData.imageHeight;

        //计算图片显示宽高
        var showWidth = position.width;
		var showHeight = naturalHeight * showWidth / naturalWidth;

        this.canvasWidth = showWidth;
        this.canvasHeight = showHeight;
    }
  }
}
</script>

<style lang="scss" scoped>

.point_source_active{
  align-items: center;
    background: hsla(0,0%,47%,.5);
    border: 3rpx solid transparent;
    border-radius: 50%;
    display: flex;
    height: 48rpx;
    justify-content: center;
    opacity: 1;
    padding: 0;
    transition: border-color .25s ease-in-out,opacity .25s ease-in-out,visibility .25s ease-in-out;
    width: 48rpx;

    &:after {
      background: #fff;
      border-radius: 50%;
      box-shadow: 0 1rpx 4rpx #0000008c;
      content: "";
      display: block;
      height: 18rpx;
      position: relative;
      transition: transform .25s ease-in-out;
      width: 18rpx;
      transform: scale(.667);
    }
}
.point_source {
  align-items: center;
    background: hsla(0,0%,47%,.5);
    border: 3rpx solid transparent;
    border-radius: 50%;
    display: flex;
    height: 48rpx;
    justify-content: center;
    opacity: 1;
    padding: 0;
    transition: border-color .25s ease-in-out,opacity .25s ease-in-out,visibility .25s ease-in-out;
    width: 48rpx;
    
    &:after {
      background: #fff;
      border-radius: 50%;
      box-shadow: 0 1px 4px #0000008c;
      content: "";
      display: block;
      height: 18rpx;
      position: relative;
      transition: transform .25s ease-in-out;
      width: 18rpx;
    }
}

.mainContent {
  margin: 0 auto;
  width: 750rpx;
  height: auto;
      display: flex;
      flex-direction: column;
      flex-wrap: nowrap;
      align-content: flex-start;
      justify-content: flex-start;
      align-items: flex-start;
  

  .canvasContent {
    width: 100%;
    height: 100%;
    position: relative;

    .img-bg {
      width: 100%;
      height: 100%;
      object-fit: contain;
    }


    .drap-container-item {
      -webkit-user-select: none;
      -moz-user-select: none;
      -o-user-select: none;
      user-select: none;
      position: absolute;
      user-select: none;
      cursor: pointer;
      border: 1px solid transparent;

      .drap-item-img {
        width: 40rpx;
        height: 40rpx;
        object-fit: contain;
      }

      .drap-item-name {
        text-align: center;
      }
      .product-detail-top{
        position: relative;
        top: -100rpx;
      }
      .product-detail-bottom{
        
      }
      .product-detail-left{
        position: relative;
        left: -100rpx;
      }
      .product-detail-right{
      }
      .product-detail-centerv{
        margin-top: -25%;
        margin-bottom: 25%;
      }
      .product-detail-centerh{
        margin-left: -25%;
        margin-right: 25%;
      }
      .product-detail{
        display: flex;
        flex-direction: column;
        flex-wrap: nowrap;
        align-content: flex-start;
        justify-content: center;
        align-items: flex-start;
        background: white;
        padding-left: 10rpx;
        padding-right: 10rpx;
        padding-top: 8rpx;
        padding-bottom: 8rpx;
        border-radius: 4rpx;
        margin-left: -25%;
        margin-right: 25%;
        .product-name{
          width: 100%;
          height: auto;
          font-size: 16rpx;
          font-family: Source Han Sans CN;
          font-weight: bold;
          color: #252744;
          display: block;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          line-height: 20px;
          text-align: left;
        }
        .product-price{
          width: auto;
          height: 20rpx;
          line-height: 20rpx;
          font-size: 14rpx;
          font-family: Source Han Sans CN;
          font-weight: bold;
          color: #252744;
        }
      }
    }

    .drap-container-item-active {
      border: 1rpx solid skyblue;
    }
  }
}
</style>
