'use strict';
angular.module('qrzk')
.controller('LoginCtrl',function($scope,appConst){
    $scope.appType = appConst.sysType;
})
.controller('RootCtrl',function($scope,$http,UserMark,$state,$location,$modal,toaster,appConst){
	$scope.menus = [];
	//设置应用标题
	$scope.appTitle = appConst.sysTitle[appConst.sysType];
	$scope.appType = appConst.sysType;
	
	$scope.load = function(){
		$http.post('user/queryCurUserRole').success(function(data){
			$scope.curUserRole = data;
			var menuUrl = 'resources/app/menu.json';
			if(data.code == 'BUSINESS_ADMIN'){
				menuUrl = 'resources/app/business_admin_menu.json';
			}else if(data.code == 'SYS_ADMIN'){
				menuUrl = 'resources/app/sys_admin_menu.json';
			}else if(data.code == 'INPUTER'){
				menuUrl = 'resources/app/inputer_menu.json';
			}else if(data.code == 'SCANNER'){
				menuUrl = 'resources/app/scanner_menu.json';
			}
			
			$http.get(menuUrl).success(function(data){
				$scope.menus = data;
			});
			
		})
		.error(function(data, code){
			alert(code);
		});
	};
	$scope.load();
	
	$scope.userMarks = UserMark.query();
	
	$scope.userMark  = {
		name:null,
		url:null
	}
	
	$scope.changePassword  = {
		password:null,
		password2:null
	}
	
	var markModal = $modal({title:'收藏本页',scope: $scope, templateUrl: 'resources/app/mark.html', show: false});
	
	$scope.showModal = function() {
		var name = $state.$current.ncyBreadcrumb?$state.$current.ncyBreadcrumb.label:'';
		$scope.userMark.name = name;
		markModal.$promise.then(markModal.show);
	};
	
	var changePasswordModal = $modal({title:'修改密码',scope: $scope, templateUrl: 'resources/app/changePassword.html', show: false});
	
	$scope.showChangePasswordModal = function() {
		changePasswordModal.$promise.then(changePasswordModal.show);
	};
	
	$scope.save = function(){
		$scope.userMark.url = $location.path();
		$scope.mark = UserMark.save($scope.userMark,function(data){
			if(data.result){
				toaster.pop('success','收藏成功！');
				$scope.userMarks = UserMark.query();
				$scope.userMark.name = null;
			}
			else{
				toaster.pop('warning','保存失败',data.msg);
			}
			markModal.hide();
		});
	};
	
	$scope.savePassword = function(){
		if($scope.changePassword.password != $scope.changePassword.password2){
			$scope.changePassword.password = null;
			$scope.changePassword.password2 = null;
			toaster.pop('error','两次输入的密码不一致。');
		}else{
			$http.post('user/changePassword', $scope.changePassword.password)
			.success(function(data){
				if(data.result){
					toaster.pop('success','更新成功！');
					$scope.changePassword.password = null;
					$scope.changePassword.password2 = null;
				}
				else{
					toaster.pop('warning','保存失败！');
				}
				changePasswordModal.hide();
			});
		}
	};
})
//批次管理//
/** 批次列表 **/
.controller('BatchTopCtrl',function($rootScope,$scope,$http,$state,$window,toaster,$cookieStore,appConst,$stateParams,$modal,FileUploader,$q,$filter){
	$scope.batchTypes = appConst.batchTypes[appConst.sysType];
	
	$scope.pageModel = {};
	$scope.pageModel.pageSize = 10;
	$scope.search = {};

	$scope.load = function(){
		_goPage(1);
	};
	$scope.load();
	
	$scope.goPage = function(pageNum){
		_goPage(pageNum);
	}
	
	function _goPage(pageNum){
		if(pageNum < 1 || (pageNum > $scope.pageModel.totalPage && $scope.pageModel.totalPage > 0)){
			return;
		}
		$scope.pageModel.curPage = pageNum;
		var params = {'page': pageNum
				, 'rows': $scope.pageModel.pageSize
				, 'keyword': $scope.search.title
				, 'type': $scope.search.type};
		
		$http.post('batch/queryBatch' , params).success(function(data){
			$scope.pageModel.array = data.rows;
			$scope.pageModel.total = data.total;
			$scope.pageModel.totalPage = Math.ceil(data.total / $scope.pageModel.pageSize);
		})
		.error(function(data, code){alert(code);});
	}
	$scope.load();

	$scope.showInfo = function(batch){
		var route = 'batch.info.';
		var bt = batch.batchType;
		if(bt == 'ENTER'){
			route+= 'ruku';
		}
		else if(bt == 'REVIEW'){
			route+= 'review';
		}
		else if(bt == 'USE'){
			route+= 'use';
		}
		else if(bt == 'SUPPLY'){
			route+= 'supply';
		}
		$state.go(route,{'id':batch.id});
	};
	//删除批次
	$scope.removeBatch = function(batchId){
		var r = $window.confirm('确定要删除吗？');
		if(r){
			$http.delete('batch/'+batchId).success(function(data){
		    	if(data.result){
		    		toaster.pop('success','删除成功！');
		    		$scope.load();
		    	}else{
		    		toaster.pop('error', data.msg);
		    	}
		    	
		    });
		}
	};
	
})

