angular.module('push') .controller('HomeCtrl', function ($scope, UserService, HomeService, $ionicTabsDelegate, $rootScope, $timeout, $ionicSlideBoxDelegate, $ionicModal, UtilService, LoginService, ConfigService, $ionicScrollDelegate, AreaService, LocationService) { $scope.$on("$ionicView.beforeEnter", function () { if (angular.isDefined(AreaService.cityname) && AreaService.cityname.length > 0) { $scope.city = AreaService.cityname; AreaService.cityname = ""; } else { $scope.city = ConfigService.location.city; if (!UtilService.isDefined($scope.city)) { LocationService.getCurrentLocation().then(function () { console.log(ConfigService.location); }, function () { $scope.city = "全国"; }); } } if($scope.app){ $scope.setStatusBar(1); } }); $scope.tabs = [];//默认频道 $scope.categoryListOtherData = [];//推荐频道 var chooseIndex = 0;//当前频道索引 $scope.index = chooseIndex; /*当有本地频道时,与本地进行比较,存储对应索引*/ var initRecommedChannel = function (templist, channellist) { var indexlist = []; angular.forEach(templist, function (channel, index) { angular.forEach(channellist, function (data, ind) { if (data.appModuleName == channel.appModuleName) { indexlist.unshift(index); } }); }); //根据索引剔除已存在的推荐频道 angular.forEach(indexlist, function (value, key) { templist.splice(value, 1); }); $scope.categoryListOtherData = templist; }; /*获取所有频道列表*/ var initChannel = function (chatype, channellist) { HomeService.getChannelList(82).then(function (response) { if (chatype == 0) { $scope.tabs = channellist; initRecommedChannel(response.channelList, channellist); } if (chatype == 1) { $scope.tabs = channellist; initRecommedChannel(response.channelList, channellist); } if (chatype == 2) { angular.forEach(response.channelList, function (value, key) { if (value.fixType == 0) { $scope.tabs.push(value); } }); angular.forEach(response.channelList, function (value, key) { if (value.fixType == 1) { $scope.categoryListOtherData.push(value); } }); } $timeout(function () { $(".Chanel_scroll_a").eq(0).addClass("scroll_a_on").siblings().removeClass("scroll_a_on"); }, 50); $scope.doRefresh(); }, function () { $scope.tabs = channellist; }); }; if (ConfigService.islogin && UtilService.isDefined(ConfigService.mychannellist) && ConfigService.mychannellist.length > 0) { //登录后且有我的频道信息 initChannel(0, ConfigService.mychannellist); } else { //未登录或没有我的频道,取本地频道信息 var localchannel = JSON.parse(localStorage.getItem("localchannel")); if (UtilService.isDefined(localchannel) && localchannel.length > 0) { initChannel(1, localchannel); } else { //初始化频道信息 initChannel(2, []); } } $scope.editaction = "编辑"; //长按显示已选频道的删选框; $scope.onHold = function () { $scope.myChannel = true; $scope.editaction = "完成"; }; //频道编辑完成删除框隐藏; $scope.editaAction = function () { if ($scope.editaction == "编辑") { $scope.myChannel = true; $scope.editaction = "完成"; } else { $scope.myChannel = false; $scope.editaction = "编辑"; } }; var editSlide = function (index) { var tablength = $scope.tabs.length;//标题个数 var middlewidth = $(window).width() / 2;//获取当前手机屏幕宽度一般 var OffLeft = $(".Chanel_scroll_a").eq(index).offset().left;//获取当前点击标题距离父容器左边框的距离 var SelfWidth = $(".Chanel_scroll_a").eq(index).width();//获取当前点击标题宽度 var startTranform = $("#p_Chanel .scroll").offset().left; var movewidth = OffLeft - middlewidth + SelfWidth / 2; startTranform -= movewidth; if (startTranform <= 0) { if (index < tablength - 2) { $('#p_Chanel .scroll').css({ 'transform': 'translate3d(' + startTranform + 'px,0,0)' }); } } else if (index < 4) { $('#p_Chanel .scroll').css({ 'transform': 'translate3d(0,0,0)' }); } $(".Chanel_scroll_a").eq(index).addClass("scroll_a_on").siblings().removeClass("scroll_a_on"); }; $scope.clickTab = function (index) { if (index == chooseIndex) { return; } // chooseIndex = index; // $scope.index = chooseIndex; // editSlide(index); // $scope.doRefresh(); $ionicSlideBoxDelegate.slide(index); }; //滑动频道 $scope.slideChanged = function (index) { chooseIndex = index; editSlide(index); $(".Chanel_scroll_a").eq(index).addClass("scroll_a_on").siblings().removeClass("scroll_a_on"); $scope.index = chooseIndex; $scope.doRefresh(); }; $scope.doRefresh = function () { $scope.tabs[chooseIndex].isload = false; //加载动画Loading if ($scope.updataversion != "block") { $scope.showLoadingToast(); } HomeService.getClassify($scope.tabs[chooseIndex], "", $scope.city).then(function (response) { // console.log(response.tngou); //第一次刷新完成,更新当前页数、数据 $scope.tabs[chooseIndex].currentPage = 2; $scope.tabs[chooseIndex].items = response.tngou; var trHtml = "