index.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <view class="one_1">
  5. <text :style="{background:`${prizeInfo.color}`}">{{prizeInfo.name||'待开奖中'}}</text>
  6. </view>
  7. <view class="one_2">
  8. <button :type="is_start==true?'warn':'primary'" size="mini"
  9. @tap="toCommon()">{{is_start==true?'结束':'开始'}}</button>
  10. </view>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. data() {
  17. return {
  18. // 是否开始抽奖
  19. is_start: false,
  20. // 抽奖名单
  21. list: [ //
  22. {
  23. "name": "小夫妻麻辣烫",
  24. "color": "#3d582f"
  25. },
  26. {
  27. "name": "稻花香盒饭",
  28. "color": "#c4ef4c"
  29. },
  30. {
  31. "name": "三品阁米线",
  32. "color": "#27b92b"
  33. },
  34. {
  35. "name": "新天地超市",
  36. "color": "#5d653c"
  37. },
  38. {
  39. "name": "福苑粥铺",
  40. "color": "#7e102d"
  41. },
  42. {
  43. "name": "1949豆腐脑",
  44. "color": "#51ccf"
  45. },
  46. {
  47. "name": "干锅鸭头",
  48. "color": "#332893"
  49. },
  50. {
  51. "name": "水饺",
  52. "color": "#164365"
  53. },
  54. {
  55. "name": "酱大骨头",
  56. "color": "#6dfdb4"
  57. },
  58. {
  59. "name": "青山砂锅麻辣烫",
  60. "color": "#d920e1"
  61. },
  62. {
  63. "name": "黄焖鸡米饭",
  64. "color": "#7c9d9b"
  65. },
  66. {
  67. "name": "沈老头包子",
  68. "color": "#b3dc5e"
  69. },
  70. {
  71. "name": "兰州拉面",
  72. "color": "#398fce"
  73. },
  74. {
  75. "name": "田记抻面",
  76. "color": "#d476e3"
  77. },
  78. {
  79. "name": "裤带面",
  80. "color": "#8cb2d1"
  81. },
  82. {
  83. "name": "板面",
  84. "color": "#4dfd51"
  85. }
  86. ],
  87. // 倒计时
  88. timer: null,
  89. // 中奖信息
  90. prizeInfo: {},
  91. };
  92. },
  93. methods: {
  94. toCommon() {
  95. const that = this;
  96. let list = that.list;
  97. if (that.is_start) {
  98. that.is_start = false;
  99. clearInterval(this.timer)
  100. uni.showModal({
  101. title: '中奖项',
  102. content: `恭喜${that.prizeInfo.name}获得大奖,感谢参与!`
  103. })
  104. } else {
  105. that.is_start = true;
  106. that.timer = setInterval(function() {
  107. var index = Math.floor(Math.random() * list.length)
  108. that.prizeInfo = list[index]
  109. }, 200)
  110. }
  111. }
  112. }
  113. }
  114. </script>
  115. <style lang="scss">
  116. .content {
  117. .one {
  118. text-align: center;
  119. .one_1 {
  120. margin: 2vw 0;
  121. text {
  122. display: inline-block;
  123. width: 50vw;
  124. height: 50vw;
  125. text-align: center;
  126. line-height: 50vw;
  127. border-radius: 90%;
  128. background-color: #000000;
  129. color: #ffffff;
  130. font-weight: bold;
  131. font-size: 30px;
  132. font-family: cursive;
  133. }
  134. }
  135. }
  136. }
  137. </style>