AddLookUpUserSecondVC.m 41 KB

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