<template>
  <van-popup v-model="visible" class="win-popup" :style="{ background: 'transparent' }">
    <div class="win-popup__container">
      <div class="win-popup__close" :style="closeBg" @click="onClose"></div>
      <div class="win-popup__wrap" :style="wrapBg">
        <div class="win-popup__content">
          <div v-if="isWin" class="win-popup__header">
            <img :src="winConfig.winTitle" />
          </div>
          <div v-if="isWin" class="win-popup__win-info">
            <div class="win-popup__title">恭喜获得</div>
            <div class="win-popup__prize-img" :style="prizeBg">
              <img src="@/assets/images/lottery/gift.png" alt="" />
            </div>
            <div class="win-popup__prize-name">
              {{ info.name }}
            </div>
          </div>
          <div v-else class="win-popup__thanks">
            <p>很遗憾</p>
            <slot name="thanks"></slot>
          </div>
        </div>
        <div v-if="isWin" class="win-popup__bottom">
          <van-button class="win-popup__sure" color="linear-gradient(#fff0cd, #fdbf2c)" round @click="know"
            >查看奖品详情</van-button
          >
          <p class="win-popup__win-msg">根据活动说明进行领取</p>
        </div>
        <div v-else class="win-popup__bottom">
          <van-button class="win-popup__sure" color="linear-gradient(#fff0cd, #fdbf2c)" round @click="visible = false"
            >我知道了</van-button
          >
        </div>
      </div>
    </div>
  </van-popup>
</template>

<script>
import Bus from '@/utils/Bus'

export default {
  name: 'WinPopup',
  components: {},
  props: {
    value: {
      type: Boolean,
      default: false
    },
    info: {
      type: Object,
      default: () => ({})
    },
    winConfig: {
      type: Object,
      default: () => ({})
    }
  },
  computed: {
    visible: {
      get() {
        return this.value
      },
      set(val) {
        Bus.$emit('updateMain', { isShowWin: val })
      }
    },
    isWin() {
      return !!+this.info.id
    },
    wrapBg() {
      return {
        backgroundImage: `url(${this.winConfig.bg})`
      }
    },
    closeBg() {
      return {
        backgroundImage: `url(${this.winConfig.winClose})`
      }
    },
    prizeBg() {
      return {
        backgroundImage: `url(${this.winConfig.winPrizeBg})`
      }
    }
  },
  methods: {
    know() {
      Bus.$emit('updateMain', { func: 'winCallback' })
    },
    onClose() {
      Bus.$emit('updateMain', { func: 'winCloseCallback' })
    }
  }
}
</script>

<style lang="less" scoped>
@containerWidth: 326px;
@wrapWidth: 275px;
@wrapHeight: 292px;

.win-popup {
  width: 263px;
  height: 309px;
  overflow: visible;
  &__close {
    position: absolute;
    right: -20px;
    top: -10px;
    width: 25px;
    height: 25px;
    background-size: 100% 100%;
  }
  &__container {
    width: 100%;
    height: 100%;
    position: relative;
  }
  &__wrap {
    position: relative;
    margin: 0 auto;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-size: cover;
    background-repeat: no-repeat;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }
  &__content {
    color: #fff;
    font-size: 16px;
    width: 100%;
    height: 100%;
    overflow: hidden;
  }
  &__win-info {
    position: absolute;
    top: 47%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: #0000001a;
    width: 80%;
    margin: 0 auto;
    border-radius: 20px;
    padding: 12px 0;
    z-index: 20;
  }
  &__title {
    width: 100%;
    text-align: center;
    color: #fff;
    font-weight: 500;
    font-size: 14px;
    height: 18px;
    margin-bottom: 7px;
  }
  &__prize-img {
    margin-bottom: 7px;
    background-size: 100% 100%;
    width: 65px;
    height: 65px;
    display: flex;
    justify-content: center;
    align-items: center;
    img {
      display: block;
      width: 60%;
      height: 60%;
    }
  }
  &__prize-name {
    width: 100%;
    padding: 0 10px;
    font-size: 12px;
    color: #fff;
    margin-top: 11px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    text-align: center;
  }
  &__thanks {
    position: absolute;
    top: 47%;
    left: 50%;
    transform: translate(-50%, -50%);
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    p {
      margin-bottom: 10px;
      font-size: 18px;
    }
  }
  &__bottom {
    height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: start;
    align-items: center;
  }
  &__footer {
    position: absolute;
    bottom: 14%;
    left: 50%;
    transform: translateX(-50%);
    width: 157px;
    height: 49px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  &__header {
    position: absolute;
    top: 12%;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    height: 27px;
    text-align: center;
    img {
      height: 100%;
    }
  }
  &__sure {
    width: 157px;
    height: 49px;
    line-height: 49px;
    border-radius: 20px;
    outline: none;
    /deep/ .van-button__text {
      font-size: 16px;
      color: #860300;
      font-weight: 600;
      text-shadow: 1px 0 0 #fff, 0 1px 0 #fff, -1px 0 0 #fff, 0 -1px 0 #fff;
    }
  }
  &__win-msg {
    text-align: center;
    margin: 5px 0;
    font-size: 12px;
    color: #fff;
  }
}
</style>
