DrawLotteryRaffle.vue 4.0 KB

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