index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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/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. lotteryType: {
  44. type: Number,
  45. default: 0
  46. },
  47. datatime: {
  48. type: Number,
  49. default: 0
  50. },
  51. userCount: {
  52. type: Object,
  53. default() {
  54. return {}
  55. }
  56. }
  57. },
  58. onLoad() {
  59. },
  60. methods: {
  61. luck_draw(event) {
  62. let timestamp = Date.parse(new Date())/1000;
  63. if(this.lotteryType == 1 && parseInt(timestamp)>parseInt(this.datatime)){
  64. return this.$util.Tips({
  65. title: '您抽奖的有效时间已到期'
  66. },function(){
  67. uni.switchTab({
  68. url: '/pages/index/index'
  69. })
  70. });
  71. }
  72. if (!this.userCount.total) {
  73. return this.$util.Tips({
  74. title: '您抽奖的总次数已用完'
  75. });
  76. }
  77. if (!this.userCount.today) {
  78. return this.$util.Tips({
  79. title: '您今天抽奖的次数已用完'
  80. });
  81. }
  82. let index = event.currentTarget.dataset.index;
  83. if (this.lotteryBtn && index == 8) {
  84. this.lotteryBtn = false
  85. } else {
  86. return
  87. }
  88. let that = this;
  89. if (index == 8) {
  90. // 点击抽奖之后知道获奖位置,修改父组件中lottery_draw_param的值
  91. this.$emit('get_winingIndex', function(res) {
  92. let lottery_draw_param = res;
  93. let win = new LotteryDraw({
  94. domData: that.prizeData,
  95. ...lottery_draw_param
  96. },
  97. function(index, count) {
  98. that.current_index = index;
  99. if (lottery_draw_param.winingIndex == index && lottery_draw_param.totalCount ==
  100. count) {
  101. that.lotteryBtn = true
  102. that.$emit('luck_draw_finish', that.prizeData[index])
  103. }
  104. }
  105. );
  106. });
  107. }
  108. }
  109. }
  110. };
  111. </script>
  112. <style scoped lang="scss">
  113. @import './css/grids_lottery.css';
  114. .lottery-msg {
  115. width: 100%;
  116. height: 100%;
  117. padding: 0 4rpx;
  118. .name {}
  119. }
  120. .lottery-click {
  121. width: 100%;
  122. height: 100%;
  123. }
  124. </style>