selectAuthorityMemberCtrl.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. angular.module('push')
  2. .controller('selectAuthorityMemberCtrl', function ($scope,$stateParams, $timeout,$ionicScrollDelegate,$ionicModal,ScienceCircleService,
  3. UserService, ResourceLibraryService, ConstantService, resourceLibraryModel, $ionicPopup, UtilService) {
  4. $scope.groupDetail={
  5. goupName:"",
  6. memberNum:0
  7. };
  8. $scope.mailDatas=[];
  9. // 设置来源
  10. $scope.sourcefrom = $stateParams.sourcefrom;
  11. // 从 【设置群组】 来
  12. if($scope.sourcefrom == 1){
  13. // 设置群组时选择的成员列表
  14. $scope.userlist = resourceLibraryModel.getTempUserList();
  15. }
  16. // 从 【谁可以看】 来
  17. else if($scope.sourcefrom == 2){
  18. // 选择的成员列表
  19. $scope.userlist = resourceLibraryModel.getUserList();
  20. }
  21. // 将已选择的userid组合
  22. $scope.useridlist = [];
  23. $scope.selectedSectionLength=0;
  24. if(UtilService.isDefined($scope.userlist) && $scope.userlist.length > 0){
  25. angular.forEach($scope.userlist, function (value, ind) {
  26. $scope.useridlist.push(value.userid);
  27. $scope.selectedSectionLength += 1;
  28. });
  29. }
  30. // 转换用到的userlist model
  31. $scope.requestModel=
  32. {
  33. //TODO
  34. userid:UserService.id,
  35. // userid:1,
  36. data:[]
  37. };
  38. // 我的通讯录列表
  39. var getContacts = function () {
  40. // 0:我的关注 1:我的粉丝 2:陌生人
  41. ScienceCircleService.getContacts(0).then(function (response) {
  42. // console.log(response);
  43. // 成员列表
  44. $scope.mailDatas = response;
  45. $timeout(function () {
  46. //联系人首字母字母数组
  47. $scope.letters = [];
  48. angular.forEach($scope.mailDatas, function (value) {
  49. $scope.letters.push(value.userUpper);
  50. angular.forEach(value.userlist, function (user, ind) {
  51. // 若已在群组中存在,则默认选中
  52. if($scope.useridlist.indexOf(user.userid) != -1){
  53. user.isChecked = true;
  54. }
  55. });
  56. });
  57. $scope.heightAccount=20*($scope.letters.length)+"px";
  58. }, 100);
  59. }, function () {
  60. });
  61. };
  62. getContacts();
  63. //联系人首字母字母数组
  64. $scope.letters = [];
  65. angular.forEach($scope.mailDatas, function (value) {
  66. $scope.letters.push(value.userUpper);
  67. });
  68. $scope.heightAccount=20*($scope.letters.length)+"px";
  69. // 触摸字母定位至对应联系人
  70. $scope.mTouch = function () {
  71. var handle=$ionicScrollDelegate.$getByHandle('businessList-handle');
  72. var c = $(this).attr("c");
  73. $scope.hint = c;
  74. $scope.showMiddle = true;
  75. $timeout(function () {
  76. $scope.showMiddle = false;
  77. }, 300);
  78. var scroll = document.getElementById($scope.hint).offsetTop- handle.getScrollPosition().top;
  79. $ionicScrollDelegate.scrollBy(0, scroll, true);
  80. var ele = document.getElementsByTagName("ion-content");
  81. ele[0].style.overflow = "auto"; //解决滑动右边的导航字母后,左边不能再滚动的bug,可以试着注释这两句来测试这个问题
  82. };
  83. // 手指从屏幕上离开 隐藏中间显示的字母
  84. $scope.mRelease = function () {
  85. $timeout(function () {
  86. $scope.showMiddle = false;
  87. }, 300);
  88. };
  89. // 记录选中群组列表索引
  90. var indexSectionlist = [];
  91. // 选择成员(多选)
  92. $scope.selectLabelOrgType = function (userId, parentIndex,index) {
  93. if ($scope.mailDatas[parentIndex].userlist[index].isChecked) {
  94. var ind = indexSectionlist.indexOf(index);
  95. indexSectionlist.splice(ind,1);
  96. $scope.selectedSectionLength -= 1;
  97. } else {
  98. indexSectionlist.push(userId);
  99. $scope.selectedSectionLength += 1;
  100. }
  101. $scope.mailDatas[parentIndex].userlist[index].isChecked = !$scope.mailDatas[parentIndex].userlist[index].isChecked;
  102. };
  103. //选择完成的时候判断是否把选择的成员存储为一个群组 isSetGroupEnter为是否重设置群组里的添加成员加入 0:是 1:否
  104. $scope.isSetGroupEnter = 1;
  105. $scope.judgeReturn=function () {
  106. if($scope.isSetGroupEnter==0){
  107. //function、then()、提示不显示、直接保存选择成员id
  108. }else {
  109. $ionicPopup.show({
  110. template: "<p style='text-align: center;'>保存为标签,下次可直接选用</p>",
  111. scope: $scope,
  112. buttons: [
  113. {
  114. text: "忽略",
  115. onTap: function () {
  116. //取消时function、保存成员id,成员id不组成群id
  117. console.log('取消');
  118. // 若多次进行完成,需初始化
  119. $scope.userlist = resourceLibraryModel.getUserList();
  120. // 将所有列出的成员比对,加入到传入接收userlist中
  121. angular.forEach($scope.mailDatas, function (value) {
  122. angular.forEach(value.userlist, function (user, ind) {
  123. // 若已在群组中存在,则默认选中
  124. if($scope.useridlist.indexOf(user.userid) == -1 && user.isChecked == true){
  125. $scope.userlist.push(user);
  126. }
  127. });
  128. });
  129. // 现有成员列表,传回
  130. resourceLibraryModel.setUserList($scope.userlist);
  131. console.log(resourceLibraryModel.getUserList());
  132. $timeout(function () {
  133. //TODO
  134. $scope.goback();
  135. }, 100);
  136. }
  137. },
  138. {
  139. text: '<span class="ionicAction_span">存为群组</span>',
  140. type: "button-positive",
  141. onTap: function () {
  142. // 获取传入的群组list
  143. $scope.grouplist = resourceLibraryModel.getGroupList();
  144. //确认时function保存成员id,成员id组成群id
  145. // 创建权限组
  146. // 保存时的成员列表
  147. // 将所有列出的成员比对,加入到传入接收userlist中
  148. $scope.userlist = [];// 存储为群组时,清空userlist
  149. angular.forEach($scope.mailDatas, function (value) {
  150. angular.forEach(value.userlist, function (user, ind) {
  151. // 若已在群组中存在,则默认选中
  152. if(user.isChecked == true){
  153. $scope.userlist.push(user);
  154. }
  155. });
  156. });
  157. $scope.requestModelForCreateGroup=
  158. {
  159. userid:UserService.id,
  160. data:{
  161. id:1,
  162. authname:"新群组",
  163. userlist:$scope.userlist
  164. }
  165. };
  166. // 创建组
  167. ResourceLibraryService.createAuthorityGroup($scope.requestModelForCreateGroup).then(function (response) {
  168. // console.log(response);
  169. // 获取创建好的group
  170. if (response.code == ConstantService.INTERFACE_STATUS_CODE_3350) {
  171. // 将创建好的group加入到前一页面中
  172. // 临时存储返回的group
  173. $scope.group = response.data;
  174. $scope.group.checkBoxEd = true;
  175. $scope.grouplist.push(response.data);
  176. resourceLibraryModel.setGroupList($scope.grouplist);
  177. }
  178. }, function () {
  179. UtilService.showMess(ConstantService.INTERFACE_MESSAGE_ERROR);
  180. });
  181. $scope.openModal = function() {
  182. $scope.groupDetail.groupName=$scope.groupDetail.groupNewName;
  183. $scope.isShowClear = true;
  184. $scope.modal.show();
  185. };
  186. console.log('确认保存为群组');
  187. $timeout(function () {
  188. //TODO
  189. $scope.goback();
  190. }, 100);
  191. }
  192. }
  193. ]
  194. });
  195. }
  196. }
  197. // 转换userlist为带拼音首字母的结果集
  198. var getTransferUserList = function (userlist) {
  199. $scope.requestModel.data = userlist;
  200. ResourceLibraryService.getTransferUserList($scope.requestModel).then(function (response) {
  201. if(response.code == ConstantService.INTERFACE_STATUS_CODE_3350){
  202. console.log(response);
  203. // 转换后的成员列表,放入回传数组里
  204. resourceLibraryModel.setMailDatas(response.data);
  205. }
  206. $timeout(function () {
  207. //TODO
  208. $scope.goback();
  209. }, 100);
  210. }, function () {
  211. });
  212. };
  213. // 返回至谁可以看页面
  214. $scope.gotoSourcePage=function () {
  215. // 不刷新页面
  216. resourceLibraryModel.setFlag(false);
  217. $scope.goback();
  218. };
  219. // 返回已选中的成员
  220. $scope.returnCheckedUserList=function () {
  221. // 不刷新页面
  222. resourceLibraryModel.setFlag(false);
  223. // 从 【设置群组】 来
  224. if($scope.sourcefrom == 1){
  225. // 将所有列出的成员比对,加入到传入接收userlist中
  226. angular.forEach($scope.mailDatas, function (value) {
  227. angular.forEach(value.userlist, function (user, ind) {
  228. // 若选中的人员不在传入的userlist中,则加入
  229. if($scope.useridlist.indexOf(user.userid) == -1 && user.isChecked == true){
  230. $scope.userlist.push(user);
  231. }else if($scope.useridlist.indexOf(user.userid) != -1 && user.isChecked == false){
  232. $scope.userlist.splice(ind, 1);
  233. }
  234. });
  235. });
  236. // 设置群组时选择的成员列表
  237. resourceLibraryModel.setTempUserList($scope.userlist);
  238. // 将成员列表转换格式
  239. getTransferUserList($scope.userlist);
  240. }
  241. // 从 【谁可以看】 来
  242. else if($scope.sourcefrom == 2){
  243. // 选择是否生成群组
  244. $scope.judgeReturn();
  245. }
  246. /*// 来源:设置群组
  247. if($scope.sourcefrom == 1){
  248. $scope.go('setAuthorityGroup', {sourcefrom: 1, userlist: resourceLibraryModel.getUserList()});
  249. }*/
  250. };
  251. //设置群组名称
  252. $ionicModal.fromTemplateUrl('my-modal.html', {
  253. scope: $scope,
  254. animation: 'slide-in-left'
  255. }).then(function(modal) {
  256. $scope.modal = modal;
  257. });
  258. //打开设置群组名称
  259. $scope.groupDetail.groupName=$scope.groupDetail.groupNewName;
  260. $scope.openModal = function() {
  261. $scope.groupDetail.groupName=$scope.groupDetail.groupNewName;
  262. $scope.isShowClear = true;
  263. $scope.modal.show();
  264. };
  265. //不更改群组名称
  266. $scope.closeModalAndNoset = function() {
  267. console.log('我不修改');
  268. if($scope.groupDetail.groupNewName!=''){
  269. $scope.groupDetail.groupName=$scope.groupDetail.groupNewName;
  270. }else {
  271. $scope.groupDetail.groupName=$scope.groupDetail.groupName;
  272. }
  273. $scope.modal.hide();
  274. };
  275. //更改群组名称
  276. $scope.closeModalAndreSet=function () {
  277. //function()保存群组名称更改
  278. console.log('更改成功');
  279. if($scope.groupDetail.groupNewName!=''){
  280. $scope.groupDetail.groupName=$scope.groupDetail.groupNewName;
  281. }else {
  282. $scope.groupDetail.groupName=$scope.groupDetail.groupName;
  283. }
  284. $scope.modal.hide();
  285. };
  286. // 搜索成员
  287. $scope.searchMemberList = function () {
  288. $scope.showLoadingToast();
  289. }, function () {
  290. $scope.hideLoadingToast();
  291. };
  292. $scope.keyfilter = {
  293. key: ""// 搜索关键词
  294. };
  295. //清空搜索内容
  296. $scope.clearSearch = function () {
  297. $scope.groupDetail.groupNewName = "";
  298. $timeout(function () {
  299. $scope.isShowClear = false;
  300. })
  301. };
  302. //清空搜索成员
  303. $scope.clearSearchFirst = function () {
  304. $scope.keyfilter.key = "";
  305. $scope.isShowClearFirst = false;
  306. };
  307. //是否显示清空按钮之成员
  308. $scope.isShowClearFirst = false;
  309. $scope.showFuncFirst = function () {
  310. $scope.isShowClearFirst = true;
  311. };
  312. //是否显示清空按钮之群组
  313. $scope.isShowClear = false;
  314. $scope.showFunc = function () {
  315. $scope.isShowClear = true;
  316. };
  317. });