/** 新增批次 **/
.controller('BatchAddCtrl',function($scope,$http,$state,appConst,toaster){
	//$scope.batchType = BatchType.query();
	$scope.batchTypes = appConst.batchTypes[appConst.sysType];
	
	$scope.model = {};
	$scope.submit = function(){
		$scope.myPromise = $http.post('batch',$scope.model)
		.success(function(data){
			if(!data.result){
//				alert(data.msg);
				toaster.pop('error', data.msg);
			}
			else{
				$state.go('batch.top');
			}
		})
		.error(function(data,code){
			alert(code);
		});
	};
})
/** 批次信息 **/
.controller('BatchInfoCtrl',function(Batch,$scope,$http,$stateParams){
	var batchId = $stateParams.id;
	$scope.batch = Batch.get({id:batchId});
	
	/** 批次统计信息 **/
	$scope.load = function(){
		
	};
	$scope.load();
	
	
	
	
	/** 课程管理 **/
	
	/** 启用 **/
	
	/** 抽卷 **/
	
	/** 出库 **/
	
	/** 入库 **/
	
	/** 库存统计 **/
	
})
///** 批次信息：试卷信息 **/
//.controller('BatchInfoPaperCtrl',function($stateParams,$scope,$http,appConst){
//	var batchId = $stateParams.id;
//	$scope.papers = [];
//	$scope.load = function(){
//		var url = 'examPaper/queryPaper/'+batchId;
//		$http({
//	        'url' : url,
//	        'method' : 'POST',
//	        'headers': appConst.formHeaders,
//	        'data' : 'page=1&rows=9999'
//	    }).success(function(data){
//	    	$scope.papers = data.rows;
//	    });
//	};
//	
//	function test(){
//		var url = 'printtasks/taskitems/15021?printType=0&count=2';
//		$http.put(url).success(function(data){
//	    	
//	    });
//	}
//	test();
//	$scope.load();
//})
//.controller('BatchInfoBookCtrl',function($cookieStore,$scope,$http,appConst){
//	$scope.batch = $cookieStore.get('currentBatch');
//	$scope.books = [];
//	$scope.load = function(){
//		var url = 'examPaper/queryPaper/'+$scope.batch.id;
//		$http({
//	        'url' : url,
//	        'method' : 'POST',
//	        'headers': appConst.formHeaders,
//	        'data' : 'page=1&rows=9999'
//	    }).success(function(data){
//	    	$scope.papers = data.rows;
//	    });
//	};
//	$scope.load();
//})
/** 供卷 **/
.controller('BatchInfoSupplyCtrl',function($cookieStore,$scope,$http,appConst){
	$scope.batch = $cookieStore.get('currentBatch');
	$scope.courses = [];
	$scope.load = function(){
		var url = 'resources/app/supply.json';
		$http.get(url).success(function(data){
	    	$scope.courses = data;
	    });
	};
	$scope.load();
})
/** 库存统计 **/
.controller('StockCtrl',function($cookieStore,$scope,$http,appConst,$rootScope,$state,$window,toaster,$stateParams,$modal,FileUploader,$q,$filter){
	$scope.pageModel = {};
	$scope.pageModel.pageSize = 10;
	$scope.search = {};
	$scope.load = function(){
		_goPage(1);
	};
	$scope.load();
	$scope.goPage = function(pageNum){
		_goPage(pageNum);
	}
	
	function _goPage(pageNum){
		if(pageNum < 1 || (pageNum > $scope.pageModel.totalPage && $scope.pageModel.totalPage > 0)){
			return;
		}
		$scope.pageModel.curPage = pageNum;
		var params = {'page': pageNum
				, 'rows': $scope.pageModel.pageSize
				, 'keyword': $scope.search.keyword};
		$http.post('examPaper/queryStock' , params).success(function(data){
			$scope.pageModel.array = data.rows;
			$scope.pageModel.total = data.total;
			$scope.pageModel.totalPage = Math.ceil(data.total / $scope.pageModel.pageSize);
		})
		.error(function(data, code){alert(code);});
	}
//	$scope.load = function(){
//		var url = 'examPaper/queryTotal';
//		$http({
//	        'url' : url,
//	        'method' : 'POST',
//	        'headers': appConst.formHeaders,
//	        'data' : 'page=1&rows=9999'
//	    }).success(function(data){
//			$scope.array = data.rows;
//	  		$scope.total = data.total;
//		});
//	};
//	$scope.load();
})

/** 试卷检索 **/
.controller('PaperSearchCtrl',function($cookieStore,$scope,$http,appConst,$rootScope,$state,$window,toaster,$filter){
	$scope.pageModel = {};
	$scope.pageModel.pageSize = 10;
	$scope.search = {};
	var searchText;
	$scope.load = function(){
		_goPage(1);
	};
	$scope.load();
	$scope.goPage = function(pageNum){
		_goPage(pageNum);
	}
	
	function _goPage(pageNum){
		if(pageNum < 1 || (pageNum > $scope.pageModel.totalPage && $scope.pageModel.totalPage > 0)){
			return;
		}
		if($scope.search.status != null){
			if($scope.search.status == ''){
				searchText = $scope.search.keyword;
			}else if($scope.search.status == 'DRAFT'){
				searchText = 'DRAFT';
			}else if($scope.search.status == 'FORMAL'){
				searchText = 'FORMAL';
			}else if($scope.search.status == 'USED'){
				searchText = 'USED';
			}
		}else{
			searchText = $scope.search.keyword;
		}
		$scope.pageModel.curPage = pageNum;
		var params = {'page': pageNum
				, 'rows': $scope.pageModel.pageSize
				, 'keyword': searchText};
		$http.post('examPaper/paperSearch' , params).success(function(data){
			$scope.pageModel.array = data.rows;
			$scope.pageModel.total = data.total;//总页数
			$scope.pageModel.totalPage = Math.ceil(data.total / $scope.pageModel.pageSize);
		})
		.error(function(data, code){alert(code);});
	}
//	$scope.load = function(){
//		var url = 'examPaper/paperSearch';
//		$http({
//	        'url' : url,
//	        'method' : 'POST',
//	        'headers': appConst.formHeaders,
//	        'data' : 'page=1&rows=9999'
//	    }).success(function(data){
//	    	$scope.array = data.rows;
//	  		$scope.total = data.total;
//		});
//	};
//	$scope.load();
	
	$scope.savePaper = function(data,id){
		angular.extend(data, {id: id});
	    $scope.loading = $http.post('examPaper/updatePaper', data)
	    			.success(function(res){
	    				if(res.result){
//	    					alert('保存成功！');
	    					toaster.pop('success', '保存成功！');
	    				}
	    			});
	};
})
//.filter('offset', function() { 
//	return function(input, start) {
//		start = parseInt(start, 10);
//		return input.slice(start); 
//	};
//});
/** 批次信息：试卷信息 **/
.controller('RukuBatchPaperCtrl',function($cookieStore,$scope,$http,appConst,$stateParams,$window,toaster){
	$scope.papers = [];
	$scope.load = function(){
		var url = 'examPaper/getBatchPapers/'+$stateParams.id;
		$http({
	        'url' : url,
	        'method' : 'POST',
	        'headers': appConst.formHeaders,
	        'data' : 'page=1&rows=9999'
	    }).success(function(data){
	    	$scope.papers = data.rows;
	    	
	    	var uploadedZyCount = 0;
	    	var uploadedFPaperCount = 0;
	    	var uploadedWPaperCount = 0;
	    	var uploadedAnswerCount = 0;
	    	var uploadedAnswerSheetCount = 0;
	    	var isOutBoundScannedCount = 0;
	    	var isStorageScannedCount = 0;
	    	for(var i=0; i < $scope.papers.length; i++){
	    		var paper = $scope.papers[i];
	    		if(paper.zyPath != null)
	    			uploadedZyCount ++;
	    		if(paper.separatePaperPath != null)
	    			uploadedFPaperCount ++;
	    		if(paper.wPaperPath != null)
	    			uploadedWPaperCount ++;
	    		if(paper.standardAnswerPath != null)
	    			uploadedAnswerCount ++;
	    		if(paper.answerSheetPath != null)
	    			uploadedAnswerSheetCount ++;
	    		if(paper.isOutBoundScanned == 1)
	    			isOutBoundScannedCount ++;
	    		if(paper.isStorageScanned == 1)
	    			isStorageScannedCount ++;	    		
	    	}
	    	
	    	$scope.batchSummary = "该批次下：已上传 " + uploadedWPaperCount + " 套网评卷 、"
    		+ uploadedAnswerCount +" 套标答、"
    		+ uploadedFPaperCount + " 套分卷、" 
    		+ uploadedAnswerSheetCount+" 套专卡、"
    		+ uploadedZyCount + " 套转印说明。已有 " 
    		//+data.isOutBoundScannedCount+" 套试卷出库扫描 "
    		+ isStorageScannedCount+" 套试卷入库扫描。"
	    });
	};
	$scope.load();
	
	$scope.removePaper = function(row, batchId){
		var r = $window.confirm('确定要删除试卷(试卷代码：' + row.code + ')吗？');
		if(r){			
			$http.post('examPaper/deletePaper/'+batchId+"/"+row.id).success(function(data){
		    	if(data.result){
		    		toaster.pop('success', row.code +' 删除成功！');
		    		$scope.load();
		    	}else{
		    		toaster.pop('error', row.code + " " + data.msg);
		    	}
		    });
		}
	};
	
	$scope.checkOver = function(batchId){
		var r = $window.confirm('是否确定结束检查?结束检查后将会删除不符合条件的试卷信息!');
		
		if(r){
			$scope.loading = $http.post('examPaper/checkOver', {'batchId': batchId}).success(function(data){
		    	if(data.result){
		    		toaster.pop('success', data.msg);
		    		$scope.load();
		    	}
		    }).error(function(data,code){
		    	toaster.pop('error', code);
			});
		}
	};
})

/** 批次信息：试卷信息 **/
.controller('RukuPaperAddCtrl',function($cookieStore,$scope,$http,appConst,$state,$stateParams,toaster){
	$scope.model = {};
	$scope.submit = function(){
		var obj = angular.toJson($scope.model);
		$http.post('examPaper/addPaperInfo/'+$stateParams.id,$scope.model)
		.success(function(data){
			if(!data.result){
				toaster.pop('error',data.msg);
			}
			else{
				toaster.pop('success','保存成功！');
				$state.go('batch.info.ruku',{id: $stateParams.id});
			}
		})
		.error(function(data,code){
			alert(code);
		});
	};
})

/** 上传试卷文档 **/
.controller('UploadRukuPaperFilesCtrl',function($cookieStore, $scope, $http, FileUploader, $q,$stateParams,toaster){
	var uploader = $scope.uploader = new FileUploader({
        url: 'examPaper/paperUpload/' + $stateParams.id
    });
	
	$scope.upload = function() {
		$scope.loading = $q.defer().promise;
		uploader.queue[0].upload();
    };	
    
    $scope.model = {};
    uploader.onSuccessItem = function(fileItem, response, status, headers) {
    	if(response.result){
//    		alert('导入成功');
    		toaster.pop('success', '导入成功');
    	}else{
//    		alert(response.msg);
    		toaster.pop('error', response.msg);
    	}
    	$scope.model = response.data;
    };
    
    $scope.files = $scope.uploader.queue;
    
    $scope.uploader.onCompleteAll = function() {
		$scope.loading = null;
		$scope.uploader.clearQueue();
	}
})

