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

    function productCtrl($scope,HttpService,ToolService,UtilService,$state,$rootScope,$interval){

        var UUser = ToolService.getUser();
        $scope.Prostatus = UUser.status;
        $scope.UserId = UUser.id;

        //判断状态
        $scope.UserEmail= UUser.email;
        $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{

                        UUser.status = data.status;
                        UUser.pastDate = data.pastDate;
                        ToolService.setUser(UUser);

                        $scope.initpage();

                        window.location.href = "index.html#/manage/app";
                    }
                }else{
                      UUser.status = data.status;
                      UUser.pastDate = data.pastDate;
                      ToolService.setUser(UUser);
                }
            });
        }
        $scope.findStatus();

    	$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;
                  UUser.status = data.status;
                  ToolService.setUser(UUser);
                }
            });
    	}
    	$scope.useTrackingIO = function(){
            $scope.initpage();
            if($rootScope.isSuper || $rootScope.isManage){
                $scope.goPage("collect.app");
            }
            else if($rootScope.isAppManage){
                $scope.goPage("collect.custommenu");
            }
    	}
    }
})();
