123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353 |
- '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 = "<span class=\"sp-dialog-head\"><span class=\"sp-dialog-tip\">温馨提示</span><span class=\"sp-dialog-close sp-closeDialog\" title=\"关闭\">×</span></span>";
- var dialogBody = "<div class=\"sp-dialog-body\">删除后不可恢复,您确认要删除吗?</div>";
- var dialogFoot = "<div class=\"sp-dialog-foot\"><input data-id=" + getDelID + " id='delDataTrue' type='button' value='确 认' class='sp-dialog-btnTrue' /><input type='button' value='取 消' class='sp-dialog-btnCancle sp-closeDialog' /></div>";
- $('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
- sp.openCenter(".sp-dialog");
- ///取消按钮
- $('.sp-closeDialog').click(function (event) {
- sp.closeCenter(".sp-dialog");
- event.preventDefault(); event.stopPropagation();
- });
- //post消息的id
- $("#delDataTrue").click(function () {
- var getid = $(this).attr("data-id");
- sp.dialoghide();
- var data = {
- zid: getid///角色编码
- };
- $http.post(apiurljs.login + "g2work/datazu/deleteByZid", { data: s4.encryptData_CBC(JSON.stringify(data)) }, 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);
- }
- });
- });
- // if (confirm('确定要删除么')) {
- // self.unit.ROLELIST.splice(index, 1);
- // self.activeRole = 0;
- // }
- }
- //上移一位
- self.moveUp = function () {
- if (sp.isval(self.edit.roleID)) {
- if (self.activeRole == 0) {
- sp.dialog("已处于最顶部,无法上移!");
- } else {
- var set_index = parseInt(self.activeRole - 1);
- var postData = {
- "zid1": self.rows[set_index].ZID,
- "zid2": self.edit.roleID
- };
- $http.post(apiurljs.login + "g2work/datazu/swapSortidByZid", { 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.activeRole = -1;
- self.getPersonData(self.unit, "0"); ///加载机构下方的人员
- } else {
- sp.dialog(res.message);
- }
- });
- }
- } else {
- sp.dialog("请先点击选择角色!");
- }
- }
- //下移一位
- self.moveDown = function () {
- if (sp.isval(self.edit.roleID)) {
- if (self.activeRole == self.rows.length - 1) {
- sp.dialog("已处于最底部,无法下移!");
- } else {
- var set_index = parseInt(self.activeRole + 1);
- var postData = {
- "zid1": self.rows[set_index].ZID,
- "zid2": self.edit.roleID
- };
- $http.post(apiurljs.login + "g2work/datazu/swapSortidByZid", { 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.activeRole = -1;
- self.getPersonData(self.unit, "0"); ///加载机构下方的人员
- } else {
- sp.dialog(res.message);
- }
- });
- }
- } else {
- sp.dialog("请先点击选择角色!");
- }
- }
- ///点击用户checkbox选中事件
- self.isSelected = function () {
- self.isSelectedAll = true;
- self.getPerson.forEach(function (itm) {
- itm.users.forEach(function (item2) {
- if (!item2.check) {
- return self.isSelectedAll = false;
- }
- })
- })
- }
- //全选
- self.isSelectedAll = false;
- self.selectAll = function () {
- if (self.isSelectedAll) {
- self.getPerson.forEach(function (itm) {
- itm.users.forEach(function (item2) {
- item2.check = true;
- })
- })
- } else {
- self.getPerson.forEach(function (itm) {
- itm.users.forEach(function (item2) {
- item2.check = false;
- })
- })
- }
- }
- //保存人员设置
- self.saveRole = function () {
- var get_checkedUser = [];
- self.getPerson.forEach(function (itm) {
- itm.users.forEach(function (item2) {
- if (item2.check) {
- get_checkedUser.push({
- "zid": self.edit.roleID,
- "userid": item2.userid
- })
- }
- });
- })
- // console.log(get_checkedUser);
- if (sp.isval(get_checkedUser)) {
- var postData = {
- "typeid": "zid",
- typevalue: self.edit.roleID,
- data: JSON.stringify(get_checkedUser)
- }
- // console.log(postData);
- $http.post(apiurljs.login + "g2work/datazu/updateDataUser", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfg)
- .success(function (obj) {
- var res = strToJson(s4.decryptData_CBC(obj.data));
- if (res.success) {
- sp.dialog(res.message);
- $timeout(function () {
- self.getPersonData(self.edit.roleID, "0");
- sp.dialoghide();
- }, 600);
- } else {
- sp.dialog(res.message);
- }
- });
- } else {
- sp.dialog("人员不能为空!");
- }
- }
- }])
- app.directive('repeatFinish', function () {
- return {
- link: function (scope) {
- if (scope.$last == true) {
- $(".tab").eq(0).addClass("active");
- }
- }
- }
- })
|