lowBatteryCtrl.js 6.3 KB
(function(angular) {
	function lowBatteryCtrl($scope, reportService, DTOptionsBuilder, DTColumnBuilder, $compile) {
		$scope.dtColumns = [
            DTColumnBuilder.newColumn('workOrderNo').withOption('width',140).withTitle('申请单号<div class="dt-head-ctrl"><input ng-model="workOrderNo" class="form-control sm" type="text"/></div>'),
            DTColumnBuilder.newColumn('shopName').withOption('width',200).withTitle('店面名称<div class="dt-head-ctrl"><input ng-model="shopName" class="form-control sm" type="text"/></div>'),
            DTColumnBuilder.newColumn('name').withOption('width',200).withTitle('姓名<div class="dt-head-ctrl"><input ng-model="name" class="form-control sm" type="text"/></div>'),
            DTColumnBuilder.newColumn('standNo').withOption('width',200).withTitle('车架号<div class="dt-head-ctrl"><input ng-model="standNo" class="form-control sm" type="text"/></div>'),
            DTColumnBuilder.newColumn('sn').withOption('width',200).withTitle('设备号<div class="dt-head-ctrl"><input ng-model="sn" class="form-control sm" type="text"/></div>'),
            DTColumnBuilder.newColumn('activeTime').withOption('width',220).withTitle('激活时间<div class="dt-head-ctrl"><input date-range-picker options="drActiveTimeOptions" class="form-control date-picker" placeholder="自定义" type="text" ng-model="activeTime"/></div>'),
            DTColumnBuilder.newColumn('alarmTime').withOption('width',220).withTitle('报警时间<div class="dt-head-ctrl"><input date-range-picker options="drAlarmTimeOptions" class="form-control date-picker" placeholder="自定义" type="text" ng-model="alarmTime"/></div>'),
            DTColumnBuilder.newColumn('ectricity').withOption('width',200).withTitle('剩余电量<div class="dt-head-ctrl"><input ng-model="ectricity1" class="form-control sm xs" type="text"/>% - <input ng-model="ectricity2" class="form-control sm xs" type="text"/>%</div>'),
        ];
		$scope.dtOptions = DTOptionsBuilder.newOptions()
		.withOption('id','alarmId')
		.withFixedColumns({
            leftColumns: 5,
            rightColumns: 0
        })
        .withOption('select', {
        	type: 'checkbox'
        })
        .withOption('completeCb', function() {
        	//使table头部自定义内容能够绑定到当前scope
            setTimeout(function(){
            	$compile(angular.element('.dt-head-ctrl').contents())($scope);
            },0)
        });
        

		$scope.dtInstance = {
			serverData : reportService.getLowBatteryList
		};

		//时间选择器配置项
	   	$scope.drActiveTimeOptions = {
	   		opens: 'left',
	   		eventHandlers: {
                'apply.daterangepicker':function(ev, picker){
                	$scope.activeTime.startDate = picker.startDate;
                	$scope.activeTime.endDate = picker.endDate;
                }
            }
	   	}
	   	$scope.drAlarmTimeOptions = {
	   		opens: 'left',
	   		eventHandlers: {
                'apply.daterangepicker':function(ev, picker){
                	$scope.alarmTime.startDate = picker.startDate;
                	$scope.alarmTime.endDate = picker.endDate;
                }
            }
	   	}
	   	
	   	function exportForm(url,oParam,formId){
				$scope.isExporting = true;
				if(!formId){
					formId = 'exportForm';
				}
				if($("#"+formId).length>0){
					$("#"+formId).remove();
				}
			    var _form  =
			   		$('<form action="'+url+'" id="'+formId+'" method="get" accept-charset="utf-8"  style="display:none;">'+
				    '</form>');
			    var _input='';
			    if(!$.isEmptyObject(oParam)){
				   for(var key in oParam){
					    _input+='<input type="hidden" name="'+key+'" id="'+key+'"  value="'+(oParam[key])+'"/>';
				   }
			    }
			    _form.append(_input);
			    $('body').append(_form[0]);
			    //$("#"+formId).submit();

			    $.fileDownload(url,{
		            httpMethod: 'get',
		            data:$("#"+formId).serialize(),
		            prepareCallback:function(url){
		            	console.log(url)
		            },
		            successCallback:function(url){
		            	$scope.$apply(function(){
		            		$scope.isExporting = false
		            	})
		            },
		            failCallback: function (html, url) {
		               
		            }
		         });
		}

		//table搜索
		$scope.tableSearch = function(){
			var params = getParams();
			$scope.dtInstance.query(params)
		}
		
		//table重置
		$scope.tableReset = function(){
			$scope.workOrderNo = '';
			$scope.shopName = '';
			$scope.name = '';
			$scope.standNo = '';
			$scope.sn = '';console.log($scope.activeTime)
			if(!angular.equals({}, $scope.activeTime)){
				$scope.activeTime = {
					startDate: null,
					endDate: null
				}
			}	
			if(!angular.equals({}, $scope.alarmTime)){
				$scope.alarmTime = {
					startDate: null,
					endDate: null
				}
			}	
			$scope.ectricity1 = '';
			$scope.ectricity2 = '';
			
		}

		function getParams(){
			var obj = {};
			if($scope.workOrderNo){
				obj.workOrderNo = $scope.workOrderNo;
			}
			if($scope.shopName){
				obj.shopName = $scope.shopName;
			}
			if($scope.name){
				obj.name = $scope.name;
			}
			if($scope.standNo){
				obj.standNo = $scope.standNo;
			}
			if($scope.sn){
				obj.sn = $scope.sn;
			}
			if($scope.activeTime.startDate && $scope.activeTime.endDate){
				obj.activeTime1 = $scope.activeTime.startDate.format('YYYY-MM-DD HH:mm:ss');
				obj.activeTime2 = $scope.activeTime.endDate.endOf('day').format('YYYY-MM-DD HH:mm:ss');
			}
			if($scope.alarmTime.startDate && $scope.alarmTime.endDate){
				obj.warnStartTime1 = $scope.alarmTime.startDate.format('YYYY-MM-DD HH:mm:ss');
				obj.warnStartTime2 = $scope.alarmTime.endDate.endOf('day').format('YYYY-MM-DD HH:mm:ss');
			}
			if($scope.ectricity1){
				obj.ectricity1 = $scope.ectricity1;
			}
			if($scope.ectricity2){
				obj.ectricity2 = $scope.ectricity2;
			}
			return obj;
		}

	   	$scope.exportExcel = function(){
	   		if($scope.isExporting) return;
	   		
	   		var _selectedItems = $scope.dtInstance.getSelectItems();
			var params = {};
			if(_selectedItems.length){
				var _ids = [];
				angular.forEach(_selectedItems, function(o){
					_ids.push(o.alarmId);
				});
				params.idList = _ids.join(',');
			}else{
				params = getParams();
			}	
			exportForm('powerLowAlarm/exportPowerLowAlarm', params);		
	   	}
	}
	angular.module('report').controller('lowBatteryCtrl', lowBatteryCtrl)

})(angular);