<template>
  <div v-if="showSelf" class="dialog" :style="{'z-index': zIndex}">
    <div class="dialog-mark" @click="closeMyself" :style="{'z-index': zIndex + 1}">
      <div v-show="myShareShow" class="sharetiptxt" style>
        <img style="width:100%; height:100%; z-index:46" src="../assets/popupImg/myShare.png" alt />
      </div>
      <transition name="dialog">
        <div class="dialog-sprite">
          <div class="dialog-body">
            <div class="bd2 flex-col">
              <img class="pic1" src="../assets/ShaerPopupImg/popuBgc.jpg" alt />
            </div>

            <div class="bd1 flex-col">
              <span class="btn" :style="`background-image: url(${popuSave});`"></span>
            </div>
          </div>
          <!-- 右侧 -->
          <!-- <div class="section-box">
            <div class="section-box-share" @click="()=>{this.myShareShow=true}">
              <img src="../assets/popupImg/shareImage.png" alt />
            </div>
            <div class="section-box-receive">
              <router-link :to="{path:'SaveShare',query: {  states: 0 }}">
                <img src="../assets/popupImg/receiveImage.png" alt />
              </router-link>
            </div>
            <div class="section-box-save">
              <router-link :to="{path:'SaveShare',query: {  states: 1 }}">
                <img src="../assets/popupImg/saveImage.png" alt />
              </router-link>
            </div>
          </div>-->
        </div>
      </transition>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ShaerPopup',

  props: {
    show: {
      type: Boolean,
      default: false,
      required: true
    },
    cancelText: {
      type: String,
      default: '取消',
      required: false
    }
  },

  data() {
    return {
      name: 'dialog',
      showSelf: false,
      zIndex: this.getZIndex(),
      bodyOverflow: '',
      popuSave: require('../assets/ShaerPopupImg/popuSave.png'),

      myShareShow: true
    }
  },
  watch: {
    show(val) {
      console.log('🚀 ~ file: Popup.vue ~ line 78 ~ show ~ val', val)
      this.showSelf = val

      // this.closeMyself()

      // if (!val) {
      //   this.closeMyself()
      // } else {
      //   this.showSelf = val
      // }
    }
  },
  created() {
    this.showSelf = this.show
  },
  mounted() {
    this.forbidScroll()
  },
  methods: {
    /** 禁止页面滚动 */
    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()
      this.$emit('closeMyself', true)
    },

    /** 恢复页面的滚动 */
    sloveBodyOverflow() {
      this.showSelf = false

      document.body.style.overflow = this.bodyOverflow
    }
  }
}
</script>

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

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

.flex-col {
  display: flex;
  flex-direction: column;
}
.dialog {
  position: fixed;
  top: 0;
  right: 0;
  width: 100%;
  height: 100%;
  transition: opacity 1s;

  // 内容层 z-index要比遮罩大，否则会被遮盖
  .dialog-mark {
    position: absolute;
    top: 0;
    height: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    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;
    //中间卡片
    .bd2 {
      z-index: 33;
      width: 100%;
      justify-content: flex-start;
      align-items: center;
      margin-top: 20px;

      .pic1 {
        z-index: 45;
        width: 280px;
        height: 464px;
        // div {
        //   // position: relative;
        //   position: absolute;
        //   width: 100%;
        //   height: 100%;
        //   /* 背面不显示 */
        //   // backface-visibility: hidden;
        // }

        img {
          width: 48vw;
        }
      }
      .flipped {
        animation: change 0.8s linear forwards;
      }
    }
    @keyframes change {
      from {
        top: -20vh;
        left: -20vw;
        opacity: 0;
        transform: scale(0.5);
      }
      to {
        top: -0;
        left: -0;
        opacity: 2;
        transform: scale(1);
        transform: rotateY(180deg);
      }
    }
    //底部按钮
    .bd1 {
      width: 100%;
      background-size: 100% auto;
      margin: 10px auto 0;
      .btn {
        z-index: 42;
        width: 152px;
        height: 50px;
        display: block;
        text-align: center;
        align-self: center;
        margin-top: 12px;
        background-size: 100% auto;
        background-repeat: no-repeat;
      }
    }
  }
  .section-box {
    position: absolute;
    right: 15vw;
    top: 98px;
    height: 394px;
    display: flex;
    flex-direction: column;
    width: 36px;
    justify-content: space-between;

    img {
      width: 36px;
      background-size: 100% auto;
      margin-top: 0;
      border-radius: 18px;
    }

    &-receive {
      width: 36px;
      background-size: 100% auto;
      margin-top: 0;
    }
    &-save {
      width: 36px;
      border-radius: 18px;
      background-size: 100% auto;
      width: 36px;
      margin-top: 0;

      // background: url('../assets/popupImg/receiveImage.png') no-repeat;
    }
  }
}
</style>

