zhuanpan.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title></title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
  7. <meta name="apple-mobile-web-app-capable" content="yes">
  8. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  9. <link rel="stylesheet" type="text/css" href="css/mui.min.css" />
  10. <link rel="stylesheet" type="text/css" href="css/style.css" />
  11. <style>
  12. .clear{clear:both;}
  13. /* 大转盘样式 */
  14. .drawbanner{display:block;width:95%;margin:0 auto;}
  15. .drawbanner .turnplate{display:block;width:100%;position:relative;}
  16. .drawbanner .turnplate canvas.item{width:100%;-webkit-transform: translateZ(0);transform: translateZ(0);}
  17. .drawbanner .turnplate img.pointer{ position: absolute;width: 25%;height: 30%;left: 37.5%;top: 33%;}
  18. .mui-popup.mui-popup-in{height:370px;background: urlimages/alert-bg2.png) center top /100% no-repeat;}
  19. .mui-popup-inner{background-color: transparent;margin-top:100px;padding: 15px 15px 5px 15px;position: static;}
  20. .mui-popup-title{color: #e23600;font-size: 13px;}
  21. .mui-popup-title+.mui-popup-text{margin-top: 10px;}
  22. .mui-popup-text img{width: 70px;}
  23. .mui-popup-text{font-size: 14px;color: #e23600;}
  24. .mui-popup-text strong{color: #fc5b8b;}
  25. .mui-popup-text span{color: #fc5b8b;font-size: 35px;}
  26. .mui-popup-button{background-color: transparent;}
  27. .mui-popup-button:after,.mui-popup-inner:after{display: none;}
  28. .mui-popup-button:first-child{ border-radius: 25px;
  29. height: 38px;
  30. line-height: 40px;
  31. font-weight: 100;
  32. color: #e23600;
  33. width: 50%;
  34. margin:10px auto 0 auto;}
  35. .mui-popup-button:last-child{border-radius:1px !important;background:url(images/btn-wheel-bg1.png) center center no-repeat ;background-size: 100%; height: 55px;line-height: 68px;font-weight: 100;color: #fff;width:40%;margin:0 auto;}
  36. .mui-popup-buttons{display: block;}
  37. .mui-popup.mui-popup-out{-webkit-transition-duration: 0ms;transition-duration: 0ms;}
  38. .mui-backdrop-action.mui-backdrop,.mui-popup-backdrop{
  39. background-color: rgba(0,0,0,.7);
  40. }
  41. #img-box{display:none;}
  42. .mui-popup.mui-popup-in {
  43. -webkit-transition-duration: 0ms;
  44. transition-duration: 0ms;
  45. }
  46. .mui-popup-buttons{height: 55px;}
  47. .mui-popup-text .x-close{width: 100px;
  48. height: 50px;
  49. bottom: 0;
  50. left: 83px;
  51. position: fixed;
  52. margin-top: 310px;}
  53. </style>
  54. </head>
  55. <body style="background: #000;">
  56. <div class="loading-bg">
  57. <div class="mui-loading">
  58. <div class="mui-spinner">
  59. </div>
  60. &nbsp;&nbsp;加载中...
  61. </div>
  62. </div>
  63. <div class="mui-content" style="background: #000;">
  64. <div style="padding:0">
  65. <img width="100%" src="images/wheel-body-bg.jpg" />
  66. <div style="position: absolute;top: 25%;left: 0;width: 100%;text-align: center;color: #f7630c;text-shadow: 1px 1px 1px #000;"><span id="gamecount">0</span>次免费抽 100%中奖</div>
  67. <div style="position: absolute;left: 0;top:28%;width: 100%;">
  68. <div class="drawbanner">
  69. <div class="turnplate" style="background-image:url(images/turnplate-bg1.png);background-size:100% 100%;background-repeat: no-repeat;background-position: center;">
  70. <canvas class="item" id="wheelcanvas" width="422px" height="422px"></canvas>
  71. <img class="pointer" src="images/turnplate-pointer1.png"/>
  72. </div>
  73. </div>
  74. <div style="position: relative;line-height: 0;">
  75. <div style="position: absolute;left:0;top:0;width: 50%;text-align: center;-webkit-transform: translateY(-25%);" class="go_prize_log" value="1">
  76. <img width="60%" src="images/btn-jilu1.png" />
  77. </div>
  78. <div style="position: absolute;right:0;top:0;width: 50%;text-align: center;-webkit-transform: translateY(-25%);">
  79. <a href="#guize-picture"><img width="60%" src="images/btn-guize1.png" /></a>
  80. </div>
  81. </div>
  82. </div>
  83. </div>
  84. <div id="img-box">
  85. <img src="images/alert-bg2.png" />
  86. </div>
  87. </div>
  88. <div id="guize-picture" class="mui-popover mui-popover-action mui-popover-bottom" style="top:0">
  89. <img style="margin-top:25%;margin-left: 5%;" width="90%" src="images/guize-bg1.png" />
  90. </div>
  91. <script src="js/mui.min.js"></script>
  92. <script src="js/jquery-2.1.1.min.js"></script>
  93. <script src="js/awardRotate.js"></script>
  94. <script src="js/main.js"></script>
  95. <script src="js/page/wechat-utils-1.0.js"></script>
  96. <script type="text/javascript">
  97. var turnplate={
  98. restaraunts:[], //大转盘奖品名称
  99. colors:[], //大转盘奖品区块对应背景颜色
  100. outsideRadius:156, //大转盘外圆的半径
  101. textRadius:130, //大转盘奖品位置距离圆心的距离
  102. insideRadius:35, //大转盘内圆的半径
  103. startAngle:0, //开始角度
  104. bRotate:false //false:停止;ture:旋转
  105. };
  106. var prizeList = null;
  107. var count=0,hide_dalog=true;
  108. $(document).ready(function(){
  109. window.repleFlag = false;
  110. window.wxFriend = {
  111. "appId": "",
  112. "imgUrl":'//s.iamberry.com/images/shop/8.png',
  113. "link":"https:" + domanUrl+"/iamberry/wechat/activity/go_luck_draw",
  114. "desc":"万圣节8秒冲奶,一键搞定捣蛋宝宝,快来围观爱贝源智能冲奶机,有大奖品抽哦!",//描述
  115. "title":"3次免费抽,100%中奖,宝宝手推车抱回家,快来转转转!", //标题
  116. "netError":"您的网络异常,请刷新重试!如多次刷新无效,请向我们反应 ~",
  117. "shareTimeSuccess":"分享成功", //这里是分享朋友圈后调用的文字
  118. "shareTimeCancel":"已取消分享", //这里是取消分享给朋友圈后调用的文字
  119. "shareAppSuccess":"分享成功", //这里是分享好友后调用的文字
  120. "shareAppCancel":"已取消分享" //这里是取消分享给好友后调用的文字
  121. };
  122. getConfig();
  123. getwheelcount();//加载抽奖次数
  124. //动态添加大转盘的奖品与奖品区域背景颜色
  125. $.ajax(base_path +'/game/get_prize_info',{
  126. data: {
  127. prizeGameId:2
  128. },
  129. dataType:'json',
  130. async:true,
  131. type:'post',
  132. timeout:15000,
  133. xhrFields: {
  134. withCredentials: true
  135. },
  136. crossDomain: true,
  137. success:function(dt){
  138. if (dt.isRedirect) {
  139. location.href = dt.redirectURL;
  140. } else {
  141. if (dt.status) {
  142. prizeList = dt.data;
  143. //console.log(prizeList);
  144. mui(prizeList).each(function(index){
  145. turnplate.restaraunts[index] = this.prizeName;
  146. if ((index + 1) % 2 == 0) {
  147. turnplate.colors[index] = "#694cb3";
  148. } else {
  149. turnplate.colors[index] = "#a282f5";
  150. }
  151. //先把图片加载出来
  152. $("#img-box").append('<img src="'+this.prizeImage+'" id="'+this.prizeId+'"/>');
  153. });
  154. //console.log(turnplate.restaraunts)
  155. //防止图片没加载完设置1秒后再绘制canvas
  156. setTimeout(function(){
  157. drawRouletteWheel();
  158. document.querySelector('.loading-bg').style.display = 'none';
  159. },1000);
  160. } else {
  161. alert("获取奖品信息失败!")
  162. }
  163. }
  164. },
  165. error:function(xhr,type,errorThrown){
  166. console.log(xhr)
  167. }
  168. });
  169. //旋转转盘 item:奖品位置; txt:提示语;
  170. var rotateFn = function (item, txt, to){
  171. var angles = item * (360 / turnplate.restaraunts.length) - (360 / (turnplate.restaraunts.length*2));
  172. if(angles<270){
  173. angles = 270 - angles;
  174. }else{
  175. angles = 360 - angles + 270;
  176. }
  177. //console.log(angles)
  178. $('#wheelcanvas').stopRotate();
  179. $('#wheelcanvas').rotate({
  180. angle:0,
  181. animateTo:(to == null ? (angles+1800) : to),
  182. duration:3000,
  183. callback:function (){
  184. turnplate.bRotate = !turnplate.bRotate;
  185. }
  186. });
  187. };
  188. // 奖品是否抽光
  189. var flag = true;
  190. $(".pointer").on("click",function(){
  191. wheel_ajax();
  192. });
  193. function wheel_ajax(){
  194. if (!flag) {
  195. // rotateFn(270, "");
  196. turnplate.bRotate = !turnplate.bRotate;//重置转盘
  197. //去产品列表
  198. var r=confirm("您没有抽奖次数了,是否马上前往购买商品?");
  199. if (r==true){
  200. mui.openWindow({
  201. url:'chanpin_details.html?productId=26' //chanpin_details.html
  202. });
  203. }
  204. return;
  205. }
  206. if(turnplate.bRotate)return;
  207. rotateFn(0 , "", 90000000)
  208. turnplate.bRotate = !turnplate.bRotate;//重置转盘
  209. //获取随机数(奖品个数范围内)
  210. //替换为后台代码
  211. $.ajax(base_path +'/game/luck_draw?gameId=2&orderId=',{
  212. data: {},
  213. dataType:'json',
  214. type:'get',
  215. timeout:15000,
  216. xhrFields: {
  217. withCredentials: true]
  218. },
  219. crossDomain: true,
  220. success:function(dt){
  221. if (dt.isRedirect) {
  222. location.href = dt.redirectURL;
  223. } else {
  224. //console.log(dt.data);
  225. var img,msg;
  226. if (dt.status) {
  227. var num;
  228. mui.each(prizeList, function(index) {
  229. if(this.prizeId==dt.data){
  230. msg=this.prizeName;
  231. img=this.prizeImage;
  232. num=index;
  233. }
  234. });
  235. //console.log("num:"+(num+1))
  236. rotateFn(num+1, "SUCCESS");//重置转盘
  237. count--;
  238. $("#gamecount").text(count);//点一次抽奖次数-1
  239. if(count>0){
  240. setTimeout(function(){
  241. mui.alert('<img src="'+img+'" /><span class="x-close"></span>','获得'+msg,'继续抽奖',function(){
  242. removeDalog();
  243. wheel_ajax();
  244. });
  245. },3000);
  246. }else{
  247. flag = false;
  248. setTimeout(function(){
  249. mui.alert('<img src="'+img+'" /><span class="x-close"></span>','获得'+msg,'马上下单',function(){
  250. mui.openWindow({
  251. url:'chanpin_details.html?productId=26' //chanpin_details.html
  252. });
  253. });
  254. },3000);
  255. }
  256. } else {
  257. flag = false;
  258. }
  259. }
  260. },
  261. error:function(xhr,type,errorThrown){
  262. console.log(xhr)
  263. }
  264. });
  265. }
  266. //剩余次数
  267. function getwheelcount(){
  268. $.ajax(base_path + '/game/selectHallowmasGameCount?dates=' + new Date().getTime(),{
  269. data: {
  270. gameId:2
  271. },
  272. dataType:'json',
  273. type:'post',
  274. timeout:15000,
  275. xhrFields: {
  276. withCredentials: true
  277. },
  278. crossDomain: true,
  279. success:function(dt){
  280. if (dt.isRedirect) {
  281. location.href = dt.redirectURL;
  282. } else {
  283. if (dt.status) {
  284. count=dt.data;
  285. $("#gamecount").text(dt.data);
  286. if(dt.data<=0){
  287. flag = false;
  288. }
  289. }
  290. }
  291. },
  292. error:function(xhr,type,errorThrown){
  293. console.log(xhr)
  294. }
  295. });
  296. }
  297. });
  298. //页面所有元素加载完毕后执行drawRouletteWheel()方法对转盘进行渲染
  299. window.onload=function(){
  300. //drawRouletteWheel();
  301. };
  302. function drawRouletteWheel() {
  303. var canvas = dc("wheelcanvas");
  304. if (canvas.getContext) {
  305. //根据奖品个数计算圆周角度
  306. var arc = Math.PI / (turnplate.restaraunts.length/2);
  307. var ctx = canvas.getContext("2d");
  308. //在给定矩形内清空一个矩形
  309. ctx.clearRect(0,0,422,422);
  310. //strokeStyle 属性设置或返回用于笔触的颜色、渐变或模式
  311. ctx.strokeStyle = "rgba(0,0,0,0)";//边框颜色
  312. //font 属性设置或返回画布上文本内容的当前字体属性
  313. ctx.font = '15px Arial';
  314. for(var i = 0; i < turnplate.restaraunts.length; i++) {
  315. //添加对应图标
  316. if (prizeList != null) {
  317. var angle = turnplate.startAngle + i * arc;
  318. ctx.fillStyle = turnplate.colors[i];
  319. ctx.beginPath();
  320. //arc(x,y,r,起始角,结束角,绘制方向) 方法创建弧/曲线(用于创建圆或部分圆)
  321. ctx.arc(211, 211, turnplate.outsideRadius, angle, angle + arc, false);
  322. ctx.arc(211, 211, turnplate.insideRadius, angle + arc, angle, true);
  323. ctx.stroke();
  324. ctx.fill();
  325. //锁画布(为了保存之前的画布状态)
  326. ctx.save();
  327. //----绘制奖品开始----
  328. ctx.fillStyle = "#fff";
  329. var text = turnplate.restaraunts[i];
  330. var line_height = 17;
  331. //translate方法重新映射画布上的 (0,0) 位置
  332. ctx.translate(211 + Math.cos(angle + arc / 2) * turnplate.textRadius, 211 + Math.sin(angle + arc / 2) * turnplate.textRadius);
  333. //rotate方法旋转当前的绘图
  334. ctx.rotate(angle + arc / 2 + Math.PI / 2);
  335. /** 下面代码根据奖品类型、奖品名称长度渲染不同效果,如字体、颜色、图片效果。(具体根据实际情况改变) **/
  336. //在画布上绘制填色的文本。文本的默认颜色是黑色
  337. //measureText()方法返回包含一个对象,该对象包含以像素计的指定字体宽度
  338. ctx.fillText(text, -ctx.measureText(text).width / 2, 0);
  339. var img= dc(prizeList[i].prizeId);
  340. ctx.drawImage(img,-25,10);
  341. //把当前画布返回(调整)到上一个save()状态之前
  342. }
  343. //----绘制奖品结束----
  344. ctx.restore();
  345. }
  346. }
  347. }
  348. var mask = mui.createMask(function() {
  349. }); //callback为用户点击蒙版时自动执行的回调;
  350. mui('body').on('tap', '#guize-picture,#share-picture', function(e) {
  351. mui(this).popover('toggle');
  352. });
  353. mui('body').on('tap', '.x-close', function(e) {
  354. //console.log("关闭");
  355. hide_dalog=false;
  356. removeDalog();
  357. });
  358. function removeDalog(){
  359. var dalog=$('.mui-popup');
  360. dalog.remove();
  361. $(".mui-popup-backdrop").removeClass("mui-active");
  362. }
  363. </script>
  364. </body>
  365. </html>