<template>
  <van-popup
    v-model="visible"
    class="win-popup"
    closeable
    close-icon="close"
    :style="{ background: 'transparent' }"
    @click-close-icon="onClose"
  >
    <div class="win-popup__container">
      <div class="win-popup__wrap">
        <div class="win-popup__content">
          <slot v-if="isWin" name="title-bg"></slot>
          <div v-if="isWin" class="win-popup__win-info">
            <div class="win-popup__title">恭喜获得</div>
            <div class="win-popup__prize-img">
              <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">
            <slot name="thanks">谢谢参与，再接再厉</slot>
          </div>
        </div>
        <div class="win-popup__footer">
          <template v-if="isWin">
            <van-button class="win-popup__sure" color="linear-gradient(to right, #ffde9d, #ffdbb3)" round @click="know"
              >查看奖品详情</van-button
            >
            <p class="win-popup__win-msg">根据活动说明进行领取</p>
          </template>
          <van-button
            v-else
            class="win-popup__sure"
            color="linear-gradient(to right, #ffde9d, #ffdbb3)"
            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: () => ({})
    }
  },
  computed: {
    visible: {
      get() {
        return this.value
      },
      set(val) {
        Bus.$emit('updateMain', { isShowWin: val })
      }
    },
    isWin() {
      return !!Number(this.info.id)
    }
  },
  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 {
  overflow: visible;
  /deep/ .van-popup__close-icon {
    right: 52px;
    top: -16px;
    font-size: 22px;
    color: #fff;
  }
  &__container {
    width: 100%;
    height: 100%;
    position: relative;
    width: @containerWidth;
  }
  &__wrap {
    margin: 0 auto;
    width: 184px;
    height: 211px;
    overflow: hidden;
    background-image: url('~@/assets/images/lottery/winning_bg.png');
    background-size: cover;
    background-repeat: no-repeat;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }
  &__content {
    color: #fff;
    font-size: 16px;
    flex: 1;
    width: 100%;
    overflow: hidden;
  }
  &__win-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
  }
  &__title {
    width: 100%;
    text-align: center;
    color: #fff;
    font-weight: 500;
    font-size: 16px;
    height: 18px;
    margin: 13px 0 7px;
  }
  &__prize-img {
    img {
      display: block;
      width: 65px;
    }
  }
  &__prize-name {
    width: 100%;
    padding: 0 10px;
    font-size: 13px;
    color: #fff;
    margin-top: 11px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    text-align: center;
  }
  &__thanks {
    padding-top: 24px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  &__footer {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 65px;
  }
  &__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>