/** 导入试卷信息DBF **/
.controller('ImportRukuPaperDBFCtrl',function($cookieStore, $scope, $http, FileUploader, $q,$stateParams,toaster){
	var uploader = $scope.uploader = new FileUploader({
        url: 'examPaper/DBFUpload/' + $stateParams.id,
        queueLimit: 1
    });
	
	$scope.upload = function() {
		$scope.loading = $q.defer().promise;
		uploader.queue[0].upload();
    };	
    
    uploader.onSuccessItem = function(fileItem, response, status, headers) {
    	$scope.errorMsg = response.errorMsg;
    	$scope.successMsg = response.successMsg;
    	$scope.existPaperCodes = response.existPaperCodes;
    	if($scope.errorMsg){
    		toaster.pop('error', $scope.errorMsg);
    	}
    };
    
    $scope.files = $scope.uploader.queue;
    
    $scope.uploader.onCompleteAll = function() {
		$scope.loading = null;
		$scope.uploader.clearQueue();
	}
})

/** 入库扫描 **/
.controller('InstorageScanCtrl',function($cookieStore,$scope,$http,appConst,$state,$stateParams){
	$scope.model = {};
	$scope.scanHistories = [];
	$scope.submit = function(){
		var obj = angular.toJson($scope.model);
		$scope.model.batchId = $stateParams.id;
		if($scope.model.code.length > 0){
			$http.post('examPaper/instorage', $scope.model)
			.success(function(data){
				$scope.paper=data.paper;
				$scope.scanHistories.unshift({'code':$scope.model.code, 'result': data.result, 'msg': data.msg});
				$scope.model.code='';
				if(data.result){
					$scope.soundSrc = 'resources/sound/scansuccess.wav';
				}else{
					$scope.soundSrc = 'resources/sound/scanfail.wav';
				}
				var audio = new Audio();
				audio.src=$scope.soundSrc;
				audio.play();
			})
			.error(function(data,code){
				alert(code);
			});
		}
		
	};
})

/** 批次信息：试卷信息 **/
.controller('ReviewBatchPaperCtrl',function($cookieStore,$scope,$http,appConst,$stateParams,$window,toaster){
	$scope.papers = [];
	$scope.load = function(){
		$http.post('examSetting/validateCodeBook').success(function(data){
			$scope.downloadPapers = data.canBackup;
		});
		
		var url = 'examPaper/getBatchPapers/'+$stateParams.id;
		$http({
	        'url' : url,
	        'method' : 'POST',
	        'headers': appConst.formHeaders,
	        'data' : 'page=1&rows=9999'
	    }).success(function(data){
	    	$scope.papers = data.rows;
	    	
	    	var uploadedZyCount = 0;
	    	var uploadedFPaperCount = 0;
	    	var uploadedWPaperCount = 0;
	    	var uploadedAnswerCount = 0;
	    	var uploadedAnswerSheetCount = 0;
	    	var isOutBoundScannedCount = 0;
	    	var isStorageScannedCount = 0;
	    	
	    	for(var i=0; i<$scope.papers.length; i++){
	    		var paper = $scope.papers[i];
	    		
	    		if(paper.isZyReturn == 1)
	    			uploadedZyCount ++;
	    		if(paper.isSeparatePaperReturn == 1)
	    			uploadedFPaperCount ++;
	    		if(paper.isWPaperReturn == 1)
	    			uploadedWPaperCount ++;
	    		if(paper.isStandadAnswerReturn == 1)
	    			uploadedAnswerCount ++;
	    		if(paper.isAnswerSheetReturn == 1)
	    			uploadedAnswerSheetCount ++;
	    		if(paper.isOutBoundScanned == 1)
	    			isOutBoundScannedCount ++;
	    		if(paper.isStorageScanned == 1)
	    			isStorageScannedCount ++;	    		
		    	
		    	$scope.batchSummary = "该批次下：已回库  "+uploadedWPaperCount+" 套网评卷、"
	    		+ uploadedAnswerCount +" 套标答、"
	    		+ uploadedAnswerSheetCount+" 套专卡、"
	    		+ uploadedFPaperCount + " 套分卷、" 
	    		+ uploadedZyCount + " 套转印说明。已有 " 
	    		+ isOutBoundScannedCount +" 套网评卷出库扫描 "
	    		+ isStorageScannedCount+" 套网评卷回库扫描。"
	    	}
	    	
	    	$scope.allOutScanned = (isOutBoundScannedCount == $scope.papers.length);
	    });
	};
	$scope.load();
	
	$scope.removePaperFromBatch = function(row, batchId){
		var params={
        		"batchId" : batchId,
        		"paperId" : row.id
        	};
		var r = $window.confirm('确定要移出试卷(试卷代码：' + row.code + ')吗？');
		if(r){
			$http.post('examPaper/removePaperFromBatch', params).success(function(data){
				if(data.result){
					toaster.pop('success', row.code + ' 移出成功！');
					$scope.load();
				}
			});
		}
	};
	
	$scope.downloadPapers = function(batchId){
		
	}
})

/** 批次信息：试卷信息 **/
.controller('ReviewBatchAddPaperCtrl',function($cookieStore,$scope,$http,appConst,$stateParams,$window,toaster){
	$scope.pageModel = {};
	$scope.pageModel.pageSize = 10;
	$scope.search = {};
	
	$scope.load = function(){
		_goPage(1);
	};
	$scope.load();
	
	$scope.goPage = function(pageNum){
		_goPage(pageNum);
	};
	
	function _goPage(pageNum){
		if(pageNum < 1 || (pageNum > $scope.pageModel.totalPage && $scope.pageModel.totalPage > 0)){
			return;
		}
		$scope.isCheckAll = false;
		$scope.pageModel.curPage = pageNum;
		
		var params = {'page': pageNum
				, 'rows': $scope.pageModel.pageSize
				, 'keyword': $scope.search.keyword
				, 'batchId': $stateParams.id};
		
		$http.post('examPaper/queryDraftPaperForReview' , params).success(function(data){
			$scope.pageModel.array = data.rows;
			$scope.pageModel.total = data.total;
			$scope.pageModel.totalPage = Math.ceil(data.total / $scope.pageModel.pageSize);
		}).error(function(data, code){alert(code);});
	}
	
	$scope.relatedPaper = function(row, batchId){
		var url = 'examPaper/addPapersToBatch';
		var params={
        		"batchId" : batchId,
        		"paperId" : row.id
        	};
		$http.post('examPaper/addPaperToBatch', params).success(function(data){
			row.isRelated = true;
			toaster.pop('success', row.code + ' 添加成功！');
	    });
	}
	
	$scope.relateSelectedPapers = function(){
		var selectedPaperIds = [];
		angular.forEach($scope.pageModel.array, function(item){
			if(item.isChecked){
				selectedPaperIds.push(item.id);
			}
		});
		var url = 'examPaper/addPapersToBatch?';
		var params = "batchId=" + $stateParams.id 
					+ "&paperIds=" + selectedPaperIds;
		
		$http.post(url + params).success(function(data){
			toaster.pop('success', '添加成功！');
			_goPage(1);
		}).error(function(data, code){alert(code);});
	}
	
	$scope.checkAll = function(){
		angular.forEach($scope.pageModel.array, function(item){
			item.isChecked = $scope.isCheckAll;
		});
	}
})

