areaListCtrl.js 12.9 KB
(function(angular) {
	function areaListCtrl($scope, reportService,$resource,commonResource, DTOptionsBuilder, DTColumnBuilder, $compile, $rootScope,Utils) {
		$scope.period = "1";
		$scope.dimension = null;
		
		//查询条件
		$scope.filter={
				
		};
		var periodType = {
			'1': '今日',
			'3': '本周',
			'5': '本月',
            '6': '上月',
			'14': '今年',
			'16': '展业至今'
		};
		$scope.dtColumns = [
            DTColumnBuilder.newColumn('period').withOption('width',80).withTitle('统计周期')
            .renderWith(function(data, type, full, oSettings) {
            	return periodType[data];
            }),
            DTColumnBuilder.newColumn('merchantName').withOption('width',160).withTitle('名称'),
            DTColumnBuilder.newColumn('insuranceadd').withOption('width',180).withTitle('新增服务订单数<div class="dt-head-ctrl"><input ng-model="insuranceadd1" max="9999999" oninput="if(value.length>7){value=value.slice(0,7)};" onkeyup="this.value=this.value.replace(!/[^\D]/g,\'\');this.value=this.value.replace(\'.\',\'\');" style="display: inline;width: 75px;" class="form-control sm xs" type="number"/> - <input ng-model="insuranceadd2" max="9999999" oninput="if(value.length>7)value=value.slice(0,7)" onkeyup="this.value=this.value.replace(!/[^\D]/g,\'\');this.value=this.value.replace(\'.\',\'\');" style="display: inline;width: 75px;" class="form-control sm xs" type="number"/></div>'),
            DTColumnBuilder.newColumn('insuranceaddrate').withOption('width',150).withTitle('新增服务订单数(环比增长率)<div class="dt-head-ctrl"><input ng-model="insuranceaddrate1" maxlength="5" onkeyup="if(this.value.match(/^[\-|\+]?\\d*$/)){}else{this.value=\'\';}" style="display: inline;width: 52px;" class="form-control sm xs" type="text"/>% - <input ng-model="insuranceaddrate2" maxlength="5" onkeyup="if(this.value.match(/^[\-|\+]?\\d*$/)){}else{this.value=\'\';}" style="display: inline;width: 52px;" class="form-control sm xs" type="text"/>%</div>'),
            DTColumnBuilder.newColumn('deviceadd').withOption('width',180).withTitle('新增设备数<div class="dt-head-ctrl"><input ng-model="deviceadd1" max="9999999" oninput="if(value.length>7)value=value.slice(0,7)" onkeyup="this.value=this.value.replace(!/[^\D]/g,\'\');this.value=this.value.replace(\'.\',\'\');" style="display: inline;width: 75px;" class="form-control sm xs" type="number"/> - <input ng-model="deviceadd2" max="9999999" oninput="if(value.length>7)value=value.slice(0,7)" onkeyup="this.value=this.value.replace(!/[^\D]/g,\'\');this.value=this.value.replace(\'.\',\'\');" style="display: inline;width: 75px;" class="form-control sm xs" type="number"/></div>'),
            DTColumnBuilder.newColumn('deviceaddrate').withOption('width',150).withTitle('新增设备数(环比增长率)<div class="dt-head-ctrl"><input ng-model="deviceaddrate1" maxlength="5" onkeyup="if(this.value.match(/^[\-|\+]?\\d*$/)){}else{this.value=\'\';}" style="display: inline;width: 52px;" class="form-control sm xs" type="text"/>% - <input ng-model="deviceaddrate2" maxlength="5" onkeyup="if(this.value.match(/^[\-|\+]?\\d*$/)){}else{this.value=\'\';}" style="display: inline;width: 52px;" class="form-control sm xs" type="text"/>%</div>'),
        	DTColumnBuilder.newColumn('appadd').withOption('width',180).withTitle('新增App绑定数<div class="dt-head-ctrl"><input ng-model="appadd1" max="9999999" oninput="if(value.length>7)value=value.slice(0,7)" onkeyup="this.value=this.value.replace(!/[^\D]/g,\'\');this.value=this.value.replace(\'.\',\'\');" style="display: inline;width: 75px;" class="form-control sm xs" type="number"/> - <input ng-model="appadd2" max="9999999" oninput="if(value.length>7)value=value.slice(0,7)" onkeyup="this.value=this.value.replace(!/[^\D]/g,\'\');this.value=this.value.replace(\'.\',\'\');" style="display: inline;width: 75px;" class="form-control sm xs" type="number"/></div>'),
            DTColumnBuilder.newColumn('appaddrate').withOption('width',170).withTitle('新增App绑定数(环比增长率)<div class="dt-head-ctrl"><input ng-model="appaddrate1"maxlength="5" onkeyup="if(this.value.match(/^[\-|\+]?\\d*$/)){}else{this.value=\'\';}" style="display: inline;width: 52px;" class="form-control sm xs" type="text"/>% - <input ng-model="appaddrate2" maxlength="5" onkeyup="if(this.value.match(/^[\-|\+]?\\d*$/)){}else{this.value=\'\';}" style="display: inline;width: 52px;" class="form-control sm xs" type="text"/>%</div>'),
            DTColumnBuilder.newColumn('deviceonlinerate').withOption('width',150).withTitle('设备在线率<div class="dt-head-ctrl"><input ng-model="deviceonlinerate1" max="9999" oninput="if(value.length>4)value=value.slice(0,4)" onkeyup="this.value=this.value.replace(!/[^\D]/g,\'\');this.value=this.value.replace(\'.\',\'\');" style="display: inline;width: 52px;" class="form-control sm xs" type="number"/>% - <input ng-model="deviceonlinerate2" max="9999" oninput="if(value.length>4)value=value.slice(0,4)" onkeyup="this.value=this.value.replace(!/[^\D]/g,\'\');this.value=this.value.replace(\'.\',\'\');" style="display: inline;width: 52px;" class="form-control sm xs" type="number"/>%</div>'),
        ];
		$scope.dtOptions = DTOptionsBuilder.newOptions()
		.withOption('id','alarmId')
		.withFixedColumns({
            leftColumns: 4,
            rightColumns: 0
        })
        .withOption('completeCb', function() {
        	//使table头部自定义内容能够绑定到当前scope
            setTimeout(function(){
            	$compile(angular.element('.dt-head-ctrl').contents())($scope);
            },0)
        });
		$scope.dtInstance = {
			serverData : reportService.regionreportqureyList
		};
		$scope.condition = getParams();
		$scope.clearNoNum = function(obj){
			//先把非数字的都替换掉,除了数字和.
			//this.value=this.value.replace(/[^\d]/g,\'\');this.value=this.value.replace(/\.{1,}/g,\'\');
			alert(obj.value);
		}
		
		//table搜索
		$scope.tableSearch = function(){
			var params = getParams();
			$scope.dtInstance.query(params)
		}
		
		//table重置
		$scope.tableReset = function(){
			$scope.period = '1';
			$scope.insuranceadd1 = '';
			$scope.insuranceadd2 = '';
			$scope.insuranceaddrate1 = '';
			$scope.insuranceaddrate2 = '';
			$scope.deviceadd1 = '';
			$scope.deviceadd2 = '';
			$scope.deviceaddrate1 = '';
			$scope.deviceaddrate2 = '';
			$scope.appadd1 = '';
			$scope.appadd2 = '';
			$scope.appaddrate1 = '';
			$scope.appaddrate2 = '';
			$scope.deviceonlinerate1 = '';
			$scope.deviceonlinerate2 = '';
			$scope.factoryMerchantId = '';
            $scope.provinceMerchantId = '';
            $scope.cityMerchantId = '';
            $scope.shopMerchantId = '';
            $scope.$broadcast("reset");
		}

		function getParams(){
			var obj = {};
			if($scope.period){
				obj.period = $scope.period;
			}else{
				obj.period = '1';
			}
			var cflag = false;
			var factoryMerchantId = $scope.factoryMerchantId;
            var provinceMerchantId = $scope.provinceMerchantId;
            var cityMerchantId = $scope.cityMerchantId;
            var shopMerchantId = $scope.shopMerchantId;
            var isSuper = $rootScope.loginUser.isSuper;
            switch ($rootScope.loginUser.merchantUserType){
            case 5:
				   if(shopMerchantId != null && shopMerchantId != '') {
					   obj.dimension = '2';
	    	           break;
				   }
				   if(cityMerchantId != null && cityMerchantId != '') {
					   obj.dimension = '2';
	    	           break;
				   }
				   if(provinceMerchantId != null && provinceMerchantId != '') {
					   obj.dimension = '3';
	    	           break;
				   }
				   if(factoryMerchantId != null && factoryMerchantId != '') {
					   obj.dimension = '4';
	    	           break;
				   }
				   //如果没有选,且是超级管理员的
				   if(isSuper) {
					   obj.dimension = '5';
				   } else {
					   obj.dimension = '4';
				   }
				   break;
			   case 4:
				   if(shopMerchantId != null && shopMerchantId != '') {
					   obj.dimension = '2';
	    	           break;
				   }
				   if(cityMerchantId != null && cityMerchantId != '') {
					   obj.dimension = '2';
	    	           break;
				   }
				   if(provinceMerchantId != null && provinceMerchantId != '') {
					   obj.dimension = '3';
	    	           break;
				   }
				   if(factoryMerchantId != null && factoryMerchantId != '') {
					   obj.dimension = '4';
	    	           break;
				   }
				   obj.dimension = '3';
				   break;
			   case 6:
				   if(shopMerchantId != null && shopMerchantId != '') {
					   obj.dimension = '2';
	    	           break;
				   }
				   if(cityMerchantId != null && cityMerchantId != '') {
					   obj.dimension = '2';
	    	           break;
				   }
				   if(provinceMerchantId != null && provinceMerchantId != '') {
					   obj.dimension = '3';
	    	           break;
				   }
				   if(factoryMerchantId != null && factoryMerchantId != '') {
					   obj.dimension = '4';
	    	           break;
				   }
				   obj.dimension = '3';
				   break;
			   case 3:
				   if(shopMerchantId != null && shopMerchantId != '') {
					   obj.dimension = '2';
	    	           break;
				   }
				   if(cityMerchantId != null && cityMerchantId != '') {
					   obj.dimension = '2';
	    	           break;
				   }
				   if(provinceMerchantId != null && provinceMerchantId != '') {
					   obj.dimension = '3';
	    	           break;
				   }
				   if(factoryMerchantId != null && factoryMerchantId != '') {
					   obj.dimension = '4';
	    	           break;
				   }
				   obj.dimension = '2';
				   break;
			   case 2:
				   if(shopMerchantId != null && shopMerchantId != '') {
					   obj.dimension = '2';
	    	           break;
				   }
				   if(cityMerchantId != null && cityMerchantId != '') {
					   obj.dimension = '2';
	    	           break;
				   }
				   if(provinceMerchantId != null && provinceMerchantId != '') {
					   obj.dimension = '3';
	    	           break;
				   }
				   if(factoryMerchantId != null && factoryMerchantId != '') {
					   obj.dimension = '4';
	    	           break;
				   }
				   obj.dimension = '2';
				   break;
			   case 1:
				   if(shopMerchantId != null && shopMerchantId != '') {
					   obj.dimension = '2';
	    	           break;
				   }
				   obj.dimension = '2';
				   break;
            }
			if(factoryMerchantId) {
				obj.factoryMerchantId = factoryMerchantId;
			}
            if(provinceMerchantId) {
            	obj.provinceMerchantId = provinceMerchantId;
            }
			if(cityMerchantId) {
				obj.cityMerchantId = cityMerchantId;
			}
			if(shopMerchantId) {
				obj.merchantId = shopMerchantId;
			}
			
			if($scope.insuranceadd1){
				obj.insuranceadd1 = $scope.insuranceadd1;
			}
			if($scope.insuranceadd2){
				obj.insuranceadd2 = $scope.insuranceadd2;
			}
			if($scope.insuranceaddrate1){
				obj.insuranceaddrate1 = $scope.insuranceaddrate1;
			}
			if($scope.insuranceaddrate2){
				obj.insuranceaddrate2 = $scope.insuranceaddrate2;
			}
			if($scope.deviceadd1){
				obj.deviceadd1 = $scope.deviceadd1;
			}
			if($scope.deviceadd2){
				obj.deviceadd2 = $scope.deviceadd2;
			}
			if($scope.deviceaddrate1){
				obj.deviceaddrate1 = $scope.deviceaddrate1;
			}
			if($scope.deviceaddrate2){
				obj.deviceaddrate2 = $scope.deviceaddrate2;
			}
			if($scope.appadd1){
				obj.appadd1 = $scope.appadd1;
			}
			if($scope.appadd2){
				obj.appadd2 = $scope.appadd2;
			}
			if($scope.appaddrate1){
				obj.appaddrate1 = $scope.appaddrate1;
			}
			if($scope.appaddrate2){
				obj.appaddrate2 = $scope.appaddrate2;
			}
			if($scope.deviceonlinerate1){
				obj.deviceonlinerate1 = $scope.deviceonlinerate1;
			}
			if($scope.deviceonlinerate2){
				obj.deviceonlinerate2 = $scope.deviceonlinerate2;
			}
			return obj;
		}

	   	$scope.exportExcel = function(){
	   		if($scope.isExporting) return;
	   		var params = getParams();
	   		var myDate = new Date();
	   		var dataFm = '' + myDate.getFullYear()+(myDate.getMonth()+1)+myDate.getDate()+'';
	   		var areaTitles = '区域报表';
	   		areaTitles = areaTitles + dataFm;
	   		if(params.period == '1') {
	   			areaTitles = areaTitles + '(今日)';
	   		} else if(params.period == '3') {
	   			areaTitles = areaTitles + '(本周)';
	   		} else if(params.period == '5') {
	   			areaTitles = areaTitles + '(本月)';
	   		} else if(params.period == '6') {
	   			areaTitles = areaTitles + '(上月)';
	   		} else if(params.period == '14') {
	   			areaTitles = areaTitles + '(今年)';
	   		} else if(params.period == '16') {
	   			areaTitles = areaTitles + '(展业至今)';
	   		} else {
	   			areaTitles = areaTitles + '(今日)';
	   		}
			//var options={
			//	url:"regionreport/exportregionreport"
			//}
			Utils.exportExcel3("regionreport/exportregionreport",params,areaTitles,'GET',function(){
				$scope.isExporting = false;
			});
			// Utils.exportExcel(options, params, function(){
			// 	$scope.$apply(function(){
            //		$scope.isExporting = false
            //	})
			// });	
	   	}
	}
	angular.module('report').controller('areaListCtrl', areaListCtrl)

})(angular);