(function ($ang, win) { 'use strict'; $ang.module('gtPartyApp', []) .controller('detailController', function ($scope, $http) { $scope.is = false; $scope.sysName = ""; var url = location.search //获取url中"?"符后的字串 ('?modFlag=business&role=1') var theRequest = new Object() if (url.indexOf('?') != -1) { var str = url.substr(1) //substr()方法返回从参数值开始到结束的字符串; var strs = str.split('&') for (var i = 0; i < strs.length; i++) { theRequest[strs[i].split('=')[0]] = strs[i].split('=')[1] } } $scope.clearFlag = 1; $scope.moduleid = theRequest.moduleid; $scope.childmoduleid = theRequest.childmoduleid; $scope.selectdata = {pageindex: 1, pagesize: 15, ptotal: 0}; $scope.modulename = ''; $scope.menuLists = []; $scope.clearNum = function(){ if ($scope.clearFlag == 1){ $scope.clearFlag == 0; }else { $scope.clearFlag == 1; } } $scope.getHomeUrl=function(){ $http.get("../../api/news/GetHomeUrl", {} ).then(function (res) { $scope.homeUrl=res.data.item; }); }; $scope.getHomeUrl(); //加载所有的父菜单记录 $scope.getMenuList = function () { $http.get("../../api/news/moduleList", { params: { 'modulename': $scope.modulename, 'pageindex': $scope.selectdata.pageindex, 'pagesize': $scope.selectdata.pagesize } }).then(function (value) { $scope.menuLists = value.data.item.list; $scope.selectdata.total = value.data.item.total; }, function (reason) { console.log(reason); }); $http ({ method: 'get', url: '../../api/news/sysName', params: { } }).then(function (result) { $scope.sysName=result.data.item; }, function (resp) { $scope.showMsg('错误', '服务器错误'); }) }; //根据当前项的menuID找到其所有的子菜单 $scope.getMenuByParentID = function (item) { if ($scope.clearFlag == 1){ $http.get("../../api/news/getmoduleList", { params: { 'parentModuleId': item.moduleid, pageindex : 1, pagesize : 999 } }).then(function (result) { item.childMenus = result.data.item.list; }, function (reason) { console.log("无匹配项"); }); } }; //加载单个菜单 $scope.getSingleMenu = function () { $http.get("../../api/news/getModule", { params: { 'moduleId': $scope.moduleid, } }).then(function (value) { $scope.menuInfo = value.data.item; }, function (reason) { console.log(reason); }); }; //获取需要展示的菜单 $scope.getShowMenuByParentID = function () { $http.get("../../api/news/getmoduleList", { params: { 'parentModuleId': $scope.moduleid, pageindex: 1, pagesize: 999 } }).then(function (result) { $scope.showModuleList = result.data.item.list.filter(it=>it.moduleid==$scope.childmoduleid); angular.forEach($scope.showModuleList, function (module, index, objs) { $scope.getNewsList(module); }); }, function (reason) { console.log("无匹配项"); }); }; $scope.getNewsList = function (item) { $http ({ method: 'get', url: '../../api/news/newsList', params: { moduleId: item.moduleid, pageindex: 1, pagesize: 999 } }).then(function (result) { item.newsList = result.data.item.list; }, function (resp) { $scope.showMsg('错误', '服务器错误'); }) } $scope.loadData = function () { $scope.getMenuList(); $scope.getSingleMenu(); $scope.getShowMenuByParentID(); } $scope.loadData(); }); })(angular, this);