/** 清样库建设批次-出库扫描 **/
.controller('ReviewOutScanCtrl',function($cookieStore,$scope,$http,appConst,$state,$stateParams){
	$scope.model = {};
	$scope.scanHistories = [];
	$scope.submit = function(){
		var obj = angular.toJson($scope.model);
		$scope.model.batchId = $stateParams.id;
		$http.post('examPaper/outbound', $scope.model)
		.success(function(data){
			$scope.paper=data.paper;
			$scope.scanHistories.unshift({'code':$scope.model.code, 'result': data.result, 'msg': data.msg});
			$scope.model.code='';
			if(data.result){
				$scope.soundSrc = 'resources/sound/scansuccess.wav';
			}else{
				$scope.soundSrc = 'resources/sound/scanfail.wav';
			}
			var audio = new Audio();
			audio.src=$scope.soundSrc;
			audio.play();
		})
		.error(function(data,code){
			alert(code);
		});
		
	};
})

/** 上传试卷文档 **/
.controller('UploadReviewPaperFilesCtrl',function($cookieStore, $scope, $http, FileUploader, $q,$stateParams, toaster){
	var uploader = $scope.uploader = new FileUploader({
        url: 'examPaper/paperReviewedUpload/' + $stateParams.id,
        queueLimit: 1
    });
	
	$scope.upload = function() {
		$scope.loading = $q.defer().promise;
		uploader.queue[0].upload();
    };	
    
    $scope.model = {};
    uploader.onSuccessItem = function(fileItem, response, status, headers) {
    	if(response.result){
//    		alert('导入成功');
    		toaster.pop('success', '导入成功！');
    	}else{
//    		alert(response.msg);
    		toaster.pop('error', response.msg);
    	}
    	$scope.model = response.data;
    	$scope.result = response.result;
    };
    
    $scope.files = $scope.uploader.queue;
    
    $scope.uploader.onCompleteAll = function() {
		$scope.loading = null;
		$scope.uploader.clearQueue();
	}
})

/** 清样库建设批次-出库扫描 **/
.controller('ReviewInScanCtrl',function($cookieStore,$scope,$http,appConst,$state,$stateParams){
	$scope.model = {};
	$scope.scanHistories = [];
	$scope.submit = function(){
		var obj = angular.toJson($scope.model);
		$scope.model.batchId = $stateParams.id;
		$http.post('examPaper/reviewInScan', $scope.model)
		.success(function(data){
			$scope.paper=data.paper;
			$scope.scanHistories.unshift({'code':$scope.model.code, 'result': data.result, 'msg': data.msg});
			$scope.model.code='';
			if(data.result){
				$scope.soundSrc = 'resources/sound/scansuccess.wav';
			}else{
				$scope.soundSrc = 'resources/sound/scanfail.wav';
			}
			var audio = new Audio();
			audio.src=$scope.soundSrc;
			audio.play();
		})
		.error(function(data,code){
			alert(code);
		});
		
	};
})
