edit.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. (function ($app) {
  2. $app.module('ylmis').controller('editRoleCtrl', function ($scope, $http, $filter, $modal, $ocLazyLoad, $alert, $loading, $state, AuthUser, $bsRouterState) {
  3. $scope.params = $scope.$parent.$parent.editData.params;
  4. $scope.parentLoad = $scope.$parent.$parent.editData.parentLoad;
  5. $scope.role = {};
  6. $scope.roleFunctionCode = {};
  7. $scope.functionCodeList = {};
  8. $scope.delRole = function () {
  9. if (confirm('是否确定删除发布角色?')) {
  10. for (var i = $scope.roleList.length - 1; i >= 0; i--) {
  11. if ($scope.roleList[i].rowChecked) {
  12. $scope.roleList.splice(i, 1);
  13. }
  14. }
  15. }
  16. }
  17. $scope.delUser = function () {
  18. if (confirm('是否确定删除发布用户?')) {
  19. for (var i = $scope.userList.length - 1; i >= 0; i--) {
  20. if ($scope.userList[i].rowChecked) {
  21. $scope.userList.splice(i, 1);
  22. }
  23. }
  24. }
  25. }
  26. $scope.loadData = function () {
  27. $loading.show();
  28. $http({
  29. method: "post",
  30. url: "../../api/systemsetting/Role/GetRole",
  31. data: {
  32. roleID: $scope.params.roleID
  33. }
  34. }).then(function (result) {
  35. $loading.hide();
  36. $scope.role = result.data.Data;
  37. });
  38. }
  39. $scope.loadFunctionCodeList = function () {
  40. $loading.show();
  41. $http({
  42. method: "post",
  43. url: "../../api/systemsetting/Role/GetFunctionCodeList"
  44. }).then(function (result) {
  45. $loading.hide();
  46. $scope.functionCodeList = result.data.Data;
  47. $scope.loadRoleFunctionCode();
  48. });
  49. }
  50. $scope.loadRoleFunctionCode = function () {
  51. $loading.show();
  52. $http({
  53. method: "post",
  54. url: "../../api/systemsetting/Role/GetRoleFunctionCode",
  55. data: {
  56. roleID: $scope.params.roleID
  57. }
  58. }).then(function (result) {
  59. $loading.hide();
  60. $scope.roleFunctionCode = result.data.Data;
  61. //循环遍历所有的Menulist与返回结果的content的值进行比对,然后设置MenuList的isChecked=true
  62. angular.forEach($scope.roleFunctionCode, function (val, key) {
  63. var data = $filter('filter')($scope.functionCodeList, function (value) {
  64. return value.FunctionCode == val
  65. });
  66. if (data.length > 0) {
  67. data[0].isChecked = true;
  68. }
  69. });
  70. $scope.PcodeLists = [];
  71. $scope.getPcodeLists($scope.PcodeLists, '');
  72. });
  73. }
  74. //使用递归将所有节点的内容填好
  75. $scope.getPcodeLists = function (dataList, functionCode) {
  76. angular.forEach($scope.functionCodeList, function (data) {
  77. if (data.ParentFunctionCode == functionCode) {
  78. var childList = [];
  79. $scope.getPcodeLists(childList, data.FunctionCode);
  80. dataList.push({
  81. myCode: data,
  82. isChecked: data.isChecked,
  83. childCode: childList,
  84. changeShow: false,
  85. changeClass: 'glyphicon-chevron-right'
  86. });
  87. }
  88. });
  89. };
  90. //根据父节点来显示对应的子节点
  91. $scope.getCodeByPCode = function (item) {
  92. //改变样式
  93. item.changeClass = item.changeClass == 'glyphicon-chevron-down' ? 'glyphicon-chevron-right' : 'glyphicon-chevron-down';
  94. //改变child的显示
  95. angular.forEach(item.childCode, function (data) {
  96. data.changeShow = data.changeShow == true ? false : true;
  97. });
  98. };
  99. //父节点的过滤
  100. $scope.codefilter = function (value) {
  101. return !value.ParentFunctionCode;
  102. }
  103. //checkbox的判断
  104. $scope.chkchildren = function (item) {
  105. if (angular.isDefined(item.childCode)) {
  106. angular.forEach(item.childCode, function (val, key) {
  107. val.isChecked = item.isChecked;
  108. $scope.chkchildren(val);
  109. });
  110. }
  111. $scope.chkparent(item);
  112. };
  113. $scope.chkparent = function (item) {
  114. $scope.tempCode = "";
  115. dataList = $scope.PcodeLists;
  116. functionCode = item.myCode.ParentFunctionCode;
  117. $scope.getPcode = function (dataList, functionCode) {
  118. var flag = true;
  119. angular.forEach(dataList, function (val) {
  120. if (flag) {
  121. if (functionCode == val.myCode.FunctionCode) {
  122. //找到父级
  123. $scope.tempCode = val;
  124. //选择一个全部勾选父节点
  125. if (item.isChecked) {
  126. val.isChecked = item.isChecked;
  127. } else {
  128. $scope.Amt = 0;
  129. var flag2 = true;
  130. angular.forEach(val.childCode, function (val_child) {
  131. if (flag2) {
  132. if (val_child.isChecked == item.isChecked) {
  133. $scope.Amt = $scope.Amt + 1;
  134. }
  135. flag = false;
  136. }
  137. })
  138. if (val.childCode.length == $scope.Amt) {
  139. // val.isChecked = item.isChecked;
  140. }
  141. }
  142. flag = false;
  143. }
  144. $scope.getPcode(val.childCode, functionCode);
  145. }
  146. });
  147. }
  148. if (functionCode) {
  149. $scope.getPcode(dataList, functionCode);
  150. }
  151. if ($scope.tempCode && $scope.tempCode.myCode.ParentFunctionCode != null) {
  152. $scope.getPcode(dataList, $scope.tempCode.myCode.ParentFunctionCode);
  153. //var grandChk = $scope.tempCode;
  154. //$scope.chkparent(grandChk);
  155. }
  156. };
  157. $scope.saveData = function (isflag) {
  158. if (isflag) {
  159. //遍历所有的isChecked的属性,用,去拼接;
  160. var functionCodeArr = [];
  161. $scope.GetPcodeChecked = function (dataList) {
  162. angular.forEach(dataList, function (data) {
  163. if (data.isChecked) {
  164. this.push(data.myCode.FunctionCode);
  165. }
  166. $scope.GetPcodeChecked(data.childCode);
  167. }, functionCodeArr);
  168. }
  169. $scope.GetPcodeChecked($scope.PcodeLists);
  170. $loading.show();
  171. var url = "../../api/systemsetting/Role/Add";
  172. if ($scope.role.RoleID) {
  173. url = "../../api/systemsetting/Role/Edit";
  174. }
  175. $http({
  176. method: "post",
  177. url: url,
  178. data: {
  179. role: $scope.role,
  180. "functionCodes": functionCodeArr
  181. }
  182. }).then(function (result) {
  183. $loading.hide();
  184. if (result.data.IsSuccess) {
  185. $scope.showMsg('成功', '保存成功。');
  186. //重新刷新列表
  187. $scope.parentLoad();
  188. $scope.$hide();
  189. } else {
  190. $scope.showMsg('成功', result.data.Message);
  191. }
  192. }, function (resp) {
  193. $loading.hide();
  194. $scope.showMsg('错误', '服务器错误');
  195. });
  196. }
  197. }
  198. if ($scope.params.roleID) {
  199. $scope.loadData();
  200. }
  201. $scope.loadFunctionCodeList();
  202. });
  203. })(angular);