(function(){
    angular.module("app.active")
        .controller("productCtrl",["$scope","HttpService","ToolService","UtilService","$state","$rootScope","$interval",productCtrl])

    function productCtrl($scope,HttpService,ToolService,UtilService,$state,$rootScope,$interval){
        $scope.Prostatus = UtilService.getCookie("ryioStatus");
        $scope.UserId = UtilService.getCookie("ryioUid");

        //判断状态
        $scope.UserEmail= $.cookie("ryioUname");
        $scope.findStatus = function(){
            var statusPM = HttpService.getInfo("reged/findbyemail?email="+$scope.UserEmail);
            ToolService.showLoading();
            statusPM.then(function(data){
                ToolService.hideLoading();
                if(data.status == 1){
                    if(data.appSize == 0 && data.isChannelPerson == true){
                        ToolService.showTips("没有控制权限");
                        $scope.time= 2000;
                        $one_minute = $interval(function(){
                            $scope.time -= 1000;
                            if($scope.time == 0){
                                window.location.href = "login.html";
                            }
                        },1000);
                    }else{
                        UtilService.setCookie("ryioStatus",data.status,7);
                        UtilService.setCookie("ryioPastDate",data.pastDate,7);
                        $scope.initpage();
                        // if(data.isSuperUser == true){
                        //     window.location.href = "index.html#/manage/app";
                        // }else{
                        window.location.href = "index.html";
                        // }
                    }
                }else{
                    UtilService.setCookie("ryioStatus",data.status,7);
                    UtilService.setCookie("ryioPastDate",data.pastDate,7);
                }
            });
        }
        $scope.findStatus();

        /*if($scope.Prostatus == 1){
            $scope.initpage();
            if($rootScope.isSuper){
                $scope.goPage("collect.app");
            }
        }*/

    	$scope.postApply = function(){
    		var savePM = HttpService.getInfo("reged/verify/"+$scope.UserId);
            ToolService.showLoading();
            savePM.then(function(data){
                ToolService.hideLoading();
                if(data.status == -1){
                	$scope.Prostatus = -1;
                	UtilService.setCookie("ryioStatus",data.status,7);
                }
            });
    	}
    	$scope.useTrackingIO = function(){
            $scope.initpage();
            if($rootScope.isSuper || $rootScope.isManage){
                $scope.goPage("collect.app");
            }
            else if($rootScope.isAppManage){
                $scope.goPage("collect.custommenu");
            }
    	}
    }
})();
