Advertisement
Bluefissure

joke

Jul 25th, 2019
2,431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. //小轮播==================
  3. //获取接口json数据
  4. function loadData(_url,data,fn){
  5.     var url = _url+"?"+data+"&callback="+fn;
  6.     var t=document.createElement("script");
  7.     t.src=url,t.type="text/javascript",t.async=!0;
  8.     document.getElementsByTagName("head")[0].appendChild(t);
  9.     t.onload=function(){document.getElementsByTagName("head")[0].removeChild(t);}
  10. }
  11. //获取接口json数据
  12.  
  13. // banner事件
  14. loadData('http://api.act.sdo.com/UnionNews/List','gameCode=ma&category=7161&pageIndex=0&pageSize=10','handleBannerData');
  15. function handleBannerData(data){
  16.     //console.log(JSON.stringify(data));
  17.     if(data.Code=='0'&&data.TotalCount>0){
  18.         var html='';
  19.         for(var i=0;i<data.TotalCount;i++){
  20.             if(i==0){
  21.                 html+='<li class="dis">';
  22.             }else{
  23.                 html+='<li class="">';
  24.             }
  25.             if(data.Data[i].OutLink) {
  26.               html+='<a href="'+data.Data[i].OutLink+'" target="_blank"><img src="'+data.Data[i].HomeImagePath+'"></a></li>';
  27.             }else {
  28.               html+='<img src="'+data.Data[i].HomeImagePath+'"></li>';
  29.             }
  30.            
  31.         }
  32.         $("#lundiv").html(html);
  33.         bannerScroll();
  34.     }
  35. }
  36. // banner事件
  37.  
  38. function bannerScroll(){
  39.     // 定义一个信号量
  40.     var num = 0;
  41.     var len=$("#lundiv li").length;
  42.     var timer = null;
  43.     if (len == 1){
  44.       $('#lunsrol').html('');
  45.     } else {
  46.       for(i=0;i<len;i++){
  47.         $("<li></li>").appendTo("#lunsrol");
  48.       }
  49.     }
  50.    
  51.     $("#lunsrol li:first").addClass("on");
  52.     // 1 实现下方小li鼠标移上相应动画
  53.     $('.lunsrol li').mouseover(function(){
  54.       var index = $(this).index();
  55.       num = index;
  56.       $(this).addClass('on').siblings().removeClass('on');
  57.       // 下面是我们实现交叉淡入的一个原理
  58.       $('.lundiv li').eq(num).fadeIn(200).siblings().fadeOut(200);
  59.     });
  60.  
  61.     // 点击事件
  62.     $('.left').click(function(){
  63.       // 看下当前li是否正在做动画。
  64.       if( !$('.lundiv li').is(":animated") ){
  65.         num--;
  66.         if( num == -1 ){
  67.           num = len-1;
  68.         }
  69.  
  70.         $('.lunsrol li').eq(num).addClass('on').siblings().removeClass('on');
  71.         // 下面是我们实现交叉淡入的一个原理
  72.         $('.lundiv li').eq(num).fadeIn(200).siblings().fadeOut(200);
  73.       }
  74.     });
  75.  
  76.     $('.right').click(function(){
  77.       // 看下当前li是否正在做动画。
  78.       if( !$('.lundiv li').is(":animated") ){
  79.         num++;
  80.         if( num == len ){
  81.           num = 0;
  82.         }
  83.         $('.lunsrol li').eq(num).addClass('on').siblings().removeClass('on');
  84.         // 下面是我们实现交叉淡入的一个原理
  85.         $('.lundiv li').eq(num).fadeIn(200).siblings().fadeOut(200);
  86.       }
  87.     });
  88.  
  89.     // 开启定时器
  90.     timer = setInterval( autoplay,2000 );
  91.     // 封装动画
  92.     function autoplay(){
  93.       if( !$('.lundiv li').is(":animated") ){
  94.         num++;
  95.         if( num == len){
  96.           num = 0;
  97.         }
  98.         $('.lunsrol li').eq(num).addClass('on').siblings().removeClass('on');
  99.         // 下面是我们实现交叉淡入的一个原理
  100.         $('.lundiv li').eq(num).fadeIn(200).siblings().fadeOut(200);
  101.       }
  102.     }
  103.  
  104.     $('.banner').mouseover(function(){
  105.       clearInterval( timer );
  106.       // $('.lunBtn').show();
  107.     }).mouseout(function(){
  108.       timer = setInterval( autoplay,2000 );
  109.       // $('.lunBtn').hide();
  110.     });
  111.     lent();
  112. }
  113. //定位轮播下标的位置
  114. function lent(){
  115.             var numX= $("#lunsrol li").length;
  116.             var lent=-($("#lunsrol li").width()+8);
  117.             $('#lunsrol').css({'margin-left':lent})
  118.         }
  119.  
  120.  
  121. $('.mask').height($('body,html').height());
  122. //登陆选择角色
  123. $('.close_btn').click(function () {
  124.   $(this).parent().hide();
  125.   $('.mask').hide();
  126. });
  127. function isRoleName() {
  128.   var isrol = false;
  129.   if($('#LoginRoleName').html()){
  130.     isrol = true;
  131.   }else {
  132.     isrol = false;
  133.   }
  134.   return isrol;
  135. }
  136.  
  137. var ajaxUrl = "./Server/Item.ashx";
  138.  
  139. var pageAct = 1;
  140.  
  141. var Cookie = {
  142.   set: function(key, val, expiresDays){//这里传天数
  143.       //判断是否设置expiresDays
  144.       if (expiresDays){
  145.           //说明要保存Cookie有效期
  146.           var date = new Date();
  147.           date.setTime(date.getTime()+expiresDays*1*3600*1000);//这里是微秒,格式化时间
  148.           var expiresStr = "expires=" + date.toGMTString() + ';' ;
  149.       } else {
  150.           var expiresStr = '';
  151.       }
  152.       //拼接Cookie,注意大小写
  153.       document.cookie = key+'='+escape(val)+';' + expiresStr;//escape()字符串进行编码
  154.   },
  155.   get: function(key){
  156.       //Cookie存储格式:"key1=val1; key2=val2; key3=val3"
  157.       var getCookie = document.cookie.replace(/[ ]/g,'');//把[ ] 换成 ''
  158.       //通过';'分割成数组
  159.       var resArr = getCookie.split(';');
  160.       var res;
  161.       for (var i = 0; i < resArr.length; i++) {
  162.           var arr = resArr[i].split('=');
  163.           //判断传入key是否找到存储对应的val
  164.           if (arr[0] == key){
  165.               res = arr[1];
  166.               break;
  167.           }
  168.       }
  169.       return unescape(res);//解码
  170.   }
  171. }
  172.  
  173.  
  174. var cookNum = Cookie.get('ffPageNum');
  175. if(!!cookNum&&cookNum!=='undefined'){
  176.   itemlistFun(cookNum);
  177. } else {
  178.   itemlistFun(1);
  179.   Cookie.set('ffPageNum',1,1);
  180. }
  181.  
  182.  
  183. var initFlag = true;
  184. function itemlistFun(num) {
  185.   var dataPrams = "method=itemlist";
  186.   dataPrams = dataPrams + "&pageNum=" + num;
  187.   dataPrams = dataPrams + "&i=" + Math.random();
  188.   $.ajax({
  189.       type: "post",
  190.       dataType: "json",
  191.       url: ajaxUrl,
  192.       data: dataPrams,
  193.       success: function (data) {
  194.         if (data.Code == 0) {
  195.           // console.log(data);
  196.           if (initFlag) {
  197.              
  198.               $('.M-box4').pagination({
  199.                 pageCount: data.Attach.PageCount,
  200.                 coping: true,
  201.                 current:num,
  202.                 homePage: '首页',
  203.                 endPage: '末页',
  204.                 prevContent: '上页',
  205.                 nextContent: '下页',
  206.                 callback: function (api) {
  207.                   // console.log('测试当前=' + api.getCurrent())
  208.                   itemlistFun(api.getCurrent())
  209.                   Cookie.set('ffPageNum',api.getCurrent(),1);
  210.                 }
  211.             });
  212.               initFlag = false;
  213.           }
  214.           $("#shoplist").html("");
  215.           creatLiFun(data.Attach.ItemList);
  216.         } else {
  217.           // alert(data.Message);
  218.         }
  219.       }
  220.   });
  221. }
  222.  
  223.  
  224. function getCurrentDate(format) {    
  225.   var now = new Date();  
  226.   var year = now.getFullYear(); //得到年份   
  227.   var month = now.getMonth();//得到月份  
  228.   var date = now.getDate();//得到日期    
  229.   var day = now.getDay();//得到周几  
  230.   var hour = now.getHours();//得到小时   
  231.   var minu = now.getMinutes();//得到分钟     
  232.   var sec = now.getSeconds();//得到秒     
  233.   month = month + 1;     
  234.   if (month < 10) month = "0" + month;   
  235.   if (date < 10) date = "0" + date;  
  236.   if (hour < 10) hour = "0" + hour;  
  237.   if (minu < 10) minu = "0" + minu;  
  238.   if (sec < 10) sec = "0" + sec;     
  239.   var time = "";      //精确到天     
  240.   if(format==1){        time = year + "-" + month + "-" + date;   }   //精确到分     
  241.   else if(format==2){      
  242.     time = year + "/" + month + "/" + date+ " " + hour + ":" + minu + ":" + sec;     
  243.   }  
  244.   return time; 
  245. }
  246.  
  247.  
  248. // 对Date的扩展,将 Date 转化为指定格式的String
  249. // 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
  250. // 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
  251. // 例子:
  252. // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
  253. // (new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18
  254. Date.prototype.Format = function (fmt) { //author: meizz
  255.     var o = {
  256.         "M+": this.getMonth() + 1,                 //月份
  257.         "d+": this.getDate(),                    //日
  258.         "h+": this.getHours(),                   //小时
  259.         "m+": this.getMinutes(),                 //分
  260.         "s+": this.getSeconds(),                 //秒
  261.         "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  262.         "S": this.getMilliseconds()             //毫秒
  263.     };
  264.     if (/(y+)/.test(fmt))
  265.         fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  266.     for (var k in o)
  267.         if (new RegExp("(" + k + ")").test(fmt))
  268.             fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o [k] ) : (("00" + o [k] ).substr(("" + o [k] ).length)));
  269.     return fmt;
  270. }
  271.  
  272.  
  273.     // var time1 = listdata[i].CreateTime;
  274.     // var time2 = time1.replace("/Date(", "").replace(")/", ""); //先替换掉 /date( )/
  275.     // time2 = time2.split('+')[0];
  276.     // var newDate = new Date(); //转成date类型
  277.     // newDate.setTime(time2); //这步很关键
  278.     // newDate.Format("yyyy-MM-dd hh:mm:ss")
  279. function creatLiFun(ret) {
  280.   var listHtml = '';
  281.   for (var i = 0; i < ret.length; i++) {
  282.  
  283.     var ntimes = getCurrentDate(2);
  284.     var myDate = new Date(ntimes).getTime();
  285.    
  286.     var timeSta = ret[i].StartTime1.replace("/Date(", "").replace(")/", "");
  287.     var timeSta2 = ret[i].StartTime2.replace("/Date(", "").replace(")/", "");
  288.     var timeEnd = ret[i].EndTime1.replace("/Date(", "").replace(")/", "");
  289.     var timeEnd2 = ret[i].EndTime2.replace("/Date(", "").replace(")/", "");
  290.    
  291.     // var ttimexxx = ret[i].StartTime1.replace("/Date(", "").replace(")/", "");
  292.     // console.log(ttimexxx)
  293.     // console.log(myDate)
  294.  
  295.     listHtml += '<div class="sitem">';
  296.     if(ret[i].Type == 3) {
  297.       //普通商品
  298.       listHtml += '<a href="productp.html?itemid='+ ret[i].Id +'">';
  299.       if(myDate > timeEnd) {
  300.         listHtml += '<div class="tit titp titover">暂无货</div>';
  301.       } else if (myDate < timeSta) {
  302.         listHtml += '<div class="tit titp titover">敬请期待</div>';
  303.       } else {
  304.         listHtml += '<div class="tit titp">普通商品</div>';
  305.       }
  306.     }
  307.     if(ret[i].Type == 2) {
  308.       // 抽选商品
  309.      
  310.       // if (myDate < timeSta) {
  311.       //   listHtml += '<a href="javascript:;">';
  312.       // } else {
  313.       //   listHtml += '<a href="productc.html?itemid='+ ret[i].Id +'">';
  314.       // }
  315.       listHtml += '<a href="productc.html?itemid='+ ret[i].Id +'">';
  316.       if(myDate > timeEnd2) {
  317.         listHtml += '<div class="tit titc titover">暂无货</div>';
  318.       }
  319.       if (myDate > timeEnd && myDate < timeSta2) {
  320.         listHtml += '<div class="tit titc titover">抽选结束</div>';
  321.       }
  322.       if (myDate > timeSta && myDate < timeEnd) {
  323.         listHtml += '<div class="tit titc">抽选商品</div>';
  324.       }
  325.       if (myDate < timeSta) {
  326.         listHtml += '<div class="tit titc titover">敬请期待</div>';
  327.       }
  328.      
  329.     }
  330.     if(ret[i].Type == 1) {
  331.       // 预定商品
  332.      
  333.       // if (myDate < timeSta) {
  334.       //   listHtml += '<a href="javascript:;">';
  335.       // } else {
  336.       //   listHtml += '<a href="product.html?itemid='+ ret[i].Id +'">';
  337.       // }
  338.       listHtml += '<a href="product.html?itemid='+ ret[i].Id +'">';
  339.       if(myDate > timeEnd2) {
  340.         listHtml += '<div class="tit tity titover">暂无货</div>';
  341.       }
  342.       if (myDate > timeEnd && myDate < timeSta2) {
  343.         listHtml += '<div class="tit tity titover">预售结束</div>';
  344.       }
  345.       if(myDate > timeSta2 && myDate <timeEnd2) {
  346.         listHtml += '<div class="tit tity titstart">补款开启</div>';
  347.       }
  348.       if (myDate > timeSta && myDate < timeEnd) {
  349.         listHtml += '<div class="tit tity">预售商品</div>';
  350.       }
  351.       if (myDate < timeSta) {
  352.         listHtml += '<div class="tit tity titover">敬请期待</div>';
  353.       }
  354.       // listHtml += '<div class="tit tity"></div>';
  355.     }
  356.    
  357.     // if (myDate < timeSta) {
  358.     //   listHtml += '<div class="pic"><img src="'+ ret[i].Image1 +'" alt=""></div>';
  359.     //   listHtml += '<div class="name">敬请期待</div>';
  360.     // } else {
  361.     //   listHtml += '<div class="pic"><img src="'+ ret[i].Image1 +'" alt=""></div>';
  362.     //   listHtml += '<div class="name">'+ret[i].ItemName+'</div>';
  363.     // }
  364.     listHtml += '<div class="pic"><img src="'+ ret[i].Image1 +'" alt=""></div>';
  365.     listHtml += '<div class="name">'+ret[i].ItemName+'</div>';
  366.     // listHtml += '<div class="pic"><img src="'+ ret[i].Image1 +'" alt=""></div>';
  367.     // listHtml += '<div class="name">'+ret[i].ItemName+'</div>';
  368.     listHtml += '</a>';
  369.     listHtml += '</div>';
  370.   }
  371.   // for (var i = listdata.length-1; i >= 0; i--) {}
  372.   $("#shoplist").html(listHtml);
  373. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement