AddLookUpUserSecondVC.m 42 KB

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