123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570 |
- var click=false,flagClick = true;
- var luck={
- index:-1, //当前转动到哪个位置,起点位置
- count:0, //总共有多少个位置
- timer:0, //setTimeout的ID,用clearTimeout清除
- speed:20, //初始转动速度
- times:0, //转动次数
- cycle:40, //转动基本次数:即至少需要转动多少次再进入抽奖环节
- prize:-1, //中奖位置
- init:function(id){
- if ($("#"+id).find(".luck-unit").length>0) {
- $luck = $("#"+id);
- $units = $luck.find(".luck-unit");
- this.obj = $luck;
- this.count = $units.length;
- $luck.find(".luck-unit-"+this.index).addClass("liActive");
- };
- },
- roll:function(){
- var index = this.index;
- var count = this.count;
- var luck = this.obj;
- $(luck).find(".luck-unit-"+index).removeClass("liActive");
- index += 1;
- if (index>count-1) {
- index = 0;//当index == 7 时置 0
- };
- $(luck).find(".luck-unit-"+index).addClass("liActive");
- this.index=index;
- return false;
- },
- stop:function(index){
- this.prize=index;
- return false;
- }
- };
- var scrollTop,scrollTop02,times;//times 抽奖次数
- var token = null,level;
- var prize_content = null;//目前淘口令
- var prizeName = null;//所中奖项的name
- var prizeList;//我的奖品列表
- $().ready(function () {
- shandeng();//闪灯
- new scrollTxt().init();
- getTkl();//淘口令红包领取
- getToken();//获取token
- $(window).scroll(function(){
- scrollTop = $(this).scrollTop(); //scrollTop() 方法返回或设置匹配元素的滚动条的垂直位置
- })
- $('.goChongjiang').click(function () {
- if(!token){
- getToken();
- return;
- }
- if($(this).attr('status') == 1){
- //我的列表页
- window.location.href='prizeList.html?token=' + token;
- closeTankuang();//关闭其他弹窗
- return;
- }
- if($(this).attr('class').indexOf('deq_jjixuchoujiang') != -1){
- //去大额券列表页
- window.location.href = 'goods/goodsList.html?token=' + token +'&category_id=3786&name=品牌券';
- closeTankuang();//关闭其他弹窗
- }else if($(this).attr('class').indexOf('dd_dingdantianxie') != -1){
- //去填单号
- $('.tanchuang').show();
- $('.tanchuang').find('.content_danhao').show();
- $('body').css({'position':'fixed',"top":-scrollTop});
- scrollTop02 = scrollTop;
- }else{
- $(window).scrollTop(0)
- }
- })
-
- $("#close").click(function () {
- closeTankuang();//关闭其他弹窗
- })
- $("#tijiaodingdan").click(function () {
- writeOrderId();//提交订单
- })
- })
- //获取token
- function getToken () {
- var param = '{"js_callback" : "callBackMethodName"}';
- try{
- if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){
- window.webkit.messageHandlers.app_h5_login.postMessage(param);
- }
- if(navigator.userAgent.match(/android/i)){
- obj4H5.app_h5_login(param);
- }
- }catch(e){
- //TODO handle the exception
- // showMsg("请更新app")
- // token = '5cdfb93b9df9e610634f5f338d798dd9182';
- // luckyDrawIndex();//抽奖首页
- }
-
- }
- function callBackMethodName (data) {//app token 回调
- var data = JSON.parse(data)
- token = data.token;
- luckyDrawIndex();//抽奖首页
- }
- //抽奖进行中
- function roll(){
- luck.times += 1;
- luck.roll();
- if (luck.times > luck.cycle+10 && luck.prize==luck.index) {
- //当中奖编号等于转动到的位置时 停止转动
- //中奖商品效果
- var yes = ".luck-unit-" + luck.prize;
- $(yes).find('img').addClass('zhongActive');
- setTimeout(function(){ //200ms后执行抽中的办法 纯属为了好看
- $(".luck-unit img").removeClass("zhongActive");
- luckyDraw();//剩余抽奖次数接口
- successZhongjiang(luck.prize);
- },600);
- }else{
- //luck.times 转动的次数 luck.cycle 转动基本次数:即至少需要转动多少次再进入抽奖环节
- if (luck.times<luck.cycle) {
- luck.speed -= 10;
- }else if(luck.times==luck.cycle) {
- //选定选中的奖品
- // var index = Math.random()*(luck.count)|0;
- // luck.prize = index;
- }else{
- if (luck.times > luck.cycle+10 && ((luck.prize==0 && luck.index==7) || luck.prize==luck.index+1)) {
- //当转动的次数大于基本次数加十 并且 (中奖编号为0且传动到的位置为7) 或者 中奖编号等于传动到的位置加1 时速度骤加110-------------即停止转动????????????
- luck.speed += 110;
- }else{
- luck.speed += 20;
- }
- }
- if (luck.speed<40) {
- //传懂速度最低为40
- luck.speed=40;
- };
- luck.timer = setTimeout(roll,luck.speed);
- }
- return false;
- }
- //中奖时的操作
- function successZhongjiang (num) {
- //弹窗
- closeTankuang();//关闭其他弹窗
- if(num == 1){//超级红包 幸运红包
- $('.tanchuang').show();
- $('.tanchuang').find('.content_tkl').show();
- // $('.content_tkl .price').html('2.0元')
- $('body').css({'position':'fixed',"top":-scrollTop});
- scrollTop02 = scrollTop;
- }
- if(num == 3){//超级红包 幸运红包
- $('.tanchuang').show();
- $('.tanchuang').find('.content_tkl').show();
- // $('.content_tkl .price').html('100元')
- $('body').css({'position':'fixed',"top":-scrollTop});
- scrollTop02 = scrollTop;
- }
- if(num == 6){//很遗憾
- $('.tanchuang').show();
- $('.tanchuang').find('.content_fail').show();
- $('body').css({'position':'fixed',"top":-scrollTop});
- scrollTop02 = scrollTop;
- }
- if(num == 7){//100大额优惠券
- $('.tanchuang').show();
- $('.tanchuang').find('.content_yhq').show();
- $('body').css({'position':'fixed',"top":-scrollTop});
- scrollTop02 = scrollTop;
- }
- clearTimeout(luck.timer);
- luck.prize=-1;//中奖编号
- luck.times=0;//转动的次数清零
- click=false;
- }
- function goChoujiang () {
- //点击抽奖按钮 判断有没有token
- if(!token){
- getToken();
- return;
- }
- //关闭所有弹框 兼容 上次没有抽中 再来一次
- $('.tanchuang').hide();
- $('.tanchuang').children().hide();
- $("body").css({"position":"initial"});//页面开启滚动
- if(!times){
- //没有抽奖次数为0了
- luckyDrawIndex();//首页接口刷新
- showMsg('抽奖机会不足,明日再来吧~');
- return;
- }
- if(click) {
- return false;
- }else{
- // 按下弹起效果
- $(".btn").addClass("cjBtnDom");
- setTimeout(function(){
- $(".btn").removeClass("cjBtnDom");
- },600);
- luck.speed=120;
- roll();
- click=true;
- if(!flagClick){//第一次点击不加载接口
- luckyDrawIndex();
- }
- return false;
- }
- }
- function shandeng () {
- //闪灯效果
- var num = 0;
- $("#deng").attr("class",function(){
- setInterval(function(){
- num++;
- if(num%2==0){
- $('#deng').removeClass('choujiang_deng_two');
- $('#deng').addClass("choujiang_deng");
- }else{
- $('#deng').removeClass('choujiang_deng');
- $('#deng').addClass("choujiang_deng_two");
- }
- },500)
- })
- }
- //scroll滚动
- function scrollTxt(){
- var controls={},
- values={},
- t1=800, /*播放动画的时间*/
- t2=1500, /*播放时间间隔*/
- si;
- controls.rollWrap=$("#roll-wrap");
- controls.rollWrapUl=controls.rollWrap.children();
- controls.rollWrapLIs=controls.rollWrapUl.children();
- values.liNums=controls.rollWrapLIs.length;
- values.liHeight=controls.rollWrapLIs.eq(0).height();
- values.ulHeight=controls.rollWrap.height();
- this.init=function(){
- autoPlay();
- }
- /*滚动*/
- function play(){
- controls.rollWrapUl.animate({"margin-top" : "-"+values.liHeight}, t1, 'linear',function(){
- $(this).css("margin-top" , "0").children().eq(0).appendTo($(this));
- });
- }
- /*自动滚动*/
- function autoPlay(){
- /*如果所有li标签的高度和大于.roll-wrap的高度则滚动*/
- if(values.liHeight*values.liNums > values.ulHeight){
- si=setInterval(function(){
- play();
- },t2);
- }
- }
- }
- //淘口令红包领取
- function getTkl () {
- $(".content_tkl button").click(function () {
- if($(".content_tkl button").attr('data-status') == 1){
- //点击领取
- copyPassword();//复制淘口令
- }else{
- //我知道了
- luckyDrawIndex();//首页接口
- $(".content_tkl .gongxi").css('display','block');
- $(".content_tkl .gongxi_tkl").css('display','none');
- $(".content_tkl button").attr('data-status','1').html('立即领取');
- $('.tanchuang').hide();
- $('.tanchuang').children().hide();
- $("body").css({"position":"initial"});//页面开启滚动
- $(window).scrollTop(scrollTop02);
- }
- })
- }
- //打开规则弹窗
- function goGuize () {
- $('.tanchuang').show();
- $('.tanchuang').find('.content_gz').show();
- $('body').css({'position':'fixed',"top":-scrollTop});
- scrollTop02 = scrollTop;
- }
- //关闭弹框
- function closeTankuang () {
- $('.tanchuang').hide();
- $('.tanchuang').children().hide();
- $("body").css({"position":"initial"});//页面开启滚动
- $(window).scrollTop(scrollTop02);
- }
- //关闭弹框02
- function closeTankuang_02 () {
- $('.tanchuang').hide();
- $('.tanchuang').children().hide();
- $("body").css({"position":"initial"});//页面开启滚动
- $(window).scrollTop(scrollTop02);
- luckyDrawIndex();//首页接口刷新
- }
- //打开我的奖品弹框
- function goMyjiangpin () {
- window.location.href='prizeList.html?token=' + token;
- closeTankuang();//关闭其他弹窗
- // userPrizeList();//奖品列表
- // $('.tanchuang').show();
- // $('.tanchuang').find('.content_my_jiangpin').show();
- // $('body').css({'position':'fixed',"top":-scrollTop});
- // scrollTop02 = scrollTop;
- }
- //抽奖首页接口
- function luckyDrawIndex () {
- $.ajax({
- type:"post",
- url:"/api/v2/luckyDraw/luckyDrawIndex",
- dataType:'json',
- headers:{
- token:token,
- },
- success:function (res) {
- // console.log(res)
- if(res && res.errno == 0){
- flagClick = false;
- $("#times_cishu span").text(res.rst.times);//剩余抽奖次数
- times = res.rst.times;
- level = res.rst.level;//level中奖等级
- var step = res.rst.step;//用户的步骤
- if(res.rst.prize_content != ''){
- prize_content = res.rst.prize_content;//中奖奖品内容 ------- 淘口令
- }
- prizeName = res.rst.prize_name;//所中奖项的名称
- 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 ){
- //更多机会的第一项变为查看奖品 查看奖品的状态为1
- $('.jixuchoujiang #frist .right').attr("status","1")
- $('.jixuchoujiang #frist .right').html('查看奖品')
- }
- if(step == 2 || step == 3){//是否需要去大额券页面
- $('.jixuchoujiang #yhq .right').removeClass('deq_jjixuchoujiang');
- $('.jixuchoujiang #yhq .right').html('去抽奖')
- if(step == 2 && times == 0 || step == 3 && times == 1 || step == 3 && times == 2 || step == 3 && times == 0){
- $('.jixuchoujiang #yhq .right').html('查看奖品')
- $('.jixuchoujiang #yhq .right').attr("status","1")
- }
- }
- if(step == 3){
- $('.jixuchoujiang #dingdantianxie .right').removeClass('dd_dingdantianxie')
- $('.jixuchoujiang #dingdantianxie .right').html('去抽奖')
- if(times == 0 && step == 3){
- $('.jixuchoujiang #dingdantianxie .right').html('查看奖品')
- $('.jixuchoujiang #dingdantianxie .right').attr("status","1")
- }
- }
- var arrHtml = Array.prototype.slice.call($(".choujiang_zhuanpan #luck li"));
- luck.prize = level-1;//抽中的位置
- // console.log(luck.prize)
- luck.init('luck');//抽奖事件
- $(".myJiangpin").html(`<div style="display:block;" onclick="goMyjiangpin()">我的奖品<i></i></div>`)
- // arrHtml.forEach(function(item, index) {
- // if($(item).attr('data-level') == level - 1){
- // //奖品
- // luck.prize = $(item).attr('num');//抽中的位置
- // console.log(luck.prize)
- // }
- // })
- }
- }
- });
- }
- //去大额券列表页
- function godaequanList () {
- // gainPrize(prizeName);//中奖领取接口
- window.location.href = 'goods/goodsList.html?token=' + token +'&category_id=2414' + '&name=大额券';
- closeTankuang_02();//关闭弹窗
- }
- //抽奖接口 返回抽奖次数 每次抽奖完毕就要调一下
- function luckyDraw () {
- $.ajax({
- type:"post",
- url:"/api/v2/luckyDraw/luckyDraw",
- dataType:'json',
- headers:{
- token:token,
- },
- data:{
- prize_name:prizeName,
- level:level,
- prize_content:prize_content
- },
- success:function (res) {
- console.log(res)
- if(res && res.errno == 0){
- $("#times_cishu span").text(res.rst.times);//剩余抽奖次数
- times = res.rst.times
- }
- }
- });
- }
- //填写订单号
- function writeOrderId () {
- var value = $(".content_danhao input").val().trim();
- if(!value){
- showMsg('请输入订单号');
- return;
- }
- $.ajax({
- type:"post",
- url:"/api/v2/luckyDraw/writeOrderId",
- dataType:'json',
- headers:{
- token:token,
- },
- data:{
- order_id:value
- },
- success:function (res) {
- if(res){
- if(res.errno == 7000){
- closeTankuang();//关闭弹窗
- luckyDrawIndex();//首页接口刷新
- }else{
- showMsg(res.rst.msg);
- }
- }
- }
- });
- }
- //用户中奖列表
- //function userPrizeList () {
- // $.ajax({
- // type:"post",
- // url:"/api/v2/luckyDraw/userPrizeList",
- // dataType:'json',
- // headers:{
- // token:token,
- // },
- // success:function (res) {
- // if(res && res.errno == 0) {
- // if(res.rst.prizeList.length == 0){
- // prizeList = null;
- // }else{
- // prizeList = res.rst.prizeList
- // }
- // var html = '';
- // if(!prizeList){
- // //暂未有奖品
- // html += `<div style="text-align: center;">暂无奖品</div>`
- // }else{
- // prizeList.forEach(function (item, index) {
- // html += `<li data_level="${item.level}" data_prize_content="${item.prize_content}"><span>${item.prize}</span><span>${item.create_time}</span><span>详情 ></span></li>`
- // })
- // }
- // $(".content_my_jiangpin ul").html(html)
- // lookPrize();//点击查看奖品
- // }
- // }
- // });
- //}
- //奖品领取接口
- //function gainPrize (prize_name) {
- // $.ajax({
- // type:"post",
- // url:"/api/v2/luckyDraw/gainPrize",
- // dataType:'json',
- // headers:{
- // token:token,
- // },
- // data:{
- // prize_name:prize_name,
- // level: level,
- // prize_content:prize_content
- // },
- // success:function (res) {
- // console.log(res)
- // }
- // });
- //}
- //复制淘口令
- function copyPassword() {
- $("#taokouling").text(prize_content);
- var data=document.getElementById("taokouling").innerHTML;
- copy_2.innerHTML = data;
- copy_1.value = data;
- if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
- //区分iPhone设备
- window.getSelection().removeAllRanges();//这段代码必须放在前面否则无效
- var Url2=document.getElementById("copy_2");//要复制文字的节点
- var range = document.createRange();
- // 选中需要复制的节点
- range.selectNode(Url2);
- // 执行选中元素
- window.getSelection().addRange(range);
- // 执行 copy 操作
- var successful = document.execCommand('copy');
- // 移除选中的元素
- window.getSelection().removeAllRanges();
- }else{
- var Url2=document.getElementById("copy_1");//要复制文字的节点
- Url2.select(); // 选择对象
- document.execCommand("Copy"); // 执行浏览器复制命令
- }
- openTaobao(prize_content)//复制淘口令打开淘宝
- closeTankuang_02();//关闭弹窗
- // $(".content_tkl .gongxi").css('display','none');
- // $(".content_tkl .gongxi_tkl").css('display','block');
- // $(".content_tkl button").attr('data-status','0').html('我知道了');
- // gainPrize(prizeName);//中奖领取接口
- }
- /**
- * [showMsg 提示各种错误信息,3s后消失]
- */
- function showMsg(msg) {
- var msgBox = $('.alert-info');
- msgBox.children('p').text(msg);
- msgBox.show();
- setTimeout(function() {
- msgBox.hide();
- }, 1500);
- }
- //我的奖品列表 点击查看奖品
- //function lookPrize () {
- // $(".content_my_jiangpin li").click(function () {
- // console.log($(this))
- // var data_level = $(this).attr('data_level');
- // var data_prize_content = $(this).attr('data_prize_content');
- // console.log(data_level);
- // console.log(data_prize_content)
- // if(data_level == 8){
- // $('.tanchuang').show();
- // $('.tanchuang').find('.content_yhq').show();
- // $('body').css({'position':'fixed',"top":-scrollTop});
- // scrollTop02 = scrollTop;
- // }
- // })
- //}
- // 打开淘宝
- function openTaobao (url) {
- var goUrl = url;
- if(url.indexOf('http') == -1){
- goUrl = 'https://s.click.taobao.com/uVxgtMw';
- }else{
- goUrl = '22222222222222'
- }
- var param = {"taobaoUrl" : goUrl}
- param = JSON.stringify(param)
- try{
- if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){
- window.webkit.messageHandlers.app_h5_open_taobao_url.postMessage(param);
- }
- if(navigator.userAgent.match(/android/i)){
- obj4H5.app_h5_open_taobao_url(param);
- }
- }catch(e){
- //TODO handle the exception
- // alert('请更新版本就行购买')
- }
- }
- // 刷新页面
- function refresh_h5(){
- setTimeout(function () {
- location.reload();
- },1000)
- }
|