index.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <view class="lottery_container">
  3. <view class="grid_wrap">
  4. <view class="lottery_wrap">
  5. <ul class="lottery_grid">
  6. <li v-for="(item, index) in prizeData" :class="{ active: current_index == index && index != 8 }"
  7. :key="index" @click="luck_draw" :data-index="index">
  8. <view :class="{in_line:index != 8 }" class="lottery-msg">
  9. <image v-if="index != 8" class="grid_img" mode='aspectFit' :src="item.image" alt="" />
  10. <text v-if="index !=8" class="name">
  11. {{ index == 8 ? '抽奖' : item.name }}
  12. </text>
  13. <image v-else class="lottery-click" src="../../static/images/lottery-click.png" mode="">
  14. </image>
  15. </view>
  16. </li>
  17. </ul>
  18. </view>
  19. <!-- <view class="lottery_wrap_border">
  20. <ul v-for="(item, index) in 4" :key="index">
  21. <li v-for="(item, index) in 12" :key="index"></li>
  22. </ul>
  23. </view> -->
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import LotteryDraw from './js/grids_lottery.js';
  29. export default {
  30. data() {
  31. return {
  32. current_index: -1,
  33. lotteryBtn: true
  34. };
  35. },
  36. props: {
  37. prizeData: {
  38. type: Array,
  39. default: function() {
  40. return []
  41. }
  42. },
  43. },
  44. onLoad() {
  45. },
  46. methods: {
  47. luck_draw(event) {
  48. if (this.lotteryBtn) {
  49. this.lotteryBtn = false
  50. } else {
  51. return
  52. }
  53. let index = event.currentTarget.dataset.index;
  54. let that = this;
  55. if (index == 8) {
  56. // 点击抽奖之后知道获奖位置,修改父组件中lottery_draw_param的值
  57. this.$emit('get_winingIndex', function(res) {
  58. let lottery_draw_param = res;
  59. let win = new LotteryDraw({
  60. domData: that.prizeData,
  61. ...lottery_draw_param
  62. },
  63. function(index, count) {
  64. that.current_index = index;
  65. if (lottery_draw_param.winingIndex == index && lottery_draw_param.totalCount ==
  66. count) {
  67. that.lotteryBtn = true
  68. that.$emit('luck_draw_finish', that.prizeData[index])
  69. }
  70. }
  71. );
  72. });
  73. }
  74. }
  75. }
  76. };
  77. </script>
  78. <style scoped lang="scss">
  79. @import './css/grids_lottery.css';
  80. .lottery-msg {
  81. width: 100%;
  82. height: 100%;
  83. padding: 0 4rpx;
  84. .name {}
  85. }
  86. .lottery-click {
  87. width: 100%;
  88. height: 100%;
  89. }
  90. </style>