var Balljump=function(e,c,t){ var _this=this; this.SX=["鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"]; this.JJ=["春","夏","秋","冬"]; this.FW=["东","南","西","北"]; this.PK3 = ["fangpian", "heitao", "hongtao", "meihua"]; this.PK3Code = ["A","1","2", "3","4","5","6","7","8","9","10","J","Q","K"]; this.ele=e; this.code=c; this.time=t; this.opts=null; this.interval = null; this.time1 = null; this.active = true; this.updateTime = function (t) { if (!_this.active) { return false; }; var t1 = new Date(t).getTime(); var t2 = new Date().getTime(); if (t2 - t1 > 0) { //setTimeout(_this.refresh, 3000); return false; }; var countdown = formatTime(t); if (countdown) { _this.addData("timebox", 0, countdown); setTimeout(function () { _this.updateTime(t) }, 1000); } else { _this.refresh(); this.time1 = new Date().getTime(); } }; this.refresh = function () { if (!_this.active) { return false; }; _this.addData("timebox", 0, "开奖中..."); _this.interval = setInterval(_this.balljump, 30); setTimeout(function () { _this.getAjax(function () { var countdown = formatTime(_this.opts.NextOpenTime); if (!countdown) { var time = new Date().getTime(); clearInterval(_this.interval); if (time - _this.time1 <= 20000) { _this.refresh(); } else { _this.getData(); this.time1 = null; _this.addData("timebox", 0, "等待开奖"); } } else { clearInterval(_this.interval); _this.getData(); this.time1 = null; _this.updateTime(_this.opts.NextOpenTime); } }) }, 5000) }; this.getAjax = function (callback) { if (!_this.active) { return false; }; $.ajax({ url: "/Template/_getKjData", type: "post", data: { lotterytype: _this.code, }, success: function (res) { var data = JSON.stringify(res); _this.opts = JSON.parse(data); if (callback) { callback(); } }, error: function (XMLHttpRequest, textStatus, errorThrown) { setTimeout(function () { _this.getAjax(callback) }, 20000); } }) }; this.getData = function () { if (!_this.active) { return false; }; var balls = []; _this.addData("qishu", 0, _this.opts.Term); if (_this.opts.LotteryType == "GP_KLPK3_ShanDong") { for (var i = 0; i < _this.opts.Details.length; i++) { _this.addData("ball-pk3", i, _this.opts.Details[i].Value); var className = _this.opts.Details[i].Label; var pk3list = _this.ele.getElementsByClassName("pk3-list")[i]; var icon = _this.ele.getElementsByClassName("icon-pk3")[i]; pk3list.className = "pk3-list " + className; icon.className = "iconfont icon-pk3 icon-" + className; } } else { if (_this.opts.RedBall || _this.opts.RedBall != null) { for (var i = 0; i < _this.opts.RedBall.length; i++) { balls.push(_this.opts.RedBall[i]); } } if (_this.opts.BlueBall || _this.opts.BlueBall != null) { for (var i = 0; i < _this.opts.BlueBall.length; i++) { balls.push(_this.opts.BlueBall[i]); } } for (var i = 0; i < balls.length; i++) { _this.addData("ball-list", i, balls[i]); } } _this.lineHeight(); }; this.balljump = function () { if (!_this.active) { return false; }; var redList = _this.ele.getElementsByClassName("red"); if (redList) { for (var i = 0; i < redList.length; i++) { _this.addData("red", i, getRandomNum(1, 33)); } _this.lineHeight(true); } var blueList = _this.ele.getElementsByClassName("blue"); if (blueList) { for (var i = 0; i < blueList.length; i++) { _this.addData("blue", i, getRandomNum(1, 16)); } _this.lineHeight(true); } var sxList = _this.ele.getElementsByClassName("shengxiao"); if (sxList) { for (var i = 0; i < sxList.length; i++) { _this.addData("shengxiao", i, _this.SX[getRandomNum(0, 11)]); } _this.lineHeight(true); } var jjList = _this.ele.getElementsByClassName("jijie"); if (jjList) { for (var i = 0; i < jjList.length; i++) { _this.addData("jijie", i, _this.JJ[getRandomNum(0, 3)]); } _this.lineHeight(true); } var fwList = _this.ele.getElementsByClassName("fangwei"); if (fwList) { for (var i = 0; i < fwList.length; i++) { _this.addData("fangwei", i, _this.FW[getRandomNum(0, 3)]); } _this.lineHeight(true); } var pk3lists = _this.ele.getElementsByClassName("pk3-list"); if (pk3lists) { for (var i = 0; i < pk3lists.length; i++) { _this.action.addData("ball-pk3", i, _this.PK3Code[getRandomNum(0, 12)]); var className = _this.PK3[getRandomNum(0, 3)]; var pk3list = _this.ele.getElementsByClassName("pk3-list")[i]; var icon = _this.ele.getElementsByClassName("icon-pk3")[i]; pk3list.className = "pk3-list " + className; icon.className = "iconfont icon-pk3 icon-" + className; } } }; this.lineHeight = function (jump) { if (!_this.active) { return false; }; var newLineheight = 30; if (jump) { newLineheight = getRandomNum(10, 50); } var balllists = _this.ele.getElementsByClassName("ball-list"); for (var i = 0; i < balllists.length; i++) { balllists[i].style.lineHeight = newLineheight + "px" } }; this.addData = function (className, i, t) { if (!_this.active) { return false; }; _this.ele.getElementsByClassName(className)[i].innerText = t; }; this.dele = function () { _this.active=false; }; _this.updateTime(_this.time); return this; }