index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. 'use strict';
  2. var app = angular.module('app', ["angularUtils.directives.dirPagination"]);
  3. app.controller("roleCtrl", ["$scope", "$http", "$compile", "$timeout", function ($scope, $http, $compile, $timeout) {
  4. var self = this;
  5. var s4 = new SM4Util();
  6. self.userId = $.cookie("GlWorkPlatform-userid");
  7. self.userName = $.cookie("GlWorkPlatform-username");
  8. self.userCName = $.cookie("GlWorkPlatform-chineseName");
  9. self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
  10. self.userTypeEng = $.cookie("GlWorkPlatform-userTypeEng");
  11. var postCfg = {
  12. headers: {
  13. 'Content-Type': 'application/json',
  14. 'Authorization': "Bearer " + self.get_AccessToken
  15. }
  16. };
  17. self.loading = false;
  18. ///加载机构
  19. self.unitList = []; ///数组
  20. self.unit = ""; ///机构名称
  21. self.getUnit = function () {
  22. self.loading = true;
  23. $http.post(apiurljs.login + "g2work/sect/querySectAdmin", { data: s4.encryptData_CBC("") }, postCfg)
  24. .success(function (obj) {
  25. var res = strToJson(s4.decryptData_CBC(obj.data));
  26. ///console.log(res);
  27. if (res.success) {
  28. if (sp.isval(res.data)) {
  29. self.unitList = res.data;
  30. self.unit = res.data[0].CODE;
  31. self.getRole();///根据当前第一个机构进行加载其下面的部门数据
  32. self.getPersonData(self.unit, "0"); ///加载机构下方的人员
  33. } else {
  34. self.unitList = [];
  35. self.loading = false;
  36. }
  37. } else {
  38. sp.dialog(res.message);
  39. self.unitList = [];
  40. self.loading = false;
  41. }
  42. })
  43. .error(function (XMLHttpRequest, textStatus, errorThrown) {
  44. if (textStatus != 200) {
  45. self.loading = false;
  46. }
  47. })
  48. };
  49. self.getUnit();
  50. self.rows = [];
  51. self.users = [];
  52. self.getRole = function () {
  53. var time1 = sp.getLocalDate();
  54. self.activeRole = -1;
  55. self.edit = {
  56. roleID: "",
  57. roleName: ""
  58. }
  59. var postData = {
  60. unitid: self.unit
  61. }
  62. $http.post(apiurljs.login + "g2work/datazu/queryData", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfg)
  63. .success(function (obj) {
  64. var res = strToJson(s4.decryptData_CBC(obj.data));
  65. ///console.log(JSON.stringify(res));
  66. if (res.success) {
  67. if (sp.isval(res.data)) {
  68. self.rows = res.data;
  69. } else {
  70. self.rows = [];
  71. }
  72. } else {
  73. sp.dialog(res.message);
  74. }
  75. });
  76. }
  77. ////加载用户列表
  78. self.getPerson = [];///声明用户列表数组
  79. self.getPersonData = function (zid, levels) {
  80. var postData = {
  81. zid: zid,///角色id为空加载全部用户数据
  82. levels: levels ///以几级的形式传
  83. }
  84. $http.post(apiurljs.login + "g2work/datazu/queryDataUser", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfg)
  85. .success(function (obj) {
  86. var res = strToJson(s4.decryptData_CBC(obj.data));
  87. self.loading = false;
  88. ///console.log(JSON.stringify(res));
  89. if (res.success) {
  90. if (sp.isval(res.data)) {
  91. self.isSelectedAll = true;
  92. self.getPerson = res.data;
  93. self.getPerson.forEach(function (itm) {
  94. itm.users.forEach(function (itm2) {
  95. if (itm2.auth == "1") {
  96. itm2.check = true;
  97. } else {
  98. itm2.check = false;
  99. self.isSelectedAll = false; //有一个未选中就是未全选
  100. }
  101. });
  102. });
  103. } else {
  104. self.getPerson = [];
  105. }
  106. } else {
  107. sp.dialog(res.message);
  108. }
  109. })
  110. .error(function (XMLHttpRequest, textStatus, errorThrown) {
  111. if (textStatus != 200) {
  112. self.loading = false;
  113. }
  114. })
  115. };
  116. // 点击选中角色管理事件
  117. self.activeRole = -1;
  118. self.chooseRole = function (index, $item) {
  119. self.activeRole = index;
  120. self.edit = {
  121. roleID: $item.ZID,
  122. roleName: $item.ZUM
  123. };
  124. self.getPersonData(self.edit.roleID, "0");
  125. }
  126. //增加角色
  127. self.addRoleName = '';
  128. self.addRole = function () {
  129. ///增加角色
  130. var postData = {
  131. unitid: self.unit,//机构编码
  132. zum: self.addRoleName//角色名称
  133. }
  134. $http.post(apiurljs.login + "g2work/datazu/insertData", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfg)
  135. .success(function (obj) {
  136. var res = strToJson(s4.decryptData_CBC(obj.data));
  137. if (res.success) {
  138. self.getRole();
  139. self.addRoleName = '';
  140. self.activeRole = -1;
  141. self.getPersonData(self.unit, "0"); ///加载机构下方的人员
  142. sp.dialoghide();
  143. } else {
  144. sp.dialog(res.message);
  145. }
  146. });
  147. }
  148. //修改角色
  149. self.edit = {
  150. roleID: "",
  151. roleName: ""
  152. }
  153. self.editRole = function () {
  154. var postData = {
  155. zid: self.edit.roleID,//角色编码
  156. zum: self.edit.roleName//角色名称
  157. }
  158. $http.post(apiurljs.login + "g2work/datazu/updateDataByZid", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfg)
  159. .success(function (obj) {
  160. var res = strToJson(s4.decryptData_CBC(obj.data));
  161. if (res.success) {
  162. self.getRole();
  163. sp.dialoghide();
  164. } else {
  165. sp.dialog(res.message);
  166. }
  167. });
  168. }
  169. //删除角色
  170. self.removeRole = function ($item) {
  171. var getDelID = $item.ZID;
  172. var dialogHead = "<span class=\"sp-dialog-head\"><span class=\"sp-dialog-tip\">温馨提示</span><span class=\"sp-dialog-close sp-closeDialog\" title=\"关闭\">×</span></span>";
  173. var dialogBody = "<div class=\"sp-dialog-body\">删除后不可恢复,您确认要删除吗?</div>";
  174. 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>";
  175. $('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
  176. sp.openCenter(".sp-dialog");
  177. ///取消按钮
  178. $('.sp-closeDialog').click(function (event) {
  179. sp.closeCenter(".sp-dialog");
  180. event.preventDefault(); event.stopPropagation();
  181. });
  182. //post消息的id
  183. $("#delDataTrue").click(function () {
  184. var getid = $(this).attr("data-id");
  185. sp.dialoghide();
  186. var data = {
  187. zid: getid///角色编码
  188. };
  189. $http.post(apiurljs.login + "g2work/datazu/deleteByZid", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
  190. .success(function (obj) {
  191. var res = strToJson(s4.decryptData_CBC(obj.data));
  192. if (res.success) {
  193. self.getRole();
  194. self.addRoleName = '';
  195. self.activeRole = -1;
  196. self.getPersonData(self.unit, "0"); ///加载机构下方的人员
  197. sp.dialoghide();
  198. } else {
  199. sp.dialog(res.message);
  200. }
  201. });
  202. });
  203. // if (confirm('确定要删除么')) {
  204. // self.unit.ROLELIST.splice(index, 1);
  205. // self.activeRole = 0;
  206. // }
  207. }
  208. //上移一位
  209. self.moveUp = function () {
  210. if (sp.isval(self.edit.roleID)) {
  211. if (self.activeRole == 0) {
  212. sp.dialog("已处于最顶部,无法上移!");
  213. } else {
  214. var set_index = parseInt(self.activeRole - 1);
  215. var postData = {
  216. "zid1": self.rows[set_index].ZID,
  217. "zid2": self.edit.roleID
  218. };
  219. $http.post(apiurljs.login + "g2work/datazu/swapSortidByZid", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfg)
  220. .success(function (obj) {
  221. var res = strToJson(s4.decryptData_CBC(obj.data));
  222. if (res.success) {
  223. self.getRole();
  224. self.activeRole = -1;
  225. self.getPersonData(self.unit, "0"); ///加载机构下方的人员
  226. } else {
  227. sp.dialog(res.message);
  228. }
  229. });
  230. }
  231. } else {
  232. sp.dialog("请先点击选择角色!");
  233. }
  234. }
  235. //下移一位
  236. self.moveDown = function () {
  237. if (sp.isval(self.edit.roleID)) {
  238. if (self.activeRole == self.rows.length - 1) {
  239. sp.dialog("已处于最底部,无法下移!");
  240. } else {
  241. var set_index = parseInt(self.activeRole + 1);
  242. var postData = {
  243. "zid1": self.rows[set_index].ZID,
  244. "zid2": self.edit.roleID
  245. };
  246. $http.post(apiurljs.login + "g2work/datazu/swapSortidByZid", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfg)
  247. .success(function (obj) {
  248. var res = strToJson(s4.decryptData_CBC(obj.data));
  249. if (res.success) {
  250. self.getRole();
  251. self.activeRole = -1;
  252. self.getPersonData(self.unit, "0"); ///加载机构下方的人员
  253. } else {
  254. sp.dialog(res.message);
  255. }
  256. });
  257. }
  258. } else {
  259. sp.dialog("请先点击选择角色!");
  260. }
  261. }
  262. ///点击用户checkbox选中事件
  263. self.isSelected = function () {
  264. self.isSelectedAll = true;
  265. self.getPerson.forEach(function (itm) {
  266. itm.users.forEach(function (item2) {
  267. if (!item2.check) {
  268. return self.isSelectedAll = false;
  269. }
  270. })
  271. })
  272. }
  273. //全选
  274. self.isSelectedAll = false;
  275. self.selectAll = function () {
  276. if (self.isSelectedAll) {
  277. self.getPerson.forEach(function (itm) {
  278. itm.users.forEach(function (item2) {
  279. item2.check = true;
  280. })
  281. })
  282. } else {
  283. self.getPerson.forEach(function (itm) {
  284. itm.users.forEach(function (item2) {
  285. item2.check = false;
  286. })
  287. })
  288. }
  289. }
  290. //保存人员设置
  291. self.saveRole = function () {
  292. var get_checkedUser = [];
  293. self.getPerson.forEach(function (itm) {
  294. itm.users.forEach(function (item2) {
  295. if (item2.check) {
  296. get_checkedUser.push({
  297. "zid": self.edit.roleID,
  298. "userid": item2.userid
  299. })
  300. }
  301. });
  302. })
  303. // console.log(get_checkedUser);
  304. if (sp.isval(get_checkedUser)) {
  305. var postData = {
  306. "typeid": "zid",
  307. typevalue: self.edit.roleID,
  308. data: JSON.stringify(get_checkedUser)
  309. }
  310. // console.log(postData);
  311. $http.post(apiurljs.login + "g2work/datazu/updateDataUser", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfg)
  312. .success(function (obj) {
  313. var res = strToJson(s4.decryptData_CBC(obj.data));
  314. if (res.success) {
  315. sp.dialog(res.message);
  316. $timeout(function () {
  317. self.getPersonData(self.edit.roleID, "0");
  318. sp.dialoghide();
  319. }, 600);
  320. } else {
  321. sp.dialog(res.message);
  322. }
  323. });
  324. } else {
  325. sp.dialog("人员不能为空!");
  326. }
  327. }
  328. }])
  329. app.directive('repeatFinish', function () {
  330. return {
  331. link: function (scope) {
  332. if (scope.$last == true) {
  333. $(".tab").eq(0).addClass("active");
  334. }
  335. }
  336. }
  337. })