edit.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. var editAnnounceCtrl = function ($scope, $http, $filter, $loading) {
  2. $scope.params = announceModal.params;
  3. $scope.parentLoad = announceModal.parentLoad;
  4. $scope.announce = {};
  5. $scope.roleList = [];
  6. $scope.userList = [];
  7. $scope.selectRoleParams = {
  8. url: '../../api/systemsetting/Role/GetRolesForSelect',
  9. isMulti: true,
  10. selectData: { roleName: '角色名称' },
  11. columns: { RoleName: '角色名称', Description: '说明' },
  12. selectLabelKey: 'RoleName',
  13. selectValuekey: 'RoleID',
  14. selectedValueData: '',
  15. selectedLabeData: '',
  16. selectedJData: [],
  17. selectParams: {
  18. }
  19. };
  20. $scope.selectUserParams = {
  21. url: '../../api/systemsetting/Account/GetUsersForSelect',
  22. isMulti: true,
  23. selectData: { loginID: '登录账号', name: '姓名' },
  24. columns: { LoginID: '登录账号', Name: '姓名', SexName: '性别' },
  25. selectLabelKey: 'Name',
  26. selectValuekey: 'UserID',
  27. selectedValueData: '',
  28. selectedLabeData: '',
  29. selectedJData: [],
  30. selectParams: {
  31. }
  32. };
  33. $scope.$watch('selectRoleParams.selectedValueData', function (newVal) {
  34. if (newVal != '' && newVal != undefined) {
  35. angular.forEach($scope.selectRoleParams.selectedJData, function (val) {
  36. if ($filter('filter')($scope.roleList, { RoleID: val.RoleID }).length == 0) {
  37. $scope.roleList.push({
  38. RoleID: val.RoleID,
  39. RoleName: val.RoleName,
  40. Description: val.Description,
  41. rowChecked: false
  42. });
  43. }
  44. });
  45. }
  46. });
  47. $scope.$watch('selectUserParams.selectedValueData', function (newVal) {
  48. if (newVal != '' && newVal != undefined) {
  49. angular.forEach($scope.selectUserParams.selectedJData, function (val) {
  50. if ($filter('filter')($scope.userList, { UserID: val.UserID }).length == 0) {
  51. $scope.userList.push({
  52. UserID: val.UserID,
  53. LoginID: val.LoginID,
  54. Name: val.Name,
  55. Sex: val.Sex,
  56. SexName: val.SexName,
  57. rowChecked: false
  58. });
  59. }
  60. });
  61. }
  62. });
  63. $scope.delRole = function () {
  64. if (confirm('是否确定删除发布角色?')) {
  65. for (var i = $scope.roleList.length - 1; i >= 0; i--) {
  66. if ($scope.roleList[i].rowChecked) {
  67. $scope.roleList.splice(i, 1);
  68. }
  69. }
  70. }
  71. }
  72. $scope.delUser = function () {
  73. if (confirm('是否确定删除发布用户?')) {
  74. for (var i = $scope.userList.length - 1; i >= 0; i--) {
  75. if ($scope.userList[i].rowChecked) {
  76. $scope.userList.splice(i, 1);
  77. }
  78. }
  79. }
  80. }
  81. $scope.loadData = function () {
  82. $loading.show();
  83. $http({
  84. method: "post",
  85. url: "../../api/systemsetting/Announce/GetAnnouncement",
  86. data: {
  87. announceID: $scope.params.announceID
  88. }
  89. }).then(function (result) {
  90. $loading.hide();
  91. $scope.announce = result.data.Data;
  92. });
  93. }
  94. $scope.loadRoleList = function () {
  95. $loading.show();
  96. $http({
  97. method: "post",
  98. url: "../../api/systemsetting/Announce/AnnounceRoleList",
  99. data: {
  100. announceID: $scope.params.announceID
  101. }
  102. }).then(function (result) {
  103. $loading.hide();
  104. $scope.roleList = angular.forEach(result.data.Data, function (x) { x = angular.extend(x, { rowChecked: false }) });
  105. });
  106. }
  107. $scope.loadUserList = function () {
  108. $loading.show();
  109. $http({
  110. method: "post",
  111. url: "../../api/systemsetting/Announce/AnnounceUserList",
  112. data: {
  113. announceID: $scope.params.announceID
  114. }
  115. }).then(function (result) {
  116. $loading.hide();
  117. $scope.userList = angular.forEach(result.data.Data, function (x) { x = angular.extend(x, { rowChecked: false }) });
  118. });
  119. }
  120. if ($scope.params.announceID) {
  121. $scope.loadData();
  122. $scope.loadUserList();
  123. $scope.loadRoleList();
  124. }
  125. $scope.saveData = function (isflag) {
  126. if (isflag) {
  127. $loading.show();
  128. var url = "../../api/systemsetting/Announce/Add";
  129. if ($scope.announce.AnnouncementID) {
  130. url = "../../api/systemsetting/Announce/Edit";
  131. }
  132. $http({
  133. method: "post",
  134. url: url,
  135. data: {
  136. announce: $scope.announce,
  137. roleList: $scope.roleList,
  138. userList: $scope.userList
  139. }
  140. }).then(function (result) {
  141. $loading.hide();
  142. if (result.data.IsSuccess) {
  143. $scope.showMsg('成功', '保存成功。');
  144. //重新刷新列表
  145. $scope.parentLoad();
  146. $scope.$hide();
  147. } else {
  148. $scope.showMsg('成功', result.data.Message);
  149. }
  150. }, function (resp) {
  151. $loading.hide();
  152. $scope.showMsg('错误', '服务器错误');
  153. });
  154. }
  155. }
  156. };
  157. //定义模态框
  158. var announceModal;