index.vue 2.6 KB

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