index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //index.js
  2. //获取应用实例
  3. var app = getApp()
  4. Page({
  5. data: {
  6. circleList: [],//圆点数组
  7. awardList: [],//奖品数组
  8. colorCircleFirst: '#FFDF2F',//圆点颜色1
  9. colorCircleSecond: '#FE4D32',//圆点颜色2
  10. colorAwardDefault: '#F5F0FC',//奖品默认颜色
  11. colorAwardSelect: '#ffe400',//奖品选中颜色
  12. indexSelect: 0,//被选中的奖品index
  13. isRunning: false,//是否正在抽奖
  14. imageAward: [
  15. '../../images/1.jpg',
  16. '../../images/2.jpg',
  17. '../../images/3.jpg',
  18. '../../images/4.jpg',
  19. '../../images/5.jpg',
  20. '../../images/6.jpg',
  21. '../../images/7.jpg',
  22. '../../images/8.jpg',
  23. ],//奖品图片数组
  24. },
  25. onLoad: function () {
  26. var _this = this;
  27. //圆点设置
  28. var leftCircle = 7.5;
  29. var topCircle = 7.5;
  30. var circleList = [];
  31. for (var i = 0; i < 24; i++) {
  32. if (i == 0) {
  33. topCircle = 15;
  34. leftCircle = 15;
  35. } else if (i < 6) {
  36. topCircle = 7.5;
  37. leftCircle = leftCircle + 102.5;
  38. } else if (i == 6) {
  39. topCircle = 15
  40. leftCircle = 620;
  41. } else if (i < 12) {
  42. topCircle = topCircle + 94;
  43. leftCircle = 620;
  44. } else if (i == 12) {
  45. topCircle = 565;
  46. leftCircle = 620;
  47. } else if (i < 18) {
  48. topCircle = 570;
  49. leftCircle = leftCircle - 102.5;
  50. } else if (i == 18) {
  51. topCircle = 565;
  52. leftCircle = 15;
  53. } else if (i < 24) {
  54. topCircle = topCircle - 94;
  55. leftCircle = 7.5;
  56. } else {
  57. return
  58. }
  59. circleList.push({ topCircle: topCircle, leftCircle: leftCircle });
  60. }
  61. this.setData({
  62. circleList: circleList
  63. })
  64. //圆点闪烁
  65. setInterval(function () {
  66. if (_this.data.colorCircleFirst == '#FFDF2F') {
  67. _this.setData({
  68. colorCircleFirst: '#FE4D32',
  69. colorCircleSecond: '#FFDF2F',
  70. })
  71. } else {
  72. _this.setData({
  73. colorCircleFirst: '#FFDF2F',
  74. colorCircleSecond: '#FE4D32',
  75. })
  76. }
  77. }, 500)
  78. //奖品item设置
  79. var awardList = [];
  80. //间距,怎么顺眼怎么设置吧.
  81. var topAward = 25;
  82. var leftAward = 25;
  83. for (var j = 0; j < 8; j++) {
  84. if (j == 0) {
  85. topAward = 25;
  86. leftAward = 25;
  87. } else if (j < 3) {
  88. topAward = topAward;
  89. //166.6666是宽.15是间距.下同
  90. leftAward = leftAward + 166.6666 + 15;
  91. } else if (j < 5) {
  92. leftAward = leftAward;
  93. //150是高,15是间距,下同
  94. topAward = topAward + 150 + 15;
  95. } else if (j < 7) {
  96. leftAward = leftAward - 166.6666 - 15;
  97. topAward = topAward;
  98. } else if (j < 8) {
  99. leftAward = leftAward;
  100. topAward = topAward - 150 - 15;
  101. }
  102. var imageAward = this.data.imageAward[j];
  103. awardList.push({ topAward: topAward, leftAward: leftAward, imageAward: imageAward });
  104. }
  105. this.setData({
  106. awardList: awardList
  107. })
  108. },
  109. //开始游戏
  110. startGame: function () {
  111. if (this.data.isRunning) return
  112. this.setData({
  113. isRunning: true
  114. })
  115. var _this = this;
  116. var indexSelect = 0
  117. var i = 0;
  118. var timer = setInterval(function () {
  119. indexSelect++;
  120. //这里我只是简单粗暴用y=30*x+200函数做的处理.可根据自己的需求改变转盘速度
  121. i += 30;
  122. if (i > 1000) {
  123. //去除循环
  124. clearInterval(timer)
  125. //获奖提示
  126. wx.showModal({
  127. title: '恭喜您',
  128. content: '获得了第' + (_this.data.indexSelect + 1) + "个优惠券",
  129. showCancel: false,//去掉取消按钮
  130. success: function (res) {
  131. if (res.confirm) {
  132. _this.setData({
  133. isRunning: false
  134. })
  135. }
  136. }
  137. })
  138. }
  139. indexSelect = indexSelect % 8;
  140. _this.setData({
  141. indexSelect: indexSelect
  142. })
  143. }, (200 + i))
  144. }
  145. })