ChatMsgEditVC.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. //
  2. // ChatMsgEditVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/10/14.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "ChatMsgEditVC.h"
  9. #import "ChatMsgListCell.h"
  10. #import "ChatListMoveVC.h"
  11. @interface ChatMsgEditVC ()<UITableViewDelegate,UITableViewDataSource>
  12. @property (weak, nonatomic) IBOutlet UIButton *selectBtn;
  13. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  14. @property (weak, nonatomic) IBOutlet UIButton *deleteBtn;
  15. @property (weak, nonatomic) IBOutlet UIButton *moveBtn;
  16. @property (assign,nonatomic) BOOL isAllselect;
  17. @property (assign,nonatomic) BOOL isEnable;
  18. @property (strong,nonatomic) NSMutableArray *selectArray;
  19. @property (strong,nonatomic) NSMutableArray *chatListIMArray;
  20. @end
  21. @implementation ChatMsgEditVC
  22. +(ChatMsgEditVC *)initChatMsgEditVC{
  23. ChatMsgEditVC *controller = [StoryboardManager.shared.chatMsg instantiateViewControllerWithIdentifier:@"ChatMsgEditVC"];
  24. return controller;
  25. }
  26. - (NSMutableArray *)selectArray
  27. {
  28. if (!_selectArray) {
  29. _selectArray = [NSMutableArray array];
  30. }
  31. return _selectArray;
  32. }
  33. - (void)viewDidLoad {
  34. [super viewDidLoad];
  35. self.fd_prefersNavigationBarHidden = YES;
  36. self.tableView.delegate = self;
  37. self.tableView.dataSource = self;
  38. self.chatListIMArray = [NSMutableArray arrayWithArray:self.dataArray];
  39. [self.tableView reloadData];
  40. WS(weakSelf);
  41. [self.moveBtn setTitleColor:UIColorHex(0x3979D3) forState:UIControlStateNormal];
  42. [self.deleteBtn setAction:^{
  43. [weakSelf.selectArray removeAllObjects];
  44. for (ChatMsgListImModel * model in weakSelf.chatListIMArray) {
  45. if (model.isSelected) {
  46. [weakSelf.selectArray addObject:model];
  47. }
  48. }
  49. if (weakSelf.selectArray.count > 0) {
  50. [weakSelf isDel:weakSelf.selectArray];
  51. }
  52. }];
  53. [self.moveBtn setAction:^{
  54. if (weakSelf.isEnable) {
  55. [weakSelf.selectArray removeAllObjects];
  56. for (ChatMsgListImModel * model in weakSelf.chatListIMArray) {
  57. if (model.isSelected) {
  58. [weakSelf.selectArray addObject:@(model.Id)];
  59. }
  60. }
  61. if (weakSelf.selectArray.count > 0) {
  62. [weakSelf chatListMove:weakSelf.selectArray];
  63. }
  64. }else{
  65. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"文件夹无法移动" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  66. UIAlertAction *noOk = [UIAlertAction actionWithTitle:@"我知道了" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  67. }];
  68. [alertVC addAction:noOk];
  69. [weakSelf presentViewController:alertVC animated:YES completion:nil];
  70. }
  71. }];
  72. [self.selectBtn setAction:^{
  73. NSLog(@"全选");
  74. for (ChatMsgListImModel *model in weakSelf.chatListIMArray) {
  75. model.isSelected = !weakSelf.isAllselect;
  76. }
  77. [weakSelf.tableView reloadData];
  78. }];
  79. }
  80. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  81. return 1;
  82. }
  83. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  84. return self.chatListIMArray.count;
  85. }
  86. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  87. ChatMsgListImModel * model = self.chatListIMArray[indexPath.row];
  88. switch (model.AttributeValue) {
  89. case 2:
  90. {
  91. return [ChatMsgListCell configCell2Height];
  92. }
  93. break;
  94. default:
  95. {
  96. return [ChatMsgListCell configCell3Height];
  97. }
  98. break;
  99. }
  100. }
  101. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  102. WS(weakSelf);
  103. ChatMsgListImModel * model = [self.chatListIMArray objectAtIndex:indexPath.row];
  104. if (self.IsMove) {
  105. switch (model.AttributeValue) {
  106. case 2:
  107. {
  108. ChatMsgListCell *cell = [ChatMsgListCell configCell2:tableView indexPath:indexPath];
  109. cell.cell2IconImgView.image = IMG(@"find_1");
  110. cell.cell2TimeLabel.text = @"进入";
  111. cell.cell2TitleLabel.text = model.FolderName;
  112. cell.cell2isTop.hidden = !model.IsTop;
  113. cell.cell2TimeLabel.textColor = RGB(57, 121, 211);
  114. return cell;
  115. }
  116. break;
  117. default:{
  118. ChatMsgListCell *cell = [ChatMsgListCell configCell3:tableView indexPath:indexPath];
  119. cell.cell3MengCengView.hidden = NO;
  120. [cell setCell3DataWithModel:model];
  121. return cell;
  122. }break;
  123. break;
  124. }
  125. }else{
  126. switch (model.AttributeValue) {
  127. case 2:
  128. {
  129. ChatMsgListCell *cell = [ChatMsgListCell configCell6:tableView indexPath:indexPath];
  130. cell.cell2IconImgView.image = IMG(@"find_1");
  131. cell.cell6SelectBtn.selected = model.isSelected;
  132. cell.cell2TitleLabel.text = model.FolderName;
  133. cell.cell2TimeLabel.hidden = YES;
  134. cell.enterBtn.hidden = YES;
  135. cell.cell2RightArrowImgView.hidden = YES;
  136. cell.IsTopView.hidden = YES;
  137. self.isAllselect = [self checkChatListArray];
  138. [self checkMoveBtnEnable];
  139. [self.selectBtn setTitle:self.isAllselect ? @"取消全选": @"全选" forState:UIControlStateNormal];
  140. return cell;
  141. }
  142. break;
  143. default:{
  144. ChatMsgListCell *cell = [ChatMsgListCell configCell5:tableView indexPath:indexPath];
  145. self.isAllselect = [self checkChatListArray];
  146. [self checkMoveBtnEnable];
  147. [cell setCell5DataWithModel:model];
  148. cell.IsTopView.hidden = YES;
  149. self.isAllselect = [self checkChatListArray];
  150. [self checkMoveBtnEnable];
  151. [self.selectBtn setTitle:self.isAllselect ? @"取消全选": @"全选" forState:UIControlStateNormal];
  152. [cell.cell5SelectBtn setAction:^{
  153. model.isSelected = !model.isSelected;
  154. dispatch_async(dispatch_get_main_queue(), ^{
  155. [weakSelf.tableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationAutomatic];
  156. });
  157. }];
  158. return cell;
  159. }break;
  160. break;
  161. }
  162. }
  163. }
  164. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  165. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  166. ChatMsgListImModel *model = [self.chatListIMArray objectAtIndex:indexPath.row];
  167. switch (model.AttributeValue) {
  168. case 2:
  169. {
  170. model.isSelected = !model.isSelected;
  171. [self.tableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone];
  172. }
  173. break;
  174. default:
  175. {
  176. model.isSelected = !model.isSelected;
  177. [self.tableView reloadRow:indexPath.row inSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone];
  178. }
  179. break;
  180. }
  181. }
  182. - (void)checkMoveBtnEnable
  183. {
  184. self.isEnable = YES;
  185. for (ChatMsgListImModel *model in self.chatListIMArray) {
  186. if (model.AttributeValue == 2 && model.isSelected) {
  187. self.isEnable = NO;
  188. }
  189. }
  190. }
  191. - (BOOL)checkChatListArray
  192. {
  193. if (self.chatListIMArray.count == 0) {
  194. return NO;
  195. }
  196. for (ChatMsgListImModel * model in self.chatListIMArray) {
  197. if (!model.isSelected) {
  198. return NO;
  199. }
  200. }
  201. return YES;
  202. }
  203. #pragma mark - delete move
  204. - (void)chatListMove:(NSArray *)array
  205. {
  206. ChatListMoveVC * vc = [ChatListMoveVC initChatListMoveVC];
  207. vc.Id = 0;
  208. vc.titleStr = @"移动到";
  209. vc.listArray = [NSMutableArray arrayWithArray:array];
  210. [self.navigationController pushViewController:vc animated:YES];
  211. }
  212. -(void)isDel:(NSMutableArray *)array
  213. {
  214. WS(weakSelf);
  215. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"确认删除?" preferredStyle:UIAlertControllerStyleAlert];
  216. UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  217. }];
  218. UIAlertAction *ok = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  219. [weakSelf chatListDelete:array];
  220. }];
  221. [alertController addAction:cancel];
  222. [alertController addAction:ok];
  223. [self presentViewController:alertController animated:YES completion:nil];
  224. }
  225. - (void)chatListDelete:(NSMutableArray *)array
  226. {
  227. NSMutableArray * addArray = [NSMutableArray array];
  228. for (ChatMsgListImModel * model in array) {
  229. [addArray addObject:@(model.Id)];
  230. [self getUserInfoInDocument:[NSString stringWithFormat:@"%ld",(long)model.ImId]];
  231. }
  232. SHOWLOADING
  233. WS(weakSelf);
  234. NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
  235. [dic setValue:addArray forKey:@"MiddleIds"];
  236. [dic setValue:@(10) forKey:@"FolderType"];
  237. [[HttpManager sharedHttpManager] POSTUrl:Host(API_Find_DeleteRecord) parameters:dic responseStyle:DATA success:^(id _Nonnull responseObject) {
  238. REMOVESHOW
  239. if (weakSelf.upDataBlock) {
  240. weakSelf.upDataBlock();
  241. }
  242. [weakSelf.chatListIMArray removeObjectsInArray:array];
  243. dispatch_async(dispatch_get_main_queue(), ^{
  244. [weakSelf.tableView reloadData];
  245. });
  246. } failure:^(NSError * _Nonnull error) {
  247. REMOVESHOW
  248. NSLog(@"%@",error);
  249. SHOWERROR([ZYCTool handerResultData:error])
  250. }];
  251. }
  252. - (void)getUserInfoInDocument:(NSString *)ImId{
  253. NSMutableArray * array = [[NSMutableArray alloc] initWithArray:USERDEFAULTSGET(@"ChatList")];
  254. for (NSMutableDictionary * dict in array) {
  255. if ([[dict objectForKey:@"ImId"] isEqualToString:ImId]) {
  256. [array removeObject:dict];
  257. }
  258. }
  259. USERDEFAULTSSET(array,@"ChatList");
  260. }
  261. @end