var myDate = new Date(), id, nowTime = new Date().getTime(), dataList;//获取系统当前时间 var timeArr = [{ time:new Date('2018-11-01 00:00'.replace(/-/ig,'/')).getTime(), img:'https://kx-youhuiquan.oss-cn-beijing.aliyuncs.com/shuangshiyi/wishlist/progress_two.png', id:1 },{ time:new Date('2018-11-10 21:00'.replace(/-/ig,'/')).getTime(), img:'https://kx-youhuiquan.oss-cn-beijing.aliyuncs.com/shuangshiyi/wishlist/progress_three.png', id:2 },{ time:new Date('2018-11-11 00:00'.replace(/-/ig,'/')).getTime(), img:'https://kx-youhuiquan.oss-cn-beijing.aliyuncs.com/shuangshiyi/wishlist/progress_one.png', id:3 }]; $().ready(function () { writeLogH5({action:'wishList-home',channel:'H5',url:window.location.href});//埋点 isWeixinEvent();//判断是否是微信端 activeTbkPassword();//获取淘口令 timeArr.forEach(function (item, index) { if(nowTime > item.time){ $(".activityTime .changeTime .progress").css({'background':'url(' + item.img + ')','background-size':'100%'}) id = item.id } }) }) //获取淘口令,淘宝链接 function activeTbkPassword () { $.ajax({ type:'post', url:'/api/v2/goods/activeTbkPassword', data:{ flag:'wishlist' }, dataType:'json', success:function (res) { if(res && res.errno == 0){ dataList = res.rst.list } } }) } //立即参与 function goPartake (i) { if(i <= id && dataList.length >=id){ //可以点击 var url = dataList[0].url; var tkl = dataList[0].tbk_password; openTaobao(url,tkl) }else{ //不可点击 showMsg('【暂未开启】') } writeLogH5({action:'wishList-partake',channel:'H5',url:window.location.href});//埋点 } //立即兑换 function goCash (i) { if(i <= id && dataList.length >=id){ //可以点击 var url = dataList[1].url; var tkl = dataList[1].tbk_password; openTaobao(url,tkl) }else{ //不可点击 showMsg('【暂未开启】') } writeLogH5({action:'wishList-exchange',channel:'H5',url:window.location.href});//埋点 } //立即下单 function goOrder (i) { if(i <= id && dataList.length >=id){ //可以点击 var url = dataList[2].url; var tkl = dataList[2].tbk_password; openTaobao(url,tkl) }else{ //不可点击 showMsg('【暂未开启】') } writeLogH5({action:'wishList-order',channel:'H5',url:window.location.href});//埋点 } // 打开淘宝 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('复制淘口令成功,请打开淘宝参与活动') } //分享到微信url function goShare () { writeLogH5({action:'wishList-shareWechat',channel:'H5',url:window.location.href});//分享埋点 var param = { "shareImageUrl" : "https://kx-youhuiquan.oss-cn-beijing.aliyuncs.com/shuangshiyi/wishlist/shareWechat.jpg", "shareTitle": "双11最不能错过的活动", "shareDescirpt":"参与立享折上折,最大优惠等着你!", "shareUrl":window.location.href,//详情链接 "shareType":"1" //1:微信好友 2:朋友圈 } param = JSON.stringify(param) try{ if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){ window.webkit.messageHandlers.app_h5_wx_share_url.postMessage(param); } if(navigator.userAgent.match(/android/i)){ obj4H5.app_h5_wx_share_url(param); } }catch(e){ showMsg("先更新,再分享哦~") } } //H5页面埋点 function writeLogH5 (data) { $.ajax({ type:'post', url:'/api/v2/channel/writeLogH5', dataType:'json', data:data, success:function (res) { } }) } //判断是否是微信浏览器 function isWeixinEvent () { //判断是不是微信端,选择app方法获取token 还是后端提供 if(navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == "micromessenger"){ //微信 $("#share").css("display","none"); }else{ //app端 $("#share").css("display","block"); } } //提示弹框 function showMsg(msg) { var msgBox = $('.alert-info'); msgBox.children('p').text(msg); msgBox.show(); setTimeout(function() { msgBox.hide(); }, 2000); }