首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

秒杀记时控件

2014-01-22 
秒杀倒计时控件/** * User: yongwang * Date: 12-01-17 * Time: 上午9:54 */define(function(require,expo

秒杀倒计时控件

/** * User: yongwang * Date: 12-01-17 * Time: 上午9:54 */define(function(require,exports,module){require("../../common/utils");var Detail=require("./detail");var PatList=require("./list");function CountDown(){this.options = {//countdown元素idcountId : '',//outerCountId元素idouterCountId : '',//销售开始倒计时是否结束isSellBeginEnd : false,//销售结束倒计时是否结束isSellEndEnd : false,//销售开始时间点sellBeginTimeStemp:null,//销售结束时间点sellEndTimeStemp:null,//输入的服务器当前时间对象currStemp:null,//销售开始倒计时时间结束点 以ms为单位countDownBeginStemp:0,//ms//销售结束倒计时时间结束点 以ms为单位countDownEndStemp:0,//mstype:0,//默认倒计时   1为商品销售倒计时  autStatus:null,//出价状态  00为未出价  01为出局   02为领先minAmount:0,//当前最低价validateCodeStats:null,//验证码验证状态  0为未验证 1为验证过  activityStatus:0,//活动状态  0有效  1结束inputStatus:0,//输入状态mdseDetailJson:null,//商品详情rootPath:"",//链接根目录isDutchEnd:false,//总倒计时已经结束/** * 初始化倒计时 * @param currnt * @param end */init : function(o){this.countId = o.countId || 'CountDown';this.outerCountId = o.outerCountId||'';this.rootPath=o.rootPath||'';this.sellBeginTimeStemp=o.sellBeginTimeStemp||null;this.sellEndTimeStemp=o.sellEndTimeStemp||null;this.currStemp=o.currStemp||null;if(o.mdseDetailJson){this.mdseDetailJson=(new Function("","return "+o.mdseDetailJson))();;}if(this.currStemp){this.currStemp=HP.parseDateMilliseconds(this.currStemp);}else{console.error("传入的服务器时间不符合规则!请检查");return;}if(this.sellBeginTimeStemp){this.sellBeginTimeStemp=HP.parseDateMilliseconds(this.sellBeginTimeStemp);this.countDownBeginStemp=this.sellBeginTimeStemp- this.currStemp;}else{console.error("传入的活动开始时间不符合规则!请检查");return;}if(this.sellEndTimeStemp){this.sellEndTimeStemp=HP.parseDateMilliseconds(this.sellEndTimeStemp);if(this.sellBeginTimeStemp<this.currStemp){this.countDownEndStemp=this.sellEndTimeStemp- this.currStemp;}else{this.countDownEndStemp=this.sellEndTimeStemp- this.sellBeginTimeStemp;}}else{console.error("传入的活动结束时间不符合规则!请检查");return;}//测试//this.countDownEndStemp=0;this.type=o.type||0;this.validateCodeStats=o.validateCodeStats||0;this.autStatus=o.autStatus||"00";this._CountDownLoop();},_CountDownLoop : function(){if(this.activityStatus==1){//转向抢拍结果页Detail.gotoAuctionResult(this);}if(this.countDownBeginStemp<= 0){this.isSellBeginEnd = true;}if(this.countDownEndStemp<= 0){this.isSellEndEnd = true;}//如果结束则调用结束回调if(this.isSellBeginEnd === true){console.log('销售开始时间已经到了');if(this.isSellEndEnd===true){console.log('销售结束时间已经到了');this._renderEndEnd();return;}else{//console.log('销售结束倒计时开始');switch(this.type){case 1:this._renderSellEnd(this.countDownEndStemp);break;case 2:this._renderSellEnd(this.countDownEndStemp);break;case 3:this._renderSellEnd(this.countDownEndStemp);break;default:this._renderSellEnd(this.countDownEndStemp);break;}}}else{console.log('销售开始倒计时开始');switch(this.type){case 1:this._renderSellerGoods(this.countDownBeginStemp);break;case 2:this._renderSellerGoods(this.countDownBeginStemp);break;case 3:this._renderSellerGoods(this.countDownBeginStemp);break;default:this._renderSellerGoods(this.countDownBeginStemp);break;}                     }if(this.isDutchEnd===true){//已经完全结束return;}var that=this;requestAnimation(function(){that._CountDownLoop();});},//活动开始倒计时方法_renderSellerGoods:function(){this.countDownBeginStemp=this.countDownBeginStemp-1000;var t =this.countDownBeginStemp;//小时var remain_hour=parseInt(t/(1000*60*60));if (remain_hour < 10){remain_hour = "0" + remain_hour; }//分钟var remain_minute=parseInt((t-(remain_hour*1000*60*60))/(1000*60));if (remain_minute < 10){remain_minute = "0" + remain_minute;}//秒数var remain_sec=parseInt((t-(remain_hour*1000*60*60)-(remain_minute*1000*60))/1000);if (remain_sec < 10){remain_sec = "0" + remain_sec; }if(this.type==0){//列表页处理PatList.showListActNoCountDown(this,remain_hour,remain_minute,remain_sec);}else if(this.type==2){//详情页处理Detail.showAuctStatus(this,null);Detail.actNoInfoShow(this);Detail.showAuctStatus(this,null);//提前10分钟显示验证码输入  //根据验证码状态显示验证码输入框this.inputStatus=Detail.showValidateCodeInputBefore10Min(this);Detail.showDetailActNoCountDown(this,remain_hour,remain_minute,remain_sec);}},//活动结束倒计时调用方法_renderSellEnd:function(){this.countDownEndStemp=this.countDownEndStemp-1000;var t = this.countDownEndStemp;//小时var remain_hour=parseInt(t/(1000*60*60));if (remain_hour < 10){remain_hour = "0" + remain_hour; }//分钟var remain_minute=parseInt((t-(remain_hour*1000*60*60))/(1000*60));if (remain_minute < 10){remain_minute = "0" + remain_minute;}//秒数var remain_sec=parseInt((t-(remain_hour*1000*60*60)-(remain_minute*1000*60))/1000);if (remain_sec < 10){remain_sec = "0" + remain_sec; }if(this.type==0){//列表页处理PatList.showListActStartCountDown(this,remain_hour,remain_minute,remain_sec);//活动详情页  活动开始   出价列表}else if(this.type==2){ //type==2为详情页使用Detail.actStartInfoShow(this);//根据验证码状态显示验证码输入框Detail.showValidateCodeInput(this);Detail.showAuctStatus(this,this.autStatus);Detail.showDetailActStartCountDown(this,remain_hour,remain_minute,remain_sec);Detail.setAuctionPriceListEnable(this);}},//活动开始调用方法_renderBeginEnd:function(){this.isDutchEnd=true;//倒计时完全结束if(this.type==0){//列表页处理PatList.showListActNoEndCountDown(this);//活动详情页  活动未开始   出价列表}else if(this.type==2){//type==2为详情页使用Detail.showAuctStatus(this,null);Detail.showDetailActNoEndCountDown(this);Detail.setAuctionPriceListEnable(this);}},_renderEndEnd:function(){this.isDutchEnd=true;//倒计时完全结束if(this.type==0){//列表页处理PatList.showListActStartEndCountDown(this);//活动详情页  活动结束   }else if(this.type==2){Detail.showAuctStatus(this,null);Detail.showDetailActStartEndCountDown(this);//type==2为详情页使用  出价列表Detail.setAuctionPriceListDisable(this);}}    };};var requestAnimation = (function(callback,time){return function(callback,time) {if(time){window.setTimeout(callback, time);}else{window.setTimeout(callback, 1000);   }};})();module.exports=CountDown;});

?

热点排行