balljump.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. var Balljump=function(e,c,t){
  2. var _this=this;
  3. this.SX=["鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"];
  4. this.JJ=["春","夏","秋","冬"];
  5. this.FW=["东","南","西","北"];
  6. this.PK3 = ["fangpian", "heitao", "hongtao", "meihua"];
  7. this.PK3Code = ["A","1","2", "3","4","5","6","7","8","9","10","J","Q","K"];
  8. this.ele=e;
  9. this.code=c;
  10. this.time=t;
  11. this.opts=null;
  12. this.interval = null;
  13. this.time1 = null;
  14. this.active = true;
  15. this.updateTime = function (t) {
  16. if (!_this.active) {
  17. return false;
  18. };
  19. var t1 = new Date(t).getTime();
  20. var t2 = new Date().getTime();
  21. if (t2 - t1 > 0) {
  22. //setTimeout(_this.refresh, 3000);
  23. return false;
  24. };
  25. var countdown = formatTime(t);
  26. if (countdown) {
  27. _this.addData("timebox", 0, countdown);
  28. setTimeout(function () { _this.updateTime(t) }, 1000);
  29. }
  30. else {
  31. _this.refresh();
  32. this.time1 = new Date().getTime();
  33. }
  34. };
  35. this.refresh = function () {
  36. if (!_this.active) {
  37. return false;
  38. };
  39. _this.addData("timebox", 0, "开奖中...");
  40. _this.interval = setInterval(_this.balljump, 30);
  41. setTimeout(function () {
  42. _this.getAjax(function () {
  43. var countdown = formatTime(_this.opts.NextOpenTime);
  44. if (!countdown) {
  45. var time = new Date().getTime();
  46. clearInterval(_this.interval);
  47. if (time - _this.time1 <= 20000) {
  48. _this.refresh();
  49. }
  50. else {
  51. _this.getData();
  52. this.time1 = null;
  53. _this.addData("timebox", 0, "等待开奖");
  54. }
  55. }
  56. else {
  57. clearInterval(_this.interval);
  58. _this.getData();
  59. this.time1 = null;
  60. _this.updateTime(_this.opts.NextOpenTime);
  61. }
  62. })
  63. }, 5000)
  64. };
  65. this.getAjax = function (callback) {
  66. if (!_this.active) {
  67. return false;
  68. };
  69. $.ajax({
  70. url: "/Template/_getKjData",
  71. type: "post",
  72. data: {
  73. lotterytype: _this.code,
  74. },
  75. success: function (res) {
  76. var data = JSON.stringify(res);
  77. _this.opts = JSON.parse(data);
  78. if (callback) {
  79. callback();
  80. }
  81. },
  82. error: function (XMLHttpRequest, textStatus, errorThrown) {
  83. setTimeout(function () { _this.getAjax(callback) }, 20000);
  84. }
  85. })
  86. };
  87. this.getData = function () {
  88. if (!_this.active) {
  89. return false;
  90. };
  91. var balls = [];
  92. _this.addData("qishu", 0, _this.opts.Term);
  93. if (_this.opts.LotteryType == "GP_KLPK3_ShanDong") {
  94. for (var i = 0; i < _this.opts.Details.length; i++) {
  95. _this.addData("ball-pk3", i, _this.opts.Details[i].Value);
  96. var className = _this.opts.Details[i].Label;
  97. var pk3list = _this.ele.getElementsByClassName("pk3-list")[i];
  98. var icon = _this.ele.getElementsByClassName("icon-pk3")[i];
  99. pk3list.className = "pk3-list " + className;
  100. icon.className = "iconfont icon-pk3 icon-" + className;
  101. }
  102. }
  103. else {
  104. if (_this.opts.RedBall || _this.opts.RedBall != null) {
  105. for (var i = 0; i < _this.opts.RedBall.length; i++) {
  106. balls.push(_this.opts.RedBall[i]);
  107. }
  108. }
  109. if (_this.opts.BlueBall || _this.opts.BlueBall != null) {
  110. for (var i = 0; i < _this.opts.BlueBall.length; i++) {
  111. balls.push(_this.opts.BlueBall[i]);
  112. }
  113. }
  114. for (var i = 0; i < balls.length; i++) {
  115. _this.addData("ball-list", i, balls[i]);
  116. }
  117. }
  118. _this.lineHeight();
  119. };
  120. this.balljump = function () {
  121. if (!_this.active) {
  122. return false;
  123. };
  124. var redList = _this.ele.getElementsByClassName("red");
  125. if (redList) {
  126. for (var i = 0; i < redList.length; i++) {
  127. _this.addData("red", i, getRandomNum(1, 33));
  128. }
  129. _this.lineHeight(true);
  130. }
  131. var blueList = _this.ele.getElementsByClassName("blue");
  132. if (blueList) {
  133. for (var i = 0; i < blueList.length; i++) {
  134. _this.addData("blue", i, getRandomNum(1, 16));
  135. }
  136. _this.lineHeight(true);
  137. }
  138. var sxList = _this.ele.getElementsByClassName("shengxiao");
  139. if (sxList) {
  140. for (var i = 0; i < sxList.length; i++) {
  141. _this.addData("shengxiao", i, _this.SX[getRandomNum(0, 11)]);
  142. }
  143. _this.lineHeight(true);
  144. }
  145. var jjList = _this.ele.getElementsByClassName("jijie");
  146. if (jjList) {
  147. for (var i = 0; i < jjList.length; i++) {
  148. _this.addData("jijie", i, _this.JJ[getRandomNum(0, 3)]);
  149. }
  150. _this.lineHeight(true);
  151. }
  152. var fwList = _this.ele.getElementsByClassName("fangwei");
  153. if (fwList) {
  154. for (var i = 0; i < fwList.length; i++) {
  155. _this.addData("fangwei", i, _this.FW[getRandomNum(0, 3)]);
  156. }
  157. _this.lineHeight(true);
  158. }
  159. var pk3lists = _this.ele.getElementsByClassName("pk3-list");
  160. if (pk3lists) {
  161. for (var i = 0; i < pk3lists.length; i++) {
  162. _this.action.addData("ball-pk3", i, _this.PK3Code[getRandomNum(0, 12)]);
  163. var className = _this.PK3[getRandomNum(0, 3)];
  164. var pk3list = _this.ele.getElementsByClassName("pk3-list")[i];
  165. var icon = _this.ele.getElementsByClassName("icon-pk3")[i];
  166. pk3list.className = "pk3-list " + className;
  167. icon.className = "iconfont icon-pk3 icon-" + className;
  168. }
  169. }
  170. };
  171. this.lineHeight = function (jump) {
  172. if (!_this.active) {
  173. return false;
  174. };
  175. var newLineheight = 30;
  176. if (jump) {
  177. newLineheight = getRandomNum(10, 50);
  178. }
  179. var balllists = _this.ele.getElementsByClassName("ball-list");
  180. for (var i = 0; i < balllists.length; i++) {
  181. balllists[i].style.lineHeight = newLineheight + "px"
  182. }
  183. };
  184. this.addData = function (className, i, t) {
  185. if (!_this.active) {
  186. return false;
  187. };
  188. _this.ele.getElementsByClassName(className)[i].innerText = t;
  189. };
  190. this.dele = function () {
  191. _this.active=false;
  192. };
  193. _this.updateTime(_this.time);
  194. return this;
  195. }