index.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. lotteryNum: {
  39. type: Number | String,
  40. default: 0
  41. }
  42. },
  43. onLoad() {
  44. },
  45. methods: {
  46. luck_draw(event) {
  47. if (Number(this.lotteryNum) <= 0) {
  48. return this.$util.Tips({
  49. title: this.$t(`剩余抽奖次数为0`)
  50. });
  51. } else if (this.lotteryBtn) {
  52. this.lotteryBtn = false
  53. } else {
  54. return
  55. }
  56. let index = event.currentTarget.dataset.index;
  57. let that = this;
  58. if (index == 8) {
  59. // 点击抽奖之后知道获奖位置,修改父组件中lottery_draw_param的值
  60. this.$emit('get_winingIndex', function(res) {
  61. let lottery_draw_param = res;
  62. let win = new LotteryDraw({
  63. domData: that.prizeData,
  64. ...lottery_draw_param
  65. },
  66. function(index, count) {
  67. that.current_index = index;
  68. if (lottery_draw_param.winingIndex == index && lottery_draw_param.totalCount ==
  69. count) {
  70. that.lotteryBtn = true
  71. that.$emit('luck_draw_finish', that.prizeData[index])
  72. }
  73. }
  74. );
  75. });
  76. }
  77. }
  78. }
  79. };
  80. </script>
  81. <style scoped lang="scss">
  82. @import './css/grids_lottery.css';
  83. .lottery-msg {
  84. width: 100%;
  85. height: 100%;
  86. padding: 0 4rpx;
  87. .name {}
  88. }
  89. .lottery-click {
  90. width: 100%;
  91. height: 100%;
  92. }
  93. </style>