app.controller('StdReportCtl', [ '$rootScope', '$scope', '$http', '$location', '$q', '$timeout', '$sce', '$compile', function($rootScope, $scope, $http, $location, $q, $timeout, $sce, $compile) { $scope.nextStd = undefined; $scope.auto = false;//是否自动打印 $scope.queryRet = false;//查询考生是否返回 $scope.foot_date = ""; //查询pad mac $rootScope.ajaxRequest({ url : '../std/report/padmac/fresh.htm', data : {} }, function(response) { var macArray = response.map["padMacArray"]; $scope.foot_date = response.map["foot_date"]; if (macArray) { for (var i=0; i' + short + ' '); } $("#padDiv").append($compile(' ')($scope)); } }); //回车搜索查询下一个考生 $scope.changeSearchNext = function($event) { if ($event.keyCode == 13) { $scope.searchNext(); } } //查询下一个考生 $scope.searchNext = function() { var macArr = document.getElementsByName('ipad_mac'); var macStr=""; var i; debugger; for (i=0; i 0){ macStr = macStr.substr(0, macStr.length - 1); } debugger; var ret = false; //查询考生数据 $rootScope.ajaxRequest({ url : '../std/report/next.htm', data : { cert_id : $("#cert_id").val(), ipad_mac : macStr } }, function(response) { if (response.map) { $scope.nextStd = response.map; $scope.queryRet = true; //自动打印处理 if($scope.auto) { debugger; //调用打印 $scope.print(); if (!$scope.timer) { //定时调用下一个 $scope.timer = setInterval(function() { $scope.$apply(function() { $scope.searchNext(); }); }, 5000); } } } else { if ($.trim($("#cert_id").val()) == "") { } else { alert("没有找到该身份证对应的考生."); } //没找到考生,继续轮询 $scope.searchNext(); } }); //检查考生数据是否返回 /*$scope.retVal = setInterval(function() { $scope.$apply(function() { if ($scope.queryRet) {//$scope.nextStd $scope.queryRet = false; clearTimeout($scope.retVal); //go to print //自动打印处理 if($scope.auto) { //debugger; //调用打印 $scope.print(); if (!$scope.timer) { //定时调用下一个 $scope.timer = setInterval(function() { $scope.$apply(function() { $scope.searchNext(); }); }, 5000); } } } }); }, 100);*/ } //打印 $scope.print = function() { if (!$scope.nextStd) { alert("请先搜索考生!"); return; } if ($.trim($("#cert_id").val()) != "") { $("#cert_id").val(""); } //打印窗口 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"); $scope.timer2 = setInterval(function() { $scope.$apply(function() { if (win.document.getElementById("div_print")) { clearTimeout($scope.timer2); win.document.getElementById("div_print").innerHTML = $("#main").html(); win.print2(); win.close(); //修改打印时间 $scope.updatePrintTime($scope.nextStd.cert_id); } }); }, 100); } //自动连续打印 $scope.autoPrint = function() { if(!$scope.auto) { $("#cert_id").val(""); $("#autobtn").html("正在自动打印..."); $scope.auto = true; $scope.searchNext(); } else { if ($scope.timer) { clearTimeout($scope.timer); } $("#autobtn").html("开始自动打印"); $scope.auto = false; } } //修改打印时间 $scope.updatePrintTime = function(cert_id_val) { //alert("修改已打印...."); $rootScope.ajaxRequest({ url : '../std/report/print.htm', data : { cert_id : cert_id_val } }, function(response) { }); } $timeout(function() { $('#login_name').focus(); }, 100); } ]);