(function(){
     angular.module("app.home")
        .controller("homeCtrl",["$scope","OptionService","UtilService","$interval","HttpService","$rootScope","ToolService","$interval",homeCtrl]);

    function homeCtrl($scope,OptionService,UtilService,$interval,HttpService,$rootScope,ToolService,$interval){
        //loading加载
        $scope.showLoading = function(){
            document.getElementById("sysLoad").style.display = "block";
        }
        $scope.hideLoading = function(){
            document.getElementById("sysLoad").style.display = "none";
        }

        $scope.Homename = UtilService.getCookie("ryioUname");
        if($scope.Homename == undefined || $scope.Homename == null){
            $scope.Homename = "";
        }
        $scope.HomeId = UtilService.getCookie("ryioUid");
        if($scope.HomeId == undefined || $scope.HomeId == null){
            $scope.HomeId = "";
        }
        $scope.Logout = function(){
            HttpService.logOutCookie();
            window.location.href = "home.html";
        }
        $scope.goSet = function(){
            UtilService.setCookie("ryioHome",true);
            window.location.href = "index.html#/manage/userinfo";
        }

        $scope.HomeDemo = function(){
            UtilService.setCookie("ryioDemoapk",'e31caee07ebedf8c172267e73204802f',7);
            window.location.href = "demo.html";
        }

        $scope.channelMoreType = true;
        $scope.clickMore = function(){
            $scope.channelMoreType = false;
        }

        $scope.isSuper = UtilService.getCookie("ryioIsSuper")=='true' || UtilService.getCookie("ryioIsSuper")==true;
        var ryioRole = UtilService.getCookie("ryioRole");
        if(ryioRole && ryioRole == '1'){ //管理员
            $scope.isManage = true;
        }

        $scope.companyMoreType = true;
        $scope.companyMore = function(){
            $scope.companyMoreType = false;
        }
        $scope.UserEmail= $.cookie("ryioUname");
        $scope.userNow = function(){
            var status = UtilService.getCookie("ryioStatus");
            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);
                        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);
                    window.location.href = "index.html#/active/product";
                }
            });
        }

        $scope.goApp = function(){
            window.location.href = "index.html#/manage/app";
        }
    }
})();
