// // ChangeTopicVC.m // smartRhino // // Created by niuzhen on 2019/12/25. // Copyright © 2019 tederen. All rights reserved. // #import "ChangeTopicVC.h" #import "SmartBar.h" #import "NewTopicModel.h" #import "NewTopicCell.h" #import "NewTopicTextView.h" #import "LYLPhotoTailoringTool.h" #import "FWZFileGetTool.h" #import "FWZGetNoteBookTool.h" #define BARHEIGHT 42.5f #define TextViewTag 1000 @interface ChangeTopicVC () @property (weak, nonatomic) IBOutlet UIView *NavBarV; @property (weak, nonatomic) IBOutlet UIButton *DoneBtn; @property (strong, nonatomic) UITableView *tableView; @property (strong, nonatomic) SmartBar *SmartBar; @property (strong, nonatomic) NSMutableArray *dataArray; @property (strong, nonatomic) NewTopicTextView *defualtView; @end @implementation ChangeTopicVC + (ChangeTopicVC *)initChangeTopicVC{ ChangeTopicVC *controller = [StoryboardManager.shared.myTDTopicExtent instantiateViewControllerWithIdentifier:@"ChangeTopicVC"]; return controller; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[IQKeyboardManager sharedManager] setEnable:YES]; } - (void)viewDidLoad { [super viewDidLoad]; self.fd_prefersNavigationBarHidden = YES; [self.view addSubview:self.tableView]; self.SmartBar.delegate = self; [self.view addSubview:self.SmartBar]; [self.SmartBar mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(self.view); make.height.mas_offset(BARHEIGHT); if (@available(iOS 11.0, *)) { make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(BARHEIGHT); } else { make.bottom.equalTo(self.view.mas_bottom).offset(BARHEIGHT); } }]; self.tableView.delegate = self; self.tableView.dataSource = self; [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(self.view); make.top.mas_equalTo(self.NavBarV.mas_bottom); make.bottom.mas_equalTo(self.SmartBar.mas_top); }]; WS(weakSelf); [self.DoneBtn setAction:^{ [weakSelf editTopicPut]; }]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillShow:) name:UIKeyboardWillShowNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillHide:) name:UIKeyboardWillHideNotification object:nil]; [self editData:self.dataDict]; } - (void)editData:(NSDictionary *)dict { [self.dataArray removeAllObjects]; NewTopicModel * titleModel = [[NewTopicModel alloc] init]; titleModel.title = @"编辑标题"; titleModel.content = [dict objectForKey:@"Title"]; titleModel.type = CollectDataType_Text; [self.dataArray addObject:titleModel]; if ([[dict objectForKey:@"Data"] isKindOfClass:[NSArray class]]) { NSArray * array = [dict objectForKey:@"Data"]; for (NSInteger i = 0; i < array.count; i ++) { NSDictionary * dataDic = array[i]; NewTopicModel * model = [[NewTopicModel alloc] initWithDict:dataDic]; switch (model.type) { case CollectDataType_Text: { if (i == 0) { [self.dataArray addObject:model]; } } break; case CollectDataType_IMG: { NSDictionary * pdDict = array[i + 1]; if ([[pdDict objectForKey:@"Type"] integerValue] == CollectDataType_Text) { model.content = [pdDict objectForKey:@"Text"]; }else{ model.content = @""; } [self.dataArray addObject:model]; } break; default: { if (array.count == i + 1) { break; } NSDictionary * pdDict = array[i + 1]; if ([[pdDict objectForKey:@"Type"] integerValue] == CollectDataType_Text) { model.content = [pdDict objectForKey:@"Text"]; }else{ model.content = @""; } [self.dataArray addObject:model]; } break; } } } [self.tableView reloadData]; } #pragma -mark UItableViewDelegate - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataArray.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { WS(weakSelf); NewTopicModel *model = [self.dataArray objectAtIndex:indexPath.row]; if (indexPath.row == 0) { NewTopicCell *cell = [NewTopicCell configCell0:tableView indexPath:indexPath]; if (!self.defualtView) { self.defualtView = cell.textView; } cell.textView.placeholder = model.title; cell.textView.text = model.content; cell.bgLabel.text = cell.textView.text; cell.textView.tag = TextViewTag + indexPath.row; cell.textView.delegate = self; return cell; } switch (model.type) { case CollectDataType_Text: { NewTopicCell *cell = [NewTopicCell configCell1:tableView indexPath:indexPath]; cell.textView.placeholder = model.title; cell.textView.text = model.content; cell.bgLabel.text = cell.textView.text; cell.textView.tag = TextViewTag + indexPath.row; cell.textView.delegate = self; return cell; } break; case CollectDataType_File: { NewTopicCell *cell = [NewTopicCell configCell2:tableView indexPath:indexPath]; cell.textView.placeholder = @""; cell.textView.text = model.content; cell.cell2TitleL.text = model.FileName; cell.cell2SubTitleL.text = model.fileSize; cell.bgLabel.text = cell.textView.text; cell.textView.tag = TextViewTag + indexPath.row; cell.textView.delegate = self; NSString * imageName = [ZYCTool getFileNameImage:model.File]; if (imageName.length > 0) { cell.cell2ImagV.image = IMG(imageName); }else{ [cell.cell2ImagV sd_setImageWithURL:[NSURL URLWithString:model.File] placeholderImage:IMG(@"icon_weizhiwenjian")]; } [cell.cell2CloseBtn setAction:^{ UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)]; UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { [weakSelf.dataArray removeObjectAtIndex:indexPath.row]; [weakSelf.tableView reloadData]; }]; UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [alert addAction:sureAction]; [alert addAction:cancelAction]; [weakSelf presentViewController:alert animated:YES completion:^{ }]; }]; return cell; } break; case CollectDataType_IMG: { NewTopicCell *cell = [NewTopicCell configCell3:tableView indexPath:indexPath]; cell.textView.placeholder =@""; cell.textView.text = model.content; cell.bgLabel.text = cell.textView.text; cell.textView.tag = TextViewTag + indexPath.row; cell.textView.delegate = self; [cell.cell3ImagV sd_setImageWithURL:[NSURL URLWithString:model.imageUrl]]; [cell.cell3CloseBtn setAction:^{ UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)]; UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { [weakSelf.dataArray removeObjectAtIndex:indexPath.row]; [weakSelf.tableView reloadData]; }]; UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [alert addAction:sureAction]; [alert addAction:cancelAction]; [weakSelf presentViewController:alert animated:YES completion:^{ }]; }]; return cell; } break; case CollectDataType_Collect: { NewTopicCell *cell = [NewTopicCell configCell2:tableView indexPath:indexPath]; cell.textView.text = model.content; cell.bgLabel.text = cell.textView.text; cell.textView.tag = TextViewTag + indexPath.row; cell.textView.delegate = self; cell.cell2TitleL.text = model.FileName; cell.cell2SubTitleL.attributedText = [ZYCTool checkOfString:[NSString stringWithFormat:@"来自-%@的收藏",model.AuthorName] KeyString:model.AuthorName]; cell.cell2ImagV.image = IMG(@"收藏"); [cell.cell2CloseBtn setAction:^{ UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)]; UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { [weakSelf.dataArray removeObjectAtIndex:indexPath.row]; [weakSelf.tableView reloadData]; }]; UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [alert addAction:sureAction]; [alert addAction:cancelAction]; [weakSelf presentViewController:alert animated:YES completion:^{ }]; }]; return cell; } break; case CollectDataType_Note: { NewTopicCell *cell = [NewTopicCell configCell2:tableView indexPath:indexPath]; cell.textView.placeholder = @""; cell.textView.text = model.content; cell.cell2TitleL.text = model.FileName; cell.bgLabel.text = cell.textView.text; cell.textView.tag = TextViewTag + indexPath.row; cell.textView.delegate = self; cell.cell2SubTitleL.attributedText = [ZYCTool checkOfString:[NSString stringWithFormat:@"来自-%@的笔记",model.AuthorName] KeyString:model.AuthorName]; cell.cell2ImagV.image = IMG(@"noteBook_icon"); [cell.cell2CloseBtn setAction:^{ UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)]; UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { [weakSelf.dataArray removeObjectAtIndex:indexPath.row]; [weakSelf.tableView reloadData]; }]; UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [alert addAction:sureAction]; [alert addAction:cancelAction]; [weakSelf presentViewController:alert animated:YES completion:^{ }]; }]; return cell; } break; case CollectDataType_NoteFile: { NewTopicCell *cell = [NewTopicCell configCell2:tableView indexPath:indexPath]; cell.textView.placeholder = @""; cell.textView.text = model.content; cell.cell2TitleL.text = model.FileName; cell.bgLabel.text = cell.textView.text; cell.textView.tag = TextViewTag + indexPath.row; cell.textView.delegate = self; cell.cell2SubTitleL.attributedText = [ZYCTool checkOfString:[NSString stringWithFormat:@"来自-%@的笔记文件夹",model.AuthorName] KeyString:model.AuthorName]; cell.cell2ImagV.image = IMG(@"find_1"); [cell.cell2CloseBtn setAction:^{ UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)]; UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { [weakSelf.dataArray removeObjectAtIndex:indexPath.row]; [weakSelf.tableView reloadData]; }]; UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [alert addAction:sureAction]; [alert addAction:cancelAction]; [weakSelf presentViewController:alert animated:YES completion:^{ }]; }]; return cell; }break; case CollectDataType_CollectFile: { NewTopicCell *cell = [NewTopicCell configCell2:tableView indexPath:indexPath]; cell.textView.placeholder = @""; cell.textView.text = model.content; cell.cell2TitleL.text = model.FileName; cell.bgLabel.text = cell.textView.text; cell.textView.tag = TextViewTag + indexPath.row; cell.textView.delegate = self; cell.cell2SubTitleL.attributedText = [ZYCTool checkOfString:[NSString stringWithFormat:@"来自-%@的收藏文件夹",model.AuthorName] KeyString:model.AuthorName]; cell.cell2ImagV.image = IMG(@"find_1"); [cell.cell2CloseBtn setAction:^{ UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)]; UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { [weakSelf.dataArray removeObjectAtIndex:indexPath.row]; [weakSelf.tableView reloadData]; }]; UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [alert addAction:sureAction]; [alert addAction:cancelAction]; [weakSelf presentViewController:alert animated:YES completion:^{ }]; }]; return cell; }break; case CollectDataType_Group: { NewTopicCell *cell = [NewTopicCell configCell2:tableView indexPath:indexPath]; cell.textView.placeholder = @""; cell.textView.text = model.content; cell.cell2TitleL.text = model.FileName; cell.bgLabel.text = cell.textView.text; cell.textView.tag = TextViewTag + indexPath.row; cell.textView.delegate = self; cell.cell2SubTitleL.attributedText = [ZYCTool checkOfString:[NSString stringWithFormat:@"来自-%@小组",model.AuthorName] KeyString:model.AuthorName]; cell.cell2ImagV.image = IMG(@"笔记小组"); [cell.cell2CloseBtn setAction:^{ UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)]; UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { [weakSelf.dataArray removeObjectAtIndex:indexPath.row]; [weakSelf.tableView reloadData]; }]; UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [alert addAction:sureAction]; [alert addAction:cancelAction]; [weakSelf presentViewController:alert animated:YES completion:^{ }]; }]; return cell; }break; case CollectDataType_Topic: { NewTopicCell *cell = [NewTopicCell configCell2:tableView indexPath:indexPath]; cell.textView.placeholder = @""; cell.textView.text = model.content; cell.cell2TitleL.text = model.FileName; cell.bgLabel.text = cell.textView.text; cell.textView.tag = TextViewTag + indexPath.row; cell.textView.delegate = self; cell.cell2SubTitleL.attributedText = [ZYCTool checkOfString:[NSString stringWithFormat:@"来自-%@",model.AuthorName] KeyString:model.AuthorName]; cell.cell2ImagV.image = IMG(@"话题"); [cell.cell2CloseBtn setAction:^{ UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)]; UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { [weakSelf.dataArray removeObjectAtIndex:indexPath.row]; [weakSelf.tableView reloadData]; }]; UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [alert addAction:sureAction]; [alert addAction:cancelAction]; [weakSelf presentViewController:alert animated:YES completion:^{ }]; }]; return cell; }break; case CollectDataType_InterMail: { NewTopicCell *cell = [NewTopicCell configCell2:tableView indexPath:indexPath]; cell.textView.placeholder = @""; cell.textView.text = model.content; cell.cell2TitleL.text = model.FileName; cell.bgLabel.text = cell.textView.text; cell.textView.tag = TextViewTag + indexPath.row; cell.textView.delegate = self; cell.cell2SubTitleL.attributedText = [ZYCTool checkOfString:[NSString stringWithFormat:@"来自-%@的站内信",model.AuthorName] KeyString:model.AuthorName]; cell.cell2ImagV.image = IMG(@"站内信"); [cell.cell2CloseBtn setAction:^{ UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)]; UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { [weakSelf.dataArray removeObjectAtIndex:indexPath.row]; [weakSelf.tableView reloadData]; }]; UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [alert addAction:sureAction]; [alert addAction:cancelAction]; [weakSelf presentViewController:alert animated:YES completion:^{ }]; }]; return cell; }break; case CollectDataType_Notice: { NewTopicCell *cell = [NewTopicCell configCell2:tableView indexPath:indexPath]; cell.textView.placeholder = @""; cell.textView.text = model.content; cell.cell2TitleL.text = model.FileName; cell.bgLabel.text = cell.textView.text; cell.textView.tag = TextViewTag + indexPath.row; cell.textView.delegate = self; cell.cell2SubTitleL.attributedText = [ZYCTool checkOfString:[NSString stringWithFormat:@"来自-%@的通知",model.AuthorName] KeyString:model.AuthorName]; cell.cell2ImagV.image = IMG(@"通知图标"); [cell.cell2CloseBtn setAction:^{ UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)]; UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { [weakSelf.dataArray removeObjectAtIndex:indexPath.row]; [weakSelf.tableView reloadData]; }]; UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [alert addAction:sureAction]; [alert addAction:cancelAction]; [weakSelf presentViewController:alert animated:YES completion:^{ }]; }]; return cell; }break; case CollectDataType_Meeting: { NewTopicCell *cell = [NewTopicCell configCell2:tableView indexPath:indexPath]; cell.textView.placeholder = @""; cell.textView.text = model.content; cell.cell2TitleL.text = model.FileName; cell.bgLabel.text = cell.textView.text; cell.textView.tag = TextViewTag + indexPath.row; cell.textView.delegate = self; cell.cell2SubTitleL.hidden = YES; cell.cell2ImagV.image = IMG(@"会议"); [cell.cell2CloseBtn setAction:^{ UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)]; UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { [weakSelf.dataArray removeObjectAtIndex:indexPath.row]; [weakSelf.tableView reloadData]; }]; UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [alert addAction:sureAction]; [alert addAction:cancelAction]; [weakSelf presentViewController:alert animated:YES completion:^{ }]; }]; return cell; }break; case CollectDataType_Article: { NewTopicCell *cell = [NewTopicCell configCell2:tableView indexPath:indexPath]; cell.textView.placeholder = @""; cell.textView.text = model.content; cell.cell2TitleL.text = model.FileName; cell.bgLabel.text = cell.textView.text; cell.textView.tag = TextViewTag + indexPath.row; cell.textView.delegate = self; cell.cell2SubTitleL.attributedText = [ZYCTool checkOfString:[NSString stringWithFormat:@"来自-%@的文章",model.AuthorName] KeyString:model.AuthorName]; cell.cell2ImagV.image = IMG(@"文章"); [cell.cell2CloseBtn setAction:^{ UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)]; UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { [weakSelf.dataArray removeObjectAtIndex:indexPath.row]; [weakSelf.tableView reloadData]; }]; UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [alert addAction:sureAction]; [alert addAction:cancelAction]; [weakSelf presentViewController:alert animated:YES completion:^{ }]; }]; return cell; }break; case CollectDataType_Approval: { NewTopicCell *cell = [NewTopicCell configCell2:tableView indexPath:indexPath]; cell.textView.placeholder = @""; cell.textView.text = model.content; cell.cell2TitleL.text = model.FileName; cell.bgLabel.text = cell.textView.text; cell.textView.tag = TextViewTag + indexPath.row; cell.textView.delegate = self; cell.cell2SubTitleL.attributedText = [ZYCTool checkOfString:[NSString stringWithFormat:@"来自-%@的审批",model.AuthorName] KeyString:model.AuthorName]; cell.cell2ImagV.image = IMG(@"审批"); [cell.cell2CloseBtn setAction:^{ UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"确认删除" preferredStyle:(UIAlertControllerStyleAlert)]; UIAlertAction * sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { [weakSelf.dataArray removeObjectAtIndex:indexPath.row]; [weakSelf.tableView reloadData]; }]; UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [alert addAction:sureAction]; [alert addAction:cancelAction]; [weakSelf presentViewController:alert animated:YES completion:^{ }]; }]; return cell; }break; default: { NewTopicCell *cell = [NewTopicCell configCell0:tableView indexPath:indexPath]; return cell; } break; } } #pragma -mark loadView - (UITableView *)tableView{ if (!_tableView) { _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; } return _tableView; } - (SmartBar *)SmartBar { if (!_SmartBar) { _SmartBar = [[SmartBar alloc] init]; } return _SmartBar; } - (NSMutableArray *)dataArray { if (!_dataArray) { _dataArray = [NSMutableArray array]; } return _dataArray; } #pragma -mark UItextViewDelegate - (void)textViewDidBeginEditing:(UITextView *)textView { self.defualtView = (NewTopicTextView *)textView; } - (void)textViewDidChange:(UITextView *)textView { self.defualtView = (NewTopicTextView *)textView; NSInteger index = textView.tag - TextViewTag; NewTopicModel * model = [self.dataArray objectAtIndex:index]; model.content = textView.text; CGRect bounds = textView.bounds; CGSize maxSize = CGSizeMake(bounds.size.width, CGFLOAT_MAX); CGSize newSize = [textView sizeThatFits:maxSize]; if (model.height != newSize.height) { [self.tableView beginUpdates]; [self.tableView endUpdates]; model.height = newSize.height; } } #pragma mark - SmartBarDelegate - (void)didSelectBarWithType:(SmartBarType)type { WS(weakSelf); switch (type) { case SmartBarPhoto: { [[LYLPhotoTailoringTool sharedTool] selectPhotoWithPhoroOrCamera:SelectPhotoWithTypePhoroOrCamera1 crop:YES showImgBlock:^(NSString *imageUrlStr) { } choosImgBlock:^(UIImage *image) { [weakSelf didSelectImage:image]; }]; } break; case SmartBarCamera: { [[LYLPhotoTailoringTool sharedTool] selectPhotoWithPhoroOrCamera:SelectPhotoWithTypePhoroOrCamera2 crop:YES showImgBlock:^(NSString *imageUrlStr) { } choosImgBlock:^(UIImage *image) { [weakSelf didSelectImage:image]; }]; } break; case SmartBarNotes: { [[FWZGetNoteBookTool sharedTool] openNoteBookListChooseNoteBookBlock:^(NSMutableArray * _Nonnull noteArr) { NSLog(@"SmartBarNotes %@",noteArr); [weakSelf disSelectNoteBook:noteArr]; }]; } break; case SmartBarCollection: { [[FWZGetNoteBookTool sharedTool] openCollectListChooseCollectBlock:^(NSMutableArray * _Nonnull collectArr) { NSLog(@"SmartBarCollection %@",collectArr); [weakSelf disSelectCollect:collectArr]; }]; } break; case SmartBarFile: { WS(weakSelf); [[FWZFileGetTool sharedTool] openFileWithCrop:YES showImgBlock:^(NSString * _Nonnull fileUrlStr) { } choosFileBlock:^(NSData * _Nonnull fileData, NSString * _Nonnull fileName) { SHOWLOADING [[HttpManager sharedHttpManager] HeaderUploadFileUrl:Host(Modify_UserImages_Post) parameters:@{} fileData:fileData fileKey:@"file" fileName:fileName mimeType:@"multipart/form-data" success:^(id _Nonnull responseObject) { REMOVESHOW NSLog(@"上传成功的文件%@",responseObject); [weakSelf fileSizeWithData:fileData withDict:responseObject[0]]; } failure:^(NSError * _Nonnull error) { REMOVESHOW }]; }]; } break; default: break; } } - (void)disSelectNoteBook:(NSMutableArray*_Nonnull )noteArr{ for (MyNoteBookSubModel *dataModel in noteArr ) { if (dataModel.AttributeValue == 1) { NewTopicModel * model = [[NewTopicModel alloc] init]; model.ID = dataModel.MiddleId; model.FileId =dataModel.MiddleId; model.imageUrl = dataModel.AvatarUrl; model.AuthorName = dataModel.Name; model.FileName = dataModel.Title; model.type = CollectDataType_Note; [self.dataArray addObject:model]; WS(weakSelf); dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf.tableView reloadData]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [weakSelf.tableView scrollToRow:weakSelf.dataArray.count - 1 inSection:0 atScrollPosition:UITableViewScrollPositionTop animated:NO]; }); }); }else{ NewTopicModel * model = [[NewTopicModel alloc] init]; model.ID = dataModel.Id; model.FileId = dataModel.Id; model.imageUrl = dataModel.AvatarUrl; model.AuthorName = [AppUserModel sharedAppUserModel].Name; model.FileName = dataModel.FolderName; model.type = CollectDataType_NoteFile; [self.dataArray addObject:model]; WS(weakSelf); dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf.tableView reloadData]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [weakSelf.tableView scrollToRow:weakSelf.dataArray.count - 1 inSection:0 atScrollPosition:UITableViewScrollPositionTop animated:NO]; }); }); } } } - (void)disSelectCollect:(NSMutableArray * _Nonnull) collectArr{ for (MyFavoriteSubModel *dataModel in collectArr ) { if(dataModel.AttributeValue == 1) { NewTopicModel * model = [[NewTopicModel alloc] init]; model.ID = dataModel.CollectionDataId; model.FileId = dataModel.CollectionDataId; model.imageUrl = dataModel.Data.AvatarUrl; model.AuthorName = dataModel.Data.Author; model.FileName = dataModel.Title; model.type = [ZYCTool returnDataType:dataModel.CollectionType]; [self.dataArray addObject:model]; WS(weakSelf); dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf.tableView reloadData]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [weakSelf.tableView scrollToRow:weakSelf.dataArray.count - 1 inSection:0 atScrollPosition:UITableViewScrollPositionTop animated:NO]; }); }); }else{ NewTopicModel * model = [[NewTopicModel alloc] init]; model.ID = dataModel.Id; model.FileId = dataModel.Id; model.imageUrl = dataModel.Data.AvatarUrl; model.AuthorName = [AppUserModel sharedAppUserModel].Name; model.FileName = dataModel.FolderName; model.type = CollectDataType_CollectFile; [self.dataArray addObject:model]; WS(weakSelf); dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf.tableView reloadData]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [weakSelf.tableView scrollToRow:weakSelf.dataArray.count - 1 inSection:0 atScrollPosition:UITableViewScrollPositionTop animated:NO]; }); }); } } } - (void)fileSizeWithData:(NSData *)fileData withDict:(NSDictionary *)dict { unsigned long long size = [fileData length]; NSString * fileZise; if (size >= pow(10, 9)) { // size >= 1GB fileZise = [NSString stringWithFormat:@"%.2fGB", size / pow(10, 9)]; } else if (size >= pow(10, 6)) { // 1GB > size >= 1MB fileZise = [NSString stringWithFormat:@"%.2fMB", size / pow(10, 6)]; } else if (size >= pow(10, 3)) { // 1MB > size >= 1KB fileZise = [NSString stringWithFormat:@"%.2fKB", size / pow(10, 3)]; } else { // 1KB > size fileZise = [NSString stringWithFormat:@"%lluB", size]; } [self didSelectFile:dict withSize:fileZise]; } - (void)didSelectImage:(UIImage *)image { WS(weakSelf); NSString *urlString = [[NSString alloc] initWithFormat:@"%@%@",BaseUrl,Modify_UserImages_Post]; [[HttpManager sharedHttpManager] HeaderUploadUrl:urlString parameters:@{} pictureArray:@[UIImageJPEGRepresentation(image,1.0f)] pictureKey:@"file" success:^(id _Nonnull responseObject) { NSLog(@"%@",responseObject); NSDictionary * dict = responseObject[0]; NewTopicModel * model = [[NewTopicModel alloc] init]; model.title = @""; model.content = @""; model.imageUrl = dict[@"AbsolutePath"]; model.FileId = [dict[@"FileId"] integerValue]; model.FileName = dict[@"FileName"]; model.type = CollectDataType_IMG; [weakSelf.dataArray addObject:model]; dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf.tableView reloadData]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [weakSelf.tableView scrollToRow:weakSelf.dataArray.count - 1 inSection:0 atScrollPosition:UITableViewScrollPositionTop animated:NO]; }); }); } failure:^(NSError * _Nonnull error) { }]; } - (void)didSelectFile:(NSDictionary *)dict withSize:(NSString *)fileSize { NewTopicModel * model = [[NewTopicModel alloc] init]; model.title = @""; model.content = @""; model.imageUrl = dict[@"AbsolutePath"]; model.FileId = [dict[@"FileId"] integerValue]; model.FileName = dict[@"FileName"]; model.type = CollectDataType_File; model.fileSize = fileSize; [self.dataArray addObject:model]; WS(weakSelf); dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf.tableView reloadData]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [weakSelf.tableView scrollToRow:weakSelf.dataArray.count - 1 inSection:0 atScrollPosition:UITableViewScrollPositionTop animated:NO]; }); }); } - (void)didSelectBarAddBtnIsShow:(BOOL)isShow { [self.view endEditing:YES]; } - (void)didSelectBarKeyBtnIsShow:(BOOL)isShow { [self.defualtView resignFirstResponder]; } #pragma mark - KeyBoard - (void)keyBoardWillShow:(NSNotification *)note { // 获取用户信息 NSDictionary *userInfo = [NSDictionary dictionaryWithDictionary:note.userInfo]; // 获取键盘高度 CGRect keyBoardBounds = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; CGFloat keyBoardHeight = keyBoardBounds.size.height; // 获取键盘动画时间 CGFloat animationTime = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]; // 定义好动作 WS(weakSelf); void (^animation)(void) = ^void(void) { [weakSelf.SmartBar mas_updateConstraints:^(MASConstraintMaker *make) { if (@available(iOS 11.0, *)) { make.bottom.equalTo(weakSelf.view.mas_safeAreaLayoutGuideBottom).offset(-keyBoardHeight); } else { make.bottom.equalTo(weakSelf.view.mas_bottom).offset(-keyBoardHeight); } }]; }; if (animationTime > 0) { [UIView animateWithDuration:animationTime animations:animation completion:^(BOOL finished) { }]; } else { animation(); } } - (void)keyBoardWillHide:(NSNotification *)note { // 获取用户信息 NSDictionary *userInfo = [NSDictionary dictionaryWithDictionary:note.userInfo]; // 获取键盘动画时间 CGFloat animationTime = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]; // 定义好动作 WS(weakSelf); void (^animation)(void) = ^void(void) { [weakSelf.SmartBar mas_updateConstraints:^(MASConstraintMaker *make) { if (@available(iOS 11.0, *)) { make.bottom.equalTo(weakSelf.view.mas_safeAreaLayoutGuideBottom).offset(BARHEIGHT); } else { make.bottom.equalTo(weakSelf.view.mas_bottom).offset(BARHEIGHT); } }]; }; if (animationTime > 0) { [UIView animateWithDuration:animationTime animations:animation]; } else { animation(); } } #pragma mark - 修改话题 - (void)editTopicPut { NSMutableArray * array = [NSMutableArray array]; for (NSInteger i = 1; i < self.dataArray.count; i ++) { NewTopicModel * model = self.dataArray[i]; switch (model.type) { case CollectDataType_Text: { if (model.content.length == 0) { break; } NSDictionary * dict = @{@"TextType":@"", @"File":@"", @"FileName":@"", @"Text":model.content, @"Title":@"", @"Type":@(CollectDataType_Text), @"Author":@"", @"Content":@"", @"Id":@(0), @"CreatedData":@"" }; [array addObject:dict]; } break; case CollectDataType_IMG: { if (model.imageUrl.length == 0) { break; } NSDictionary * dict = @{@"TextType":@"", @"File":model.imageUrl, @"FileName":model.FileName, @"Text":@"", @"Title":@"", @"Type":@(CollectDataType_IMG), @"Author":@"", @"Content":@"", @"Id":@(model.FileId), @"CreatedData":@"" }; [array addObject:dict]; if (model.content.length > 0) { NSDictionary * subDict = @{@"TextType":@"", @"File":@"", @"FileName":@"", @"Text":model.content, @"Title":@"", @"Type":@(CollectDataType_Text), @"Author":@"", @"Content":@"", @"Id":@(0), @"CreatedData":@"" }; [array addObject:subDict]; } } break; case CollectDataType_File: { if (model.FileName.length == 0) { break; } NSDictionary * dict = @{@"TextType":@"", @"File":model.File, @"FileName":model.FileName, @"Text":@"", @"Title":@"", @"Type":@(CollectDataType_File), @"Author":@"", @"Content":@"", @"Id":@(model.FileId), @"CreatedData":@"" }; [array addObject:dict]; if (model.content.length > 0) { NSDictionary * subDict = @{@"TextType":@"", @"File":@"", @"FileName":@"", @"Text":model.content, @"Title":@"", @"Type":@(CollectDataType_Text), @"Author":@"", @"Content":@"", @"Id":@(0), @"CreatedData":@"" }; [array addObject:subDict]; } } break; case CollectDataType_Group: { if (model.FileName.length == 0) { break; } NSDictionary * dict = @{@"TextType":@"", @"File":model.imageUrl, @"FileName":model.FileName, @"Text":@"", @"Title":@"", @"Type":@(CollectDataType_Group), @"Author":@"", @"Content":@"", @"Id":@(model.FileId), @"CreatedData":@"" }; [array addObject:dict]; if (model.content.length > 0) { NSDictionary * subDict = @{@"TextType":@"", @"File":@"", @"FileName":@"", @"Text":model.content, @"Title":@"", @"Type":@(CollectDataType_Text), @"Author":@"", @"Content":@"", @"Id":@(0), @"CreatedData":@"" }; [array addObject:subDict]; } } break; case CollectDataType_Collect: { if (model.FileName.length == 0) { break; } NSDictionary * dict = @{@"TextType":@"", @"File":model.imageUrl, @"FileName":@"", @"Text":@"", @"Title":model.FileName, @"Type":@(CollectDataType_Collect), @"Author":model.AuthorName, @"Content":@"", @"Id":@(model.FileId), @"CreatedData":@"" }; [array addObject:dict]; if (model.content.length > 0) { NSDictionary * subDict = @{@"TextType":@"", @"File":@"", @"FileName":@"", @"Text":model.content, @"Title":@"", @"Type":@(CollectDataType_Text), @"Author":@"", @"Content":@"", @"Id":@(0), @"CreatedData":@"" }; [array addObject:subDict]; } }break; case CollectDataType_Note: { if (model.FileName.length == 0) { break; } NSDictionary * dict = @{@"TextType":@"", @"File":model.imageUrl, @"FileName":@"", @"Text":@"", @"Title":model.FileName, @"Type":@(CollectDataType_Note), @"Author":model.AuthorName, @"Content":@"", @"Id":@(model.FileId), @"CreatedData":@"" }; [array addObject:dict]; if (model.content.length > 0) { NSDictionary * subDict = @{@"TextType":@"", @"File":@"", @"FileName":@"", @"Text":model.content, @"Title":@"", @"Type":@(CollectDataType_Text), @"Author":@"", @"Content":@"", @"Id":@(0), @"CreatedData":@"" }; [array addObject:subDict]; } }break; case CollectDataType_CollectFile: { if (model.FileName.length == 0) { break; } NSDictionary * dict = @{@"TextType":@"", @"File":model.imageUrl, @"FileName":@"", @"Text":@"", @"Title":model.FileName, @"Type":@(CollectDataType_CollectFile), @"Author":model.AuthorName, @"Content":@"", @"Id":@(model.FileId), @"CreatedData":@"" }; [array addObject:dict]; if (model.content.length > 0) { NSDictionary * subDict = @{@"TextType":@"", @"File":@"", @"FileName":@"", @"Text":model.content, @"Title":@"", @"Type":@(CollectDataType_Text), @"Author":@"", @"Content":@"", @"Id":@(0), @"CreatedData":@"" }; [array addObject:subDict]; } }break; case CollectDataType_NoteFile: { if (model.FileName.length == 0) { break; } NSDictionary * dict = @{@"TextType":@"", @"File":model.imageUrl, @"FileName":@"", @"Text":@"", @"Title":model.FileName, @"Type":@(CollectDataType_NoteFile), @"Author":model.AuthorName, @"Content":@"", @"Id":@(model.FileId), @"CreatedData":@"" }; [array addObject:dict]; if (model.content.length > 0) { NSDictionary * subDict = @{@"TextType":@"", @"File":@"", @"FileName":@"", @"Text":model.content, @"Title":@"", @"Type":@(CollectDataType_Text), @"Author":@"", @"Content":@"", @"Id":@(0), @"CreatedData":@"" }; [array addObject:subDict]; } }break; case CollectDataType_Notice: { if (model.FileName.length == 0) { break; } NSDictionary * dict = @{@"TextType":@"", @"File":model.imageUrl, @"FileName":model.FileName, @"Text":@"", @"Title":model.FileName, @"Type":@(CollectDataType_Notice), @"Author":model.AuthorName, @"Content":@"", @"Id":@(model.FileId), @"CreatedData":@"" }; [array addObject:dict]; if (model.content.length > 0) { NSDictionary * subDict = @{@"TextType":@"", @"File":@"", @"FileName":@"", @"Text":model.content, @"Title":@"", @"Type":@(CollectDataType_Text), @"Author":@"", @"Content":@"", @"Id":@(0), @"CreatedData":@"" }; [array addObject:subDict]; } }break; case CollectDataType_InterMail: { if (model.FileName.length == 0) { break; } NSDictionary * dict = @{@"TextType":@"", @"File":model.imageUrl, @"FileName":@"", @"Text":@"", @"Title":model.FileName, @"Type":@(CollectDataType_InterMail), @"Author":model.AuthorName, @"Content":@"", @"Id":@(model.FileId), @"CreatedData":@"" }; [array addObject:dict]; if (model.content.length > 0) { NSDictionary * subDict = @{@"TextType":@"", @"File":@"", @"FileName":@"", @"Text":model.content, @"Title":@"", @"Type":@(CollectDataType_Text), @"Author":@"", @"Content":@"", @"Id":@(0), @"CreatedData":@"" }; [array addObject:subDict]; } }break; case CollectDataType_Meeting: { if (model.FileName.length == 0) { break; } NSDictionary * dict = @{@"TextType":@"", @"File":model.imageUrl, @"FileName":@"", @"Text":@"", @"Title":model.FileName, @"Type":@(CollectDataType_Meeting), @"Author":model.AuthorName, @"Content":@"", @"Id":@(model.FileId), @"CreatedData":@"" }; [array addObject:dict]; if (model.content.length > 0) { NSDictionary * subDict = @{@"TextType":@"", @"File":@"", @"FileName":@"", @"Text":model.content, @"Title":@"", @"Type":@(CollectDataType_Text), @"Author":@"", @"Content":@"", @"Id":@(0), @"CreatedData":@"" }; [array addObject:subDict]; } }break; case CollectDataType_Approval: { if (model.FileName.length == 0) { break; } NSDictionary * dict = @{@"TextType":@"", @"File":model.imageUrl, @"FileName":@"", @"Text":@"", @"Title":model.FileName, @"Type":@(CollectDataType_Approval), @"Author":model.AuthorName, @"Content":@"", @"Id":@(model.FileId), @"CreatedData":@"" }; [array addObject:dict]; if (model.content.length > 0) { NSDictionary * subDict = @{@"TextType":@"", @"File":@"", @"FileName":@"", @"Text":model.content, @"Title":@"", @"Type":@(CollectDataType_Text), @"Author":@"", @"Content":@"", @"Id":@(0), @"CreatedData":@"" }; [array addObject:subDict]; } }break; case CollectDataType_Article: { if (model.FileName.length == 0) { break; } NSDictionary * dict = @{@"TextType":@"", @"File":model.imageUrl, @"FileName":@"", @"Text":@"", @"Title":model.FileName, @"Type":@(CollectDataType_Article), @"Author":model.AuthorName, @"Content":@"", @"Id":@(model.FileId), @"CreatedData":@"" }; [array addObject:dict]; if (model.content.length > 0) { NSDictionary * subDict = @{@"TextType":@"", @"File":@"", @"FileName":@"", @"Text":model.content, @"Title":@"", @"Type":@(CollectDataType_Text), @"Author":@"", @"Content":@"", @"Id":@(0), @"CreatedData":@"" }; [array addObject:subDict]; } }break; default: break; } } NSMutableDictionary * paraDict = [NSMutableDictionary dictionary]; NewTopicModel * fristModel = [self.dataArray firstObject]; [paraDict setObject:fristModel.content forKey:@"Title"]; [paraDict setObject:@([AppUserModel sharedAppUserModel].Id) forKey:@"UserId"]; [paraDict setObject:@(self.topicId) forKey:@"Id"]; if (array.count == 0 && fristModel.content.length == 0) { SHOWERROR(@"话题标题和内容不能都为空"); return; } [paraDict setObject:[self arrayToJSONString:array] forKey:@"Content"]; WS(weakSelf); SHOWLOADING [[HttpManager sharedHttpManager] PUTUrl:Host(API_APP_Topic_Update) parameters:paraDict responseStyle:DATA success:^(id _Nonnull responseObject) { NSLog(@"%@",responseObject); REMOVESHOW SHOWSUCCESS(@"创建成功"); if (weakSelf.upDateBlock) { weakSelf.upDateBlock(); } [weakSelf.navigationController popViewControllerAnimated:YES]; } failure:^(NSError * _Nonnull error) { REMOVESHOW }]; } - (NSString *)arrayToJSONString:(NSArray *)array { NSError *error = nil; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:array options:NSJSONWritingPrettyPrinted error:&error]; NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; return jsonString; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [[IQKeyboardManager sharedManager] setEnable:NO]; WS(weakSelf); [self.view endEditing:YES]; [self.SmartBar downBar]; [self.SmartBar mas_updateConstraints:^(MASConstraintMaker *make) { if (@available(iOS 11.0, *)) { make.bottom.equalTo(weakSelf.view.mas_safeAreaLayoutGuideBottom).offset(BARHEIGHT); } else { make.bottom.equalTo(weakSelf.view.mas_bottom).offset(BARHEIGHT); } }]; } - (NSString *)getFileNameImage:(NSString *)fileName { if ([fileName hasPrefix:@".doc"]) { return @"icon_word"; }else if([fileName hasPrefix:@".xls"]){ return @"icon_excel"; }else if([fileName hasPrefix:@".ppt"]){ return @"icon_ppt"; }else if([fileName hasPrefix:@".pdf"]){ return @"icon_pdf"; }else if([fileName hasPrefix:@".zip"]){ return @"icon_yasuowenjian"; }else if([fileName hasPrefix:@".psd"]){ return @"icon_psd"; }else if([fileName hasPrefix:@".ai"]){ return @"icon_ai"; }else if([fileName hasPrefix:@".txt"]){ return @"icon_txt"; }else if([fileName hasPrefix:@".html"]){ return @"icon_html"; }else{ return @"icon_weizhiwenjian"; } } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } @end