DrawLotteryRaffle.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <view class="draw-lottery">
  3. <view class="title">{{ t('wallet.item65') }}</view>
  4. <view class="times">{{ t('wallet.item10') }}{{ curLuckyDrawTimesF }}{{ t('wallet.item11') }}</view>
  5. <view class="lottery-grid">
  6. <view v-for="(item, index) in lotteryList" :key="index" class="lottery-item"
  7. :class="{ active: drawIndex === index }">
  8. <image :src="item.icon" mode="aspectFill" />
  9. <text>{{ item.name }}</text>
  10. </view>
  11. </view>
  12. <button class="draw-btn" type="primary" :disabled="curLuckyDrawTimesF <= 0 || drawing" @click="startDraw">
  13. {{ drawing ? t('common.drawing') : t('wallet.item66') }}
  14. </button>
  15. <view v-if="drawResult" class="draw-result">
  16. <text>{{ t('wallet.item67') }}: {{ drawResult.name }}</text>
  17. </view>
  18. </view>
  19. </template>
  20. <script setup lang="ts">
  21. import { ref } from 'vue'
  22. import { useI18n } from 'vue-i18n'
  23. const { t } = useI18n()
  24. const props = defineProps<{
  25. curLuckyDrawTimesF: string | number
  26. }>()
  27. const emit = defineEmits(['draw-complete'])
  28. const lotteryList = ref([
  29. { name: '$10', icon: '/static/images/lottery/10.png' },
  30. { name: '$20', icon: '/static/images/lottery/20.png' },
  31. { name: '$50', icon: '/static/images/lottery/50.png' },
  32. { name: '$100', icon: '/static/images/lottery/100.png' },
  33. { name: '$200', icon: '/static/images/lottery/200.png' },
  34. { name: '$500', icon: '/static/images/lottery/500.png' },
  35. { name: '$1000', icon: '/static/images/lottery/1000.png' },
  36. { name: t('wallet.item68'), icon: '/static/images/lottery/thanks.png' }
  37. ])
  38. const drawIndex = ref(-1)
  39. const drawing = ref(false)
  40. const drawResult = ref<any>(null)
  41. const startDraw = () => {
  42. if (drawing.value) return
  43. drawing.value = true
  44. drawResult.value = null
  45. let count = 0
  46. const maxCount = 20
  47. const interval = setInterval(() => {
  48. drawIndex.value = Math.floor(Math.random() * lotteryList.value.length)
  49. count++
  50. if (count >= maxCount) {
  51. clearInterval(interval)
  52. drawing.value = false
  53. const result = lotteryList.value[drawIndex.value]
  54. drawResult.value = result
  55. emit('draw-complete', result)
  56. }
  57. }, 100)
  58. }
  59. </script>
  60. <style scoped lang="scss">
  61. .draw-lottery {
  62. padding: 20rpx;
  63. .title {
  64. font-size: 32rpx;
  65. font-weight: bold;
  66. color: var(--bs-heading-color);
  67. text-align: center;
  68. margin-bottom: 20rpx;
  69. }
  70. .times {
  71. font-size: 28rpx;
  72. color: var(--bs-heading-color);
  73. text-align: center;
  74. margin-bottom: 40rpx;
  75. }
  76. .lottery-grid {
  77. display: grid;
  78. grid-template-columns: repeat(4, 1fr);
  79. gap: 20rpx;
  80. margin-bottom: 40rpx;
  81. .lottery-item {
  82. display: flex;
  83. flex-direction: column;
  84. align-items: center;
  85. padding: 20rpx;
  86. background-color: #f5f5f5;
  87. border-radius: 16rpx;
  88. transition: all 0.3s;
  89. image {
  90. width: 80rpx;
  91. height: 80rpx;
  92. margin-bottom: 10rpx;
  93. }
  94. text {
  95. font-size: 24rpx;
  96. color: var(--bs-heading-color);
  97. }
  98. &.active {
  99. transform: scale(1.1);
  100. background-color: #ffd700;
  101. box-shadow: 0 0 20rpx rgba(255, 215, 0, 0.5);
  102. text {
  103. color: var(--bs-heading-color);
  104. font-weight: bold;
  105. }
  106. }
  107. }
  108. }
  109. .draw-btn {
  110. width: 100%;
  111. height: 80rpx;
  112. line-height: 80rpx;
  113. font-size: 28rpx;
  114. border-radius: 40rpx;
  115. margin-bottom: 30rpx;
  116. &[disabled] {
  117. opacity: 0.5;
  118. }
  119. }
  120. .draw-result {
  121. text-align: center;
  122. font-size: 28rpx;
  123. color: #ff4d4f;
  124. font-weight: bold;
  125. }
  126. }
  127. </style>