index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <view class="lottery_container">
  3. <view class="grid_wrap">
  4. <view class="lottery_wrap">
  5. <view class="lottery_grid">
  6. <view v-for="(item, index) in prizeData" :key="index" :class="{ active: current_index == index && index != 8 }" class="item" @click="luck_draw">
  7. <view :class="{in_line:index != 8 }" class="lottery-msg">
  8. <image v-if="index != 8" class="grid_img" mode='aspectFit' :src="item.image" alt="" />
  9. <text v-if="index !=8" class="name line1">
  10. {{ index == 8 ? '抽奖' : item.name }}
  11. </text>
  12. <view v-else class="flex-col flex-center lottery-click">
  13. <!-- <text class="fs-36">立即抽奖</text> -->
  14. <text class="fs-36">{{lotteryNum}}次</text>
  15. <text class="fs-20 lh-28rpx">抽奖机会</text>
  16. </view>
  17. </view>
  18. </view>
  19. </view>
  20. </view>
  21. <!-- <view class="lottery_wrap_border">
  22. <ul v-for="(item, index) in 4" :key="index">
  23. <li v-for="(item, index) in 12" :key="index"></li>
  24. </ul>
  25. </view> -->
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import LotteryDraw from './js/grids_lottery.js';
  31. export default {
  32. data() {
  33. return {
  34. current_index: -1,
  35. lotteryBtn: true
  36. };
  37. },
  38. props: {
  39. prizeData: {
  40. type: Array,
  41. default: function() {
  42. return []
  43. }
  44. },
  45. lotteryType: {
  46. type: Number,
  47. default: 0
  48. },
  49. datatime: {
  50. type: Number,
  51. default: 0
  52. },
  53. lotteryNum: {
  54. type: Number,
  55. default: 0
  56. },
  57. isRotating: {
  58. type: Boolean,
  59. default: false
  60. },
  61. winingIndex: {
  62. type: Number,
  63. default: 0
  64. },
  65. },
  66. watch: {
  67. isRotating(newValue, oldValue) {
  68. let that = this;
  69. if (newValue) {
  70. // let lottery_draw_param = res;
  71. let win = new LotteryDraw({
  72. domData: that.prizeData,
  73. // ...lottery_draw_param
  74. startIndex: 3, //开始抽奖位置,从0开始
  75. totalCount: 3, //一共要转的圈数
  76. winingIndex: this.winingIndex, //中奖的位置,从0开始
  77. speed: 100 //抽奖动画的速度 [数字越大越慢,默认100]
  78. },
  79. function(index, count) {
  80. that.current_index = index;
  81. if (that.winingIndex == index && 3 ==
  82. count) {
  83. that.lotteryBtn = true
  84. that.$emit('luck_draw_finish', that.prizeData[index])
  85. }
  86. }
  87. );
  88. }
  89. }
  90. },
  91. mounted() {},
  92. methods: {
  93. luck_draw(event) {
  94. let timestamp = Date.parse(new Date()) / 1000;
  95. if (this.lotteryType == 1 && parseInt(timestamp) > parseInt(this.datatime)) {
  96. return this.$util.Tips({
  97. title: '您抽奖的有效时间已到期'
  98. }, function() {
  99. uni.switchTab({
  100. url: '/pages/index/index'
  101. })
  102. });
  103. }
  104. let index = event.currentTarget.dataset.index;
  105. if (this.lotteryBtn && index == 8) {
  106. this.lotteryBtn = false
  107. } else {
  108. return
  109. }
  110. let that = this;
  111. if (index == 8) {
  112. // 点击抽奖之后知道获奖位置,修改父组件中lottery_draw_param的值
  113. this.$emit('get_winingIndex', function(res) {
  114. let lottery_draw_param = res;
  115. let win = new LotteryDraw({
  116. domData: that.prizeData,
  117. ...lottery_draw_param
  118. },
  119. function(index, count) {
  120. that.current_index = index;
  121. if (lottery_draw_param.winingIndex == index && lottery_draw_param.totalCount ==
  122. count) {
  123. that.lotteryBtn = true
  124. that.$emit('luck_draw_finish', that.prizeData[index])
  125. }
  126. }
  127. );
  128. });
  129. }
  130. }
  131. }
  132. };
  133. </script>
  134. <style scoped lang="scss">
  135. @import './css/grids_lottery.css';
  136. .lottery-msg {
  137. width: 100%;
  138. height: 100%;
  139. padding: 0 4rpx;
  140. .name {}
  141. }
  142. .lottery-click {
  143. width: 100%;
  144. height: 100%;
  145. }
  146. .lottery_grid .name {
  147. width: 100%;
  148. text-align: center;
  149. }
  150. </style>