turnplate.jsp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <%@ include file="../meta.jsp"%>
  4. <title>大转盘</title>
  5. <style>
  6. /* 大转盘样式 */
  7. .banner {
  8. display: block;
  9. width: 90%;
  10. margin-left: auto;
  11. margin-right: auto;
  12. margin-bottom: 20px;
  13. }
  14. .banner .panel{
  15. display: block;
  16. width:100%;
  17. position: absolute;
  18. z-index: -1;
  19. }
  20. .banner .turnplate {
  21. display: block;
  22. width: 100%;
  23. position: relative;
  24. }
  25. .banner .turnplate img.pointer {
  26. position: absolute;
  27. width: 31.5%;
  28. height: 42.5%;
  29. left: 34.6%;
  30. top: 26%;
  31. }
  32. .prize_chance_bg {
  33. position: relative;
  34. text-align: center;
  35. }
  36. .prize-chance {
  37. color: #fff;
  38. background: #bf3737;
  39. }
  40. .prize_chance_bg span {
  41. font-size: 16px;
  42. font-family: 'Microsoft YaHei';
  43. word-wrap: break-word;
  44. color: #fff;
  45. text-align: center;
  46. line-height: 18px;
  47. min-width: 134px;
  48. height: 18px;
  49. border-radius: 40px;
  50. padding: 1px 26px;
  51. }
  52. em {
  53. font-style: normal;
  54. font-weight: 400;
  55. }
  56. .prize-content {
  57. box-sizing: border-box;
  58. padding: 15px;
  59. height: auto;
  60. overflow: hidden;
  61. color: #fff;
  62. border-color: #fff;
  63. }
  64. .prize-content p{
  65. color: #fff;
  66. }
  67. .prize-content .prize-wrapper {
  68. margin-top: 20px;
  69. }
  70. .prize-title {
  71. position: relative;
  72. height: 18px;;
  73. font-size: 16px;
  74. text-align: center;
  75. line-height: 18px;
  76. }
  77. .prize-title .prize-divider {
  78. width: 38%;
  79. height: 1px;
  80. border-top: 1px #fff solid;
  81. display: inline-block;
  82. position: absolute;
  83. bottom: 0;
  84. top: 0;
  85. margin: auto;
  86. }
  87. .prize-title .title-text {
  88. font-weight: bolder;
  89. position: absolute;
  90. top: 0;
  91. left: 0;
  92. bottom: 0;
  93. right: 0;
  94. margin: auto;
  95. text-align: center;
  96. }
  97. .prize-content .prize-wrapper .tab-wrapper {
  98. margin-top: 15px;
  99. height: 30px;
  100. line-height: 30px;
  101. text-align: center;
  102. font-size: 14px;
  103. border: 1px #fff solid;
  104. border-radius: 2px;
  105. }
  106. .prize-content .prize-wrapper .tab-wrapper .tab.selected {
  107. color: #eb4a4a;
  108. background: #ffffff;
  109. }
  110. .prize-content .prize-wrapper .tab-wrapper .tab {
  111. transition: background 1s;
  112. -webkit-transition: background 1s;
  113. border-radius: 1px;
  114. float: left;
  115. width: 50%;
  116. height: 100%;
  117. display: inline-block;
  118. vertical-align: middle;
  119. text-align: center;
  120. background: transparent;
  121. }
  122. .prize-content .prize-wrapper .prize-info {
  123. width: 100%;
  124. margin-top: 10px;
  125. font-size: 14px;
  126. }
  127. .prize-content .rule-wrapper {
  128. margin-top: 35px;
  129. }
  130. .prize-content .rule-wrapper .rule-title {
  131. margin-bottom: 12px;
  132. }
  133. .prize-content .rule-wrapper .rule-line {
  134. clear: both;
  135. margin-bottom: 10px;
  136. font-size: 12px;
  137. }
  138. .prize-content .rule-wrapper .rule-line>span {
  139. margin-bottom: 10px;
  140. margin-right: 9px;
  141. float: left;
  142. }
  143. .rule-prizes{
  144. overflow: hidden;
  145. }
  146. .rule-content {
  147. overflow: hidden;
  148. }
  149. .mui-popup-inner{
  150. background: #eb4a4a;
  151. color: #fff;
  152. }
  153. .mui-popup-button{
  154. background: #e23d3d;
  155. color: #fff;
  156. }
  157. </style>
  158. <body style="background: #eb4a4a; overflow-x: hidden;">
  159. <!-- 代码 开始 -->
  160. <img src="${base}/static/mobile/image/act/1.png" id="shan-img" style="display: none;">
  161. <img src="${base}/static/mobile/image/act/2.png" id="sorry-img" style="display: none;">
  162. <img id="actImg" style="width: 100%">
  163. <div class="banner">
  164. <div class="turnplate">
  165. <img class="panel" src="${base}/static/mobile/image/act/panel3.png">
  166. <canvas id="wheelcanvas" width="422px" height="422px" style="width:100%"></canvas>
  167. <img class="pointer" src="${base}/static/mobile/image/act/btn_attend2.png">
  168. </div>
  169. </div>
  170. <div id="prize_chance_bg" class="prize_chance_bg">
  171. <span class="prize-chance">您还有 <em id="chance"
  172. class="color-yellow">0</em> 次机会
  173. </span>
  174. </div>
  175. <div class="prize-content">
  176. <div class="prize-wrapper">
  177. <div class="prize-title">
  178. <div class="prize-divider" style="left: 0"></div>
  179. <div class="title-text">奖品列表</div>
  180. <div class="prize-divider" style="right: 0"></div>
  181. </div>
  182. <div class="tab-wrapper">
  183. <div class="tab selected">我的奖品</div>
  184. <div class="tab">最新中奖</div>
  185. </div>
  186. <div id="my-prizeList-info">
  187. </div>
  188. <div id="new-prizeList-info" style="display:none">
  189. </div>
  190. <a href="${base}/mobile/userCenter.jsp" class="mui-btn mui-btn-warning mui-btn-block mt10">查看我的奖品</a>
  191. </div>
  192. <div class="rule-wrapper">
  193. <div class="prize-title rule-title">
  194. <div class="prize-divider" style="left: 0"></div>
  195. <div class="title-text">活动规则</div>
  196. <div class="prize-divider" style="right: 0"></div>
  197. </div>
  198. <div class="rule-line">
  199. <span>活动时间:</span>
  200. <p class="rule-date" id="rule-date">2018-05-15 至 2018-07-31</p>
  201. </div>
  202. <div class="rule-line rule-activity-prize">
  203. <span>活动奖品:</span>
  204. <p class="rule-prizes" id="rule-prizes"></p>
  205. </div>
  206. <div class="rule-line">
  207. <span class="">活动规则:</span>
  208. <div id="rule-content" class="clear-float rule-content">三水网大转盘活动</div>
  209. </div>
  210. </div>
  211. </div>
  212. <!-- 代码 结束 -->
  213. </body>
  214. <script src="${base}/static/mobile/js/act/turntable.js?v=${version}"></script>
  215. <script type="text/javascript">
  216. var turnplate={
  217. prize:[], //大转盘奖品名称
  218. colors:["#fff6c9", "#ffd919", "#fff6c9", "#ffd919","#fff6c9", "#ffd919"], //大转盘奖品区块对应背景颜色
  219. outsideRadius:195, //大转盘外圆的半径
  220. textRadius:155, //大转盘奖品位置距离圆心的距离
  221. insideRadius:56, //大转盘内圆的半径
  222. startAngle:0, //开始角度
  223. bRotate:false //false:停止;ture:旋转
  224. };
  225. var actId=mobile.getUrlVars("id");
  226. var act;
  227. $(document).ready(function(){
  228. if(!actId){
  229. layer.open({content:'参数错误',time:3});
  230. return;
  231. }
  232. getActInfo();
  233. $('.tab-wrapper').on('tap','.tab',function(){
  234. if($(this).hasClass("selected")){
  235. return;
  236. }
  237. $(this).addClass("selected");
  238. $(this).siblings().removeClass("selected");
  239. if($(this).index()==0){
  240. $("#my-prizeList-info").show();
  241. $("#new-prizeList-info").hide();
  242. }else{
  243. $("#my-prizeList-info").hide();
  244. $("#new-prizeList-info").show();
  245. }
  246. });
  247. //旋转转盘 item:奖品位置; txt:提示语;
  248. var rotateFn = function (item, txt){
  249. $('#wheelcanvas').stopRotate();
  250. $('#wheelcanvas').rotate({
  251. angle:0,
  252. animateTo:1800+360-(item-1) * 60,
  253. duration:8000,
  254. callback:function (){
  255. if(item!=6){
  256. var prize = getPrize(item);
  257. var remark;
  258. if(prize.prize_type=="10"){
  259. remark="奖品已经入账,请在平台“我的抢购”中查看";
  260. }else{
  261. remark="奖品已经入账,请在平台“我的卡券”中查看";
  262. }
  263. mui.alert("<br><div class='fs16 bold'>"+txt+"</div><div class='color-yellow'>"+remark+"</div>", "恭喜中奖");
  264. }else{
  265. layer.open({content:"未中奖 再接再厉",time:3});
  266. }
  267. turnplate.bRotate = !turnplate.bRotate;
  268. refresh();
  269. }
  270. });
  271. };
  272. //抽奖
  273. $('.pointer').click(function (){
  274. if(act.chance<1){
  275. mui.alert('您已经没有抽奖机会,每天分享还可以再获得一次抽奖机会', '提示信息');
  276. return;
  277. }
  278. if(turnplate.bRotate)return;
  279. turnplate.bRotate = !turnplate.bRotate;
  280. mobile.ajaxPost(base+'/actInfo/luck',{actId: actId},function(json){
  281. if(json.success){
  282. rotateFn(json.data, turnplate.prize[json.data-1]);
  283. }else{
  284. if(json.msg=="subscribe"){
  285. var html=[];
  286. html.push('<img src="'+imgUrl+act.subscribe_img+'" style="width:100%">');
  287. html.push('<div>请先关注我们,大奖等着你拿。</div>');
  288. mui.alert(html.join(""), "提示信息");
  289. }else{
  290. layer.open({content:json.msg,time:3});
  291. }
  292. turnplate.bRotate = !turnplate.bRotate;
  293. }
  294. });
  295. });
  296. });
  297. function getActInfo(){
  298. mobile.ajaxPost(base+'/actInfo/getById',{id: actId},function(json){
  299. if(json.success){
  300. act = json.data;
  301. $("#actImg").attr("src",imgUrl+act.act_img);
  302. share.title=act.share_title;
  303. share.link=location.href;
  304. share.imgUrl=imgUrl+act.share_img;
  305. share.desc=act.share_content;
  306. share.callback=function(type){
  307. if(type=="1"){
  308. mobile.ajaxPost(base+'/actInfo/share',{actId: actId},function(json){
  309. refresh();
  310. });
  311. }else{
  312. layer.open({content:"分享朋友圈才可以获得抽奖机会",time:3});
  313. }
  314. }
  315. $(document).attr("title",act.act_name);
  316. $("#chance").html(act.chance);
  317. $.each(act.prize,function(id,item){
  318. turnplate.prize.push(mobile.getDictVal("prize_no",item.prize_no)+item.prize_name);
  319. $("#rule-prizes").append(mobile.getDictVal("prize_no",item.prize_no)+":"+item.prize_name+""+
  320. "。奖品数量:"+item.prize_num+"<br>");
  321. });
  322. turnplate.prize.push("谢谢参与");
  323. drawRouletteWheel();
  324. var my_prize=[];
  325. if(act.myPrize&&act.myPrize.length>0){
  326. $.each(act.myPrize,function(id,item){
  327. my_prize.push('<div class="prize-info items"><span class="item">您抽中了'+mobile.getDictVal("prize_no",item.prize_no)+''+
  328. ''+item.prize_name+'</span><span>'+new Date(item.create_time.replace(/-/g, "/")).format("MM-dd hh:mm")+'</span></div>');
  329. });
  330. }else{
  331. my_prize.push('<div class="prize-info">暂无中奖纪录</div>');
  332. }
  333. $("#my-prizeList-info").html(my_prize.join(""));
  334. var new_prize=[];
  335. if(act.newPrize&&act.newPrize.length>0){
  336. $.each(act.newPrize,function(id,item){
  337. new_prize.push('<div class="prize-info items"><span class="item">'+item.nickname+'抽中了'+mobile.getDictVal("prize_no",item.prize_no)+''+
  338. ''+item.prize_name+'</span><span>'+new Date(item.create_time.replace(/-/g, "/")).format("MM-dd hh:mm")+'</span></div>');
  339. });
  340. }else{
  341. new_prize.push('<div class="prize-info">暂无中奖纪录</div>');
  342. }
  343. $("#new-prizeList-info").html(new_prize.join(""));
  344. $("#rule-date").html(act.start_date+"至"+act.end_date);
  345. $("#rule-content").html(act.act_desc);
  346. }
  347. });
  348. }
  349. function refresh(){
  350. mobile.ajaxPost(base+'/actInfo/refresh',{actId: actId},function(json){
  351. if(json.success){
  352. act.chance = json.data.chance;
  353. $("#chance").html(json.data.chance);
  354. var my_prize=[];
  355. if(json.data.myPrize&&act.myPrize.length>0){
  356. $.each(json.data.myPrize,function(id,item){
  357. my_prize.push('<div class="prize-info items"><span class="item">您抽中了'+mobile.getDictVal("prize_no",item.prize_no)+''+
  358. ''+item.prize_name+'</span><span>'+new Date(item.create_time.replace(/-/g, "/")).format("MM-dd hh:mm")+'</span></div>');
  359. });
  360. }else{
  361. my_prize.push('<div class="prize-info">暂无中奖纪录</div>');
  362. }
  363. $("#my-prizeList-info").html(my_prize.join(""));
  364. var new_prize=[];
  365. if(json.data.newPrize&&act.newPrize.length>0){
  366. $.each(json.data.newPrize,function(id,item){
  367. new_prize.push('<div class="prize-info items"><span class="item">'+item.nickname+'抽中了'+mobile.getDictVal("prize_no",item.prize_no)+''+
  368. ''+item.prize_name+'</span><span>'+new Date(item.create_time.replace(/-/g, "/")).format("MM-dd hh:mm")+'</span></div>');
  369. });
  370. }else{
  371. new_prize.push('<div class="prize-info">暂无中奖纪录</div>');
  372. }
  373. $("#new-prizeList-info").html(new_prize.join(""));
  374. }
  375. });
  376. }
  377. function getPrize(prizeNo){
  378. var prize;
  379. $.each(act.prize,function(id,item){
  380. if(item.prize_no==prizeNo){
  381. prize = item;
  382. }
  383. });
  384. return prize;
  385. }
  386. function drawRouletteWheel() {
  387. var canvas = document.getElementById("wheelcanvas");
  388. if (canvas.getContext) {
  389. //根据奖品个数计算圆周角度
  390. var arc = Math.PI / (turnplate.prize.length/2);
  391. var ctx = canvas.getContext("2d");
  392. //在给定矩形内清空一个矩形
  393. ctx.clearRect(0,0,422,422);
  394. //strokeStyle 属性设置或返回用于笔触的颜色、渐变或模式
  395. ctx.strokeStyle = "#ffd919";
  396. //font 属性设置或返回画布上文本内容的当前字体属性
  397. ctx.font = '18px Microsoft YaHei';
  398. for(var i = 0; i < turnplate.prize.length; i++) {
  399. var angle = turnplate.startAngle + (i+4) * arc;
  400. ctx.fillStyle = turnplate.colors[i];
  401. ctx.beginPath();
  402. //arc(x,y,r,起始角,结束角,绘制方向) 方法创建弧/曲线(用于创建圆或部分圆)
  403. ctx.arc(211, 211, turnplate.outsideRadius, angle, angle + arc, false);
  404. ctx.arc(211, 211, turnplate.insideRadius, angle + arc, angle, true);
  405. ctx.stroke();
  406. ctx.fill();
  407. //锁画布(为了保存之前的画布状态)
  408. ctx.save();
  409. //----绘制奖品开始----
  410. ctx.fillStyle = "#702428";
  411. var text = turnplate.prize[i];
  412. var line_height = 26;
  413. //translate方法重新映射画布上的 (0,0) 位置
  414. ctx.translate(211 + Math.cos(angle + arc / 2) * turnplate.textRadius, 211 + Math.sin(angle + arc / 2) * turnplate.textRadius);
  415. //rotate方法旋转当前的绘图
  416. ctx.rotate(angle + arc / 2 + Math.PI / 2);
  417. /** 下面代码根据奖品类型、奖品名称长度渲染不同效果,如字体、颜色、图片效果。(具体根据实际情况改变) **/
  418. if(text.indexOf("奖")>0){//流量包
  419. var texts = text.split("奖");
  420. for(var j = 0; j<texts.length; j++){
  421. ctx.font = j == 0?'bold 20px Microsoft YaHei':'16px Microsoft YaHei';
  422. if(j == 0){
  423. ctx.fillText(texts[j]+"奖", -ctx.measureText(texts[j]+"奖").width / 2, j * line_height);
  424. }else{
  425. if (texts[j].length>6){
  426. ctx.fillText(texts[j].substring(0,6), -ctx.measureText(texts[j].substring(0,6)).width / 2, j * line_height);
  427. ctx.fillText(texts[j].substring(6), -ctx.measureText(texts[j].substring(6)).width / 2, (j+1) * line_height);
  428. }else{
  429. ctx.fillText(texts[j], -ctx.measureText(texts[j]).width / 2, j * line_height);
  430. }
  431. }
  432. }
  433. }else if(text.indexOf("奖") == -1 && text.length>6){//奖品名称长度超过一定范围
  434. text = text.substring(0,6)+"||"+text.substring(6);
  435. var texts = text.split("||");
  436. for(var j = 0; j<texts.length; j++){
  437. ctx.fillText(texts[j], -ctx.measureText(texts[j]).width / 2, j * line_height);
  438. }
  439. }else{
  440. //在画布上绘制填色的文本。文本的默认颜色是黑色
  441. //measureText()方法返回包含一个对象,该对象包含以像素计的指定字体宽度
  442. ctx.fillText(text, -ctx.measureText(text).width / 2, 0);
  443. }
  444. //添加对应图标
  445. if(text.indexOf("闪币")>0){
  446. var img= document.getElementById("shan-img");
  447. img.onload=function(){
  448. ctx.drawImage(img,-15,10);
  449. };
  450. ctx.drawImage(img,-15,10);
  451. }else if(text.indexOf("谢谢参与")>=0){
  452. var img= document.getElementById("sorry-img");
  453. img.onload=function(){
  454. ctx.drawImage(img,-15,10);
  455. };
  456. ctx.drawImage(img,-15,10);
  457. }
  458. //把当前画布返回(调整)到上一个save()状态之前
  459. ctx.restore();
  460. //----绘制奖品结束----
  461. }
  462. }
  463. }
  464. </script>
  465. </html>