// JavaS
cript Document var getSalesListUrl=$("#getSalesListUrl").val(), getItemListUrl=$("#getItemListUrl").val(), getSignCodeUrl=$("#getSignCodeUrl").val(), promotion_id=$("#promotion_id").val(), co
de_arr=[]; function getSales(){ var sales_id=$("#sales_id").val(), sal_id=0, t_type=0; $.ajax({ url:getSalesListUrl, type:'POST', da
ta:{'promotion_id':promotion_id,"sales_id":sales_id}, dataType:'jsonp', success:function(da
ta){ var str=''; $.each(da
ta,function(item,d){ var time_type='', cls = ''; if(sales_id==0 && item==0){ $("#sales_id").val(d.sales_id); var sal_id=d.sales_id; //alert(sal_id); }; if(sales_id==d.sales_id || sal_id==d.sales_id){ switch(d.time_type){ case 0: time_type = '活动尚未开始:'; break; case 1: time_type = '活动正在进行:'; break; default: time_type = '活动已经结束:'; } t_type=d.time_type; cls = 'active'; $("#zhuanchang").html('
'+d.name+'
'+changeForm(d.time)+'
'); $(".ac-time").find("em").html(time_type); timing(d.time_left,"time_left",d.time_type); } str+='- '+d.time.substring(11,16)+'
- '; }); $("#getSales").html(str); //加载位置编码 getSignCode(); }, //success回调函数结束 complete:function(){ num=$("#getSales").find("li").length; leg=$("#getSales").find("li").outerWidth(true); $("#getSales").attr("style",'width:'+num*leg+"px"); //加载场次商品 getItem(t_type); } }); //ajax结束 }; //getSales 结束 /** *格式化日期时间 */ function changeForm(timeStr){ var str = timeStr, newStr = str.split(' '), mytime = newStr[0].split('-')[1]+'月'+newStr[0].split('-')[2]+'日'+newStr[1].split(':')[0]+'时'; return mytime; }; /** *根据场次获取商品数据 */ function getItem(t_type){ sales_id=$("#sales_id").val(); $.ajax({ url:getItemListUrl, type:"get", da
ta:{'sales_id':sales_id}, dataType:"jsonp", success:function (da ta){ if(t_type==0){ time_type='即将开始'; }else if(t_type==1){ time_type='正在进行'; }else{ time_type='已经结束'; } //重点推荐商品 var str_recommend=""; //普通商品 var str="", item_arr=[], seckill_arr=[],//有位置编码 other_seckill_arr=[],//没有位置编码 toobj={}; $.each(da ta,function(i,item){ if(item.recommend==1){ str_recommend+=" - \n"; str_recommend+="
\n"; str_recommend+="
\n"; str_recommend+="\n" str_recommend+="\n" str_recommend+="\n" str_recommend+="
【"+item.promotion_type+"】"+item.name+"
\n"; str_recommend+=""+item.content+"
\n"; str_recommend+="¥"+item.price+"
\n"; str_recommend+=" "+time_type+""; str_recommend+="
¥"+item.original_price+""+item.discount+" - \n"; }else{ item_arr.push(item); } }); $.each(co
de_arr,function(i,item){ var seckill_arr=[], other_seckill_arr=[]; $.each(item_arr,function(j,item_c){ if(item.co de==item_c.co de && item_c.co de!=''){ seckill_arr.push(item_c); toobj[item.co de]= seckill_arr; } if(item_c.co de==''){ other_seckill_arr.push(item_c); toobj['other']=other_seckill_arr; } }) }); $.each(co de_arr,function(i,item_c){ $.each(toobj,function(j,item_j){ if(item_c.co de==j && item_c.co de!=''){ str+=" \n"; str+=" - \n"; $.each(item_j,function(k,item){ str+="
- \n"; str+="\n"; str+="
\n"; str+=""; str+="
【"+item.promotion_type+"】"+item.name+"
\n"; str+="¥"+item.price+"
\n"; str+=" "+time_type+""; str+="
¥"+item.original_price+""+item.discount+" - "; }) str+="
- \n"; $.each(toobj['other'],function(o,item){ str+="
- \n"; str+="\n"; str+="
\n"; str+=""; str+="
【"+item.promotion_type+"】"+item.name+"
\n"; str+="¥"+item.price+"
\n"; str+=" "+time_type+""; str+="
¥"+item.original_price+""+item.discount+" - "; }); str+="
ta:{'sales_id':sales_id}, dataType:"jsonp", success:function(da ta){ co de_arr=da ta; var str=""; $.each(da ta,function(i,item){ if(item.co de!=''){ str+=" - "+item.co
de+" - "; } }); $("#ac-pup").find("ul").html(str); } }) }; //倒计时 var timing = function(second,idName,t_type){ var startTime = new Date(); var dm = $("#"+idName); var EndTime=startTime.getTime()+parseInt(second)*1000; //alert(EndTime); function checkTime(ts){ //格式化时间 return ts = ts > 9 ? ts : '0'+ts; } function tt(){ var NowTime = new Date(); var nMS =EndTime - NowTime.getTime(); var nd = Math.floor(nMS/(1000 * 60 * 60 * 24)); var nH=Math.floor(nMS/(1000*60*60)) % 24; var nM=Math.floor(nMS/(1000*60)) % 60; var nS=Math.floor(nMS/1000) % 60; if(nMS<=1){ if(t_type==0 || t_type==1){ window.reload(); }else{ dm.html('
- 00
- :
- 00
- :
- 00
- :
- 00
'); } }else{ setTimeout(tt,1000); } dm.html('- '+checkTime(nd)+'
- :
- '+checkTime(nH)+'
- :
- '+checkTime(nM)+'
- :
- '+checkTime(nS)+'
') } tt(); }; /** *点击切换场次 */ var timeFn = function(){ $("#ac-pup").on("click","A",function(e){ var that = $(this).attr("data-id"); var thatPoint = document.getElementById(that).getBoundingClientRect().top + document.documentElement.scrollTop + document.body.scrollTop; window.scrollTo(0,thatPoint) }) $(".prev,.next").click(function(){ var _ul = $(".choose"), len = _ul.find("li").length, slen = -((len-4)*70), ul_margin = parseInt(_ul.css("margin-left")); if(this.className=='prev'){ if(ul_margin<0){ _ul.animate({marginLeft:ul_margin+70},200) } return }else if(this.className=='next'){ if(ul_margin>slen){ _ul.animate({marginLeft:(ul_margin-70)},200) } return; } return false; }); $(".choose").find("li").not("active").click(function(){ $(".choose").find("li").removeClass("active"); $(this).addClass("active") }); }; $(function(){ //加载所有场次 getSales(); //跳转链接 $("#rule").live('click',function(){ var da ta_url=$(this).attr('da ta_url'); window.open(da ta_url,'活动规则'); }); timeFn(); })