// // ChatMsgEditVC.m // smartRhino // // Created by niuzhen on 2020/10/14. // Copyright © 2020 tederen. All rights reserved. // #import "ChatMsgEditVC.h" #import "ChatMsgListCell.h" #import "ChatListMoveVC.h" @interface ChatMsgEditVC () @property (weak, nonatomic) IBOutlet UIButton *selectBtn; @property (weak, nonatomic) IBOutlet UITableView *tableView; @property (weak, nonatomic) IBOutlet UIButton *deleteBtn; @property (weak, nonatomic) IBOutlet UIButton *moveBtn; @property (assign,nonatomic) BOOL isAllselect; @property (assign,nonatomic) BOOL isEnable; @property (strong,nonatomic) NSMutableArray *selectArray; @property (strong,nonatomic) NSMutableArray *chatListIMArray; @end @implementation ChatMsgEditVC +(ChatMsgEditVC *)initChatMsgEditVC{ ChatMsgEditVC *controller = [StoryboardManager.shared.chatMsg instantiateViewControllerWithIdentifier:@"ChatMsgEditVC"]; return controller; } - (NSMutableArray *)selectArray { if (!_selectArray) { _selectArray = [NSMutableArray array]; } return _selectArray; } - (void)viewDidLoad { [super viewDidLoad]; self.fd_prefersNavigationBarHidden = YES; self.tableView.delegate = self; self.tableView.dataSource = self; self.chatListIMArray = [NSMutableArray arrayWithArray:self.dataArray]; [self.tableView reloadData]; WS(weakSelf); [self.moveBtn setTitleColor:UIColorHex(0x3979D3) forState:UIControlStateNormal]; [self.deleteBtn setAction:^{ [weakSelf.selectArray removeAllObjects]; for (ChatMsgListImModel * model in weakSelf.chatListIMArray) { if (model.isSelected) { [weakSelf.selectArray addObject:model]; } } if (weakSelf.selectArray.count > 0) { [weakSelf isDel:weakSelf.selectArray]; } }]; [self.moveBtn setAction:^{ if (weakSelf.isEnable) { [weakSelf.selectArray removeAllObjects]; for (ChatMsgListImModel * model in weakSelf.chatListIMArray) { if (model.isSelected) { [weakSelf.selectArray addObject:@(model.Id)]; } } if (weakSelf.selectArray.count > 0) { [weakSelf chatListMove:weakSelf.selectArray]; } }else{ UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"文件夹无法移动" message:@"" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *noOk = [UIAlertAction actionWithTitle:@"我知道了" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }]; [alertVC addAction:noOk]; [weakSelf presentViewController:alertVC animated:YES completion:nil]; } }]; [self.selectBtn setAction:^{ NSLog(@"全选"); for (ChatMsgListImModel *model in weakSelf.chatListIMArray) { model.isSelected = !weakSelf.isAllselect; } [weakSelf.tableView reloadData]; }]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.chatListIMArray.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ ChatMsgListImModel * model = self.chatListIMArray[indexPath.row]; switch (model.AttributeValue) { case 2: { return [ChatMsgListCell configCell2Height]; } break; default: { return [ChatMsgListCell configCell3Height]; } break; } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ WS(weakSelf); ChatMsgListImModel * model = [self.chatListIMArray objectAtIndex:indexPath.row]; if (self.IsMove) { switch (model.AttributeValue) { case 2: { ChatMsgListCell *cell = [ChatMsgListCell configCell2:tableView indexPath:indexPath]; cell.cell2IconImgView.image = IMG(@"find_1"); cell.cell2TimeLabel.text = @"进入"; cell.cell2TitleLabel.text = model.FolderName; cell.cell2isTop.hidden = !model.IsTop; cell.cell2TimeLabel.textColor = RGB(57, 121, 211); return cell; } break; default:{ ChatMsgListCell *cell = [ChatMsgListCell configCell3:tableView indexPath:indexPath]; cell.cell3MengCengView.hidden = NO; [cell setCell3DataWithModel:model]; return cell; }break; break; } }else{ switch (model.AttributeValue) { case 2: { ChatMsgListCell *cell = [ChatMsgListCell configCell6:tableView indexPath:indexPath]; cell.cell2IconImgView.image = IMG(@"find_1"); cell.cell6SelectBtn.selected = model.isSelected; cell.cell2TitleLabel.text = model.FolderName; cell.cell2TimeLabel.hidden = YES; cell.enterBtn.hidden = YES; cell.cell2RightArrowImgView.hidden = YES; cell.IsTopView.hidden = YES; self.isAllselect = [self checkChatListArray]; [self checkMoveBtnEnable]; [self.selectBtn setTitle:self.isAllselect ? @"取消全选": @"全选" forState:UIControlStateNormal]; return cell; } break; default:{ ChatMsgListCell *cell = [ChatMsgListCell configCell5:tableView indexPath:indexPath]; self.isAllselect = [self checkChatListArray]; [self checkMoveBtnEnable]; [cell setCell5DataWithModel:model]; cell.IsTopView.hidden = YES; self.isAllselect = [self checkChatListArray]; [self checkMoveBtnEnable]; [self.selectBtn setTitle:self.isAllselect ? @"取消全选": @"全选" forState:UIControlStateNormal]; [cell.cell5SelectBtn setAction:^{ model.isSelected = !model.isSelected; dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf.tableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationAutomatic]; }); }]; return cell; }break; break; } } } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [tableView deselectRowAtIndexPath:indexPath animated:YES]; ChatMsgListImModel *model = [self.chatListIMArray objectAtIndex:indexPath.row]; switch (model.AttributeValue) { case 2: { model.isSelected = !model.isSelected; [self.tableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone]; } break; default: { model.isSelected = !model.isSelected; [self.tableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone]; } break; } } - (void)checkMoveBtnEnable { self.isEnable = YES; for (ChatMsgListImModel *model in self.chatListIMArray) { if (model.AttributeValue == 2 && model.isSelected) { self.isEnable = NO; } } } - (BOOL)checkChatListArray { if (self.chatListIMArray.count == 0) { return NO; } for (ChatMsgListImModel * model in self.chatListIMArray) { if (!model.isSelected) { return NO; } } return YES; } #pragma mark - delete move - (void)chatListMove:(NSArray *)array { ChatListMoveVC * vc = [ChatListMoveVC initChatListMoveVC]; vc.Id = 0; vc.titleStr = @"移动到"; vc.listArray = [NSMutableArray arrayWithArray:array]; [self.navigationController pushViewController:vc animated:YES]; } -(void)isDel:(NSMutableArray *)array { WS(weakSelf); UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"确认删除?" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { }]; UIAlertAction *ok = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [weakSelf chatListDelete:array]; }]; [alertController addAction:cancel]; [alertController addAction:ok]; [self presentViewController:alertController animated:YES completion:nil]; } - (void)chatListDelete:(NSMutableArray *)array { NSMutableArray * addArray = [NSMutableArray array]; for (ChatMsgListImModel * model in array) { [addArray addObject:@(model.Id)]; [self getUserInfoInDocument:[NSString stringWithFormat:@"%ld",(long)model.ImId]]; } SHOWLOADING WS(weakSelf); NSMutableDictionary *dic = [[NSMutableDictionary alloc]init]; [dic setValue:addArray forKey:@"MiddleIds"]; [dic setValue:@(10) forKey:@"FolderType"]; [[HttpManager sharedHttpManager] POSTUrl:Host(API_Find_DeleteRecord) parameters:dic responseStyle:DATA success:^(id _Nonnull responseObject) { REMOVESHOW if (weakSelf.upDataBlock) { weakSelf.upDataBlock(); } [weakSelf.chatListIMArray removeObjectsInArray:array]; dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf.tableView reloadData]; }); } failure:^(NSError * _Nonnull error) { REMOVESHOW NSLog(@"%@",error); SHOWERROR([ZYCTool handerResultData:error]) }]; } - (void)getUserInfoInDocument:(NSString *)ImId{ NSMutableArray * array = [[NSMutableArray alloc] initWithArray:USERDEFAULTSGET(@"ChatList")]; for (NSMutableDictionary * dict in array) { if ([[dict objectForKey:@"ImId"] isEqualToString:ImId]) { [array removeObject:dict]; } } USERDEFAULTSSET(array,@"ChatList"); } @end