<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="closePopup"></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 class="win-popup__footer" @click="know">
          <img :src="winConfig.winKnow" />
        </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' })
    },
    closePopup() {
      Bus.$emit('updateMain', { isShowWin: false })
    }
  }
}
</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%;
    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;
    }
  }
  &__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: 126px;
    height: 33px;
    line-height: 33px;
    border: 0;
    outline: none;
    /deep/ .van-button__text {
      font-size: 13px;
      color: #fb1f34;
      font-weight: 500;
    }
  }
  &__win-msg {
    margin: 13px 0 20px;
    font-size: 12px;
    color: #fff;
  }
}
</style>
