//获取地址栏参数 function parseQueryString(url) { var urlObj = {}; var reg = /([^?=&]+)=([^?=&]+)/g; url.replace(reg, ($0, $1, $2) => { urlObj[$1] = decodeURIComponent($2); }) return urlObj; } var qs = parseQueryString(window.location.href); var dataList =[]; var tkl = ''; var serverTime = 1000; //服务器时间,毫秒数 $().ready(function() { activeTbkPassword();//获取淘口令,淘宝链接 }) //获取淘口令,淘宝链接 function activeTbkPassword () { $.ajax({ type:'post', url:'/api/v2/goods/activeTbkPassword', data:{ flag:'wishRedEnvelopes' }, dataType:'json', success:function (res) { if(res && res.errno == 0){ dataList = res.rst.list; count_down('2018-11-10 18:00:00') } } }) } //立即兑换 function goExchange () { var url = dataList[0].url; var tkl = dataList[0].tbk_password; openTaobao(url,tkl) } // 打开淘宝 function openTaobao (url,tkl) { var param = {"taobaoUrl" : url} 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 copyPassword(tkl) } } //复制淘口令 function copyPassword(tkl) { var data=tkl; copy_2.innerHTML = data; copy_1.setAttribute('value',data) if(Boolean(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");//执行浏览器复制命令 } showMsg('复制淘口令成功,请打开淘宝参与活动') } //提示弹框 function showMsg(msg) { var msgBox = $('.alert-info'); msgBox.children('p').text(msg); msgBox.show(); setTimeout(function() { msgBox.hide(); }, 3000); } //倒计时 function count_down(o){ var html = null;//页面 var time = null; time = setTimeout(function(){count_down(o)},1000); var datatime=/^[\d]{4}-[\d]{1,2}-[\d]{1,2}( [\d]{1,2}:[\d]{1,2}(:[\d]{1,2})?)?$/ig,str='',conn,s; if(!o.match(datatime)){ // alert('参数格式为2020-01-01[ 01:01[:01]].\r其中[]内的内容可省略'); return false; } var sec=(new Date(o.replace(/-/ig,'/')).getTime() - new Date().getTime())/1000; if(sec == 0 || sec < 0){ //倒计时结束时----都为0 $('.red_tip').hide(); html = `
红包有限 先到先得点击开始兑换
` $('.daojishi').html(html).css('margin-top','0.25rem'); $(".button").addClass('buttonActive'); $(".button").click(function () { goExchange(); }) clearTimeout(time); }else{ s={'天':sec/24/3600,'时':Math.floor(sec/3600%24),'分':Math.floor(sec/60%60),'秒':Math.floor(sec%60)}; for(i in s){ if(s[i] < 10){s[i] = '0' + s[i]}; if(i != '天'){ str += '' + s[i] + '' + i; } } html = `
倒计时
${str}
` $('.daojishi').html(html); $(".button").removeClass('buttonActive'); $(".button").click(function () { showMsg('兑换尚未开启,请耐心等待~') }) } }