/*  list module */
app.service('ListService', ['UtilService', function(utilS){
	
}]);
app.controller('ListController', ['$scope','$timeout' , 'ListService', function($scope, $timeout, listS){
	
	$scope.ionContentScrollComplete = function(){
		console.log("ionContentScrollComplete....");
	};

	$scope.noMoreData = true;
	$scope.isLoadingMore = false;
	$scope.$on('stateChangeSuccess', function() {
		$scope.loadMoreData();
	});
	$scope.loadMoreData = function(){
		$scope.isLoadingMore = true;
		$timeout(function(){
			var data = $scope.todoListData;
			var max = data[data.length-1].RECORD_ID || 0;
				max = parseInt(max);
			/*if(max >= 17){
				$scope.noMoreData = false;
				return;
			}*/			
			for (var i = 1; i <= 50; i++) {
				var trackId = max + i;
				var newItem = {
					COMPANY_DOC_TYPE: 'loadMore - '+trackId,
					EMPLOYEE_NAME: '刘丽平',
					DOC_AMOUNT: 1,
					RECORD_ID: trackId,
					DOC_TITLE: '日常费用报销单据'
				};
				data.push(newItem);			
				$scope.$broadcast('scroll.infiniteScrollComplete');				
			};
			$scope.isLoadingMore = false;			
		}, 1000);
	};

	$scope.todoListData = [
		{
			COMPANY_DOC_TYPE: '20106-日常费用报销单据',
			EMPLOYEE_NAME: '刘丽平',
			DOC_AMOUNT: 1,
			RECORD_ID: '00001',
			DOC_TITLE: '日常费用报销单据'
		},
		{
			COMPANY_DOC_TYPE: '20106-日常费用报销单据',
			EMPLOYEE_NAME: '刘丽平',
			DOC_AMOUNT: 1,
			RECORD_ID: '00002',
			DOC_TITLE: '日常费用报销单据'
		},
		{
			COMPANY_DOC_TYPE: '20106-日常费用报销单据',
			EMPLOYEE_NAME: '刘丽平',
			DOC_AMOUNT: 1,
			RECORD_ID: '00003',
			DOC_TITLE: '日常费用报销单据'
		},
		{
			COMPANY_DOC_TYPE: '20106-日常费用报销单据',
			EMPLOYEE_NAME: '刘丽平',
			DOC_AMOUNT: 1,
			RECORD_ID: '00004',
			DOC_TITLE: '日常费用报销单据'
		},
		{
			COMPANY_DOC_TYPE: '20106-日常费用报销单据',
			EMPLOYEE_NAME: '刘丽平',
			DOC_AMOUNT: 1,
			RECORD_ID: '00005',
			DOC_TITLE: '日常费用报销单据'
		},
		{
			COMPANY_DOC_TYPE: '20106-日常费用报销单据',
			EMPLOYEE_NAME: '刘丽平',
			DOC_AMOUNT: 1,
			RECORD_ID: '00006',
			DOC_TITLE: '日常费用报销单据'
		},
		{
			COMPANY_DOC_TYPE: '20106-日常费用报销单据',
			EMPLOYEE_NAME: '刘丽平',
			DOC_AMOUNT: 1,
			RECORD_ID: '00007',
			DOC_TITLE: '日常费用报销单据'
		},
		{
			COMPANY_DOC_TYPE: '20106-日常费用报销单据',
			EMPLOYEE_NAME: '刘丽平',
			DOC_AMOUNT: 1,
			RECORD_ID: '00008',
			DOC_TITLE: '日常费用报销单据'
		},
		{
			COMPANY_DOC_TYPE: '20106-日常费用报销单据',
			EMPLOYEE_NAME: '刘丽平',
			DOC_AMOUNT: 1,
			RECORD_ID: '00009',
			DOC_TITLE: '日常费用报销单据'
		},
		{
			COMPANY_DOC_TYPE: '20106-日常费用报销单据',
			EMPLOYEE_NAME: '刘丽平',
			DOC_AMOUNT: 1,
			RECORD_ID: '00010',
			DOC_TITLE: '日常费用报销单据'
		},
		{
			COMPANY_DOC_TYPE: '20106-日常费用报销单据',
			EMPLOYEE_NAME: '刘丽平',
			DOC_AMOUNT: 1,
			RECORD_ID: '00011',
			DOC_TITLE: '日常费用报销单据'
		},
		{
			COMPANY_DOC_TYPE: '20106-日常费用报销单据',
			EMPLOYEE_NAME: '刘丽平',
			DOC_AMOUNT: 1,
			RECORD_ID: '00012',
			DOC_TITLE: '日常费用报销单据'
		},
		{
			COMPANY_DOC_TYPE: '20106-日常费用报销单据',
			EMPLOYEE_NAME: '刘丽平',
			DOC_AMOUNT: 1,
			RECORD_ID: '00013',
			DOC_TITLE: '日常费用报销单据'
		},
		{
			COMPANY_DOC_TYPE: '20106-日常费用报销单据',
			EMPLOYEE_NAME: '刘丽平',
			DOC_AMOUNT: 1,
			RECORD_ID: '00014',
			DOC_TITLE: '日常费用报销单据'
		},
		{
			COMPANY_DOC_TYPE: '20106-日常费用报销单据',
			EMPLOYEE_NAME: '刘丽平',
			DOC_AMOUNT: 1,
			RECORD_ID: '00015',
			DOC_TITLE: '日常费用报销单据'
		}
	];
	$scope.allSelected = false;
	$scope.selectAll = function(){
		for (var i = $scope.todoListData.length - 1; i >= 0; i--) {
			$scope.todoListData[i].selected = !$scope.allSelected;
		};
		$scope.allSelected = !$scope.allSelected;
	};

	$scope.listConfig = {
		listCanSwipe: true,
		shouldShowDelete: false
	};
	$scope.refresherText = "刷新页面";
	$scope.onItemDelete = function(item){

	};
	$scope.showDelete = function(){
		$scope.listConfig.shouldShowDelete = !$scope.listConfig.shouldShowDelete;

	};
	$scope.onPulling = function(abc,def,ghq){
		//$scope.refresherText = "松开刷新";
	};
	$scope.downRefresh = function(){
		$timeout( function() {
	      //Stop the ion-refresher from spinning
	      $scope.$broadcast('scroll.refreshComplete');	    
	    }, 1000);	    
	};

	$scope.init = function(){
		var data = $scope.todoListData;
		var max = data[data.length-1].RECORD_ID || 0;
		max = parseInt(max);
		/*if(max >= 17){
			$scope.noMoreData = false;
			return;
		}*/	
		for (var i = 1; i <= 100; i++) {
			var trackId = max + i;
			var newItem = {
				COMPANY_DOC_TYPE: 'loadMore - '+trackId,
				EMPLOYEE_NAME: '刘丽平',
				DOC_AMOUNT: 1,
				RECORD_ID: trackId,
				DOC_TITLE: '日常费用报销单据'
			};
			data.push(newItem);	
		}
	};

	$scope.init();

}]);