index.vue 2.0 KB

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