No Description

index.js 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. var click=false,flagClick = true;
  2. var luck={
  3. index:-1, //当前转动到哪个位置,起点位置
  4. count:0, //总共有多少个位置
  5. timer:0, //setTimeout的ID,用clearTimeout清除
  6. speed:20, //初始转动速度
  7. times:0, //转动次数
  8. cycle:40, //转动基本次数:即至少需要转动多少次再进入抽奖环节
  9. prize:-1, //中奖位置
  10. init:function(id){
  11. if ($("#"+id).find(".luck-unit").length>0) {
  12. $luck = $("#"+id);
  13. $units = $luck.find(".luck-unit");
  14. this.obj = $luck;
  15. this.count = $units.length;
  16. $luck.find(".luck-unit-"+this.index).addClass("liActive");
  17. };
  18. },
  19. roll:function(){
  20. var index = this.index;
  21. var count = this.count;
  22. var luck = this.obj;
  23. $(luck).find(".luck-unit-"+index).removeClass("liActive");
  24. index += 1;
  25. if (index>count-1) {
  26. index = 0;//当index == 7 时置 0
  27. };
  28. $(luck).find(".luck-unit-"+index).addClass("liActive");
  29. this.index=index;
  30. return false;
  31. },
  32. stop:function(index){
  33. this.prize=index;
  34. return false;
  35. }
  36. };
  37. var scrollTop,scrollTop02,times;//times 抽奖次数
  38. var token = null,level;
  39. var prize_content = null;//目前淘口令
  40. var prizeName = null;//所中奖项的name
  41. var prizeList;//我的奖品列表
  42. $().ready(function () {
  43. shandeng();//闪灯
  44. new scrollTxt().init();
  45. getTkl();//淘口令红包领取
  46. getToken();//获取token
  47. $(window).scroll(function(){
  48. scrollTop = $(this).scrollTop(); //scrollTop() 方法返回或设置匹配元素的滚动条的垂直位置
  49. })
  50. $('.goChongjiang').click(function () {
  51. if(!token){
  52. getToken();
  53. return;
  54. }
  55. if($(this).attr('status') == 1){
  56. //我的列表页
  57. window.location.href='prizeList.html?token=' + token;
  58. closeTankuang();//关闭其他弹窗
  59. return;
  60. }
  61. if($(this).attr('class').indexOf('deq_jjixuchoujiang') != -1){
  62. //去大额券列表页
  63. window.location.href = 'goods/goodsList.html?token=' + token +'&category_id=3786&name=品牌券';
  64. closeTankuang();//关闭其他弹窗
  65. }else if($(this).attr('class').indexOf('dd_dingdantianxie') != -1){
  66. //去填单号
  67. $('.tanchuang').show();
  68. $('.tanchuang').find('.content_danhao').show();
  69. $('body').css({'position':'fixed',"top":-scrollTop});
  70. scrollTop02 = scrollTop;
  71. }else{
  72. $(window).scrollTop(0)
  73. }
  74. })
  75. $("#close").click(function () {
  76. closeTankuang();//关闭其他弹窗
  77. })
  78. $("#tijiaodingdan").click(function () {
  79. writeOrderId();//提交订单
  80. })
  81. })
  82. //获取token
  83. function getToken () {
  84. var param = '{"js_callback" : "callBackMethodName"}';
  85. try{
  86. if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){
  87. window.webkit.messageHandlers.app_h5_login.postMessage(param);
  88. }
  89. if(navigator.userAgent.match(/android/i)){
  90. obj4H5.app_h5_login(param);
  91. }
  92. }catch(e){
  93. //TODO handle the exception
  94. // showMsg("请更新app")
  95. // token = '5cdfb93b9df9e610634f5f338d798dd9182';
  96. // luckyDrawIndex();//抽奖首页
  97. }
  98. }
  99. function callBackMethodName (data) {//app token 回调
  100. var data = JSON.parse(data)
  101. token = data.token;
  102. luckyDrawIndex();//抽奖首页
  103. }
  104. //抽奖进行中
  105. function roll(){
  106. luck.times += 1;
  107. luck.roll();
  108. if (luck.times > luck.cycle+10 && luck.prize==luck.index) {
  109. //当中奖编号等于转动到的位置时 停止转动
  110. //中奖商品效果
  111. var yes = ".luck-unit-" + luck.prize;
  112. $(yes).find('img').addClass('zhongActive');
  113. setTimeout(function(){ //200ms后执行抽中的办法 纯属为了好看
  114. $(".luck-unit img").removeClass("zhongActive");
  115. luckyDraw();//剩余抽奖次数接口
  116. successZhongjiang(luck.prize);
  117. },600);
  118. }else{
  119. //luck.times 转动的次数 luck.cycle 转动基本次数:即至少需要转动多少次再进入抽奖环节
  120. if (luck.times<luck.cycle) {
  121. luck.speed -= 10;
  122. }else if(luck.times==luck.cycle) {
  123. //选定选中的奖品
  124. // var index = Math.random()*(luck.count)|0;
  125. // luck.prize = index;
  126. }else{
  127. if (luck.times > luck.cycle+10 && ((luck.prize==0 && luck.index==7) || luck.prize==luck.index+1)) {
  128. //当转动的次数大于基本次数加十 并且 (中奖编号为0且传动到的位置为7) 或者 中奖编号等于传动到的位置加1 时速度骤加110-------------即停止转动????????????
  129. luck.speed += 110;
  130. }else{
  131. luck.speed += 20;
  132. }
  133. }
  134. if (luck.speed<40) {
  135. //传懂速度最低为40
  136. luck.speed=40;
  137. };
  138. luck.timer = setTimeout(roll,luck.speed);
  139. }
  140. return false;
  141. }
  142. //中奖时的操作
  143. function successZhongjiang (num) {
  144. //弹窗
  145. closeTankuang();//关闭其他弹窗
  146. if(num == 1){//超级红包 幸运红包
  147. $('.tanchuang').show();
  148. $('.tanchuang').find('.content_tkl').show();
  149. // $('.content_tkl .price').html('2.0元')
  150. $('body').css({'position':'fixed',"top":-scrollTop});
  151. scrollTop02 = scrollTop;
  152. }
  153. if(num == 3){//超级红包 幸运红包
  154. $('.tanchuang').show();
  155. $('.tanchuang').find('.content_tkl').show();
  156. // $('.content_tkl .price').html('100元')
  157. $('body').css({'position':'fixed',"top":-scrollTop});
  158. scrollTop02 = scrollTop;
  159. }
  160. if(num == 6){//很遗憾
  161. $('.tanchuang').show();
  162. $('.tanchuang').find('.content_fail').show();
  163. $('body').css({'position':'fixed',"top":-scrollTop});
  164. scrollTop02 = scrollTop;
  165. }
  166. if(num == 7){//100大额优惠券
  167. $('.tanchuang').show();
  168. $('.tanchuang').find('.content_yhq').show();
  169. $('body').css({'position':'fixed',"top":-scrollTop});
  170. scrollTop02 = scrollTop;
  171. }
  172. clearTimeout(luck.timer);
  173. luck.prize=-1;//中奖编号
  174. luck.times=0;//转动的次数清零
  175. click=false;
  176. }
  177. function goChoujiang () {
  178. //点击抽奖按钮 判断有没有token
  179. if(!token){
  180. getToken();
  181. return;
  182. }
  183. //关闭所有弹框 兼容 上次没有抽中 再来一次
  184. $('.tanchuang').hide();
  185. $('.tanchuang').children().hide();
  186. $("body").css({"position":"initial"});//页面开启滚动
  187. if(!times){
  188. //没有抽奖次数为0了
  189. luckyDrawIndex();//首页接口刷新
  190. showMsg('抽奖机会不足,明日再来吧~');
  191. return;
  192. }
  193. if(click) {
  194. return false;
  195. }else{
  196. // 按下弹起效果
  197. $(".btn").addClass("cjBtnDom");
  198. setTimeout(function(){
  199. $(".btn").removeClass("cjBtnDom");
  200. },600);
  201. luck.speed=120;
  202. roll();
  203. click=true;
  204. if(!flagClick){//第一次点击不加载接口
  205. luckyDrawIndex();
  206. }
  207. return false;
  208. }
  209. }
  210. function shandeng () {
  211. //闪灯效果
  212. var num = 0;
  213. $("#deng").attr("class",function(){
  214. setInterval(function(){
  215. num++;
  216. if(num%2==0){
  217. $('#deng').removeClass('choujiang_deng_two');
  218. $('#deng').addClass("choujiang_deng");
  219. }else{
  220. $('#deng').removeClass('choujiang_deng');
  221. $('#deng').addClass("choujiang_deng_two");
  222. }
  223. },500)
  224. })
  225. }
  226. //scroll滚动
  227. function scrollTxt(){
  228. var controls={},
  229. values={},
  230. t1=800, /*播放动画的时间*/
  231. t2=1500, /*播放时间间隔*/
  232. si;
  233. controls.rollWrap=$("#roll-wrap");
  234. controls.rollWrapUl=controls.rollWrap.children();
  235. controls.rollWrapLIs=controls.rollWrapUl.children();
  236. values.liNums=controls.rollWrapLIs.length;
  237. values.liHeight=controls.rollWrapLIs.eq(0).height();
  238. values.ulHeight=controls.rollWrap.height();
  239. this.init=function(){
  240. autoPlay();
  241. }
  242. /*滚动*/
  243. function play(){
  244. controls.rollWrapUl.animate({"margin-top" : "-"+values.liHeight}, t1, 'linear',function(){
  245. $(this).css("margin-top" , "0").children().eq(0).appendTo($(this));
  246. });
  247. }
  248. /*自动滚动*/
  249. function autoPlay(){
  250. /*如果所有li标签的高度和大于.roll-wrap的高度则滚动*/
  251. if(values.liHeight*values.liNums > values.ulHeight){
  252. si=setInterval(function(){
  253. play();
  254. },t2);
  255. }
  256. }
  257. }
  258. //淘口令红包领取
  259. function getTkl () {
  260. $(".content_tkl button").click(function () {
  261. if($(".content_tkl button").attr('data-status') == 1){
  262. //点击领取
  263. copyPassword();//复制淘口令
  264. }else{
  265. //我知道了
  266. luckyDrawIndex();//首页接口
  267. $(".content_tkl .gongxi").css('display','block');
  268. $(".content_tkl .gongxi_tkl").css('display','none');
  269. $(".content_tkl button").attr('data-status','1').html('立即领取');
  270. $('.tanchuang').hide();
  271. $('.tanchuang').children().hide();
  272. $("body").css({"position":"initial"});//页面开启滚动
  273. $(window).scrollTop(scrollTop02);
  274. }
  275. })
  276. }
  277. //打开规则弹窗
  278. function goGuize () {
  279. $('.tanchuang').show();
  280. $('.tanchuang').find('.content_gz').show();
  281. $('body').css({'position':'fixed',"top":-scrollTop});
  282. scrollTop02 = scrollTop;
  283. }
  284. //关闭弹框
  285. function closeTankuang () {
  286. $('.tanchuang').hide();
  287. $('.tanchuang').children().hide();
  288. $("body").css({"position":"initial"});//页面开启滚动
  289. $(window).scrollTop(scrollTop02);
  290. }
  291. //关闭弹框02
  292. function closeTankuang_02 () {
  293. $('.tanchuang').hide();
  294. $('.tanchuang').children().hide();
  295. $("body").css({"position":"initial"});//页面开启滚动
  296. $(window).scrollTop(scrollTop02);
  297. luckyDrawIndex();//首页接口刷新
  298. }
  299. //打开我的奖品弹框
  300. function goMyjiangpin () {
  301. window.location.href='prizeList.html?token=' + token;
  302. closeTankuang();//关闭其他弹窗
  303. // userPrizeList();//奖品列表
  304. // $('.tanchuang').show();
  305. // $('.tanchuang').find('.content_my_jiangpin').show();
  306. // $('body').css({'position':'fixed',"top":-scrollTop});
  307. // scrollTop02 = scrollTop;
  308. }
  309. //抽奖首页接口
  310. function luckyDrawIndex () {
  311. $.ajax({
  312. type:"post",
  313. url:"/api/v2/luckyDraw/luckyDrawIndex",
  314. dataType:'json',
  315. headers:{
  316. token:token,
  317. },
  318. success:function (res) {
  319. // console.log(res)
  320. if(res && res.errno == 0){
  321. flagClick = false;
  322. $("#times_cishu span").text(res.rst.times);//剩余抽奖次数
  323. times = res.rst.times;
  324. level = res.rst.level;//level中奖等级
  325. var step = res.rst.step;//用户的步骤
  326. if(res.rst.prize_content != ''){
  327. prize_content = res.rst.prize_content;//中奖奖品内容 ------- 淘口令
  328. }
  329. prizeName = res.rst.prize_name;//所中奖项的名称
  330. if(step == 1 && times == 0 || step == 2 && times == 1 || step == 2 && times == 0 || step == 3 && times == 0 || step == 3 && times == 1 || step == 3 && times == 2 ){
  331. //更多机会的第一项变为查看奖品 查看奖品的状态为1
  332. $('.jixuchoujiang #frist .right').attr("status","1")
  333. $('.jixuchoujiang #frist .right').html('查看奖品')
  334. }
  335. if(step == 2 || step == 3){//是否需要去大额券页面
  336. $('.jixuchoujiang #yhq .right').removeClass('deq_jjixuchoujiang');
  337. $('.jixuchoujiang #yhq .right').html('去抽奖')
  338. if(step == 2 && times == 0 || step == 3 && times == 1 || step == 3 && times == 2 || step == 3 && times == 0){
  339. $('.jixuchoujiang #yhq .right').html('查看奖品')
  340. $('.jixuchoujiang #yhq .right').attr("status","1")
  341. }
  342. }
  343. if(step == 3){
  344. $('.jixuchoujiang #dingdantianxie .right').removeClass('dd_dingdantianxie')
  345. $('.jixuchoujiang #dingdantianxie .right').html('去抽奖')
  346. if(times == 0 && step == 3){
  347. $('.jixuchoujiang #dingdantianxie .right').html('查看奖品')
  348. $('.jixuchoujiang #dingdantianxie .right').attr("status","1")
  349. }
  350. }
  351. var arrHtml = Array.prototype.slice.call($(".choujiang_zhuanpan #luck li"));
  352. luck.prize = level-1;//抽中的位置
  353. // console.log(luck.prize)
  354. luck.init('luck');//抽奖事件
  355. $(".myJiangpin").html(`<div style="display:block;" onclick="goMyjiangpin()">我的奖品<i></i></div>`)
  356. // arrHtml.forEach(function(item, index) {
  357. // if($(item).attr('data-level') == level - 1){
  358. // //奖品
  359. // luck.prize = $(item).attr('num');//抽中的位置
  360. // console.log(luck.prize)
  361. // }
  362. // })
  363. }
  364. }
  365. });
  366. }
  367. //去大额券列表页
  368. function godaequanList () {
  369. // gainPrize(prizeName);//中奖领取接口
  370. window.location.href = 'goods/goodsList.html?token=' + token +'&category_id=2414' + '&name=大额券';
  371. closeTankuang_02();//关闭弹窗
  372. }
  373. //抽奖接口 返回抽奖次数 每次抽奖完毕就要调一下
  374. function luckyDraw () {
  375. $.ajax({
  376. type:"post",
  377. url:"/api/v2/luckyDraw/luckyDraw",
  378. dataType:'json',
  379. headers:{
  380. token:token,
  381. },
  382. data:{
  383. prize_name:prizeName,
  384. level:level,
  385. prize_content:prize_content
  386. },
  387. success:function (res) {
  388. console.log(res)
  389. if(res && res.errno == 0){
  390. $("#times_cishu span").text(res.rst.times);//剩余抽奖次数
  391. times = res.rst.times
  392. }
  393. }
  394. });
  395. }
  396. //填写订单号
  397. function writeOrderId () {
  398. var value = $(".content_danhao input").val().trim();
  399. if(!value){
  400. showMsg('请输入订单号');
  401. return;
  402. }
  403. $.ajax({
  404. type:"post",
  405. url:"/api/v2/luckyDraw/writeOrderId",
  406. dataType:'json',
  407. headers:{
  408. token:token,
  409. },
  410. data:{
  411. order_id:value
  412. },
  413. success:function (res) {
  414. if(res){
  415. if(res.errno == 7000){
  416. closeTankuang();//关闭弹窗
  417. luckyDrawIndex();//首页接口刷新
  418. }else{
  419. showMsg(res.rst.msg);
  420. }
  421. }
  422. }
  423. });
  424. }
  425. //用户中奖列表
  426. //function userPrizeList () {
  427. // $.ajax({
  428. // type:"post",
  429. // url:"/api/v2/luckyDraw/userPrizeList",
  430. // dataType:'json',
  431. // headers:{
  432. // token:token,
  433. // },
  434. // success:function (res) {
  435. // if(res && res.errno == 0) {
  436. // if(res.rst.prizeList.length == 0){
  437. // prizeList = null;
  438. // }else{
  439. // prizeList = res.rst.prizeList
  440. // }
  441. // var html = '';
  442. // if(!prizeList){
  443. // //暂未有奖品
  444. // html += `<div style="text-align: center;">暂无奖品</div>`
  445. // }else{
  446. // prizeList.forEach(function (item, index) {
  447. // html += `<li data_level="${item.level}" data_prize_content="${item.prize_content}"><span>${item.prize}</span><span>${item.create_time}</span><span>详情 ></span></li>`
  448. // })
  449. // }
  450. // $(".content_my_jiangpin ul").html(html)
  451. // lookPrize();//点击查看奖品
  452. // }
  453. // }
  454. // });
  455. //}
  456. //奖品领取接口
  457. //function gainPrize (prize_name) {
  458. // $.ajax({
  459. // type:"post",
  460. // url:"/api/v2/luckyDraw/gainPrize",
  461. // dataType:'json',
  462. // headers:{
  463. // token:token,
  464. // },
  465. // data:{
  466. // prize_name:prize_name,
  467. // level: level,
  468. // prize_content:prize_content
  469. // },
  470. // success:function (res) {
  471. // console.log(res)
  472. // }
  473. // });
  474. //}
  475. //复制淘口令
  476. function copyPassword() {
  477. $("#taokouling").text(prize_content);
  478. var data=document.getElementById("taokouling").innerHTML;
  479. copy_2.innerHTML = data;
  480. copy_1.value = data;
  481. if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
  482. //区分iPhone设备
  483. window.getSelection().removeAllRanges();//这段代码必须放在前面否则无效
  484. var Url2=document.getElementById("copy_2");//要复制文字的节点
  485. var range = document.createRange();
  486. // 选中需要复制的节点
  487. range.selectNode(Url2);
  488. // 执行选中元素
  489. window.getSelection().addRange(range);
  490. // 执行 copy 操作
  491. var successful = document.execCommand('copy');
  492. // 移除选中的元素
  493. window.getSelection().removeAllRanges();
  494. }else{
  495. var Url2=document.getElementById("copy_1");//要复制文字的节点
  496. Url2.select(); // 选择对象
  497. document.execCommand("Copy"); // 执行浏览器复制命令
  498. }
  499. openTaobao(prize_content)//复制淘口令打开淘宝
  500. closeTankuang_02();//关闭弹窗
  501. // $(".content_tkl .gongxi").css('display','none');
  502. // $(".content_tkl .gongxi_tkl").css('display','block');
  503. // $(".content_tkl button").attr('data-status','0').html('我知道了');
  504. // gainPrize(prizeName);//中奖领取接口
  505. }
  506. /**
  507. * [showMsg 提示各种错误信息,3s后消失]
  508. */
  509. function showMsg(msg) {
  510. var msgBox = $('.alert-info');
  511. msgBox.children('p').text(msg);
  512. msgBox.show();
  513. setTimeout(function() {
  514. msgBox.hide();
  515. }, 1500);
  516. }
  517. //我的奖品列表 点击查看奖品
  518. //function lookPrize () {
  519. // $(".content_my_jiangpin li").click(function () {
  520. // console.log($(this))
  521. // var data_level = $(this).attr('data_level');
  522. // var data_prize_content = $(this).attr('data_prize_content');
  523. // console.log(data_level);
  524. // console.log(data_prize_content)
  525. // if(data_level == 8){
  526. // $('.tanchuang').show();
  527. // $('.tanchuang').find('.content_yhq').show();
  528. // $('body').css({'position':'fixed',"top":-scrollTop});
  529. // scrollTop02 = scrollTop;
  530. // }
  531. // })
  532. //}
  533. // 打开淘宝
  534. function openTaobao (url) {
  535. var goUrl = url;
  536. if(url.indexOf('http') == -1){
  537. goUrl = 'https://s.click.taobao.com/uVxgtMw';
  538. }else{
  539. goUrl = '22222222222222'
  540. }
  541. var param = {"taobaoUrl" : goUrl}
  542. param = JSON.stringify(param)
  543. try{
  544. if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){
  545. window.webkit.messageHandlers.app_h5_open_taobao_url.postMessage(param);
  546. }
  547. if(navigator.userAgent.match(/android/i)){
  548. obj4H5.app_h5_open_taobao_url(param);
  549. }
  550. }catch(e){
  551. //TODO handle the exception
  552. // alert('请更新版本就行购买')
  553. }
  554. }
  555. // 刷新页面
  556. function refresh_h5(){
  557. setTimeout(function () {
  558. location.reload();
  559. },1000)
  560. }