MyTDTopicGroupUserVC.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. //
  2. // MyTDTopicGroupUserVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2019/12/18.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "MyTDTopicGroupUserVC.h"
  9. #import "MyTDGroupView.h"
  10. #import "YCMenuView.h"
  11. #import "MailListCell.h"
  12. #import "MailListByZuCell.h"
  13. #import "ChineseString.h"
  14. #import "AddLookUpUserSecondVC.h"
  15. #import "MyTDTopicUserMoveVC.h"
  16. #import "MyTDTopicUserSearchVC.h"
  17. @interface MyTDTopicGroupUserVC ()<UITableViewDelegate,UITableViewDataSource,AddLookUpUserSecondVCDelegate>
  18. @property (weak, nonatomic) IBOutlet UIButton *addBtn;
  19. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  20. @property (weak, nonatomic) IBOutlet UILabel *titleL;
  21. @property (weak, nonatomic) IBOutlet UIButton *operationAllSelectButton;
  22. @property (weak, nonatomic) IBOutlet UIButton *menuBtn;
  23. @property (assign,nonatomic) OperationStateEnum operationStateEnum;
  24. @property (strong,nonatomic) UIView *operationBottomBgView;
  25. @property (nonatomic, strong) UIButton *leftCloseBtn;
  26. @property (nonatomic, strong) UIButton *rightMoveBtn;
  27. @property (nonatomic, assign) BOOL iSViewEditor;
  28. @property (nonatomic, assign) BOOL isNeedSelelct;
  29. @property (strong,nonatomic) NSMutableArray *taskActionArray;
  30. @property (strong,nonatomic) NSMutableArray *pinyinArray;
  31. @property (strong,nonatomic) NSMutableArray *nameArray;
  32. @property (nonatomic, strong) NSMutableArray *dataArray;
  33. @property (nonatomic, strong) NSMutableArray *dataSortArray;
  34. @property (nonatomic, strong) NSMutableArray *selectArray;
  35. @property (nonatomic, strong) NSMutableArray *selectIdArray;
  36. @property (nonatomic, strong) NSMutableArray *listArray;
  37. @end
  38. @implementation MyTDTopicGroupUserVC
  39. +(MyTDTopicGroupUserVC *)initMyTDTopicGroupUserVC{
  40. MyTDTopicGroupUserVC *controller = [StoryboardManager.shared.myTDTopic instantiateViewControllerWithIdentifier:@"MyTDTopicGroupUserVC"];
  41. return controller;
  42. }
  43. - (void)viewDidLoad {
  44. [super viewDidLoad];
  45. self.titleL.text = self.titleStr;
  46. [self getData];
  47. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recviveChaoSongRen:) name:NOTIFI_ChaoSongRen object:nil];
  48. self.fd_prefersNavigationBarHidden = YES;
  49. self.view.backgroundColor = RGB(255, 255, 255);
  50. if (@available(iOS 11.0, *)) {
  51. self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  52. } else {
  53. self.automaticallyAdjustsScrollViewInsets = NO;
  54. }
  55. self.tableView.delegate = self;
  56. self.tableView.dataSource = self;
  57. self.tableView.backgroundColor = [UIColor clearColor];
  58. self.iSViewEditor = NO;
  59. [self initBottomBgView];
  60. [self changeToOperation:NO];
  61. WS(weakSelf);
  62. [self.operationAllSelectButton setAction:^{
  63. for (NSArray * array in weakSelf.dataSortArray) {
  64. for (SelectModel * model in array) {
  65. model.hadSelected = weakSelf.isNeedSelelct;
  66. }
  67. }
  68. [weakSelf.tableView reloadData];
  69. }];
  70. self.isNeedSelelct = YES;
  71. [self.addBtn setAction:^{
  72. NSMutableArray *menuDataSourceArray = [weakSelf getMenuDataSource:weakSelf.taskActionArray];
  73. YCMenuView *view = [YCMenuView menuWithActions:menuDataSourceArray width:106 relyonView:weakSelf.addBtn];
  74. view.menuColor = RGB(255, 255, 255);
  75. view.separatorColor = RGB(234, 234, 234);
  76. view.textColor = RGB(102, 102, 102);
  77. view.textFont = [UIFont systemFontOfSize:16.0];
  78. view.menuCellHeight = 43.5;
  79. view.maxDisplayCount = 10;
  80. view.offset = -6;
  81. [view show];
  82. }];
  83. }
  84. -(void)initBottomBgView{
  85. self.leftCloseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  86. [self.leftCloseBtn setTitle:@"删除" forState:UIControlStateNormal];
  87. [self.leftCloseBtn setTitleColor:RGB(255, 82, 82) forState:UIControlStateNormal];
  88. self.leftCloseBtn.titleLabel.font = [UIFont systemFontOfSize:15];
  89. [self.operationBottomBgView addSubview:self.leftCloseBtn];
  90. self.leftCloseBtn.frame = CGRectMake(0, 10, SCREEN_WIDTH/2, self.operationBottomBgView.height - 10);
  91. self.self.rightMoveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  92. [self.rightMoveBtn setTitle:@"移动" forState:UIControlStateNormal];
  93. [self.rightMoveBtn setTitleColor:RGB(57, 121, 211) forState:UIControlStateNormal];
  94. [self.rightMoveBtn setTitleColor:UIColorHex(#BBBBBB) forState:UIControlStateDisabled];
  95. self.rightMoveBtn.enabled = NO;
  96. self.rightMoveBtn.titleLabel.font = [UIFont systemFontOfSize:15];
  97. [self.operationBottomBgView addSubview:self.rightMoveBtn];
  98. self.rightMoveBtn.frame = CGRectMake(SCREEN_WIDTH/2, 10, SCREEN_WIDTH/2, self.operationBottomBgView.height - 10);
  99. UIView *line = [[UIView alloc] init];
  100. line.backgroundColor = RGB(240, 239, 244);
  101. [self.operationBottomBgView addSubview:line];
  102. line.frame = CGRectMake(SCREEN_WIDTH/2, 0, .5, self.operationBottomBgView.height);
  103. UIView *topLine = [[UIView alloc] init];
  104. topLine.backgroundColor = RGB(240, 239, 244);
  105. [self.operationBottomBgView addSubview:topLine];
  106. topLine.frame = CGRectMake(0, 0, SCREEN_WIDTH, 10);
  107. WS(weakSelf);
  108. [self.leftCloseBtn setAction:^{
  109. NSMutableArray *selectIDArray = [NSMutableArray array];
  110. for (NSArray * array in weakSelf.dataSortArray) {
  111. for (SelectModel * model in array) {
  112. if (model.hadSelected) {
  113. [selectIDArray addObject:@(model.Id)];
  114. }
  115. }
  116. }
  117. if (selectIDArray.count == 0) {
  118. SHOWERROR(@"请选择要删除的通知");
  119. return ;
  120. }else{
  121. [weakSelf deleteFind:selectIDArray];
  122. }
  123. }];
  124. [self.rightMoveBtn setAction:^{
  125. NSMutableArray *selectIDArray = [NSMutableArray array];
  126. for (NSArray * array in weakSelf.dataSortArray) {
  127. for (SelectModel * model in array) {
  128. if (model.hadSelected) {
  129. [selectIDArray addObject:@(model.Id)];
  130. }
  131. }
  132. }
  133. if (selectIDArray.count == 0) {
  134. SHOWERROR(@"请选择要移动的通知或者文件夹");
  135. return ;
  136. }
  137. [weakSelf launchMoveVC:selectIDArray];
  138. }];
  139. [[UtilsTools getWindow] addSubview:self.operationBottomBgView];
  140. }
  141. #pragma Mark 左滑按钮 iOS8以上
  142. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_11_0
  143. - (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos){// delete action
  144. WS(weakSelf);
  145. SelectModel * model = [[self.dataSortArray objectAtIndex:indexPath.section-1] objectAtIndex:indexPath.row];
  146. UIContextualAction *action1 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"删除" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
  147. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)];
  148. UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  149. [weakSelf deleteFind:@[@(model.Id)]];
  150. }];
  151. UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  152. }];
  153. [alert addAction:sureAction];
  154. [alert addAction:cancelAction];
  155. [weakSelf presentViewController:alert animated:YES completion:^{
  156. }];
  157. }];
  158. action1.backgroundColor = UIColorHex(#F64A33);
  159. UIContextualAction *action2 = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"移动" handler:^(UIContextualAction * _Nonnull action,__kindof UIView * _Nonnull sourceView,void (^ _Nonnull completionHandler)(BOOL)) {
  160. [weakSelf launchMoveVC:@[@(model.Id)]];
  161. }];
  162. action2.backgroundColor = RGB(61, 156, 248);
  163. UISwipeActionsConfiguration *actions = [UISwipeActionsConfiguration configurationWithActions:@[action1,action2]];
  164. actions.performsFirstActionWithFullSwipe = NO;
  165. return actions;
  166. }
  167. #else
  168. - (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
  169. WS(weakSelf);
  170. SelectModel * model = [[self.dataSortArray objectAtIndex:indexPath.section-1] objectAtIndex:indexPath.row];
  171. UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  172. [weakSelf deleteFind:@[@(model.Id)]];
  173. }];
  174. action1.backgroundColor = UIColorHex(#F64A33);
  175. UITableViewRowAction *action2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"移动" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  176. SelectModel * model = [[weakSelf.dataSortArray objectAtIndex:indexPath.section-1] objectAtIndex:indexPath.row];
  177. [weakSelf launchMoveVC:@[@(model.Id)]];
  178. }];
  179. action2.backgroundColor = RGB(61, 156, 248);
  180. return @[action1,action2];
  181. }
  182. #endif
  183. - (void)deleteFind:(NSArray *)array
  184. {
  185. WS(weakSelf);
  186. [[HttpManager sharedHttpManager] DeleteUrl:Host(APP_Topic_Group_User) parameters:@{@"Ids":array} responseStyle:DATA success:^(id _Nonnull responseObject) {
  187. [weakSelf getData];
  188. } failure:^(NSError * _Nonnull error) {
  189. SHOWERROR([ZYCTool handerResultData:error])
  190. }];
  191. }
  192. - (void)launchMoveVC:(NSArray *)selectIDArray{
  193. MyTDTopicUserMoveVC * vc = [MyTDTopicUserMoveVC initMyTDTopicUserMoveVC];
  194. vc.selectIdArray = selectIDArray;
  195. [self.navigationController pushViewController:vc animated:YES];
  196. [self changeToOperation:NO];
  197. }
  198. -(UIView *)operationBottomBgView{
  199. if(!_operationBottomBgView){
  200. _operationBottomBgView = [[UIView alloc] init];
  201. CGFloat bottomBgViewH = self.tabBarController.tabBar.height + 10;
  202. _operationBottomBgView.frame = CGRectMake(0, SCREEN_HEIGHT - bottomBgViewH, SCREEN_WIDTH, bottomBgViewH);
  203. _operationBottomBgView.backgroundColor = RGB(255, 255, 255);
  204. _operationBottomBgView.hidden = YES;
  205. }
  206. return _operationBottomBgView;
  207. }
  208. #pragma mark 批量操作与正常操作界面切换
  209. -(void)changeToOperation:(BOOL)operation{
  210. if(operation){
  211. self.iSViewEditor = YES;
  212. //默认操作状态为批量编辑状态
  213. self.addBtn.hidden = YES;
  214. self.menuBtn.hidden = YES;
  215. self.operationStateEnum = OperationStateEnum1;
  216. self.operationAllSelectButton.hidden = NO;
  217. self.tabBarController.tabBar.hidden = YES;
  218. self.operationBottomBgView.hidden = NO;
  219. self.view.height -= self.tabBarController.tabBar.height;
  220. self.tableView.height -= self.tabBarController.tabBar.height;
  221. [self.view layoutIfNeeded];
  222. [self.tableView layoutIfNeeded];
  223. }else{
  224. self.iSViewEditor = NO;
  225. self.menuBtn.hidden = NO;
  226. self.addBtn.hidden = NO;
  227. //默认操作状态为无状态
  228. self.operationStateEnum = OperationStateEnum0;
  229. self.operationAllSelectButton.hidden = YES;
  230. self.tabBarController.tabBar.hidden = YES;
  231. self.tableView.height += self.tabBarController.tabBar.height;
  232. self.view.height += self.tabBarController.tabBar.height;
  233. [self.view layoutIfNeeded];
  234. [self.tableView layoutIfNeeded];
  235. self.operationBottomBgView.hidden = YES;
  236. }
  237. [self.tableView reloadData];
  238. }
  239. #pragma mark 移动 isEdit:当前是否为编辑状态
  240. -(void)userDidMove:(BOOL)move isEdit:(BOOL)isEdit{
  241. //移动
  242. if(move){
  243. //默认操作状态为移动状态
  244. self.operationStateEnum = OperationStateEnum2;
  245. self.addBtn.hidden = NO;
  246. [self resetRightBtnAction:NO];
  247. //隐藏tabBar - 并将TableView至底端
  248. self.tabBarController.tabBar.hidden = YES;
  249. self.view.height += self.tabBarController.tabBar.height;
  250. self.tableView.height += self.tabBarController.tabBar.height;
  251. [self.view layoutIfNeeded];
  252. [self.tableView layoutIfNeeded];
  253. //隐藏operationBottomBgView
  254. self.operationBottomBgView.hidden = YES;
  255. }
  256. else{
  257. //隐藏tabBar - 并将TableView至底端有tabBar.height的高
  258. self.tabBarController.tabBar.hidden = YES;
  259. self.view.height -= self.tabBarController.tabBar.height;
  260. self.tableView.height -= self.tabBarController.tabBar.height;
  261. [self.view layoutIfNeeded];
  262. [self.tableView layoutIfNeeded];
  263. //显示operationBottomBgView
  264. self.operationBottomBgView.hidden = NO;
  265. if(isEdit){
  266. self.operationStateEnum = OperationStateEnum1;
  267. self.addBtn.hidden = YES;
  268. [self resetRightBtnAction:YES];
  269. }else{
  270. [self changeToOperation:NO];
  271. }
  272. }
  273. [self.tableView reloadData];
  274. }
  275. -(void)resetRightBtnAction:(BOOL)isShowMenu{
  276. WS(weakSelf);
  277. if(isShowMenu){
  278. [self.addBtn setAction:^{
  279. NSMutableArray *menuDataSourceArray = [weakSelf getMenuDataSource:weakSelf.taskActionArray];
  280. YCMenuView *view = [YCMenuView menuWithActions:menuDataSourceArray width:106 relyonView:weakSelf.addBtn];
  281. view.menuColor = RGB(255, 255, 255);
  282. view.separatorColor = RGB(234, 234, 234);
  283. view.textColor = RGB(102, 102, 102);
  284. view.textFont = [UIFont systemFontOfSize:16.0];
  285. view.menuCellHeight = 43.5;
  286. view.maxDisplayCount = 10;
  287. view.offset = -6;
  288. [view show];
  289. }];
  290. }
  291. }
  292. - (void)backAction:(id)sender{
  293. if (self.iSViewEditor) {
  294. [self changeToOperation:NO];
  295. }else{
  296. [self.navigationController popViewControllerAnimated:true];
  297. }
  298. }
  299. - (void)menuAction:(id)sender{
  300. [super menuAction:sender];
  301. }
  302. -(NSMutableArray *)getMenuDataSource:(NSMutableArray *)titleArray{
  303. NSMutableArray *menuDataSourceArray = [[NSMutableArray alloc] init];
  304. for(int i=0;i<titleArray.count;i++){
  305. NSString *titleStr = [titleArray objectAtIndex:i];
  306. WS(weakSelf);
  307. YCMenuAction *actionMenu = [YCMenuAction actionWithTitle:titleStr image:nil handler:^(YCMenuAction *action) {
  308. if([@"添加人员" isEqualToString:action.title]){
  309. Department *defaltGroupSetion = [[Department alloc]init];
  310. defaltGroupSetion.Name = @"单位通讯录";
  311. defaltGroupSetion.Id = 0;
  312. Department *myGroupSetion = [[Department alloc]init];
  313. myGroupSetion.Name = @"自建通讯录";
  314. defaltGroupSetion.Id = 0;
  315. AddLookUpUserSecondVC *vc = [[AddLookUpUserSecondVC alloc] init];
  316. vc.departSourceDataArray = @[defaltGroupSetion,myGroupSetion].mutableCopy;
  317. vc.isDefalutPage = 1;
  318. vc.titleStr = @"添加成员";
  319. vc.delegate = weakSelf;
  320. NSMutableArray * array = [NSMutableArray array];
  321. for (SelectModel * model in weakSelf.dataArray) {
  322. [array addObject:@(model.UserId)];
  323. }
  324. vc.UserIds = array;
  325. [weakSelf.navigationController pushViewController:vc animated:YES];
  326. }else if ([@"批量编辑" isEqualToString:action.title]){
  327. [weakSelf changeToOperation:YES];
  328. }
  329. }];
  330. [menuDataSourceArray addObject:actionMenu];
  331. }
  332. return menuDataSourceArray;
  333. }
  334. -(NSMutableArray *)taskActionArray{
  335. if(!_taskActionArray){
  336. _taskActionArray = [[NSMutableArray alloc] initWithObjects:@"添加人员",@"批量编辑", nil];
  337. }
  338. return _taskActionArray;
  339. }
  340. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  341. return 1 + self.dataSortArray.count;
  342. }
  343. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  344. {
  345. switch (section) {
  346. case 0:{
  347. return 0;
  348. }break;
  349. default:{
  350. if (self.dataSortArray.count > 0) {
  351. NSArray * array = self.dataSortArray[section - 1];
  352. return array.count;
  353. }else{
  354. return 0;
  355. }
  356. }break;
  357. }
  358. }
  359. //section右侧index数组
  360. -(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
  361. return self.pinyinArray;
  362. }
  363. //点击右侧索引表项时调用 索引与section的对应关系
  364. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{
  365. return index;
  366. }
  367. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  368. UIView *headerView = [[UIView alloc]init];
  369. if(section > 0){
  370. [headerView setBackgroundColor:RGBA(238, 238, 238, 1)];
  371. NSString *returnStr = [self.pinyinArray objectAtIndex:section - 1];
  372. UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 200, 30)];
  373. [headerView addSubview:headerLabel];
  374. headerLabel.font = [UIFont systemFontOfSize:14.f];
  375. headerLabel.text = returnStr;
  376. headerLabel.textColor = RGB(153, 153, 153);
  377. }else{
  378. [headerView setBackgroundColor:[UIColor whiteColor]];
  379. [headerView setFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
  380. MyTDGroupView * view = [[MyTDGroupView alloc] init];
  381. [headerView addSubview:view];
  382. WS(weakSelf);
  383. UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) {
  384. MyTDTopicUserSearchVC * vc = [[MyTDTopicUserSearchVC alloc] init];
  385. vc.listArray = [NSMutableArray arrayWithArray:weakSelf.listArray];
  386. vc.upDateBlock = ^{
  387. [weakSelf getData];
  388. };
  389. [weakSelf.navigationController pushViewController:vc animated:YES];
  390. }];
  391. [headerView addGestureRecognizer:tap];
  392. }
  393. return headerView;
  394. }
  395. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  396. if(section > 0){
  397. return 30;
  398. }
  399. return 50.f;
  400. }
  401. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  402. {
  403. return 0.01f;
  404. }
  405. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  406. return 65.f;
  407. }
  408. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  409. SelectModel * model = [[self.dataSortArray objectAtIndex:indexPath.section-1] objectAtIndex:indexPath.row];
  410. switch (self.operationStateEnum) {
  411. case OperationStateEnum0:
  412. {
  413. MailListByZuCell *cell = [MailListByZuCell configCell0:tableView indexPath:indexPath];
  414. cell.cell0TitleLabel.text = model.UserName;
  415. [cell.cell0ImgView sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:kUserDefaultHeadImage];
  416. return cell;
  417. }
  418. break;
  419. default:
  420. {
  421. MailListByZuCell *cell = [MailListByZuCell configCell1:tableView indexPath:indexPath];
  422. cell.cell0TitleLabel.text = model.UserName;
  423. [cell.cell0ImgView sd_setImageWithURL:[NSURL URLWithString:model.AvatarUrl] placeholderImage:kUserDefaultHeadImage];
  424. cell.selectBtn.selected = model.hadSelected;
  425. self.rightMoveBtn.enabled = [self isMoveCheckData];
  426. if ([self isAllSelect]) {
  427. self.isNeedSelelct = NO;
  428. [self.operationAllSelectButton setTitle:@"取消全选" forState:UIControlStateNormal];
  429. }else{
  430. self.isNeedSelelct = YES;
  431. [self.operationAllSelectButton setTitle:@"全选" forState:UIControlStateNormal];
  432. }
  433. return cell;
  434. }
  435. break;
  436. }
  437. }
  438. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
  439. {
  440. NSLog(@"safdasfasdf");
  441. SelectModel * model = [[self.dataSortArray objectAtIndex:indexPath.section-1] objectAtIndex:indexPath.row];
  442. switch (self.operationStateEnum) {
  443. case OperationStateEnum1:{
  444. model.hadSelected = !model.hadSelected;
  445. [tableView reloadRowAtIndexPath:indexPath withRowAnimation:UITableViewRowAnimationNone];
  446. }break;
  447. default:{
  448. }break;
  449. }
  450. }
  451. - (BOOL)isAllSelect
  452. {
  453. for (NSArray * array in self.dataSortArray) {
  454. for (SelectModel * model in array) {
  455. if (!model.hadSelected) {
  456. return NO;
  457. }
  458. }
  459. }
  460. return YES;
  461. }
  462. - (BOOL)isMoveCheckData
  463. {
  464. BOOL isSelect = NO;
  465. for (NSArray * array in self.dataSortArray) {
  466. for (SelectModel * model in array) {
  467. if (model.hadSelected) {
  468. isSelect = YES;
  469. }
  470. }
  471. }
  472. if (!isSelect) {
  473. return NO;
  474. }
  475. return YES;
  476. }
  477. - (void)sortData
  478. {
  479. [self.dataSortArray removeAllObjects];
  480. self.pinyinArray = [[NSMutableArray alloc] init];
  481. self.nameArray = [[NSMutableArray alloc] init];
  482. NSMutableArray *stringsToSort = [[NSMutableArray alloc] init];
  483. for(int i = 0;i < [self.dataArray count];i++){
  484. SelectModel *model = [self.dataArray objectAtIndex:i];
  485. NSString * str = [NSString stringWithFormat:@"%@UserId%ld",model.UserName,(long)model.UserId];
  486. [stringsToSort addObject:str];
  487. }
  488. self.pinyinArray = [ChineseString IndexArray:stringsToSort];
  489. self.nameArray = [ChineseString LetterSortArray:stringsToSort];
  490. for (NSArray * array in self.nameArray) {
  491. NSMutableArray * subAddArray = [NSMutableArray array];
  492. for (NSString * string in array) {
  493. NSInteger flag = 0;
  494. BOOL isAdd = NO;
  495. for (NSInteger i = 0; i < self.dataArray.count; i ++) {
  496. SelectModel * model = self.dataArray[i];
  497. if ([string containsString:[NSString stringWithFormat:@"UserId%ld",(long)model.UserId]]) {
  498. [subAddArray addObject:model];
  499. isAdd = YES;
  500. flag = i;
  501. }
  502. }
  503. if (isAdd) {
  504. [self.dataArray removeObjectAtIndex:flag];
  505. }
  506. }
  507. if (subAddArray.count > 0) {
  508. [self.dataSortArray addObject:subAddArray];
  509. }
  510. }
  511. WS(weakSelf);
  512. dispatch_async(dispatch_get_main_queue(), ^{
  513. [weakSelf.tableView reloadData];
  514. });
  515. }
  516. - (void)getData{
  517. [self.listArray removeAllObjects];
  518. [self.dataArray removeAllObjects];
  519. WS(weakSelf);
  520. SHOWLOADING
  521. NSString * url = [NSString stringWithFormat:@"%@%ld",Host(APP_Topic_User_Get),(long)self.GroupId];
  522. [[HttpManager sharedHttpManager] GETUrl:url parameters:@{} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  523. NSLog(@"%@",responseObject);
  524. REMOVESHOW
  525. for (NSDictionary * dict in responseObject[@"Items"]) {
  526. SelectModel * model = [SelectModel modelWithDictionary:dict];
  527. model.UserName = model.Name;
  528. [weakSelf.dataArray addObject:model];
  529. [weakSelf.listArray addObject:model];
  530. }
  531. [weakSelf sortData];
  532. } failure:^(NSError * _Nonnull error) {
  533. REMOVESHOW
  534. SHOWERROR([ZYCTool handerResultData:error])
  535. }];
  536. }
  537. #pragma mark - Notification
  538. - (void)recviveChaoSongRen:(NSNotification *)notification{
  539. NSMutableArray <SelectModel *>* array = notification.userInfo[@"selectPeople"];
  540. NSMutableArray <SelectModel *>* array0 = self.selectArray;
  541. NSMutableArray <SelectModel *>* array1 = notification.userInfo[@"selectPeople"];
  542. if (array0.count == 0) {
  543. [self.selectArray addObjectsFromArray:array];
  544. }else{
  545. for (NSInteger x = 0; x < array.count; x++) {
  546. for (NSInteger y = 0 ; y < array0.count; y++) {
  547. if (array[x].UserId == array0[y].UserId) {
  548. [array1 removeObjectAtIndex:x];
  549. }
  550. }
  551. }
  552. [self.selectArray addObjectsFromArray:array1];
  553. }
  554. if (self.selectArray.count > 0) {
  555. for (NSInteger i = 0; i < self.selectArray.count; i ++) {
  556. SelectModel * model = self.selectArray[i];
  557. [self.selectIdArray addObject:@(model.UserId)];
  558. }
  559. [self addUser:self.selectIdArray];
  560. }
  561. }
  562. - (void)addUser:(NSArray *)array
  563. {
  564. NSLog(@"=============%@",array);
  565. NSDictionary * paraDict = @{@"UserIds":array,
  566. @"TopicGroupId":@(self.GroupId)
  567. };
  568. WS(weakSelf);
  569. SHOWLOADING
  570. [[HttpManager sharedHttpManager] POSTUrl:Host(APP_Topic_Add_Group_User) parameters:paraDict responseStyle:DATA success:^(id _Nonnull responseObject) {
  571. REMOVESHOW
  572. NSLog(@"添加人员成功");
  573. [weakSelf getData];
  574. } failure:^(NSError * _Nonnull error) {
  575. REMOVESHOW
  576. SHOWERROR([ZYCTool handerResultData:error])
  577. }];
  578. }
  579. - (NSMutableArray *)selectArray
  580. {
  581. if (!_selectArray) {
  582. _selectArray = [NSMutableArray array];
  583. }
  584. return _selectArray;
  585. }
  586. - (NSMutableArray *)selectIdArray
  587. {
  588. if (!_selectIdArray) {
  589. _selectIdArray = [NSMutableArray array];
  590. }
  591. return _selectIdArray;
  592. }
  593. - (NSMutableArray *)nameArray{
  594. if(!_nameArray) {
  595. _nameArray = [NSMutableArray array];
  596. }
  597. return _nameArray;
  598. }
  599. - (NSMutableArray *)dataArray{
  600. if(!_dataArray) {
  601. _dataArray = [NSMutableArray array];
  602. }
  603. return _dataArray;
  604. }
  605. - (NSMutableArray *)listArray{
  606. if(!_listArray) {
  607. _listArray = [NSMutableArray array];
  608. }
  609. return _listArray;
  610. }
  611. - (NSMutableArray *)dataSortArray{
  612. if(!_dataSortArray) {
  613. _dataSortArray = [NSMutableArray array];
  614. }
  615. return _dataSortArray;
  616. }
  617. - (void)dealloc
  618. {
  619. [[NSNotificationCenter defaultCenter] removeObserver:self];
  620. }
  621. - (void)viewWillDisappear:(BOOL)animated
  622. {
  623. [super viewWillDisappear:animated];
  624. [self changeToOperation:NO];
  625. }
  626. @end