AddLookUpUserSecondVC.m 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924
  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. #import "MailModel.h"
  14. #import "MailListCell.h"
  15. @interface AddLookUpUserSecondVC ()<UITableViewDelegate,UITableViewDataSource>
  16. @property (nonatomic, strong) TDTableView *myTableView;
  17. @property (nonatomic, strong) UIView *listHeaderVIew;
  18. @property (nonatomic, strong) TDButton *serachButton;
  19. @property (nonatomic, strong) AddressBookGroupModel *addressBookModel;
  20. @property (nonatomic,assign) NSInteger indexflag;
  21. @property (nonatomic, strong) NSMutableArray <SelectModel*>*selectArray;
  22. @property (nonatomic, strong) NSMutableArray <Department *>*selectDepartArray;
  23. @property (nonatomic, strong) NSMutableArray <SelectModel*>*usersSourceDataArray;
  24. @property (nonatomic, strong) NSMutableArray *dataSourceArray;
  25. @property (nonatomic, strong) UIView *SortView;
  26. @property (nonatomic, strong) UIButton *allSelectBtn;
  27. @property (nonatomic, strong) UILabel *selectCountL;
  28. @end
  29. @implementation AddLookUpUserSecondVC
  30. - (void)viewDidLoad {
  31. [super viewDidLoad];
  32. [self getdata];
  33. [self.view addSubview:self.listHeaderVIew];
  34. [self.listHeaderVIew mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.left.right.mas_equalTo(self.view);
  36. make.top.mas_equalTo(self.myNavigationBar.mas_bottom);
  37. make.height.mas_offset(44);
  38. }];
  39. [self addSortV];
  40. [self.view addSubview:self.myTableView];
  41. [self.myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.top.mas_equalTo(self.SortView.mas_bottom);
  43. make.left.right.mas_equalTo(self.view);
  44. make.bottom.mas_equalTo(self.view.mas_safeAreaLayoutGuideBottom);
  45. }];
  46. WS(weakSelf);
  47. UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) {
  48. MailListSearchVC *vc = [[MailListSearchVC alloc] init];
  49. vc.notChangeColor = weakSelf.notSearchChangeColor;
  50. vc.IsAddUser = YES;
  51. vc.isShow = weakSelf.isShow;
  52. vc.UserIds = weakSelf.UserIds;
  53. vc.DepartmentId = weakSelf.indexId;
  54. vc.SearchType = weakSelf.isMyGroup;
  55. [weakSelf.navigationController pushViewController:vc animated:YES];
  56. }];
  57. [self.listHeaderVIew addGestureRecognizer:tap];
  58. self.fd_prefersNavigationBarHidden = YES;
  59. self.view.backgroundColor = UIColorHex(#FFFFFF);
  60. self.myTableView.backgroundColor = UIColorHex(#F5F6F8);
  61. [self createnavi];
  62. }
  63. #pragma mark - 导航视图
  64. - (void)createnavi{
  65. self.myNavigationBar.titleLabel.text = self.titleStr;
  66. [self.myNavigationBar.rightButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
  67. [self.myNavigationBar.rightButton setTitle:@"确定" forState:UIControlStateNormal];
  68. [[self.myNavigationBar.rightButton titleLabel] setFont:[UIFont systemFontOfSize:15.f]];
  69. self.myNavigationBar.rightButton.hidden = NO;
  70. [self.myNavigationBar.rightButton mas_updateConstraints:^(MASConstraintMaker *make) {
  71. make.centerY.equalTo(self.myNavigationBar.backButton);
  72. make.height.mas_offset(@44);
  73. make.right.mas_equalTo(self.myNavigationBar.mas_right).offset(-15);
  74. }];
  75. }
  76. #pragma mark - 导航事件处理
  77. -(void)back{
  78. [self.navigationController popViewControllerAnimated:YES];
  79. }
  80. -(void)back1{
  81. for ( NSInteger i = (self.navigationController.viewControllers.count - 1); i > 0 ;i --) {
  82. NSLog(@"%@",self.navigationController.viewControllers[i]);
  83. if ([self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"MyWorkWordVC")]
  84. || [self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"ChatNewGroupVC")]
  85. || [self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"H5ViewController")]
  86. || [self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"MyTDTopicCreateVC")]
  87. || [self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"MyFavoriteNewFindVC")]
  88. || [self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"ChatNewRowVC")]
  89. || [self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"MyTDTopicGroupUserVC")]
  90. || [self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"WorkFlowOrderController")]
  91. || [self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"CreateInterLeterVC")]
  92. || [self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"MailListByZuVC")]) {
  93. [self.navigationController popToViewController:self.navigationController.viewControllers[i] animated:YES];
  94. return;
  95. }
  96. }
  97. }
  98. //全选操作
  99. - (void)selectedAction{
  100. if (self.isAllSelected) {
  101. [self.allSelectBtn setImage:IMG(@"sendinfo_yes") forState:UIControlStateNormal];
  102. }else{
  103. [self.allSelectBtn setImage:IMG(@"sendinfo_no") forState:UIControlStateNormal];
  104. }
  105. if (self.IsSubVC) {
  106. NSInteger count = 0;
  107. for(NSInteger i = 0 ; i < 2 ; i++){
  108. if (i == 0) {
  109. for (Department *depart in self.departSourceDataArray) {
  110. depart.hadSelected = self.isAllSelected;
  111. if (depart.hadSelected) {
  112. count ++;
  113. }
  114. }
  115. }
  116. if (i == 1) {
  117. for (SelectModel * model in self.usersSourceDataArray) {
  118. model.hadSelected = self.isAllSelected;
  119. if (model.hadSelected) {
  120. count ++;
  121. }
  122. }
  123. }
  124. }
  125. self.selectCountL.text = [NSString stringWithFormat:@"%ld",count];
  126. }else{
  127. NSInteger count = 0;
  128. for (NSArray * array in self.dataSourceArray) {
  129. for (MailModel * model in array) {
  130. model.IsSelect = self.isAllSelected;
  131. if (model.IsSelect) {
  132. count ++;
  133. }
  134. }
  135. }
  136. self.selectCountL.text = [NSString stringWithFormat:@"%ld",count];
  137. }
  138. [self.myTableView reloadData];
  139. }
  140. // 左边按钮 全选 取消全选
  141. - (void)secondBarButtonItems:(TDButton *)sender{
  142. [super menuAction:sender];
  143. }
  144. - (void)rightButtonAction:(TDButton *)sender{
  145. [self confirmAction:sender];
  146. }
  147. - (BOOL)hidesBottomBarWhenPushed{
  148. return YES;
  149. }
  150. - (void)confirmAction:(UIButton*)btn{
  151. // if (self.isAllSelected) {
  152. // //获取所有被选中的分组
  153. // NSMutableArray *groupIDArray = [NSMutableArray array];
  154. // for (Department *model in self.departSourceDataArray) {
  155. // if (model.hadSelected) {
  156. // [groupIDArray addObject:model];
  157. // }
  158. // }
  159. // for (SelectModel *mode in self.usersSourceDataArray) {
  160. // if (mode.hadSelected) {
  161. // mode.SourceType = 0;
  162. // mode.SourceId = mode.UserId;
  163. // mode.SourceName = mode.UserName;
  164. // [self.selectArray addObject:mode];
  165. // }
  166. // }
  167. // if (groupIDArray.count == 0) {
  168. // NSLog(@"选中%@",self.selectArray);
  169. // [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFI_ChaoSongRen object:nil userInfo:@{@"selectPeople":self.selectArray}];
  170. // [self back1];
  171. // return;
  172. // } else {
  173. // NSMutableArray *selectedUsers = [[NSMutableArray alloc] init];
  174. // //把部门转换为成员
  175. // for (Department *model in groupIDArray) {
  176. // SelectModel *selectModel = [[SelectModel alloc] init];
  177. // selectModel.UserId = model.Id;
  178. // selectModel.UserName = model.Name ? model.Name : model.GroupName;
  179. // selectModel.SourceType = self.SourceType;
  180. // selectModel.SourceId = model.Id;
  181. // selectModel.SourceName = model.Name ? model.Name : model.GroupName;
  182. // [selectedUsers addObject:selectModel];
  183. // if ([model.Name isEqualToString:@"单位通讯录"]) {
  184. // selectModel.SourceType = 1;
  185. // }else if ([model.Name isEqualToString:@"自建通讯录"]) {
  186. // selectModel.SourceType = 3;
  187. // }
  188. // }
  189. // if (self.selectArray.count > 0) {
  190. // [selectedUsers addObjectsFromArray:self.selectArray];
  191. // }
  192. // [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFI_ChaoSongRen object:nil userInfo:@{@"selectPeople":selectedUsers}];
  193. // [self back1];
  194. // return;
  195. // }
  196. // }
  197. // NSMutableArray *groupIDArray = [NSMutableArray array];
  198. // for (Department *model in self.departSourceDataArray) {
  199. // if (model.hadSelected) {
  200. // [groupIDArray addObject:@(model.Id)];
  201. // }
  202. // }
  203. // for (SelectModel *mode in self.usersSourceDataArray) {
  204. // if (mode.hadSelected) {
  205. // [self.selectArray addObject:mode];
  206. // }
  207. // }
  208. // if (self.selectArray.count > 0) {
  209. // NSLog(@"选中%@",self.selectArray);
  210. // [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFI_ChaoSongRen object:nil userInfo:@{@"selectPeople":self.selectArray}];
  211. // [self back1];
  212. // return;
  213. // }else{
  214. // NSMutableDictionary *dic = @{@"ItemId":groupIDArray}.mutableCopy;
  215. // [dic setValue:@(self.isMyGroup) forKey:@"TypeId"];
  216. // if (self.isDefalutPage == 1) {
  217. // [dic setValue:@[@(0)] forKey:@"ItemId"];
  218. // if (self.indexflag == 0) {
  219. // if (self.departSourceDataArray.firstObject.hadSelected) {
  220. // [dic setValue:@(1) forKey:@"TypeId"];
  221. // }else{
  222. // [dic setValue:@(2) forKey:@"TypeId"];
  223. // }
  224. // }else if (self.indexflag == 1) {
  225. // if (self.departSourceDataArray.firstObject.hadSelected) {
  226. // [dic setValue:@(1) forKey:@"TypeId"];
  227. // }else{
  228. // [dic setValue:@(2) forKey:@"TypeId"];
  229. // }
  230. // }else if (self.indexflag == 2){
  231. // [dic setValue:@(1) forKey:@"TypeId"];
  232. // }
  233. // }
  234. // NSLog(@"请求参数1%@",dic);
  235. SHOWLOADING
  236. WS(weakSelf);
  237. // [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,AddChaoSongRen_Post] parameters:dic responseStyle:JOSN success:^(id _Nonnull responseObject) {
  238. // REMOVESHOW
  239. // for (NSDictionary *dict in responseObject) {
  240. // SelectModel * model = [SelectModel modelWithDictionary:dict];
  241. // model.UserId = model.Id;
  242. // model.UserName = model.Name;
  243. // model.SourceType = weakSelf.SourceType;
  244. // model.SourceId = model.UserId;
  245. // model.SourceName = model.UserName;
  246. // [weakSelf.selectArray addObject:model];
  247. // }
  248. // [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFI_ChaoSongRen object:nil userInfo:@{@"selectPeople":weakSelf.selectArray}];
  249. // [weakSelf back1];
  250. // } failure:^(NSError * _Nonnull error) {
  251. // SHOWERROR([ZYCTool handerResultData:error]);
  252. // }];
  253. NSMutableDictionary * paraDict = [NSMutableDictionary dictionary];
  254. if (self.dataSourceArray.count > 0) {
  255. NSMutableArray * mArray = [NSMutableArray array];
  256. for (NSArray * array in self.dataSourceArray) {
  257. for (MailModel * model in array) {
  258. [mArray addObject:@{@"SourceType":@(model.TypeId),@"SourceId":@(0)}];
  259. }
  260. }
  261. [paraDict setValue:mArray forKey:@"Item"];
  262. }
  263. if (self.departSourceDataArray.count > 0) {
  264. NSMutableArray * mArray = [NSMutableArray array];
  265. for (Department *model in self.departSourceDataArray) {
  266. [mArray addObject:@{@"SourceType":@(1),@"SourceId":@(model.Id)}];
  267. }
  268. [paraDict setValue:mArray forKey:@"Item"];
  269. }
  270. [self.selectArray removeAllObjects];
  271. [[HttpManager sharedHttpManager] POSTUrl:Host(API_APP_User_Middle) parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
  272. REMOVESHOW
  273. for (NSDictionary *dict in responseObject) {
  274. SelectModel * model = [SelectModel modelWithDictionary:dict];
  275. model.UserId = model.Id;
  276. model.UserName = model.Name;
  277. model.SourceType = weakSelf.SourceType;
  278. model.SourceId = model.UserId;
  279. model.SourceName = model.UserName;
  280. [weakSelf.selectArray addObject:model];
  281. }
  282. [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFI_ChaoSongRen object:nil userInfo:@{@"selectPeople":weakSelf.selectArray}];
  283. [weakSelf back1];
  284. } failure:^(NSError * _Nonnull error) {
  285. SHOWERROR([ZYCTool handerResultData:error]);
  286. }];
  287. // }
  288. }
  289. - (void)setRIghtButtonTitle:(NSInteger)indeflag{
  290. [self.myNavigationBar.rightButton setTitle:[NSString stringWithFormat:@"确定(%ld)",(long)indeflag] forState:UIControlStateNormal];
  291. // if (self.isDefalutPage == 1){
  292. // if (indeflag == 2) {
  293. // [self.myNavigationBar.backButton2 setTitle:@"取消全选" forState:UIControlStateNormal];
  294. // }else{
  295. // [self.myNavigationBar.backButton2 setTitle:@"全选" forState:UIControlStateNormal];
  296. // }
  297. // }else{
  298. // [self.myNavigationBar.backButton2 setTitle:@"全选" forState:UIControlStateNormal];
  299. // }
  300. }
  301. #pragma mark - setter
  302. - (TDTableView *)myTableView{
  303. if (!_myTableView) {
  304. _myTableView = [[TDTableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  305. _myTableView.delegate = self;
  306. _myTableView.dataSource = self;
  307. [self.myTableView registerNib:[UINib nibWithNibName:@"SendInfoGroupCell" bundle:nil] forCellReuseIdentifier:@"SendInfoGroupCell"];//SendGroupBCell
  308. [self.myTableView registerNib:[UINib nibWithNibName:@"SendGroupBCell" bundle:nil] forCellReuseIdentifier:@"SendGroupBCell"];
  309. }
  310. return _myTableView;
  311. }
  312. - (UIView *)listHeaderVIew{
  313. if (!_listHeaderVIew) {
  314. _listHeaderVIew = [UIView new];
  315. _listHeaderVIew.backgroundColor = UIColorHex(#FFFFFF);
  316. MyTDGroupView * groupView = [[MyTDGroupView alloc] initWithFrame:CGRectMake(0, 4, SCREEN_WIDTH, 36)];
  317. [_listHeaderVIew addSubview:groupView];
  318. }
  319. return _listHeaderVIew;
  320. }
  321. - (TDButton *)serachButton{
  322. if (!_serachButton) {
  323. _serachButton = [[TDButton alloc]initWithFrame:CGRectMake(20,5, kGXScreenWidth-40,40)];
  324. [_serachButton setTitle:@"搜索" forState:UIControlStateNormal];
  325. [[_serachButton titleLabel] setFont:[UIFont systemFontOfSize:14.f]];
  326. [_serachButton setImage:IMG(@"sendinfo_search") forState:UIControlStateNormal];
  327. [_serachButton setTitleColor:UIColorHex(B6B7B9) forState:UIControlStateNormal];
  328. _serachButton.backgroundColor = UIColorHex(F5F6F8);
  329. [_serachButton addTarget:self action:@selector(searchhander:) forControlEvents:UIControlEventTouchDown];
  330. [_serachButton layoutButtonWithEdgeInsetsStyle:GLButtonEdgeInsetsStyleLeft imageTitleSpace:2];
  331. _serachButton.layer.cornerRadius = 20;
  332. _serachButton.layer.masksToBounds = YES;
  333. }
  334. return _serachButton;
  335. }
  336. - (NSMutableArray<SelectModel *> *)selectArray{
  337. if (!_selectArray) {
  338. _selectArray = [NSMutableArray array];
  339. }
  340. return _selectArray;
  341. }
  342. #pragma mark -UITableViewDelegate,UITableViewDataSource
  343. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  344. if (!self.IsSubVC) {
  345. return self.dataSourceArray.count;
  346. }else{
  347. return 2;
  348. }
  349. }
  350. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  351. if (!self.IsSubVC) {
  352. NSArray * array = self.dataSourceArray[section];
  353. return [array count];
  354. }else{
  355. if (section == 0) {
  356. return self.departSourceDataArray.count;
  357. }else{
  358. return self.usersSourceDataArray.count;
  359. }
  360. }
  361. }
  362. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  363. WS(weakSelf);
  364. NSInteger count = [self countOfSelectArray];
  365. if (count > 0) {
  366. [self.myNavigationBar.rightButton setTitle:[NSString stringWithFormat:@"确定(%ld)",(long)count] forState:UIControlStateNormal];
  367. }else{
  368. [self.myNavigationBar.rightButton setTitle:@"确定" forState:UIControlStateNormal];
  369. }
  370. if (!self.IsSubVC) {
  371. if ([self checkAllSelect:2]) {
  372. [self.allSelectBtn setImage:IMG(@"sendinfo_yes") forState:UIControlStateNormal];
  373. }else{
  374. [self.allSelectBtn setImage:IMG(@"sendinfo_no") forState:UIControlStateNormal];
  375. }
  376. NSString *cellIdentifier2 = @"SendGroupBCell";
  377. SendGroupBCell * cell = (SendGroupBCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier2];
  378. NSArray * array = self.dataSourceArray[indexPath.section];
  379. if (array.count > 0) {
  380. MailModel * model = array[indexPath.row];
  381. [cell setDataModel:model];
  382. [cell.selectbuton setAction:^{
  383. model.IsSelect = !model.IsSelect;
  384. [weakSelf checkSelectCount:2];
  385. [weakSelf.myTableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone];
  386. }];
  387. }
  388. return cell;
  389. }
  390. if (indexPath.section == 1) {
  391. if ([self checkAllSelect:0]) {
  392. [self.allSelectBtn setImage:IMG(@"sendinfo_yes") forState:UIControlStateNormal];
  393. }else{
  394. [self.allSelectBtn setImage:IMG(@"sendinfo_no") forState:UIControlStateNormal];
  395. }
  396. NSString *cellIdentifier = @"SendInfoGroupCell";
  397. SendInfoGroupCell * detailCommentCell = (SendInfoGroupCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  398. SelectModel *model = self.usersSourceDataArray[indexPath.row];
  399. if (model.IsDisable) {
  400. [detailCommentCell.selectbuton setEnabled:NO];
  401. [detailCommentCell.contentView setBackgroundColor:[UIColor grayColor]];
  402. }
  403. [detailCommentCell loadDataDepartUserModel:model indexWith:indexPath];
  404. [detailCommentCell.selectbuton setAction:^{
  405. model.hadSelected = !model.hadSelected;
  406. [weakSelf checkSelectCount:0];
  407. [weakSelf.myTableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone];
  408. }];
  409. detailCommentCell.rightImgeView.hidden = YES;
  410. return detailCommentCell;
  411. }else{
  412. if ([self checkAllSelect:1]) {
  413. [self.allSelectBtn setImage:IMG(@"sendinfo_yes") forState:UIControlStateNormal];
  414. }else{
  415. [self.allSelectBtn setImage:IMG(@"sendinfo_no") forState:UIControlStateNormal];
  416. }
  417. NSString *cellIdentifier2 = @"SendGroupBCell";
  418. SendGroupBCell * sendB = (SendGroupBCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier2];
  419. Department *model = self.departSourceDataArray[indexPath.row];
  420. [sendB loadDataModelDepartment: model WithIndex:indexPath];
  421. [sendB.selectbuton setAction:^{
  422. model.hadSelected = !model.hadSelected;
  423. [weakSelf checkSelectCount:1];
  424. [weakSelf.myTableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone];
  425. }];
  426. sendB.rightImgeView.hidden = NO;
  427. return sendB;
  428. }
  429. }
  430. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  431. return 65.f;
  432. }
  433. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  434. {
  435. if (!self.IsSubVC && section > 0) {
  436. return 36.f;
  437. }else{
  438. return 0.01f;
  439. }
  440. }
  441. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  442. {
  443. return 0.01f;
  444. }
  445. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  446. {
  447. UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)];
  448. view.backgroundColor = UIColorHex(0xF0EFF4);
  449. UILabel * titleL = [UILabel new];
  450. [view addSubview:titleL];
  451. titleL.textColor = UIColorHex(0x666666);
  452. titleL.font = Kfont(13);
  453. titleL.text = @"";
  454. [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  455. make.left.mas_offset(48);
  456. make.centerY.mas_equalTo(view);
  457. }];
  458. return view;
  459. }
  460. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  461. if (self.IsSubVC) {
  462. if (self.isDefalutPage == 1) {
  463. if (indexPath.row == 0) { //
  464. AddLookUpUserSecondVC *vc = [[AddLookUpUserSecondVC alloc] init];
  465. vc.indexId = self.departSourceDataArray[indexPath.row].Id;
  466. vc.isDefalutPage = 2;
  467. vc.isMyGroup = 1;
  468. vc.SourceType = 1;
  469. vc.IsSubVC = YES;
  470. vc.isShow = self.isShow;
  471. vc.UserIds = self.UserIds;
  472. vc.titleStr = self.titleStr;
  473. vc.grouperArray = self.grouperArray;
  474. vc.isAllSelected = self.isAllSelected;
  475. [self.navigationController pushViewController:vc animated:YES];
  476. }else{
  477. AddLookUpUserSecondVC *vc = [[AddLookUpUserSecondVC alloc] init];
  478. vc.indexId = self.departSourceDataArray[indexPath.row].Id;
  479. vc.isDefalutPage = 2;
  480. vc.isMyGroup = 2;
  481. vc.titleStr = self.titleStr;
  482. vc.SourceType = 3;
  483. vc.IsSubVC = YES;
  484. vc.isShow = self.isShow;
  485. vc.UserIds = self.UserIds;
  486. vc.grouperArray = self.grouperArray;
  487. vc.isAllSelected = self.isAllSelected;
  488. [self.navigationController pushViewController:vc animated:YES];
  489. }
  490. }else{
  491. if (indexPath.section == 0) {
  492. AddLookUpUserSecondVC *vc = [[AddLookUpUserSecondVC alloc] init];
  493. Department *model = self.departSourceDataArray[indexPath.row];
  494. vc.indexId = model.Id;
  495. vc.isDefalutPage = 2;
  496. vc.IsSubVC = YES;
  497. vc.isShow = self.isShow;
  498. vc.UserIds = self.UserIds;
  499. vc.titleStr = self.titleStr;
  500. vc.isMyGroup = self.isMyGroup;
  501. vc.SourceType = self.SourceType;
  502. vc.grouperArray = self.grouperArray;
  503. vc.isAllSelected = self.isAllSelected;
  504. [self.navigationController pushViewController:vc animated:YES];
  505. }else{
  506. SelectModel *model = self.usersSourceDataArray[indexPath.row];
  507. if (!model.IsDisable) {
  508. model.hadSelected = !model.hadSelected;
  509. [self.myTableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone];
  510. }
  511. }
  512. }
  513. }else{
  514. NSArray * array = [self.dataSourceArray objectAtIndex:indexPath.section];
  515. MailModel * model = [array objectAtIndex:indexPath.row];
  516. switch (model.TypeId) {
  517. case MailListUserType:
  518. {
  519. }
  520. break;
  521. case MailListDesType:
  522. {
  523. AddLookUpUserSecondVC *vc = [[AddLookUpUserSecondVC alloc] init];
  524. vc.indexId = self.departSourceDataArray[indexPath.row].Id;
  525. vc.isDefalutPage = 2;
  526. vc.isMyGroup = 1;
  527. vc.SourceType = 1;
  528. vc.isShow = self.isShow;
  529. vc.IsSubVC = YES;
  530. vc.UserIds = self.UserIds;
  531. vc.titleStr = self.titleStr;
  532. vc.grouperArray = self.grouperArray;
  533. vc.isAllSelected = self.isAllSelected;
  534. [self.navigationController pushViewController:vc animated:YES];
  535. }
  536. break;
  537. case MailListSysType:
  538. {
  539. }
  540. break;
  541. default:
  542. {
  543. AddLookUpUserSecondVC *vc = [[AddLookUpUserSecondVC alloc] init];
  544. vc.indexId = self.departSourceDataArray[indexPath.row].Id;
  545. vc.isDefalutPage = 2;
  546. vc.isMyGroup = 2;
  547. vc.titleStr = self.titleStr;
  548. vc.SourceType = 3;
  549. vc.IsSubVC = YES;
  550. vc.isShow = self.isShow;
  551. vc.UserIds = self.UserIds;
  552. vc.grouperArray = self.grouperArray;
  553. vc.isAllSelected = self.isAllSelected;
  554. [self.navigationController pushViewController:vc animated:YES];
  555. }
  556. break;
  557. }
  558. }
  559. }
  560. - (NSInteger)countOfSelectArray
  561. {
  562. NSInteger count = 0;
  563. for (SelectModel * model in self.usersSourceDataArray) {
  564. if (model.hadSelected) {
  565. count++;
  566. }
  567. }
  568. for (Department * model in self.departSourceDataArray) {
  569. if (model.hadSelected) {
  570. count++;
  571. }
  572. }
  573. if (count > 0) {
  574. [self.myNavigationBar.rightButton setTitleColor:UIColorHex(#3979D3) forState:UIControlStateNormal];
  575. }else{
  576. [self.myNavigationBar.rightButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
  577. }
  578. return count;
  579. }
  580. - (BOOL)checkAllSelect:(NSInteger)index
  581. {
  582. switch (index) {
  583. case 0:
  584. {
  585. for (SelectModel * model in self.usersSourceDataArray) {
  586. if (!model.hadSelected) {
  587. [self.allSelectBtn setImage:IMG(@"sendinfo_no") forState:UIControlStateNormal];
  588. return NO;
  589. }
  590. }
  591. [self.allSelectBtn setImage:IMG(@"sendinfo_yes") forState:UIControlStateNormal];
  592. return YES;
  593. }
  594. break;
  595. case 1:
  596. {
  597. for (Department * model in self.departSourceDataArray) {
  598. if (!model.hadSelected) {
  599. [self.allSelectBtn setImage:IMG(@"sendinfo_no") forState:UIControlStateNormal];
  600. return NO;
  601. }
  602. }
  603. [self.allSelectBtn setImage:IMG(@"sendinfo_yes") forState:UIControlStateNormal];
  604. return YES;
  605. }
  606. break;
  607. default:
  608. {
  609. for (NSArray * array in self.dataSourceArray) {
  610. for (MailModel * model in array) {
  611. if (!model.IsSelect) {
  612. [self.allSelectBtn setImage:IMG(@"sendinfo_no") forState:UIControlStateNormal];
  613. return NO;
  614. }
  615. }
  616. }
  617. [self.allSelectBtn setImage:IMG(@"sendinfo_yes") forState:UIControlStateNormal];
  618. return YES;
  619. }
  620. break;
  621. }
  622. }
  623. - (void)checkSelectCount:(NSInteger)index
  624. {
  625. NSInteger count = 0;
  626. switch (index) {
  627. case 0:
  628. {
  629. for (SelectModel * model in self.usersSourceDataArray) {
  630. if (model.hadSelected) {
  631. count++;
  632. }
  633. }
  634. }
  635. break;
  636. case 1:
  637. {
  638. for (Department * model in self.departSourceDataArray) {
  639. if (model.hadSelected) {
  640. count++;
  641. }
  642. }
  643. }
  644. break;
  645. default:
  646. {
  647. for (NSArray * array in self.dataSourceArray) {
  648. for (MailModel * model in array) {
  649. if (model.IsSelect) {
  650. count++;
  651. }
  652. }
  653. }
  654. }
  655. break;
  656. }
  657. self.selectCountL.text = [NSString stringWithFormat:@"%ld",count];
  658. if (count > 0) {
  659. [self.myNavigationBar.rightButton setTitleColor:UIColorHex(#3979D3) forState:UIControlStateNormal];
  660. }else{
  661. [self.myNavigationBar.rightButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
  662. }
  663. }
  664. #pragma mark - 网络数据请求
  665. - (void)getdata{
  666. if (!self.IsSubVC) {
  667. [self getRootData];
  668. }
  669. if (self.isDefalutPage == 1) {
  670. return ;
  671. }
  672. if (self.isMyGroup == 1) {
  673. [self defaltGroupData];
  674. }
  675. if (self.isMyGroup == 2) {
  676. [self myGroupData];
  677. }
  678. }
  679. - (void)getRootData
  680. {
  681. SHOWLOADING
  682. WS(weakSelf);
  683. [self.dataSourceArray removeAllObjects];
  684. [[HttpManager sharedHttpManager] GETUrl:Host(API_APP_User_Link) parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  685. NSLog(@"%@",responseObject);
  686. REMOVESHOW
  687. NSMutableArray * fArray = [NSMutableArray array];
  688. NSMutableArray * sArray = [NSMutableArray array];
  689. if ([responseObject[@"Items"] isKindOfClass:[NSArray class]]) {
  690. NSArray * array = responseObject[@"Items"];
  691. for (NSDictionary * dict in array) {
  692. MailModel * model = [MailModel modelWithDictionary:dict];
  693. [fArray addObject:model];
  694. }
  695. MailModel * omodel = [MailModel modelWithDictionary:@{@"Name":@"其他",@"TypeId":@(0)}];
  696. [fArray addObject:omodel];
  697. [weakSelf.dataSourceArray addObject:fArray];
  698. [weakSelf.dataSourceArray addObject:sArray];
  699. dispatch_async(dispatch_get_main_queue(), ^{
  700. [weakSelf.myTableView reloadData];
  701. });
  702. }
  703. } failure:^(NSError * _Nonnull error) {
  704. REMOVESHOW
  705. }];
  706. }
  707. - (void)defaltGroupData{
  708. SHOWLOADING
  709. NSDictionary * paraDict = @{@"DepartmentId":@(self.indexId),@"UserIds":self.UserIds,@"IsShow":@(self.isShow)};
  710. NSLog(@"%@",paraDict);
  711. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,AddressBookGroup_DepartemntDetail_Post] parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
  712. REMOVESHOW;
  713. NSDictionary *dic = responseObject;
  714. NSArray *departMentArray = dic[@"Departments"];
  715. NSMutableArray *departMentMutableArray = [NSMutableArray array];
  716. for (NSDictionary *dic2 in departMentArray) {
  717. Department *model = [[Department alloc]initWithDictionary:dic2 error:nil];
  718. [departMentMutableArray addObject:model];
  719. }
  720. self.departSourceDataArray = departMentMutableArray;
  721. NSArray *userArray = dic[@"Users"];
  722. NSMutableArray *usersMutableArray = [NSMutableArray array];
  723. for (NSDictionary *dic2 in userArray) {
  724. SelectModel * model = [[SelectModel alloc] initDict:dic2];
  725. [usersMutableArray addObject:model];
  726. }
  727. for (SelectModel * model in self.grouperArray) {
  728. for (SelectModel * userModel in usersMutableArray) {
  729. if (userModel.UserId == model.UserId) {
  730. userModel.IsDelete = YES;
  731. }
  732. }
  733. }
  734. NSMutableArray * checkUserArray = [NSMutableArray array];
  735. for (SelectModel * model in usersMutableArray) {
  736. if (!model.IsDelete) {
  737. [checkUserArray addObject:model];
  738. }
  739. }
  740. self.usersSourceDataArray = checkUserArray;
  741. [self.myTableView reloadData];
  742. } failure:^(NSError * _Nonnull error) {
  743. SHOWERROR([ZYCTool handerResultData:error]);
  744. }];
  745. }
  746. - (void)myGroupData{
  747. SHOWLOADING
  748. NSDictionary * paraDict = @{@"AddressBookGroupId":@(self.indexId),@"UserIds":self.UserIds,@"IsShow":@(self.isShow)};
  749. NSLog(@"%@",paraDict);
  750. [[HttpManager sharedHttpManager] POSTUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,AddressBookGroupUser_Get_Post] parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
  751. REMOVESHOW;
  752. NSDictionary *dic = responseObject;
  753. NSArray *departMentArray = dic[@"AddressBookGroups"];
  754. NSMutableArray *departMentMutableArray = [NSMutableArray array];
  755. for (NSDictionary *dic2 in departMentArray) {
  756. Department *model = [[Department alloc]initWithDictionary:dic2 error:nil];
  757. [departMentMutableArray addObject:model];
  758. }
  759. self.departSourceDataArray = departMentMutableArray;
  760. NSArray *userArray = dic[@"AddressBookGroupUsers"];
  761. NSMutableArray *usersMutableArray = [NSMutableArray array];
  762. for (NSDictionary *dic2 in userArray) {
  763. SelectModel * model = [SelectModel modelWithDictionary:dic2];
  764. [usersMutableArray addObject:model];
  765. }
  766. for (SelectModel * model in self.grouperArray) {
  767. for (SelectModel * userModel in usersMutableArray) {
  768. if (userModel.UserId == model.UserId) {
  769. userModel.IsDelete = YES;
  770. }
  771. }
  772. }
  773. NSMutableArray * checkUserArray = [NSMutableArray array];
  774. for (SelectModel * model in usersMutableArray) {
  775. if (!model.IsDelete) {
  776. [checkUserArray addObject:model];
  777. }
  778. }
  779. self.usersSourceDataArray = checkUserArray;
  780. [self.myTableView reloadData];
  781. } failure:^(NSError * _Nonnull error) {
  782. SHOWERROR([ZYCTool handerResultData:error]);
  783. }];
  784. }
  785. #pragma mark - 搜索事件处理
  786. - (void)searchhander:(TDButton *)sedner{
  787. }
  788. -(void)getSearchKeyWord:(NSString *)searchWord{
  789. NSLog(@"%@",searchWord);
  790. if(searchWord.length > 0){
  791. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  792. [dict setObject:searchWord forKey:@"Key"];
  793. WEAKSELF
  794. [[HttpManager sharedHttpManager] POSTWithUrl:Host(AddressBookGroup_Search_Post) parameters:dict success:^(id _Nonnull responseObject) {
  795. STRONGSELF
  796. NSArray *array = responseObject;
  797. if (array.count == 0) {
  798. SHOWERROR(@"没有搜到结果");
  799. }else{
  800. NSArray *userArray = responseObject;
  801. NSMutableArray *usersMutableArray = [NSMutableArray array];
  802. for (NSDictionary *dic2 in userArray) {
  803. SelectModel * model = [[SelectModel alloc] initDict:dic2];
  804. [usersMutableArray addObject:model];
  805. }
  806. [strongSelf.departSourceDataArray removeAllObjects];
  807. strongSelf.usersSourceDataArray = usersMutableArray;
  808. [strongSelf.myTableView reloadData];
  809. [strongSelf.myTableView reloadData];
  810. }
  811. } failure:^(NSError * _Nonnull error) {
  812. SHOWERROR([ZYCTool handerResultData:error])
  813. }];
  814. }else{
  815. }
  816. }
  817. - (void)canCelAllSelect
  818. {
  819. for (SelectModel * model in self.usersSourceDataArray) {
  820. model.hadSelected = NO;
  821. }
  822. for (Department * model in self.departSourceDataArray) {
  823. model.hadSelected = NO;
  824. }
  825. }
  826. - (UIButton *)allSelectBtn
  827. {
  828. if (!_allSelectBtn) {
  829. _allSelectBtn = [UIButton new];
  830. [_allSelectBtn setImage:IMG(@"sendinfo_no") forState:UIControlStateNormal];
  831. }
  832. return _allSelectBtn;
  833. }
  834. - (UILabel *)selectCountL
  835. {
  836. if (!_selectCountL) {
  837. _selectCountL = [UILabel new];
  838. _selectCountL.font = Kfont(13);
  839. _selectCountL.text = @"0";
  840. _selectCountL.textColor = UIColorHex(0x0F88EB);
  841. }
  842. return _selectCountL;
  843. }
  844. - (UIView *)SortView
  845. {
  846. if (!_SortView) {
  847. _SortView = [UIView new];
  848. _SortView.backgroundColor = UIColorHex(0xF0EFF4);
  849. }
  850. return _SortView;
  851. }
  852. - (void)addSortV
  853. {
  854. [self.view addSubview:self.SortView];
  855. [self.SortView mas_makeConstraints:^(MASConstraintMaker *make) {
  856. make.left.right.mas_equalTo(self.view);
  857. make.height.mas_offset(38);
  858. make.top.mas_equalTo(self.listHeaderVIew.mas_bottom);
  859. }];
  860. [self.SortView addSubview:self.allSelectBtn];
  861. [self.SortView addSubview:self.selectCountL];
  862. [self.allSelectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  863. make.left.mas_offset(5);
  864. make.centerY.mas_equalTo(self.SortView);
  865. make.size.mas_offset(CGSizeMake(38, 38));
  866. }];
  867. UILabel * leftL = [UILabel new];
  868. leftL.text = @"已选:";
  869. leftL.textColor = UIColorHex(0x666666);
  870. leftL.font = Kfont(13);
  871. [self.SortView addSubview:leftL];
  872. [leftL mas_makeConstraints:^(MASConstraintMaker *make) {
  873. make.left.mas_equalTo(self.allSelectBtn.mas_right).offset(5);
  874. make.centerY.mas_equalTo(self.SortView);
  875. }];
  876. [self.selectCountL mas_makeConstraints:^(MASConstraintMaker *make) {
  877. make.left.mas_equalTo(leftL.mas_right).offset(8);
  878. make.centerY.mas_equalTo(self.SortView);
  879. }];
  880. WS(weakSelf);
  881. [self.allSelectBtn setAction:^{
  882. weakSelf.isAllSelected = !weakSelf.isAllSelected;
  883. [weakSelf selectedAction];
  884. }];
  885. }
  886. - (NSMutableArray *)dataSourceArray
  887. {
  888. if (!_dataSourceArray) {
  889. _dataSourceArray = [NSMutableArray array];
  890. }
  891. return _dataSourceArray;
  892. }
  893. - (void)viewWillDisappear:(BOOL)animated
  894. {
  895. [super viewWillDisappear:animated];
  896. [self canCelAllSelect];
  897. [self.myTableView reloadData];
  898. }
  899. @end