<template>
  <van-popup
    v-model="visible"
    position="bottom"
    round
    transfer
    class="precondition-popup"
  >
  <div class="main">
    <div class="box">
      <img class="box-img" src="~@/assets/images/lottery/precondition-bg.png" alt="">
      <img class="box-close" src="~@/assets/images/lottery/force-close.png" alt="" @click="visible = false">
      <div class="box-warp">
        <div class="box-warp__title">请您先参与{{ lotteryInfo.bindService === 'vote' ? '投票' : '问卷' }}【{{ precondition.title }}】，即可进行抽奖</div>
        <div class="box-warp__btn" @click="go">立即{{ lotteryInfo.bindService === 'vote' ? '投票' : '填写' }}</div>
      </div>
    </div>
  </div>
  </van-popup>
</template>

<script>
// import Bus from '@/utils/Bus'
import { mapGetters, mapActions } from 'vuex'

export default {
  name: 'PreconditionPopup',
  props: {
    value: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
    }
  },
  computed: {
    ...mapGetters({
      uin: 'users/uin',
      precondition: 'lottery/precondition',
      lotteryInfo: 'lottery/lotteryInfo'
    }),
    visible: {
      get() {
        return this.value
      },
      set(val) {
        this.$emit('input', val)
      },
    },
  },
  methods: {
    ...mapActions({
      getLotteryDetail: 'lottery/getLotteryDetail',
      updateInfo: 'lottery/updateInfo',
    }),
    go() {
      if (this.$route.path.includes('mini')) {
        const url = this.lotteryInfo.bindService === 'vote' ? this.precondition.url.replace('/index', '/mini/index') : this.precondition.url
        window.location.href = url
      } else {
        window.location.href = this.precondition.url
      }
    }
  }
}
</script>

<style lang="less" scoped>
.precondition-popup {
  background-color: transparent;
  .main {
    height: 100vh;
    max-width: 540px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0 auto;
    .box {
      width: 70%;
      position: relative;
      margin-bottom: 10%;
      &-img {
        width: 100%;
        position: relative;
      }
      &-close {
        width: 20px;
        height: 20px;
        position: absolute;
        top: 10%;
        right: -20px;
      }
      &-warp {
        position: absolute;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        align-items: center;
        padding-bottom: 13%;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        &__title {
          font-family: PingFangSC, PingFang SC;
          font-weight: 500;
          font-size: 18px;
          color: #333333;
          text-align: center;
          margin-top: 40%;
          padding: 0 24px;
          line-height: 24px;
        }
        &__content {
          max-width: 80%;
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 14px;
          color: #666666;
          text-align: center;
          line-height: 19px;
          margin: 14px 0 37px;
        }
        &__btn {
          width: 120px;
          height: 36px;
          background: linear-gradient( 201deg, #FD8192 0%, #FF4F31 100%);
          border-radius: 37px;
          font-family: PingFangSC, PingFang SC;
          font-weight: 500;
          font-size: 14px;
          color: #FFFFFF;
          line-height: 36px;
          text-align: center;
          cursor: pointer;
        }
      }
    }
  }
}
</style>
