<template>
  <van-popup
    v-model="visible"
    class="win-popup"
    closeable
    close-icon="close"
    :style="{ background: 'transparent' }"
    @click-close-icon="onClose"
  >
    <div v-if="type === 'luckybag'" class="lucky-popup__container">
      <div class="lucky-popup__wrap">
        <div class="lucky-popup__content">
          <slot v-if="isWin" name="title-bg"></slot>
          <div v-if="isWin" class="lucky-popup__win-info">
            <div class="lucky-popup__title">恭喜获得</div>
            <div class="lucky-popup__prize-img">
              <img v-if="info.prizeIcon" :src="info.prizeIcon" alt="" />
              <img v-else src="@/assets/images/lottery/gift.png" alt="" />
            </div>
            <div class="lucky-popup__prize-name">
              {{ info.name }}
            </div>
          </div>
          <div v-else class="lucky-popup__thanks">
            <slot name="thanks">
              <div
                style="
                  font-size: 18px;
                  font-family: PingFangSC-Medium, PingFang SC;
                  font-weight: 500;
                  color: #fd0c2a;
                  line-height: 25px;
                  margin-bottom: 10px;
                "
              >
                很遗憾
              </div>
              <div
                style="
                  font-size: 14px;
                  font-family: PingFangSC-Regular, PingFang SC;
                  font-weight: 400;
                  color: #fd0c2a;
                  line-height: 20px;
                "
              >
                您未抽中福袋
              </div>
            </slot>
          </div>
        </div>
        <div class="lucky-popup__footer">
          <van-button
            class="lucky-popup__sure"
            color="linear-gradient(180deg, #FEDF96, #FF8A42)"
            round
            @click="visible = false"
            >我知道了</van-button
          >
        </div>
      </div>
    </div>
    <div v-if="type === 'treasure'" class="treasure-popup__container">
      <div class="treasure-popup__wrap">
        <div class="treasure-popup__content">
          <slot v-if="isWin" name="title-bg"></slot>
          <div v-if="isWin" class="treasure-popup__win-info">
            <div class="treasure-popup__title">恭喜获得</div>
            <div class="treasure-popup__prize-img">
              <img v-if="info.prizeIcon" :src="info.prizeIcon" alt="" />
              <img v-else src="@/assets/images/lottery/gift.png" alt="" />
            </div>
            <div class="treasure-popup__prize-name">
              {{ info.name }}
            </div>
          </div>
          <div v-else class="treasure-popup__thanks">
            <slot name="thanks">
              <div
                style="
                  font-size: 18px;
                  font-family: PingFangSC-Medium, PingFang SC;
                  font-weight: 500;
                  color: #fd0c2a;
                  line-height: 25px;
                  margin-bottom: 10px;
                "
              >
                很遗憾
              </div>
              <div
                style="
                  font-size: 14px;
                  font-family: PingFangSC-Regular, PingFang SC;
                  font-weight: 400;
                  color: #fd0c2a;
                  line-height: 20px;
                "
              >
                您未抽中宝箱
              </div>
            </slot>
          </div>
        </div>
        <div class="treasure-popup__footer">
          <van-button
            class="treasure-popup__sure"
            color="linear-gradient(180deg, #FEDF96, #FF8A42)"
            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: () => ({})
    },
    type: {
      type: String,
      default: ''
    }
  },
  computed: {
    visible: {
      get() {
        return this.value
      },
      set(val) {
        Bus.$emit('updateMain', { isShowWin: val })
      }
    },
    isWin() {
      return !!+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: 10px;
    top: -16px;
    font-size: 22px;
    color: #fff;
  }
}
.lucky-popup {
  &__container {
    width: 100%;
    height: 100%;
    position: relative;
    width: @containerWidth;
  }
  &__wrap {
    margin: 0 auto;
    width: 275px;
    height: 321px;
    overflow: hidden;
    background-image: url('img/luckybag-popup.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;
    height: 175px;
    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;
    font-size: 18px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #fd0c2a;
    line-height: 25px;
    height: 18px;
    margin: 7px 0 13px;
  }
  &__prize-img {
    img {
      display: block;
      width: 65px;
    }
  }
  &__prize-name {
    width: 100%;
    padding: 0 10px;
    font-size: 12px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #fd0c2a;
    line-height: 16.5px;
    margin-top: 11px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    text-align: center;
  }
  &__thanks {
    margin-top: -24px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
  }
  &__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: 14px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #c10000;
      line-height: 20px;
    }
  }
  &__win-msg {
    margin: 13px 0 20px;
    font-size: 12px;
    color: #fff;
  }
}
.treasure-popup {
  overflow: visible;
  /deep/ .van-popup__close-icon {
    right: 10px;
    top: -16px;
    font-size: 22px;
    color: #fff;
  }
  &__container {
    width: 100%;
    height: 100%;
    position: relative;
    width: @containerWidth;
  }
  &__wrap {
    margin: 0 auto;
    width: 275px;
    height: 321px;
    overflow: hidden;
    background-image: url('img/treasure-popup.png');
    background-size: cover;
    background-repeat: no-repeat;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
  }
  &__content {
    color: #fff;
    font-size: 16px;
    height: 142px;
    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;
    font-size: 18px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #fd0c2a;
    line-height: 25px;
    height: 18px;
    margin: 7px 0 13px;
  }
  &__prize-img {
    img {
      display: block;
      width: 65px;
    }
  }
  &__prize-name {
    width: 100%;
    padding: 0 10px;
    font-size: 12px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #fd0c2a;
    line-height: 16.5px;
    margin-top: 11px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    text-align: center;
  }
  &__thanks {
    margin-top: 0;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
  }
  &__footer {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    min-height: 65px;
  }
  &__sure {
    width: 126px;
    height: 33px;
    line-height: 33px;
    border: 0;
    outline: none;
    /deep/ .van-button__text {
      font-size: 14px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #c10000;
      line-height: 20px;
    }
  }
  &__win-msg {
    margin: 13px 0 20px;
    font-size: 12px;
    color: #fff;
  }
}
</style>
