luckdraw.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. <style lang="scss" scoped>
  2. .container {
  3. width: 100vw;
  4. .lucky-wheel {
  5. width: 100vw;
  6. height: 1200upx;
  7. background: rgb(252, 207, 133) url("../../static/color_pillar.png") no-repeat center bottom;
  8. background-size: 100%;
  9. padding-top: 60upx;
  10. .lucky-title {
  11. width: 100vw;
  12. height: 8.125rem;
  13. background: url("../../static/lucky_title.png") no-repeat center top;
  14. background-size: 100%;
  15. }
  16. .wheel-main {
  17. display: flex;
  18. align-items: center;
  19. justify-content: center;
  20. position: relative;
  21. .wheel-pointer-box {
  22. position: absolute;
  23. top: 50%;
  24. left: 50%;
  25. z-index: 100;
  26. transform: translate(-50%, -60%);
  27. width: 150upx;
  28. height: 150upx;
  29. .wheel-pointer {
  30. width: 150upx;
  31. height: 150upx;
  32. background: url("../../static/draw_btn.png") no-repeat center top;
  33. background-size: 100%;
  34. transform-origin: center 60%;
  35. }
  36. }
  37. .wheel-bg {
  38. width: 620upx;
  39. height: 620upx;
  40. background: url("../../static/draw_wheel.png") no-repeat center top;
  41. background-size: 100%;
  42. color: #fff;
  43. font-weight: 500;
  44. display: flex;
  45. flex-direction: column;
  46. justify-content: center;
  47. align-content: center;
  48. text-align: center;
  49. transition: transform 3s ease;
  50. .prize-list {
  51. width: 100%;
  52. height: 100%;
  53. position: relative;
  54. .prize-item {
  55. position: absolute;
  56. top: 0;
  57. left: 0;
  58. z-index: 2;
  59. width: 140upx;
  60. height: 300upx;
  61. &:first-child {
  62. top: 0;
  63. left: 288upx;
  64. transform: rotate(20deg);
  65. }
  66. &:nth-child(2) {
  67. top: 96upx;
  68. left: 400upx;
  69. transform: rotate(70deg);
  70. }
  71. &:nth-child(3) {
  72. top: 220upx;
  73. left: 392upx;
  74. transform: rotate(-250deg);
  75. }
  76. &:nth-child(4) {
  77. top: 9rem;
  78. left: 8.2125rem;
  79. transform: rotate(-210deg);
  80. }
  81. &:nth-child(5) {
  82. top: 9.2125rem;
  83. left: 4.4rem;
  84. transform: rotate(-160deg);
  85. }
  86. &:nth-child(6) {
  87. top: 6.3875rem;
  88. left: 1.9rem;
  89. transform: rotate(-111deg);
  90. }
  91. &:nth-child(7) {
  92. top: 2.8rem;
  93. left: 1.8125rem;
  94. transform: rotate(-69deg);
  95. }
  96. &:nth-child(8) {
  97. top: 0;
  98. left: 4.5rem;
  99. transform: rotate(-20deg);
  100. }
  101. .prize-pic {
  102. img {
  103. width: 140upx;
  104. height: 80upx;
  105. margin-top: 60upx;
  106. }
  107. }
  108. .prize-count {
  109. font-size: 30upx;
  110. }
  111. .prize-type {
  112. font-size: 24upx;
  113. }
  114. }
  115. }
  116. }
  117. }
  118. }
  119. .main {
  120. position: relative;
  121. width: 100%;
  122. min-height: 14.25rem;
  123. background: rgb(243, 109, 86);
  124. padding-bottom: 1.6875rem;
  125. .main-bg {
  126. width: 100%;
  127. height: 6.5625rem;
  128. position: absolute;
  129. top: -3.4375rem;
  130. left: 0;
  131. background: url("../../static/luck_bg.png") no-repeat center top;
  132. background-size: 100%;
  133. }
  134. .content {
  135. position: absolute;
  136. // top: 0.175rem;
  137. left: 0;
  138. background: rgb(243, 109, 86);
  139. width: 100%;
  140. height: 5.1875rem;
  141. font-size: 36upx;
  142. color: #ffeb39;
  143. // padding-left: 6.75rem;
  144. text-align: center;
  145. }
  146. .tip {
  147. position: relative;
  148. margin: 2.5rem auto 0;
  149. width: 17.5rem;
  150. border: 1px solid #fbc27f;
  151. .tip-title {
  152. position: absolute;
  153. top: -1rem;
  154. left: 50%;
  155. transform: translate(-50%, 0);
  156. font-size: 1rem;
  157. color: #fccc6e;
  158. background: rgb(243, 109, 86);
  159. padding: 0.3125rem 0.625rem;
  160. }
  161. .tip-content {
  162. padding: 1.5625rem 0.625rem;
  163. font-size: 0.875rem;
  164. color: #fff8c5;
  165. line-height: 1.5;
  166. }
  167. }
  168. }
  169. .toast {
  170. .toast-container {
  171. position: relative;
  172. width: 100%;
  173. height: 100%;
  174. border: 1px dotted #fccc6e;
  175. .toast-picture {
  176. position: absolute;
  177. top: -6.5rem;
  178. left: -1.5rem;
  179. width: 18.75rem;
  180. height: 8.5625rem;
  181. }
  182. .close {
  183. position: absolute;
  184. top: -0.9375rem;
  185. right: -0.9375rem;
  186. width: 2rem;
  187. height: 2rem;
  188. background: url("../../static/close_store.png") no-repeat center top;
  189. background-size: 100%;
  190. }
  191. .toast-title {
  192. padding: 2.8125rem 0;
  193. font-size: 18px;
  194. color: #fc7939;
  195. text-align: center;
  196. }
  197. .toast-btn {
  198. display: flex;
  199. align-items: center;
  200. justify-content: center;
  201. margin-bottom: 0.9375rem;
  202. .toast-cancel{
  203. background-image: -moz-linear-gradient(-18deg,
  204. rgb(242, 148, 85) 0%,
  205. rgb(252, 124, 88) 51%,
  206. rgb(252, 124, 88) 99%);
  207. background-image: -ms-linear-gradient(-18deg,
  208. rgb(242, 148, 85) 0%,
  209. rgb(252, 124, 88) 51%,
  210. rgb(252, 124, 88) 99%);
  211. background-image: -webkit-linear-gradient( -18deg,
  212. rgb(242, 148, 85) 0%,
  213. rgb(252, 124, 88) 51%,
  214. rgb(252, 124, 88) 99%);
  215. box-shadow: 0px 4px 0px 0px rgba(174, 34, 5, 0.7);
  216. width: 4.6875rem;
  217. height: 1.875rem;
  218. border-radius: 1.875rem;
  219. text-align: center;
  220. line-height: 1.875rem;
  221. color: #fff;
  222. }
  223. }
  224. }
  225. }
  226. .toast-mask {
  227. position: fixed;
  228. top: 0;
  229. left: 0;
  230. background: rgba(0, 0, 0, 0.6);
  231. z-index: 10000;
  232. width: 100%;
  233. height: 100%;
  234. }
  235. }
  236. </style>
  237. <template>
  238. <view class="container">
  239. <view class="lucky-wheel">
  240. <view class="lucky-title"></view>
  241. <view class="wheel-main">
  242. <view class="wheel-pointer-box">
  243. <view class="wheel-pointer" @click="rotate_handle()" :style="{transform:rotate_angle_pointer,transition:rotate_transition_pointer}"></view>
  244. </view>
  245. <view class="wheel-bg" :style="{transform:rotate_angle,transition:rotate_transition}">
  246. <view class="prize-list">
  247. <view class="prize-item" v-for="(item,index) in prize_list" :key="index">
  248. <view class="prize-pic">
  249. <img :src="item.icon">
  250. </view>
  251. <view class="prize-count" v-if="item.count">
  252. {{item.count}}
  253. </view>
  254. <view class="prize-type">
  255. {{item.name}}
  256. </view>
  257. </view>
  258. </view>
  259. </view>
  260. </view>
  261. </view>
  262. <view class="main">
  263. <view class="main-bg"></view>
  264. <view class="content">
  265. <view class="lottery_ticket">今日免费抽奖次数: {{ lottery_ticket}}</view>
  266. </view>
  267. <!-- <view class="tip">
  268. <view class="tip-title">活动规则</view>
  269. <view class="tip-content">
  270. <p> 1.每日签到后,即可获得一次幸运大转盘的机会,仅限当天有效,过期作废。 2.金币抽奖,每10个金豆可兑换一次大转盘机会。</p>
  271. <p> 2.金币抽奖,每10个金豆可以兑换一次大转盘抽奖机会</p>
  272. <p> 3.所中金豆或积分到【我的账户】中查询。累计达到100金豆及以上,可以兑换相应奖品</p>
  273. </view>
  274. </view> -->
  275. </view>
  276. <view class="toast" v-show="toast_control">
  277. <view class="toast-container">
  278. <img :src="toast_pictrue" class="toast-picture">
  279. <view class="close" @click="close_toast()"></view>
  280. <view class="toast-title">
  281. {{toast_title}}
  282. </view>
  283. <view class="toast-btn">
  284. <view class="toast-cancel" @click="close_toast">关闭</view>
  285. </view>
  286. </view>
  287. </view>
  288. <view class="toast-mask" v-show="toast_control"></view>
  289. </view>
  290. </template>
  291. <script>
  292. export default {
  293. data() {
  294. return {
  295. easejoy_bean: 0, //金豆
  296. lottery_ticket: 1, //抽奖次数
  297. prize_list: [
  298. {
  299. icon: require("../../static/bean_500.png"), // 奖品图片
  300. count: 10, // 奖品数量
  301. name: "金豆", // 奖品名称
  302. isPrize: 1 // 该奖项是否为奖品
  303. },
  304. {
  305. icon: require("../../static/bean_five.png"),
  306. count: 5,
  307. name: "金豆",
  308. isPrize: 1
  309. },
  310. {
  311. icon: require("../../static/give_up.png"),
  312. count: 0,
  313. name: "谢谢参与",
  314. isPrize: 0
  315. },
  316. {
  317. icon: require("../../static/point_five.png"),
  318. count: 5,
  319. name: "积分",
  320. isPrize: 1
  321. },
  322. {
  323. icon: require("../../static/bean_500.png"),
  324. count: 10,
  325. name: "金豆",
  326. isPrize: 1
  327. },
  328. {
  329. icon: require("../../static/point_ten.png"),
  330. count: 10,
  331. name: "积分",
  332. isPrize: 1
  333. },
  334. {
  335. icon: require("../../static/bean_500.png"),
  336. count: 10,
  337. name: "金豆",
  338. isPrize: 1
  339. },
  340. {
  341. icon: require("../../static/give_up.png"),
  342. count: 0,
  343. name: "谢谢参与",
  344. isPrize: 0
  345. }
  346. ], //奖品列表
  347. toast_control: false, //抽奖结果弹出框控制器
  348. hasPrize: false, //是否中奖
  349. start_rotating_degree: 0, //初始旋转角度
  350. rotate_angle: 0, //将要旋转的角度
  351. start_rotating_degree_pointer: 0, //指针初始旋转角度
  352. rotate_angle_pointer: 0, //指针将要旋转的度数
  353. rotate_transition: "transform 6s ease-in-out", //初始化选中的过度属性控制
  354. rotate_transition_pointer: "transform 12s ease-in-out", //初始化指针过度属性控制
  355. click_flag: true, //是否可以旋转抽奖
  356. index: 0
  357. }
  358. },
  359. created() {
  360. this.init_prize_list();
  361. },
  362. computed: {
  363. toast_title() {
  364. return this.hasPrize ? "恭喜您,获得" +this.prize_list[this.index].count + ' ' + this.prize_list[this.index].name : "未中奖";
  365. },
  366. toast_pictrue() {
  367. return this.hasPrize ? require("../../static/congratulation.png") : require("../../static/sorry.png");
  368. }
  369. },
  370. methods: {
  371. //此方法为处理奖品数据
  372. init_prize_list(list) {},
  373. rotate_handle() {
  374. this.index = 1 //指定每次旋转到的奖品下标
  375. this.rotating();
  376. },
  377. rotating() {
  378. if (!this.click_flag) return;
  379. var type = 0; // 默认为 0 转盘转动 1 箭头和转盘都转动(暂且遗留)
  380. var during_time = 5; // 默认为1s
  381. var random = Math.floor(Math.random() * 7);
  382. var result_index = this.index ; // 最终要旋转到哪一块,对应prize_list的下标
  383. var result_angle = [337.5, 292.5, 247.5, 202.5, 157.5, 112.5, 67.5, 22.5]; //最终会旋转到下标的位置所需要的度数
  384. var rand_circle = 6; // 附加多转几圈,2-3
  385. this.click_flag = false; // 旋转结束前,不允许再次触发
  386. if (type == 0) {
  387. // 转动盘子
  388. var rotate_angle = this.start_rotating_degree + rand_circle * 360 + result_angle[result_index] - this.start_rotating_degree % 360;
  389. this.start_rotating_degree = rotate_angle;
  390. this.rotate_angle = "rotate(" + rotate_angle + "deg)";
  391. // 转动指针
  392. // this.rotate_angle_pointer = "rotate("+this.start_rotating_degree_pointer + 360*rand_circle+"deg)";
  393. // this.start_rotating_degree_pointer =360*rand_circle;
  394. var that = this;
  395. // 旋转结束后,允许再次触发
  396. setTimeout(function() {
  397. that.click_flag = true;
  398. that.game_over();
  399. }, during_time * 1000 + 1500); // 延时,保证转盘转完
  400. } else {
  401. //
  402. }
  403. },
  404. game_over() {
  405. this.toast_control = true;
  406. this.hasPrize = this.prize_list[this.index].isPrize
  407. },
  408. //关闭弹窗
  409. close_toast() {
  410. this.toast_control = false;
  411. }
  412. }
  413. }
  414. </script>