// 1.判断是否失效或者过期 // 2.红包不可帮拆时,显示提现列表 // 3.帮好友助力成功,显示好友助力团 var qs = parseQueryString(window.location.href); var loadingFlag = true; var isLoadingFlag = true; var loadingFlag02 = false; var user_id = ''; var red_id = '';//red_id----红包id var presentHtml = ''; //presentHtml---提现列表内容 var helperHtml = '';//helperHtml---好友列表内容 var helperHtml02 = [];//helperHtml02---好友列表内容 var descri="";//descri----针对第一条的特殊描述 var red_money='';//red_money----红包金额 var red_mission=""//red_mission----新手红包金额 var attr_type = 'app'; var token = ''; var surplus_money = ''; var page=1;//新手红包列表分页信息 var mySwiper = ''; $().ready(function(){ _czc.push(["_trackEvent",'v3-发起者红包详情页','页面进入量','']); if(qs.user_id){user_id = qs.user_id}; if(qs.red_id){red_id = qs.red_id}; if(window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == "micromessenger"){ // 微信端 attr_type = 'wechat' getInfo();//在微信需要user_id app中需要token shareWechatUrl();//获得分享url }else{ attr_type = 'app' getToken();//获取token } $(window).scroll(function(){ if($(window).scrollTop()>= $(document).height()-$(window).height()){ //到达底部加载数据 if(loadingFlag && isLoadingFlag && loadingFlag02){ page ++ ; friendHelp(page); } } }); }) // 获取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) { // token='6ca4d1d79f0a74b1341eeed7819e3c4c324723' // getInfo() // redOldHelpers() //TODO handle the exception } } function callBackMethodName(data) {//app token 回调 var data = JSON.parse(data); token=data.token; // 如果不存在token时,在body中传递user_id getInfo() redOldHelpers(); } function shareWechatButton () { _czc.push(["_trackEvent",'v3-发起者红包详情页','【发起助力】按钮点击次数','']); //app分享到微信 if(attr_type == 'app'){ $(".shareMask").show(); }else if(attr_type == 'wechat'){ //在微信端引导用户右上角转发分享 $(".share_wechat_mask").show(); $(".share_wechat_mask .share_wechat_con .price").text(surplus_money) } } function closeMask () { //关闭弹框 $(".share_wechat_mask").hide(); $(".shareMask").hide(); } function shareWechatUrl(cb){ //获取分享url $.ajax({ type: 'post', url: '/api/v2/redactive/helpOpenRed', data:{ 'red_id':red_id, 'user_id':user_id }, success: function (data) { if (data && data.errno == 0) { var url=data.rst.url; shareUrl = url; cb?cb():""; if(attr_type == 'wechat'){ getSignPackage();//过微信审核用 } }else { // showMsg(res.err) } }, error:function () { // showMsg("请稍后再试") } }) } function getSignPackage () { //过微信审核用 var _this = this; $.ajax({ url:'/api/v2/spellgroup/getSignPackage', type:'post', data:{ url:location.href }, success: function (res) { wexinPay(shareUrl,res,function() { // 分享成功 showMsg("分享成功") _czc.push(["_trackEvent",'v3-红包分享','红包id--' + red_id,'']); },function() { //分享失败 showMsg("分享失败") },function() { //微信审核为通过 }) } }) } function shareWeixin(type){ //app分享到微信或者朋友圈 shareWechatUrl(function(){ appShareWechat(type);//调用app的方法 }) } function appShareWechat (type) { console.log(type) //app分享到微信 var param = { "shareImageUrl": "https://kx-youhuiquan.oss-cn-beijing.aliyuncs.com/H5-liedou/redEnvelopes/shareWechat.png", "shareTitle": "@帮我提现,送你22元现金!", "shareDescirpt": "领优惠券还送红包,赚钱提现超简单~", "shareUrl": shareUrl,//详情链接 "shareType": type //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); } _czc.push(["_trackEvent",'v3-红包分享','红包id--' + red_id,'']); } catch (error) { } closeMask(); } // 红包详情 function getInfo() { $(".loading").show(); $.ajax({ type: 'post', url: '/api/v2/redactive/getRedOrderDataV2', headers: { 'token':token }, data:{ 'red_id': red_id, 'user_id': user_id, 'is_new': 1//新版,本人不能给本人拆 }, success: function (res) { $(".loading").hide(); if (res && res.errno == 0) { console.log(res) user_id = res.rst.data.user_id; red_id = res.rst.data.red_id; red_mission = res.rst.red_mission; red_money = res.rst.data.red_money; surplus_money = (Number(res.rst.data.red_money) - Number(res.rst.data.red_open_money)).toFixed(2); // 如果红包没有拆开,显示新人助力 if(res.rst.data.red_open_money==0) { redPlant() }else { loadingFlag02 = true; friendHelp() } $(".userImg").attr("src",res.rst.data.headimgurl) $(".cashWithdrawalPrice span span").text(res.rst.data.red_money) // 红包进度 var precent=parseFloat(res.rst.data.red_open_money/res.rst.data.red_money*100); // $(".hint span").html(res.rst.note) if(precent<=80) { $(".progress_bar").css("width",precent+"%") }else if (precent > 80 && precent < 100){ $(".progress_bar").css("width","90%") $(".redEnvelopes .progress .progress_bar .progress_con").css('right','-0.4rem') }else{ $(".progress_bar").css("width","100%") $(".redEnvelopes .progress .progress_bar .progress_con").css('right','0rem') } // 红包状态 $(".progress_bar .progress_con").text("¥"+res.rst.data.red_open_money) var order_type = res.rst.data.type; if(order_type == 1){ //失效 $(".share").attr("disabled","disabled"); $(".share").css("background","#CBCBCB"); $(".share").html("红包已失效"); $(".progress").css('background','#CFCFCF'); $(".progress_bar").css('background','#CBCBCB'); $(".progress_con").css("background",'#CBCBCB'); }else if(order_type == 2){ //已拆完 $(".progress_bar").css("background","#CBCBCB"); $(".progress").css("background","rgb(207, 207, 207,.33)"); $(".progress_con").css("background","#CBCBCB"); $(".share").attr("disabled","disabled"); $(".share").css("background","#CBCBCB"); $(".share").html("红包已拆完") }else if(order_type == 3){ //过期 $(".time").hide(); $(".share").attr("disabled","disabled"); $(".share").css("background","#CBCBCB"); $(".progress_bar").css("background","#CBCBCB"); $(".progress").css("background","rgb(207, 207, 207,.33)"); $(".progress_con").css("background","#CBCBCB"); $(".share").html("红包已过期") }else{ //红包在拆 console.log('正在拆') count_down(res.rst.data.red_ending_time) } $(".notice").text(res.rst.note) }else{ showMsg(res.err) } }, error: function () { showMsg('请稍后再试!') $(".loading").hide(); } }) } function count_down(o){ //倒计时封装; var 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 clearInterval(time); }else{ // s={'时':Math.floor(sec/3600%24),'分':Math.floor(sec/60%60),'秒':Math.floor(sec%60),'ms':parseInt((ms=ms-1)/10)}; s={'时':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] + '' + ':'; }else { str += '' + s[i] + '' ; } } $("#count").html('
' + str + '
') } } // 好友助力榜 function friendHelp(){ loadingFlag = false; $.ajax({ type:"post", url:'/api/v2/redactive/friendHelpTop', dataType:'json', headers:{ token:token }, data:{ 'user_id':user_id, 'red_id':red_id, 'page':page }, success:function (res) { loadingFlag = true; if(res.errno==0) { var helpList=res.rst.data if(res.rst.data.length < 10){ isLoadingFlag = false; } if(helpList.length!=0) { // 广告位轮播图 helperHtml02 = helperHtml02.concat(helpList); var swiperHtml = ''; helperHtml02.forEach(function (item,index){ if(item.type == 1){ swiperHtml+='
恭喜 ' + item.helper_name + ' 获得22元现金
快去邀请他下载猎豆优选一起赚钱吧!
'; } }) if(page == 1 && swiperHtml != ''){ swiperEvent(); } if(swiperHtml != ''){ $(".swiperAdvertisement .swiper-wrapper").html(swiperHtml) mySwiper.update(); } // 好友助力团 helpList.forEach(function(item,index) { if(index==0 && page == 1) { descri='
最高助力¥'+item.helper_money+'
' }else { descri='
助力¥'+item.helper_money+'
' } // helperHtml+='
'+item.helper_name+'
'+(item.is_new==0?"来自:好友助力":(item.helper_money>=4?"来自:新用户下单助力":"来自新用户助力"))+'
'+descri+'
' helperHtml+='
'+item.helper_name+'
'+(item.type==0?"好友助力":(item.type==1?"新人助力":(item.type == 2 ? "新人注册助力" : (item.type == 3 ? "新人登录助力" : ""))))+'
'+descri+'
' //新人助力方式 type 0好友助力 1新手助力,2新手注册助力 3新手登录助力 }) $(".friendHelp .list").html(helperHtml) $(".friendHelp").show() $(".otherList").hide() }else { // $(".friendHelp").hide() $(".otherList").hide() } }else { showMsg(res.err) } }, error:function(err) { loadingFlag = true; showMsg("网络错误,请稍后再试~") } }) } // 提现列表 function redPlant(){ $.ajax({ type:"post", url:'/api/v2/redactive/redPlant', dataType:'json', success:function (res) { if(res.errno==0) { var plantList=res.rst.data $(".noLoginList .h6").html("已有"+res.rst.red_nums+"人领到红包") if(plantList.length!=0) { plantList.forEach(function(item) { presentHtml+='
'+item.nickname+'
'+item.msg+',提现了¥'+item.money+'
' }) $(".otherList .list").html(presentHtml) $(".otherList").show() $(".friendHelp").hide() }else { $(".otherList").hide() $(".friendHelp").hide() } }else { showMsg(res.err) } }, error:function(err) { showMsg("网络错误,请稍后再试~") } }) } function init(){ // 红包进度 var precent=parseFloat(res.red_open_money/res.red_money*100); if(precent<17||precent<0) { $(".progressBar").css("width","17%") }else if(precent>100) { $(".progressBar").css("width","100%") }else { $(".progressBar").css("width",precent+"%") } } function goRule () { //去规则页面 window.location.href='rule.html?time=' + new Date().getTime() } function swiperEvent () { mySwiper = new Swiper('.swiper-container', { slidesPerView: "auto", watchSlidesProgress: true, spaceBetween: 20, loop:true, centeredSlides:true, autoplay: { delay: 3000, disableOnInteraction: false, }, }); } function stopPropagationEvent (event){ //禁止冒泡 event.stopPropagation(); return false; } function redOldHelpers (){ $.ajax({ type:"post", url:'/api/v2/redactive/redOldHelpers', dataType:'json', headers:{ token:token }, success:function (res) { console.log(res) if(res.errno == 0){ if(res.rst.data.length!=0){ $(".shareMask .weixin .shareFriends").show(); var shareFriendsHtml = ''; res.rst.data.forEach(function (item,index){ shareFriendsHtml += '
  • ' + item.nickname + '
  • '; }) $(".shareMask .weixin .shareFriends .friends ul").html(shareFriendsHtml) } } }, }) } // 分享到小程序 // function wxShare() { // _czc.push(["_trackEvent",'新版好友助力','分享到小程序的助力次数','']); // var param = { // "shareUrl" : window.location.href,//兼容低版本的网页链接 // "shareThumb":"https://kx-youhuiquan.oss-cn-beijing.aliyuncs.com/H5-liedou/redEnvelopes/poster_app.png", //小程序消息封面图片 // "shareTitle" : "帮我助力,送你¥"+red_mission+"现金。我赚了¥"+red_money+",马上就能提现了",//小程序标题 // "shareDescription" : "帮我助力,送你¥"+red_mission+"现金。我赚了"+red_money+",马上就能提现了 ",//小程序描述 // "sharePath" : "pages/index/index?source=liedou_app&user_id="+user_id+"&red_id="+red_id,//小程序页面路径 // "shareID" : "gh_baf1f076e969",// 小程序原始id // "minType" : 1//minType 1.线上 2.开发 3.体验 // } // param = JSON.stringify(param); // try { // if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) { // window.webkit.messageHandlers.app_h5_wx_share_min.postMessage(param); // } // if (navigator.userAgent.match(/android/i)) { // obj4H5.app_h5_wx_share_min(param); // } // } catch (error) { // } // } //获取地址栏参数 function parseQueryString(url) { var urlObj = {}; var reg = /([^?=&]+)=([^?=&]+)/g; url.replace(reg, function($0, $1, $2) { urlObj[$1] = decodeURIComponent($2); }) return urlObj; } function showMsg(msg) { //弹框 var msgBox = document.getElementsByClassName('alert-info')[0]; msgBox.children[0].innerText = msg; msgBox.style.display="block"; setTimeout(function() { msgBox.style.display="none"; }, 1500); }