AddLookUpUserSecondVC.m 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. //
  2. // AddLookUpUserSecondVC.m
  3. // smartRhino
  4. //
  5. // Created by tederen on 2019/11/25.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "AddLookUpUserSecondVC.h"
  9. #import "SendInfoGroupCell.h"
  10. #import "SendGroupBCell.h"
  11. #import "MailListSearchVC.h"
  12. #import "MyTDGroupView.h"
  13. @interface AddLookUpUserSecondVC ()<UITableViewDelegate,UITableViewDataSource>
  14. @property (nonatomic, strong) TDTableView *myTableView;
  15. @property (nonatomic, strong) UIView *listHeaderVIew;
  16. @property (nonatomic, strong) TDButton *serachButton;
  17. @property (nonatomic, strong) AddressBookGroupModel *addressBookModel;
  18. @property (nonatomic,assign) NSInteger indexflag;
  19. @property (nonatomic, strong) NSMutableArray <SelectModel*>*selectArray;
  20. @property (nonatomic, strong) NSMutableArray <Department *>*selectDepartArray;
  21. @property (nonatomic, strong) NSMutableArray <SelectModel*>*usersSourceDataArray;
  22. @end
  23. @implementation AddLookUpUserSecondVC
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. [self getdata];
  27. [self.view addSubview:self.myTableView];
  28. self.myTableView.frame = CGRectMake(0,kNavigationHeight+5,kGXScreenWidth, kGXScreenHeigh - kNavigationHeight-5);
  29. [self.myTableView setTableHeaderView:self.listHeaderVIew];
  30. WS(weakSelf);
  31. UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) {
  32. MailListSearchVC *vc = [[MailListSearchVC alloc] init];
  33. vc.notChangeColor = weakSelf.notSearchChangeColor;
  34. vc.IsAddUser = YES;
  35. vc.isShow = weakSelf.isShow;
  36. vc.UserIds = weakSelf.UserIds;
  37. vc.DepartmentId = weakSelf.indexId;
  38. vc.SearchType = weakSelf.isMyGroup;
  39. [weakSelf.navigationController pushViewController:vc animated:YES];
  40. }];
  41. [self.listHeaderVIew addGestureRecognizer:tap];
  42. self.fd_prefersNavigationBarHidden = YES;
  43. self.view.backgroundColor = UIColorHex(#FFFFFF);
  44. self.myTableView.backgroundColor = UIColorHex(#F5F6F8);
  45. [self createnavi];
  46. }
  47. #pragma mark - 导航视图
  48. - (void)createnavi{
  49. self.myNavigationBar.titleLabel.text = self.titleStr;
  50. [self.myNavigationBar.backButton2 setImage:nil forState:UIControlStateNormal];
  51. [self.myNavigationBar.backButton2 setTitle:@"全选" forState:UIControlStateNormal];
  52. [self.myNavigationBar.backButton2 setTitleColor:UIColorHex(#3979D3) forState:UIControlStateNormal];
  53. [[self.myNavigationBar.backButton titleLabel] setFont:[UIFont systemFontOfSize:15.f]];
  54. [self.myNavigationBar.backButton2 mas_remakeConstraints:^(MASConstraintMaker *make) {
  55. make.centerY.equalTo(self.myNavigationBar.backButton);
  56. make.left.mas_equalTo(self.myNavigationBar.backButton.mas_right);
  57. make.height.mas_offset(@44);
  58. make.width.mas_greaterThanOrEqualTo(10);
  59. }];
  60. [self.myNavigationBar.rightButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
  61. [self.myNavigationBar.rightButton setTitle:@"确定" forState:UIControlStateNormal];
  62. [[self.myNavigationBar.rightButton titleLabel] setFont:[UIFont systemFontOfSize:15.f]];
  63. self.myNavigationBar.rightButton.hidden = NO;
  64. [self.myNavigationBar.rightButton mas_updateConstraints:^(MASConstraintMaker *make) {
  65. make.centerY.equalTo(self.myNavigationBar.backButton);
  66. make.height.mas_offset(@44);
  67. make.right.mas_equalTo(self.myNavigationBar.mas_right).offset(-15);
  68. }];
  69. }
  70. #pragma mark - 导航事件处理
  71. -(void)back{
  72. [self.navigationController popViewControllerAnimated:YES];
  73. }
  74. -(void)back1{
  75. for ( NSInteger i = (self.navigationController.viewControllers.count - 1); i > 0 ;i --) {
  76. NSLog(@"%@",self.navigationController.viewControllers[i]);
  77. if ([self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"MyWorkWordVC")]
  78. || [self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"ChatNewGroupVC")]
  79. || [self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"H5ViewController")]
  80. || [self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"MyTDTopicCreateVC")]
  81. || [self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"MyFavoriteNewFindVC")]
  82. || [self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"ChatNewRowVC")]
  83. || [self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"MyTDTopicGroupUserVC")]
  84. || [self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"WorkFlowOrderController")]
  85. || [self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"CreateInterLeterVC")]
  86. || [self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"MailListByZuVC")]) {
  87. [self.navigationController popToViewController:self.navigationController.viewControllers[i] animated:YES];
  88. return;
  89. }
  90. }
  91. }
  92. //全选操作
  93. - (void)selectedAction:(UIButton*)btn{
  94. btn.selected = !btn.selected;
  95. for(int i = 0 ; i < 2 ; i++){
  96. if (i == 0) {
  97. for (Department *depart in self.departSourceDataArray) {
  98. depart.hadSelected = btn.selected;
  99. }
  100. }
  101. if (i == 1) {
  102. for (SelectModel *depart in self.usersSourceDataArray) {
  103. depart.hadSelected = btn.selected;
  104. }
  105. }
  106. }
  107. [self.myTableView reloadData];
  108. }
  109. // 左边按钮 全选 取消全选
  110. - (void)secondBarButtonItems:(TDButton *)sender{
  111. [self selectedAction:sender];
  112. }
  113. - (void)rightButtonAction:(TDButton *)sender{
  114. [self confirmAction:sender];
  115. }
  116. - (BOOL)hidesBottomBarWhenPushed{
  117. return YES;
  118. }
  119. - (void)confirmAction:(UIButton*)btn{
  120. if (self.isAllSelected) {
  121. //获取所有被选中的分组
  122. NSMutableArray *groupIDArray = [NSMutableArray array];
  123. for (Department *model in self.departSourceDataArray) {
  124. if (model.hadSelected) {
  125. [groupIDArray addObject:model];
  126. }
  127. }
  128. for (SelectModel *mode in self.usersSourceDataArray) {
  129. if (mode.hadSelected) {
  130. mode.SourceType = 0;
  131. mode.SourceId = mode.UserId;
  132. mode.SourceName = mode.UserName;
  133. [self.selectArray addObject:mode];
  134. }
  135. }
  136. if (groupIDArray.count == 0) {
  137. NSLog(@"选中%@",self.selectArray);
  138. [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFI_ChaoSongRen object:nil userInfo:@{@"selectPeople":self.selectArray}];
  139. [self back1];
  140. return;
  141. } else {
  142. NSMutableArray *selectedUsers = [[NSMutableArray alloc] init];
  143. //把部门转换为成员
  144. for (Department *model in groupIDArray) {
  145. SelectModel *selectModel = [[SelectModel alloc] init];
  146. selectModel.UserId = model.Id;
  147. selectModel.UserName = model.Name ? model.Name : model.GroupName;
  148. selectModel.SourceType = self.SourceType;
  149. selectModel.SourceId = model.Id;
  150. selectModel.SourceName = model.Name ? model.Name : model.GroupName;
  151. [selectedUsers addObject:selectModel];
  152. if ([model.Name isEqualToString:@"单位通讯录"]) {
  153. selectModel.SourceType = 1;
  154. }else if ([model.Name isEqualToString:@"自建通讯录"]) {
  155. selectModel.SourceType = 3;
  156. }
  157. }
  158. if (self.selectArray.count > 0) {
  159. [selectedUsers addObjectsFromArray:self.selectArray];
  160. }
  161. [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFI_ChaoSongRen object:nil userInfo:@{@"selectPeople":selectedUsers}];
  162. [self back1];
  163. return;
  164. }
  165. }
  166. NSMutableArray *groupIDArray = [NSMutableArray array];
  167. for (Department *model in self.departSourceDataArray) {
  168. if (model.hadSelected) {
  169. [groupIDArray addObject:@(model.Id)];
  170. }
  171. }
  172. for (SelectModel *mode in self.usersSourceDataArray) {
  173. if (mode.hadSelected) {
  174. [self.selectArray addObject:mode];
  175. }
  176. }
  177. NSMutableDictionary *dic = @{@"ItemId":groupIDArray}.mutableCopy;
  178. [dic setValue:@(self.isMyGroup) forKey:@"TypeId"];
  179. NSLog(@"请求参数1%@",dic);
  180. if (groupIDArray.count == 0) {
  181. NSLog(@"选中%@",self.selectArray);
  182. [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFI_ChaoSongRen object:nil userInfo:@{@"selectPeople":self.selectArray}];
  183. [self back1];
  184. return;
  185. }else{
  186. if (self.isDefalutPage == 1) {
  187. [dic setValue:@[@(0)] forKey:@"ItemId"];
  188. if (self.indexflag == 0) {
  189. if (self.departSourceDataArray.firstObject.hadSelected) {
  190. [dic setValue:@(1) forKey:@"TypeId"];
  191. }else{
  192. [dic setValue:@(2) forKey:@"TypeId"];
  193. }
  194. }else if (self.indexflag == 1) {
  195. if (self.departSourceDataArray.firstObject.hadSelected) {
  196. [dic setValue:@(1) forKey:@"TypeId"];
  197. }else{
  198. [dic setValue:@(2) forKey:@"TypeId"];
  199. }
  200. }else if (self.indexflag == 2){
  201. [dic setValue:@(1) forKey:@"TypeId"];
  202. }
  203. }
  204. NSLog(@"请求参数1%@",dic);
  205. SHOWLOADING
  206. WS(weakSelf);
  207. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,AddChaoSongRen_Post] parameters:dic responseStyle:JOSN success:^(id _Nonnull responseObject) {
  208. REMOVESHOW
  209. for (NSDictionary *dict in responseObject) {
  210. SelectModel * model = [SelectModel modelWithDictionary:dict];
  211. model.UserId = model.Id;
  212. model.UserName = model.Name;
  213. model.SourceType = weakSelf.SourceType;
  214. model.SourceId = model.UserId;
  215. model.SourceName = model.UserName;
  216. [weakSelf.selectArray addObject:model];
  217. }
  218. [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFI_ChaoSongRen object:nil userInfo:@{@"selectPeople":weakSelf.selectArray}];
  219. [weakSelf back1];
  220. } failure:^(NSError * _Nonnull error) {
  221. SHOWERROR([ZYCTool handerResultData:error]);
  222. }];
  223. }
  224. }
  225. - (void)setRIghtButtonTitle:(NSInteger)indeflag{
  226. [self.myNavigationBar.rightButton setTitle:[NSString stringWithFormat:@"确定(%ld)",(long)indeflag] forState:UIControlStateNormal];
  227. if (self.isDefalutPage == 1){
  228. if (indeflag == 2) {
  229. [self.myNavigationBar.backButton2 setTitle:@"取消全选" forState:UIControlStateNormal];
  230. }else{
  231. [self.myNavigationBar.backButton2 setTitle:@"全选" forState:UIControlStateNormal];
  232. }
  233. }else{
  234. [self.myNavigationBar.backButton2 setTitle:@"全选" forState:UIControlStateNormal];
  235. }
  236. }
  237. #pragma mark - setter
  238. - (TDTableView *)myTableView{
  239. if (!_myTableView) {
  240. _myTableView = [[TDTableView alloc]init ];
  241. _myTableView.delegate = self;
  242. _myTableView.dataSource = self;
  243. [self.myTableView registerNib:[UINib nibWithNibName:@"SendInfoGroupCell" bundle:nil] forCellReuseIdentifier:@"SendInfoGroupCell"];//SendGroupBCell
  244. [self.myTableView registerNib:[UINib nibWithNibName:@"SendGroupBCell" bundle:nil] forCellReuseIdentifier:@"SendGroupBCell"];
  245. }
  246. return _myTableView;
  247. }
  248. - (UIView *)listHeaderVIew{
  249. if (!_listHeaderVIew) {
  250. _listHeaderVIew = [[UIView alloc]initWithFrame:CGRectMake(0,0,kGXScreenWidth,44)];
  251. _listHeaderVIew.backgroundColor = UIColorHex(#FFFFFF);
  252. MyTDGroupView * groupView = [[MyTDGroupView alloc] initWithFrame:CGRectMake(0, 4, SCREEN_WIDTH, 36)];
  253. [_listHeaderVIew addSubview:groupView];
  254. }
  255. return _listHeaderVIew;
  256. }
  257. - (TDButton *)serachButton{
  258. if (!_serachButton) {
  259. _serachButton = [[TDButton alloc]initWithFrame:CGRectMake(20,5, kGXScreenWidth-40,40)];
  260. [_serachButton setTitle:@"搜索" forState:UIControlStateNormal];
  261. [[_serachButton titleLabel] setFont:[UIFont systemFontOfSize:14.f]];
  262. [_serachButton setImage:IMG(@"sendinfo_search") forState:UIControlStateNormal];
  263. [_serachButton setTitleColor:UIColorHex(B6B7B9) forState:UIControlStateNormal];
  264. _serachButton.backgroundColor = UIColorHex(F5F6F8);
  265. [_serachButton addTarget:self action:@selector(searchhander:) forControlEvents:UIControlEventTouchDown];
  266. [_serachButton layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleLeft imageTitleSpace:2];
  267. _serachButton.layer.cornerRadius = 20;
  268. _serachButton.layer.masksToBounds = YES;
  269. }
  270. return _serachButton;
  271. }
  272. - (NSMutableArray<SelectModel *> *)selectArray{
  273. if (!_selectArray) {
  274. _selectArray = [NSMutableArray array];
  275. }
  276. return _selectArray;
  277. }
  278. #pragma mark -UITableViewDelegate,UITableViewDataSource
  279. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  280. return 2;
  281. }
  282. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  283. if (section == 0) {
  284. return self.departSourceDataArray.count;
  285. }else{
  286. return self.usersSourceDataArray.count;
  287. }
  288. return 0;
  289. }
  290. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  291. WS(weakSelf);
  292. NSInteger count = [self countOfSelectArray];
  293. if (count > 0) {
  294. [self.myNavigationBar.rightButton setTitle:[NSString stringWithFormat:@"确定(%ld)",(long)count] forState:UIControlStateNormal];
  295. }else{
  296. [self.myNavigationBar.rightButton setTitle:@"确定" forState:UIControlStateNormal];
  297. }
  298. if (indexPath.section == 1) {
  299. if ([self checkAllSelect:0]) {
  300. [self.myNavigationBar.backButton2 setTitle:@"取消全选" forState:UIControlStateNormal];
  301. }else{
  302. [self.myNavigationBar.backButton2 setTitle:@"全选" forState:UIControlStateNormal];
  303. }
  304. NSString *cellIdentifier = @"SendInfoGroupCell";
  305. SendInfoGroupCell * detailCommentCell = (SendInfoGroupCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  306. SelectModel *model = self.usersSourceDataArray[indexPath.row];
  307. if (model.IsDisable) {
  308. [detailCommentCell.selectbuton setEnabled:NO];
  309. [detailCommentCell.contentView setBackgroundColor:[UIColor grayColor]];
  310. }
  311. [detailCommentCell loadDataDepartUserModel:model indexWith:indexPath];
  312. [detailCommentCell.selectbuton setAction:^{
  313. model.hadSelected = !model.hadSelected;
  314. [weakSelf.myTableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone];
  315. }];
  316. detailCommentCell.rightImgeView.hidden = YES;
  317. return detailCommentCell;
  318. }else{
  319. if ([self checkAllSelect:1]) {
  320. [self.myNavigationBar.backButton2 setTitle:@"取消全选" forState:UIControlStateNormal];
  321. }else{
  322. [self.myNavigationBar.backButton2 setTitle:@"全选" forState:UIControlStateNormal];
  323. }
  324. NSString *cellIdentifier2 = @"SendGroupBCell";
  325. SendGroupBCell * sendB = (SendGroupBCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier2];
  326. Department *model = self.departSourceDataArray[indexPath.row];
  327. [sendB loadDataModelDepartment: model WithIndex:indexPath];
  328. [sendB.selectbuton setAction:^{
  329. model.hadSelected = !model.hadSelected;
  330. [weakSelf.myTableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone];
  331. }];
  332. sendB.rightImgeView.hidden = NO;
  333. return sendB;
  334. }
  335. }
  336. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  337. return 65;
  338. }
  339. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  340. if (self.isDefalutPage == 1) {
  341. if (indexPath.row == 0) { //
  342. AddLookUpUserSecondVC *vc = [[AddLookUpUserSecondVC alloc] init];
  343. vc.indexId = self.departSourceDataArray[indexPath.row].Id;
  344. vc.isDefalutPage = 2;
  345. vc.isMyGroup = 1;
  346. vc.SourceType = 1;
  347. vc.isShow = self.isShow;
  348. vc.UserIds = self.UserIds;
  349. vc.titleStr = self.titleStr;
  350. vc.grouperArray = self.grouperArray;
  351. vc.isAllSelected = self.isAllSelected;
  352. [self.navigationController pushViewController:vc animated:YES];
  353. }else{
  354. AddLookUpUserSecondVC *vc = [[AddLookUpUserSecondVC alloc] init];
  355. vc.indexId = self.departSourceDataArray[indexPath.row].Id;
  356. vc.isDefalutPage = 2;
  357. vc.isMyGroup = 2;
  358. vc.titleStr = self.titleStr;
  359. vc.SourceType = 3;
  360. vc.isShow = self.isShow;
  361. vc.UserIds = self.UserIds;
  362. vc.grouperArray = self.grouperArray;
  363. vc.isAllSelected = self.isAllSelected;
  364. [self.navigationController pushViewController:vc animated:YES];
  365. }
  366. }else{
  367. if (indexPath.section == 0) {
  368. AddLookUpUserSecondVC *vc = [[AddLookUpUserSecondVC alloc] init];
  369. Department *model = self.departSourceDataArray[indexPath.row];
  370. vc.indexId = model.Id;
  371. vc.isDefalutPage = 2;
  372. vc.isShow = self.isShow;
  373. vc.UserIds = self.UserIds;
  374. vc.titleStr = self.titleStr;
  375. vc.isMyGroup = self.isMyGroup;
  376. vc.SourceType = self.SourceType;
  377. vc.grouperArray = self.grouperArray;
  378. vc.isAllSelected = self.isAllSelected;
  379. [self.navigationController pushViewController:vc animated:YES];
  380. }else{
  381. SelectModel *model = self.usersSourceDataArray[indexPath.row];
  382. if (!model.IsDisable) {
  383. model.hadSelected = !model.hadSelected;
  384. [self.myTableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone];
  385. }
  386. }
  387. }
  388. }
  389. - (NSInteger)countOfSelectArray
  390. {
  391. NSInteger count = 0;
  392. for (SelectModel * model in self.usersSourceDataArray) {
  393. if (model.hadSelected) {
  394. count++;
  395. }
  396. }
  397. for (Department * model in self.departSourceDataArray) {
  398. if (model.hadSelected) {
  399. count++;
  400. }
  401. }
  402. if (count > 0) {
  403. [self.myNavigationBar.rightButton setTitleColor:UIColorHex(#3979D3) forState:UIControlStateNormal];
  404. }else{
  405. [self.myNavigationBar.rightButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
  406. }
  407. return count;
  408. }
  409. - (BOOL)checkAllSelect:(NSInteger)index
  410. {
  411. switch (index) {
  412. case 0:
  413. {
  414. for (SelectModel * model in self.usersSourceDataArray) {
  415. if (!model.hadSelected) {
  416. return NO;
  417. }
  418. }
  419. return YES;
  420. }
  421. break;
  422. default:
  423. {
  424. for (Department * model in self.departSourceDataArray) {
  425. if (!model.hadSelected) {
  426. return NO;
  427. }
  428. }
  429. return YES;
  430. }
  431. break;
  432. }
  433. }
  434. #pragma mark - 网络数据请求
  435. - (void)getdata{
  436. if (self.isDefalutPage == 1) {
  437. return ;
  438. }
  439. SHOWLOADING
  440. if (self.isMyGroup == 1) {
  441. [self defaltGroupData];
  442. }
  443. if (self.isMyGroup == 2) {
  444. [self myGroupData];
  445. }
  446. }
  447. - (void)defaltGroupData{
  448. NSDictionary * paraDict = @{@"DepartmentId":@(self.indexId),@"UserIds":self.UserIds,@"IsShow":@(self.isShow)};
  449. NSLog(@"%@",paraDict);
  450. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,AddressBookGroup_DepartemntDetail_Post] parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
  451. REMOVESHOW;
  452. NSDictionary *dic = responseObject;
  453. NSArray *departMentArray = dic[@"Departments"];
  454. NSMutableArray *departMentMutableArray = [NSMutableArray array];
  455. for (NSDictionary *dic2 in departMentArray) {
  456. Department *model = [[Department alloc]initWithDictionary:dic2 error:nil];
  457. [departMentMutableArray addObject:model];
  458. }
  459. self.departSourceDataArray = departMentMutableArray;
  460. NSArray *userArray = dic[@"Users"];
  461. NSMutableArray *usersMutableArray = [NSMutableArray array];
  462. for (NSDictionary *dic2 in userArray) {
  463. SelectModel * model = [[SelectModel alloc] initDict:dic2];
  464. [usersMutableArray addObject:model];
  465. }
  466. for (SelectModel * model in self.grouperArray) {
  467. for (SelectModel * userModel in usersMutableArray) {
  468. if (userModel.UserId == model.UserId) {
  469. userModel.IsDelete = YES;
  470. }
  471. }
  472. }
  473. NSMutableArray * checkUserArray = [NSMutableArray array];
  474. for (SelectModel * model in usersMutableArray) {
  475. if (!model.IsDelete) {
  476. [checkUserArray addObject:model];
  477. }
  478. }
  479. self.usersSourceDataArray = checkUserArray;
  480. [self.myTableView reloadData];
  481. } failure:^(NSError * _Nonnull error) {
  482. SHOWERROR([ZYCTool handerResultData:error]);
  483. }];
  484. }
  485. - (void)myGroupData{
  486. NSDictionary * paraDict = @{@"AddressBookGroupId":@(self.indexId),@"UserIds":self.UserIds,@"IsShow":@(self.isShow)};
  487. NSLog(@"%@",paraDict);
  488. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,AddressBookGroupUser_Get_Post] parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
  489. REMOVESHOW;
  490. NSDictionary *dic = responseObject;
  491. NSArray *departMentArray = dic[@"AddressBookGroups"];
  492. NSMutableArray *departMentMutableArray = [NSMutableArray array];
  493. for (NSDictionary *dic2 in departMentArray) {
  494. Department *model = [[Department alloc]initWithDictionary:dic2 error:nil];
  495. [departMentMutableArray addObject:model];
  496. }
  497. self.departSourceDataArray = departMentMutableArray;
  498. NSArray *userArray = dic[@"AddressBookGroupUsers"];
  499. NSMutableArray *usersMutableArray = [NSMutableArray array];
  500. for (NSDictionary *dic2 in userArray) {
  501. SelectModel * model = [SelectModel modelWithDictionary:dic2];
  502. [usersMutableArray addObject:model];
  503. }
  504. for (SelectModel * model in self.grouperArray) {
  505. for (SelectModel * userModel in usersMutableArray) {
  506. if (userModel.UserId == model.UserId) {
  507. userModel.IsDelete = YES;
  508. }
  509. }
  510. }
  511. NSMutableArray * checkUserArray = [NSMutableArray array];
  512. for (SelectModel * model in usersMutableArray) {
  513. if (!model.IsDelete) {
  514. [checkUserArray addObject:model];
  515. }
  516. }
  517. self.usersSourceDataArray = checkUserArray;
  518. [self.myTableView reloadData];
  519. } failure:^(NSError * _Nonnull error) {
  520. SHOWERROR([ZYCTool handerResultData:error]);
  521. }];
  522. }
  523. #pragma mark - 搜索事件处理
  524. - (void)searchhander:(TDButton *)sedner{
  525. }
  526. -(void)getSearchKeyWord:(NSString *)searchWord{
  527. NSLog(@"%@",searchWord);
  528. if(searchWord.length > 0){
  529. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  530. [dict setObject:searchWord forKey:@"Key"];
  531. WEAKSELF
  532. [[HttpManager sharedHttpManager] POSTWithUrl:Host(AddressBookGroup_Search_Post) parameters:dict success:^(id _Nonnull responseObject) {
  533. STRONGSELF
  534. NSArray *array = responseObject;
  535. if (array.count == 0) {
  536. SHOWERROR(@"没有搜到结果");
  537. }else{
  538. NSArray *userArray = responseObject;
  539. NSMutableArray *usersMutableArray = [NSMutableArray array];
  540. for (NSDictionary *dic2 in userArray) {
  541. SelectModel * model = [[SelectModel alloc] initDict:dic2];
  542. [usersMutableArray addObject:model];
  543. }
  544. [strongSelf.departSourceDataArray removeAllObjects];
  545. strongSelf.usersSourceDataArray = usersMutableArray;
  546. [strongSelf.myTableView reloadData];
  547. [strongSelf.myTableView reloadData];
  548. }
  549. } failure:^(NSError * _Nonnull error) {
  550. SHOWERROR([ZYCTool handerResultData:error])
  551. }];
  552. }else{
  553. }
  554. }
  555. - (void)canCelAllSelect
  556. {
  557. for (SelectModel * model in self.usersSourceDataArray) {
  558. model.hadSelected = NO;
  559. }
  560. for (Department * model in self.departSourceDataArray) {
  561. model.hadSelected = NO;
  562. }
  563. }
  564. - (void)viewWillDisappear:(BOOL)animated
  565. {
  566. [super viewWillDisappear:animated];
  567. [self canCelAllSelect];
  568. [self.myTableView reloadData];
  569. }
  570. @end