MyTDTopicGroupUserVC.m 28 KB

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