residenceAnalysis.js 8.07 KB
(function(angular) {
    function residenceAnalysis($scope, aiNicheService, DTOptionsBuilder, DTColumnBuilder, $compile, $rootScope, Utils, $uibModal, $filter) {
    	/**
         * 定义常量
         * */
        $scope.totalItems = 0;
        $scope.currentPage = 1;
        $scope.totalPage = '';
        $scope.maxSize = 2000;
        $scope.pageType = 0;

        $scope.displayTable = true;
        $scope.timePicked = '';
        $scope.timePick = function (timePicked) {
            this.timePicked = timePicked;
        };
        $scope.loginUserUserTypeCss='';
        if($rootScope.loginUser.merchantUserType == 2) {
        	$scope.loginUserUserTypeCss = 'display: flex;';
        } else {
        	$scope.loginUserUserTypeCss = 'display: none;';
        }
        

        $scope.ngModel = true;
        $scope.isNgModel = true;
        if($rootScope.loginUser.merchantUserType == 2) {
        	$scope.ngModel = true;
        	$scope.isNgModel = true;
        } else {
        	$scope.ngModel = false;
            $scope.isNgModel = false;
        }
        $scope.isLineXY = function () {
            if(!$scope.ngModel){
                $scope.isNgModel = false
            }else {
                $scope.isNgModel = true
            }
        };

        //常驻地标点
        var LngLat = [];
        $scope.carPermanentInfo = [];
        $scope.dtColumns = [
        	DTColumnBuilder.newColumn('name').withOption('width', '10%').withTitle('姓名'),
        	DTColumnBuilder.newColumn('standNo').withOption('width', '20%').withTitle('车架号'),
        	DTColumnBuilder.newColumn('sn').withOption('width', '20%').withTitle('设备号'),
            DTColumnBuilder.newColumn('mobile').withOption('width', '20%').withTitle('手机号'),
            DTColumnBuilder.newColumn('distance').withOption('width', '17%').withTitle('常驻地到门店距离'),
            DTColumnBuilder.newColumn('azimuthDesc').withOption('width', 101).withTitle('方位')
        ];
        $scope.dtOptions = DTOptionsBuilder.newOptions().withOption('num', true);
        $scope.dtInstance = {
            serverData: aiNicheService.getCarPermanentInfo
        };
        
        // 这边定义一个 init 方法
        $scope.umcInstance = {
            init: function () {
                //$scope.umcInstance.setMapStyle();
                $scope.umcInstance.setMapFeatures();
                var shopPoint,info;

                //点
                aiNicheService.getLngLatShop(function (response) {
                    if(response.data && response.data.lng){
                        $scope.isShop = true;
                        if($rootScope.loginUser.merchantUserType == 2) {
                        	$scope.isShop = true;
                        } else {
                        	$scope.isShop = false;
                        }
                        if($scope.isShop) {
                        	if(null != response.data.lng && null != response.data.lat) {
                            	var lngLatShopStr = response.data.lng + ","+response.data.lat;
                                shopPoint = lngLatShopStr;
                                info = response.data.store_name;
                                $scope.umcInstance.residenceCircle(shopPoint,info,$scope);
                                //drawXY()
                            }
                        }
                    }
                });

                //画点
                getHotPointInfo();
                //getCarPermanentInfoWay();

                $scope.tableSearch = function(){
                	$scope.currentPage = 1;
                	LngLat = [];
                	$scope.carPermanentInfo = [];
                    $scope.umcInstance.clearMarker();
                    getHotPointInfo();
                    var params = getParams();
                    $scope.dtInstance.query(params);
                    //$scope.doMore = new scrollLoadData();
                   // getCarPermanentInfoWay();
                };
            }
        };

        var getHotPointInfo = function () {
            var params = getParams();
            $scope.loading = true;
            aiNicheService.getHotPointInfo(params,function (res) {
                $scope.points = res.data;
                for(var i = 0; i < res.data.length; i++){
                    var thisItem = res.data[i];
                    LngLat.push(thisItem);
                }
                $scope.umcInstance.residenceMarkers(LngLat);
                $scope.loading = false;
            })
        };

        // var getCarPermanentInfoWay = function () {
        //     var paramCopy = {};
        //     var params = getParams();
        //     $scope.loading = true;
        //     angular.extend(paramCopy,  {
        //         maxSize:10
        //     });
        //     angular.extend(params, paramCopy);
        //     aiNicheService.getCarPermanentInfo(params,function(response) {
        //         $scope.totalItems = response.recordsTotal;
        //         $scope.totalPage = (response.recordsTotal/$scope.maxSize)<1?1:Math.ceil((response.recordsTotal/$scope.maxSize));
        //         for(var i = 0; i < response.data.length; i++){
        //         	var thisItem = response.data[i];
        //         	$scope.carPermanentInfo.push(thisItem);
        //         }
        //         if($scope.currentPage < $scope.totalPage) {
        //         	$scope.currentPage = $scope.currentPage + 1;
        //         	$scope.timeOutId = setTimeout(function(){
        //         		getCarPermanentInfoWay();
        //             }, 1000);
        //         } else {
        //         	clearTimeout($scope.timeOutId);
        //         }
        //         $scope.loading = false;
        //     });
        // };

        function getParams() {
            var obj = {};

            if($scope.timePicked==4){
                obj.minDistance = 0;
                obj.maxDistance = 5;
            }else if($scope.timePicked==3){
                obj.minDistance = 5;
                obj.maxDistance = 10;
            }else if($scope.timePicked==2){
                obj.minDistance = 10;
                obj.maxDistance = 20;
            }else if($scope.timePicked==1){
                obj.minDistance = 20;
                obj.maxDistance = 300;
            }
            var factoryMerchantId = $scope.factoryMerchantId;
            var provinceMerchantId = $scope.provinceMerchantId;
            var cityMerchantId = $scope.cityMerchantId;
            var shopMerchantId = $scope.shopMerchantId;
            if(factoryMerchantId) {
            	obj.factoryMerchantId = $scope.factoryMerchantId;
            }
            if(provinceMerchantId) {
            	obj.provinceMerchantId = $scope.provinceMerchantId;
            }
            if(cityMerchantId) {
            	obj.cityMerchantId = $scope.cityMerchantId;
            }
            if(shopMerchantId) {
            	obj.merchantId = $scope.shopMerchantId;
            }
            
            if($scope.minDistance){
                obj.minDistance = $scope.minDistance
            }
            if($scope.maxDistance){
                obj.maxDistance = $scope.maxDistance
            }
            //obj.currentPage = $scope.currentPage;
            // obj.maxSize = $scope.maxSize = 2000;
            // obj.pageSize = $scope.maxSize = 2000;
            return obj;
        }

        $scope.exportExcel = function () {
        	if($scope.isExporting) return;
            var params = getParams();
            $scope.isExporting = true;	
			var customerTitle = '客户热力图';
			Utils.exportExcel3("carPermanent/exportCarPermanent",params,customerTitle,'GET',function(){
				$scope.isExporting = false;
			});
			/*
            if ($scope.isExporting) return;
            var params = getParams();
            var options = {
                url: "carPermanent/exportCarPermanent"
            };
            Utils.exportExcel(options, params, function () {
                $scope.$apply(function () {
                    $scope.isExporting = false
                })
            });
            */
        };
    }

    angular.module('AIniche').controller('residenceAnalysis', residenceAnalysis)
})(angular);