<template>
  <div v-if="showSelf" class="dialog">
    <div class="dialog-mark" @click.self="closeMyself">
      <div class="sharetiptxt" style>
        <img style=" height:100%;" src="../assets/buttonImg/shareText.png" alt />
      </div>
      <transition name="dialog">
        <div class="dialog-sprite">
          <div class="dialog-body">
            <div class="card-wrapper">
              <div :class="`dialog-popuImag ${classDivAA?'flipped':''}`">
                <!-- <div class="back" :style="`background-image: url(${backimg});`"> -->
                <!-- <img
                    style="width: 180px; height:492px"
                    src="../assets/prizeImg/HappyWnning.jpg"
                    alt
                />-->
                <!-- </div> -->

                <div class="front">
                  <img
                    style="width: 180px; height:492px "
                    src="../assets/prizeImg/HappyWnning.jpg"
                    alt
                  />
                  <div class="PrizeImg">
                    <img style="width: 100%; height:100% " :src="Prize.thumb" alt />
                  </div>
                </div>
              </div>
            </div>

            <div @click="cancel" class="dialog-footer">
              <img @click="cancel" class="btn" src="../assets/buttonImg/happyAccept.png" alt />
            </div>
          </div>
          <!-- 右侧 -->
        </div>
      </transition>
    </div>
  </div>
</template>

<script>
export default {
  name: 'WinningPopup',
  props: {
    show: {
      type: Boolean,
      default: false,
      required: true
    },

    currentMonth: {
      type: Object
    },
    Prize: {
      type: Object,
      default: () => ({})
    }
  },

  data() {
    return {
      name: 'dialog',
      showSelf: false,
      zIndex: this.getZIndex(),
      bodyOverflow: '',
      classDivAA: false,
      myShareShow: false,
      backimg: require('../assets/luckyImg/2.jpg')
    }
  },
  watch: {
    show(val) {
      this.showSelf = val
      if (this.show === false) {
        this.myShareShow = false
      }
      this.transform()
    }
  },
  created() {
    this.showSelf = this.show
  },
  mounted() {
    this.forbidScroll()
    if (this.show === true) {
      this.transform()
    }
  },
  methods: {
    transform() {
      setTimeout(() => {
        this.classDivAA = this.show
      }, 0)
    },
    /** 禁止页面滚动 */
    forbidScroll() {
      this.bodyOverflow = document.body.style.overflow
      document.body.style.overflow = 'hidden'
    },

    /**  每次获取之后 zindex 自动增加 */
    getZIndex() {
      let zIndexInit = 2022112
      return zIndexInit++
    },

    /** 取消按钮操作 */
    cancel() {
      this.$emit('cancel', true)
    },

    /** 确认按钮操作 */
    confirm() {
      this.$emit('confirm', true)
    },

    /** 点击遮罩关闭弹窗 */
    closeMyself(event) {
      // this.sloveBodyOverflow()
    },

    /** 恢复页面的滚动 */
    sloveBodyOverflow() {
      document.body.style.overflow = this.bodyOverflow
    }
  }
}
</script>

<style lang="less" scoped>
// 弹窗动画

// 最外层 设置position定位
// 遮罩 设置背景层，z-index值要足够大确保能覆盖，高度 宽度设置满 做到全屏遮罩

.dialog {
  position: fixed;
  top: 0;
  right: 0;
  width: 100%;
  height: 100%;
  transition: opacity 1s;

  // 内容层 z-index要比遮罩大，否则会被遮盖
  .dialog-mark {
    position: relative;
    top: 0;
    height: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    left: 0;
    top: 0;
    z-index: 99;
    display: flex;
    align-items: center;
    justify-content: center;
    .sharetiptxt {
      background-size: 100% auto;
      background-repeat: no-repeat;
      z-index: 55;
      width: 20px;
      height: 320px;
      display: block;
      position: absolute;
      right: 1rem;
      top: 0.5em;
      animation: tipup 1s ease infinite;
    }
  }
}

@keyframes tipup {
  0% {
    transform: translateY(0%);
  }
  50% {
    transform: translateY(5%);
  }
  100% {
    transform: translateY(0%);
  }
}

.dialog-sprite {
  width: 100vw;
  display: flex;
  justify-content: center;
  position: relative;

  .header {
    padding: 15px;
    text-align: center;
    font-size: 18px;
    font-weight: 700;
    color: #333;
  }
  .dialog-body {
    flex: 1;
    overflow-x: hidden;
    overflow-y: scroll;
    padding: 0 15px 20px 15px;

    //中间卡片
    .card-wrapper {
      perspective: 600px;
      margin-top: 2em;

      .dialog-popuImag {
        position: relative;
        display: flex;
        justify-content: center;
        transform-style: preserve-3d;
        transition: all 1.2s ease;

        .front {
          position: relative;
          display: flex;
          justify-content: center;
          .PrizeImg {
            width: 55vw;
            position: absolute;
            height: 48vw;
            top: 20vh;
          }
        }
        .back {
          transform: rotateY(180deg);
          width: 180px;
          height: 492px;
          background-size: 100% auto;
          background-repeat: no-repeat;
        }

        img {
          width: 48vw;
        }
      }
      .flipped {
      }
    }

    //底部按钮
    .dialog-footer {
      width: 140px;
      margin: 10px auto 0;
      .btn {
        background-position: 50% 50%;
        background-repeat: no-repeat;
        padding-top: 0;
        width: 100%;
      }
    }
  }
}
</style>

