report.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. app.controller('StdReportCtl', [ '$rootScope', '$scope', '$http', '$location', '$q', '$timeout', '$sce', '$compile', function($rootScope, $scope, $http, $location, $q, $timeout, $sce, $compile) {
  2. $scope.nextStd = undefined;
  3. $scope.auto = false;//是否自动打印
  4. $scope.queryRet = false;//查询考生是否返回
  5. $scope.foot_date = "";
  6. //查询pad mac
  7. $rootScope.ajaxRequest({
  8. url : '../std/report/padmac/fresh.htm',
  9. data : {}
  10. }, function(response) {
  11. var macArray = response.map["padMacArray"];
  12. $scope.foot_date = response.map["foot_date"];
  13. if (macArray) {
  14. for (var i=0; i<macArray.length; i++) {
  15. var padmac = macArray[i].ipad_mac;
  16. var short = padmac.substring(0,4);
  17. $("#padDiv").append('<input type="checkbox" name="ipad_mac" value="'+ padmac +'">' + short + '&nbsp;');
  18. }
  19. $("#padDiv").append($compile('<button id="autobtn" ng-click="autoPrint();" style="height: 30px; width:150px;"><span>开始自动打印</span></button>&nbsp;')($scope));
  20. }
  21. });
  22. //回车搜索查询下一个考生
  23. $scope.changeSearchNext = function($event) {
  24. if ($event.keyCode == 13) {
  25. $scope.searchNext();
  26. }
  27. }
  28. //查询下一个考生
  29. $scope.searchNext = function() {
  30. var macArr = document.getElementsByName('ipad_mac');
  31. var macStr="";
  32. var i;
  33. debugger;
  34. for (i=0; i<macArr.length; i++) {
  35. if (macArr[i].checked) {
  36. macStr = macStr + "'" + macArr[i].value + "',";
  37. }
  38. }
  39. if (macArr.length > 0){
  40. macStr = macStr.substr(0, macStr.length - 1);
  41. }
  42. debugger;
  43. var ret = false;
  44. //查询考生数据
  45. $rootScope.ajaxRequest({
  46. url : '../std/report/next.htm',
  47. data : {
  48. cert_id : $("#cert_id").val(),
  49. ipad_mac : macStr
  50. }
  51. }, function(response) {
  52. if (response.map) {
  53. $scope.nextStd = response.map;
  54. $scope.queryRet = true;
  55. //自动打印处理
  56. if($scope.auto) {
  57. debugger;
  58. //调用打印
  59. $scope.print();
  60. if (!$scope.timer) {
  61. //定时调用下一个
  62. $scope.timer = setInterval(function() {
  63. $scope.$apply(function() {
  64. $scope.searchNext();
  65. });
  66. }, 5000);
  67. }
  68. }
  69. } else {
  70. if ($.trim($("#cert_id").val()) == "") {
  71. } else {
  72. alert("没有找到该身份证对应的考生.");
  73. }
  74. //没找到考生,继续轮询
  75. $scope.searchNext();
  76. }
  77. });
  78. //检查考生数据是否返回
  79. /*$scope.retVal = setInterval(function() {
  80. $scope.$apply(function() {
  81. if ($scope.queryRet) {//$scope.nextStd
  82. $scope.queryRet = false;
  83. clearTimeout($scope.retVal);
  84. //go to print
  85. //自动打印处理
  86. if($scope.auto) {
  87. //debugger;
  88. //调用打印
  89. $scope.print();
  90. if (!$scope.timer) {
  91. //定时调用下一个
  92. $scope.timer = setInterval(function() {
  93. $scope.$apply(function() {
  94. $scope.searchNext();
  95. });
  96. }, 5000);
  97. }
  98. }
  99. }
  100. });
  101. }, 100);*/
  102. }
  103. //打印
  104. $scope.print = function() {
  105. if (!$scope.nextStd) {
  106. alert("请先搜索考生!");
  107. return;
  108. }
  109. if ($.trim($("#cert_id").val()) != "") {
  110. $("#cert_id").val("");
  111. }
  112. //打印窗口
  113. var win = window.open("print.html", null, " height=600,width=850, Left=300px,Top=20px, menubar=no,titlebar=no,scrollbar=no,toolbar=no, status=no,location=no");
  114. $scope.timer2 = setInterval(function() {
  115. $scope.$apply(function() {
  116. if (win.document.getElementById("div_print")) {
  117. clearTimeout($scope.timer2);
  118. win.document.getElementById("div_print").innerHTML = $("#main").html();
  119. win.print2();
  120. win.close();
  121. //修改打印时间
  122. $scope.updatePrintTime($scope.nextStd.cert_id);
  123. }
  124. });
  125. }, 100);
  126. }
  127. //自动连续打印
  128. $scope.autoPrint = function() {
  129. if(!$scope.auto) {
  130. $("#cert_id").val("");
  131. $("#autobtn").html("正在自动打印...");
  132. $scope.auto = true;
  133. $scope.searchNext();
  134. } else {
  135. if ($scope.timer) {
  136. clearTimeout($scope.timer);
  137. }
  138. $("#autobtn").html("开始自动打印");
  139. $scope.auto = false;
  140. }
  141. }
  142. //修改打印时间
  143. $scope.updatePrintTime = function(cert_id_val) {
  144. //alert("修改已打印....");
  145. $rootScope.ajaxRequest({
  146. url : '../std/report/print.htm',
  147. data : {
  148. cert_id : cert_id_val
  149. }
  150. }, function(response) {
  151. });
  152. }
  153. $timeout(function() {
  154. $('#login_name').focus();
  155. }, 100);
  156. } ]);