<!--  -->
<template>
  <v-card class="default-width my-3 mt-16">
    <showText :class="showPrizeDraw ? '' : 'mb-15'"></showText>

    <!-- 抽奖 -->
    <prizeDraw v-if="showPrizeDraw" type="2" :orderId="orderId" :lotteryId="lotteryId" class="prizeDraw mx-15 my-7" @success="handleReceive"></prizeDraw>
  </v-card>
</template>

<script setup>
defineOptions({name: 'payOver-index'})
import { ref } from 'vue'
import showText from './components/show.vue'
import prizeDraw from '@/views/mall/components/prizeDraw.vue'
import { useRoute, useRouter } from 'vue-router'
import { getPrizeByGoodsId } from '@/api/mall/prize'

const { spuId, orderId } = useRoute().query
const showPrizeDraw = ref(false)
const lotteryId = ref('')
const getLottery = async () => {
  if (!spuId) return
  const data = await getPrizeByGoodsId(spuId)
  showPrizeDraw.value = data && Object.keys(data).length > 0

  lotteryId.value = data.id
}
getLottery()

// 前往我的奖品
const router = useRouter()
const handleReceive = () => {
  router.push('/mall/user/prize')
}
</script>

<style lang="scss" scoped>
</style>
