groupAddMemberCtrl.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. angular.module('push')
  2. .controller('groupAddMemberCtrl', function ($scope, AuthorityService, AuthorityModelService, CommentService, UtilService, $stateParams) {
  3. $scope.act = true;
  4. $scope.userList = [];
  5. $scope.AuthorityList = [];
  6. $scope.type = $stateParams.type;
  7. $scope.showshare = false;
  8. $scope.shownone = false;//是否显示无网络页面
  9. // console.log($scope.qrcodeurl);
  10. //已选择用户id拼接
  11. var useridlist = "";
  12. var getUserIdList = function (flg) {
  13. useridlist = "";
  14. angular.forEach(AuthorityModelService.getMemberList(), function (value, index) {
  15. var tempid = "'" + value.userId + "'";
  16. useridlist = useridlist + tempid + ",";
  17. });
  18. // console.log(useridlist);
  19. //切换tab时需用户刷选
  20. if (flg) {
  21. toSelectUserList($scope.userList);
  22. toSelectAuthorityList($scope.AuthorityList);
  23. }
  24. };
  25. getUserIdList();
  26. //关注用户刷选
  27. var toSelectUserList = function (userList) {
  28. $scope.userList = angular.copy(userList);
  29. angular.forEach(userList, function (data, index) {
  30. var tempid = "'" + data.userId + "'";
  31. if (useridlist.indexOf(tempid) != -1) {
  32. $scope.userList[index].isExisits = 1;
  33. } else {
  34. $scope.userList[index].isExisits = 0;
  35. }
  36. })
  37. };
  38. //权限用户组刷选
  39. var toSelectAuthorityList = function (authorityList) {
  40. //刷选是否有批量导入
  41. var authlist = AuthorityModelService.getAuthorityList();
  42. $scope.AuthorityList = angular.copy(authorityList);
  43. angular.forEach(authlist, function (value, index) {
  44. $scope.AuthorityList[value].isadd = 1;
  45. });
  46. //刷选权限下用户组
  47. angular.forEach(authorityList, function (value, index) {
  48. angular.forEach(value.userList, function (data, ind) {
  49. var tempid = data.userId + "";
  50. if (useridlist.indexOf(tempid) != -1) {
  51. $scope.AuthorityList[index].userList[ind].isExisits = 1;
  52. } else {
  53. $scope.AuthorityList[index].userList[ind].isExisits = 0;
  54. }
  55. });
  56. });
  57. };
  58. var initData = function () {
  59. //获取关注用户列表
  60. CommentService.getMyAttentionList(0, "", "").then(function (response) {
  61. // console.log(response.userList);
  62. toSelectUserList(response.userList);
  63. $scope.shownone = false;
  64. }, function () {
  65. $scope.shownone = true;
  66. });
  67. //获取权限列表
  68. AuthorityService.getAuthorityList("", "").then(function (response) {
  69. // console.log(response);
  70. toSelectAuthorityList(response.cloautlist);
  71. $scope.shownone = false;
  72. }, function () {
  73. $scope.shownone = true;
  74. });
  75. };
  76. initData();
  77. //切换关注、权限
  78. $scope.changeTab = function () {
  79. getUserIdList(true);
  80. $scope.act = !$scope.act;
  81. };
  82. //关注用户添加
  83. $scope.addMember = function (user, index) {
  84. $scope.userList[index].isExisits = 1;
  85. var tempobj = {
  86. userId: user.userId,
  87. userName: user.userName,
  88. photo: user.photo,
  89. iscreator: 0,
  90. comefrom: user.comefrom
  91. };
  92. AuthorityModelService.addMemberList(tempobj);
  93. };
  94. //处理批量添加user(剔除重复user)
  95. var handleAddMembers = function (userList) {
  96. //获得当前选择useridlist
  97. useridlist = "";
  98. angular.forEach(AuthorityModelService.getMemberList(), function (value, index) {
  99. useridlist = useridlist + value.userId + ",";
  100. });
  101. angular.forEach(userList, function (data, index) {
  102. var tempid = data.userId + "";
  103. if (useridlist.indexOf(tempid) == -1) {
  104. var tempobj = {
  105. userId: data.userId,
  106. userName: data.userName,
  107. photo: data.photo,
  108. iscreator: 0,
  109. comefrom: data.comefrom
  110. };
  111. AuthorityModelService.addMemberList(tempobj);
  112. }
  113. });
  114. };
  115. //批量导入权限
  116. $scope.addAuthority = function (authority, index) {
  117. handleAddMembers(authority.userList);
  118. $scope.AuthorityList[index].isadd = 1;
  119. angular.forEach($scope.AuthorityList[index].userList, function (data, ind) {
  120. $scope.AuthorityList[index].userList[ind].isExisits = 1;
  121. });
  122. AuthorityModelService.addAuthorityList(index);
  123. };
  124. //单个导入权限下用户
  125. $scope.addAuthorityMember = function (authority, user, index) {
  126. var i = $scope.AuthorityList.indexOf(authority);
  127. var tempobj = {
  128. userId: user.userId,
  129. userName: user.userName,
  130. photo: user.photo,
  131. iscreator: 0,
  132. comefrom: user.comefrom
  133. };
  134. AuthorityModelService.addMemberList(tempobj);
  135. $scope.AuthorityList[i].userList[index].isExisits = 1;
  136. };
  137. //是否现在权限下用户
  138. $scope.showMember = function (index) {
  139. $scope.AuthorityList[index].showlist = !$scope.AuthorityList[index].showlist;
  140. };
  141. $scope.goUserSearch = function () {
  142. $scope.go('userSearch', {searchtype: 1, isset: 0, modeltype: 1});
  143. };
  144. //网络重载
  145. $scope.initMember = function () {
  146. initData();
  147. }
  148. });