'use strict'; var app = angular.module('app', ["angularUtils.directives.dirPagination"]); app.controller("roleCtrl", ["$scope", "$http", "$compile", "$timeout", function ($scope, $http, $compile, $timeout) { var self = this; var s4 = new SM4Util(); self.userId = $.cookie("GlWorkPlatform-userid"); self.userName = $.cookie("GlWorkPlatform-username"); self.userCName = $.cookie("GlWorkPlatform-chineseName"); self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken"); self.userTypeEng = $.cookie("GlWorkPlatform-userTypeEng"); var postCfg = { headers: { 'Content-Type': 'application/json', 'Authorization': "Bearer " + self.get_AccessToken } }; self.loading = false; ///加载机构 self.unitList = []; ///数组 self.unit = ""; ///机构名称 self.getUnit = function () { self.loading = true; $http.post(apiurljs.login + "g2work/sect/querySectAdmin", { data: s4.encryptData_CBC("") }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); ///console.log(res); if (res.success) { if (sp.isval(res.data)) { self.unitList = res.data; self.unit = res.data[0].CODE; self.getRole();///根据当前第一个机构进行加载其下面的部门数据 self.getPersonData(self.unit, "0"); ///加载机构下方的人员 } else { self.unitList = []; self.loading = false; } } else { sp.dialog(res.message); self.unitList = []; self.loading = false; } }) .error(function (XMLHttpRequest, textStatus, errorThrown) { if (textStatus != 200) { self.loading = false; } }) }; self.getUnit(); self.rows = []; self.users = []; self.getRole = function () { var time1 = sp.getLocalDate(); self.activeRole = -1; self.edit = { roleID: "", roleName: "" } var postData = { unitid: self.unit } $http.post(apiurljs.login + "g2work/datazu/queryData", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); ///console.log(JSON.stringify(res)); if (res.success) { if (sp.isval(res.data)) { self.rows = res.data; } else { self.rows = []; } } else { sp.dialog(res.message); } }); } ////加载用户列表 self.getPerson = [];///声明用户列表数组 self.getPersonData = function (zid, levels) { var postData = { zid: zid,///角色id为空加载全部用户数据 levels: levels ///以几级的形式传 } $http.post(apiurljs.login + "g2work/datazu/queryDataUser", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); self.loading = false; ///console.log(JSON.stringify(res)); if (res.success) { if (sp.isval(res.data)) { self.isSelectedAll = true; self.getPerson = res.data; self.getPerson.forEach(function (itm) { itm.users.forEach(function (itm2) { if (itm2.auth == "1") { itm2.check = true; } else { itm2.check = false; self.isSelectedAll = false; //有一个未选中就是未全选 } }); }); } else { self.getPerson = []; } } else { sp.dialog(res.message); } }) .error(function (XMLHttpRequest, textStatus, errorThrown) { if (textStatus != 200) { self.loading = false; } }) }; // 点击选中角色管理事件 self.activeRole = -1; self.chooseRole = function (index, $item) { self.activeRole = index; self.edit = { roleID: $item.ZID, roleName: $item.ZUM }; self.getPersonData(self.edit.roleID, "0"); } //增加角色 self.addRoleName = ''; self.addRole = function () { ///增加角色 var postData = { unitid: self.unit,//机构编码 zum: self.addRoleName//角色名称 } $http.post(apiurljs.login + "g2work/datazu/insertData", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); if (res.success) { self.getRole(); self.addRoleName = ''; self.activeRole = -1; self.getPersonData(self.unit, "0"); ///加载机构下方的人员 sp.dialoghide(); } else { sp.dialog(res.message); } }); } //修改角色 self.edit = { roleID: "", roleName: "" } self.editRole = function () { var postData = { zid: self.edit.roleID,//角色编码 zum: self.edit.roleName//角色名称 } $http.post(apiurljs.login + "g2work/datazu/updateDataByZid", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); if (res.success) { self.getRole(); sp.dialoghide(); } else { sp.dialog(res.message); } }); } //删除角色 self.removeRole = function ($item) { var getDelID = $item.ZID; var dialogHead = "温馨提示×"; var dialogBody = "