// // CommomSearchVC.m // smartRhino // // Created by niuzhen on 2020/1/17. // Copyright © 2020 tederen. All rights reserved. // #import "CommomSearchVC.h" #import "CommonListCell.h" #import "MyFavoriteVC.h" #import "CommonNoteVC.h" #import "OtherFavoriteVC.h" #import "OtherNoteBookVC.h" #import "DownFileViewController.h" #import "WorkFlowDetailsController.h" #import "MyApprovalPageDetail.h" #import "CountDataVC.h" #import "CommomSearchVC.h" #import "MyFavoriteVC.h" #import "NoteBookVC.h" #import "OtherFavoriteVC.h" #import "OtherNoteBookVC.h" #import "DownFileViewController.h" #import "WorkFlowDetailsController.h" #import "MyApprovalPageDetail.h" #import "CountDataVC.h" #import "CommomSearchVC.h" #import "NoteBookShareVC.h" #import "MyTDGroupViewController.h" #import "TDGroupInfoListVC.h" #import "MailListVC.h" #import "ShareListVC.h" #import "BookWCDetailVC.h" #import "BookListenVC.h" #import "BookTeacherDetailVC.h" @interface CommomSearchVC () @property (nonatomic, copy) NSMutableArray *listArray; @end @implementation CommomSearchVC - (void)viewDidLoad { [super viewDidLoad]; self.fd_prefersNavigationBarHidden = YES; self.view.backgroundColor = RGB(255, 255, 255); self.tableView.delegate = self; self.tableView.dataSource = self; // [self.topNavSearch setBarPlaceholder:@"姓名/手机号/邮箱"]; if (self.IsAddUser) { [self.cancelBtn setAttributedTitle:[[NSAttributedString alloc] initWithString:@"确定" attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang SC" size: 15],NSForegroundColorAttributeName: UIColorHex(#3979D3)}] forState:UIControlStateNormal]; WS(weakSelf); NSMutableArray * array = [NSMutableArray array]; [self.cancelBtn setAction:^{ for (SelectModel *model in weakSelf.listArray) { if (model.hadSelected) { [array addObject:model]; } } if (array.count > 0) { [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFI_ChaoSongRen object:nil userInfo:@{@"selectPeople":array}]; [weakSelf back1]; } }]; } self.historySearchType = HistorySearchType_Common; [self addObserver:self forKeyPath:@"searchText" options:NSKeyValueObservingOptionNew context:nil]; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { id obj = [change objectForKey:@"new"]; NSString * text = @""; if ([obj isKindOfClass:[NSString class]]) { text = obj; }else{ text = [obj stringValue]; } if (text.length > 0) { [self getData:text]; } } - (void)getData:(NSString *)searchKey { [self.listArray removeAllObjects]; WS(weakSelf); SHOWLOADING [[HttpManager sharedHttpManager] POSTUrl:Host(API_Collection_List) parameters:@{@"FolderId":@(0),@"Page":@(1),@"PerPage":@(99999999),@"VisitUserId":@(0),@"SearchKey":searchKey} responseStyle:JOSN success:^(id _Nonnull responseObject) { REMOVESHOW MyFavoriteModel *listModel = [[MyFavoriteModel alloc] initWithDictionary:responseObject error:nil]; [weakSelf.listArray addObjectsFromArray:listModel.Items]; for (MyFavoriteSubModel *model in weakSelf.listArray) { if (model.CollectionType == CollectModel_Text) { model.CollectionType = CollectModel_Aritle; } } dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf.tableView reloadData]; }); } failure:^(NSError * _Nonnull error) { REMOVESHOW }]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.listArray.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewAutomaticDimension; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { CommonListCell *cell = [CommonListCell configCell1:tableView indexPath:indexPath]; MyFavoriteSubModel * model = [self.listArray objectAtIndex:indexPath.row]; if (model.CollectionType == CollectModel_TopicBooK) { CommonListCell *cell = [CommonListCell configCell2:tableView indexPath:indexPath]; [cell setCellTopicBookData:model]; WS(weakSelf); [cell.desBtn setAction:^{ MyFavoriteVC * vc = [MyFavoriteVC initMyFavoriteVC]; vc.listType = model.FolderId == 0 ? MyFavoriteListLevelTypeA : MyFavoriteListLevelTypeB; vc.FolderId = model.FolderId; vc.myTitle = model.FolderName; [weakSelf.navigationController pushViewController:vc animated:YES]; }]; return cell; }else{ switch (model.CollectionType) { case CollectModel_Teacher: { CommonListCell *cell = [CommonListCell configCell2:tableView indexPath:indexPath]; [cell setCellNoAuthorData:model withText:self.searchText]; WS(weakSelf); [cell.desBtn setAction:^{ MyFavoriteVC * vc = [MyFavoriteVC initMyFavoriteVC]; vc.listType = model.FolderId == 0 ? MyFavoriteListLevelTypeA : MyFavoriteListLevelTypeB; vc.FolderId = model.FolderId; vc.myTitle = model.FolderName; [weakSelf.navigationController pushViewController:vc animated:YES]; }]; return cell; } break; default: { if (model.CollectionType != CollectModel_Toipc && model.Data.Author.length == 0) { CommonListCell *cell = [CommonListCell configCell2:tableView indexPath:indexPath]; [cell setCellNoAuthorData:model withText:self.searchText]; WS(weakSelf); [cell.desBtn setAction:^{ MyFavoriteVC * vc = [MyFavoriteVC initMyFavoriteVC]; vc.listType = model.FolderId == 0 ? MyFavoriteListLevelTypeA : MyFavoriteListLevelTypeB; vc.FolderId = model.FolderId; vc.myTitle = model.FolderName; [weakSelf.navigationController pushViewController:vc animated:YES]; }]; return cell; }else{ CommonListCell *cell = [CommonListCell configCell1:tableView indexPath:indexPath]; [cell setCellData:model withText:self.searchText]; WS(weakSelf); [cell.desBtn setAction:^{ MyFavoriteVC * vc = [MyFavoriteVC initMyFavoriteVC]; vc.listType = model.FolderId == 0 ? MyFavoriteListLevelTypeA : MyFavoriteListLevelTypeB; vc.FolderId = model.FolderId; vc.myTitle = model.FolderName; [weakSelf.navigationController pushViewController:vc animated:YES]; }]; if (model.CollectionType == CollectModel_Toipc) { [cell.comeBtn setAction:^{ TDGroupInfoListVC * vc = [TDGroupInfoListVC initTDGroupInfoListVC]; vc.GroupId = model.Data.GroupId; vc.titleStr = model.Data.GroupName; [weakSelf.navigationController pushViewController:vc animated:YES]; }]; } return cell; } } break; } } } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; MyFavoriteSubModel * model = [self.listArray objectAtIndex:indexPath.row]; switch (model.CollectionType) { case CollectModel_Aritle:{ MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC]; vc.type = CollectModel_Aritle; vc.Id = model.CollectionDataId; [self.navigationController pushViewController:vc animated:YES]; }break; case CollectModel_Toipc: { MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC]; vc.type = CollectModel_Toipc; vc.Id = model.CollectionDataId; [self.navigationController pushViewController:vc animated:YES]; }break; case CollectModel_NewTopic: { MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC]; vc.type = CollectModel_NewTopic; vc.Id = model.CollectionDataId; [self.navigationController pushViewController:vc animated:YES]; }break; case CollectModel_Collect:{ }break; case CollectModel_NoteBook:{ MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC]; vc.type = CollectModel_NoteBook; vc.Id = model.CollectionDataId; vc.isNoteBook = YES; [self.navigationController pushViewController:vc animated:YES]; }break; case CollectModel_CollectFile:{ if (model.SourceUserId == [AppUserModel sharedAppUserModel].Id || model.SourceUserId == 0) { MyFavoriteVC * vc = [MyFavoriteVC initMyFavoriteVC]; vc.listType = model.CollectionDataId == 0 ? MyFavoriteListLevelTypeA : MyFavoriteListLevelTypeB; vc.FolderId = model.CollectionDataId; vc.myTitle = model.Title; [self.navigationController pushViewController:vc animated:YES]; }else{ OtherFavoriteVC * vc = [OtherFavoriteVC initOtherFavoriteVC]; vc.listType = model.CollectionDataId == 0 ? MyFavoriteListLevelTypeA : MyFavoriteListLevelTypeB; vc.FolderId = model.CollectionDataId; vc.CollectionDataId = model.CollectionDataId; vc.CollectionType = model.CollectionType; vc.Author = model.Data.Author; vc.myTitle = model.Title; vc.VisitUserId = model.SourceUserId; [self.navigationController pushViewController:vc animated:YES]; } }break; case CollectModel_NoteFile: { if (model.SourceUserId == [AppUserModel sharedAppUserModel].Id || model.SourceUserId == 0) { NoteBookVC * vc = [NoteBookVC initNoteBookVC]; vc.listType = model.CollectionDataId == 0 ? MyFavoriteListLevelTypeA : MyFavoriteListLevelTypeB; vc.FolderId = model.CollectionDataId; vc.myTitle = model.Title; [self.navigationController pushViewController:vc animated:YES]; }else{ OtherNoteBookVC * vc = [OtherNoteBookVC initOtherNoteBookVC]; vc.listType = model.CollectionDataId == 0 ? MyFavoriteListLevelTypeA : MyFavoriteListLevelTypeB; vc.FolderId = model.CollectionDataId; vc.CollectionDataId = model.CollectionDataId; vc.CollectionType = model.CollectionType; vc.Author = model.Data.Author; vc.myTitle = model.Title; vc.VisitUserId = model.SourceUserId; [self.navigationController pushViewController:vc animated:YES]; } }break; case CollectModel_TopicBooK:{ if (model.SourceUserId == [AppUserModel sharedAppUserModel].Id || model.SourceUserId == 0) { NoteBookVC * vc = [NoteBookVC initNoteBookVC]; vc.listType = MyFavoriteListLevelTypeA; vc.FolderId = model.CollectionDataId; vc.TypeValue = 1; vc.myTitle = model.Title; [self.navigationController pushViewController:vc animated:YES]; }else{ OtherNoteBookVC * vc = [OtherNoteBookVC initOtherNoteBookVC]; vc.listType = MyFavoriteListLevelTypeA ; vc.FolderId = model.CollectionDataId; vc.CollectionDataId = model.CollectionDataId; vc.CollectionType = model.CollectionType; vc.Author = model.Data.Author; vc.TypeValue = 1; vc.myTitle = model.Title; vc.VisitUserId = model.SourceUserId; [self.navigationController pushViewController:vc animated:YES]; } }break; case CollectModel_TopicSubBooK:{ if (model.SourceUserId == [AppUserModel sharedAppUserModel].Id || model.SourceUserId == 0) { NoteBookVC * vc = [NoteBookVC initNoteBookVC]; vc.listType = MyFavoriteListLevelTypeB; vc.FolderId = model.CollectionDataId; vc.TypeValue = 1; vc.myTitle = model.Title; [self.navigationController pushViewController:vc animated:YES]; }else{ OtherNoteBookVC * vc = [OtherNoteBookVC initOtherNoteBookVC]; vc.listType = MyFavoriteListLevelTypeB; vc.FolderId = model.CollectionDataId; vc.CollectionDataId = model.CollectionDataId; vc.CollectionType = model.CollectionType; vc.Author = model.Data.Author; vc.TypeValue = 1; vc.myTitle = model.Title; vc.VisitUserId = model.SourceUserId; [self.navigationController pushViewController:vc animated:YES]; } }break; case CollectModel_Notice:{ MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC]; vc.type = CollectModel_Notice; vc.Id = model.CollectionDataId; [self.navigationController pushViewController:vc animated:YES]; }break; case CollectModel_InterMail:{ MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC]; vc.type = CollectModel_InterMail; vc.Id = model.CollectionDataId; [self.navigationController pushViewController:vc animated:YES]; }break; case CollectModel_file:{ FlowAttachmentsModel *wMdoel = [[FlowAttachmentsModel alloc]init]; wMdoel.Url = model.Data.File; wMdoel.MinUrl = model.Data.File; wMdoel.Title = model.Data.FileName; wMdoel.SoureId = model.Data.Id; wMdoel.SoureTypeId = CollectModel_file; wMdoel.Size = model.Data.FileSize; DownFileViewController *downFileViewController = [[DownFileViewController alloc]init]; downFileViewController.model = wMdoel; [self.navigationController pushViewController:downFileViewController animated:YES]; }break; case CollectModel_meetDetail: { WorkFlowDetailsController * vc = [[WorkFlowDetailsController alloc] initWithId:model.CollectionDataId]; [self.navigationController pushViewController:vc animated:YES]; } break; case CollectModel_work: { MyApprovalPageDetail * vc = [[MyApprovalPageDetail alloc]init]; vc.pageType = Type_ONEC; vc.indexId = model.CollectionDataId; vc.title = model.Data.Title; vc.TodoId = model.CollectionDataId; [self.navigationController pushViewController:vc animated:YES]; } case CollectModel_meetMian:{ MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC]; vc.Id = model.CollectionDataId; vc.type = CollectModel_meetMian; [self.navigationController pushViewController:vc animated:YES]; }break; case CollectModel_StoreSound: { BookListenVC * vc = [BookListenVC initBookListenVC]; vc.Id = model.CollectionDataId; vc.MediaType = MediaMusicType; [self.navigationController pushViewController:vc animated:YES]; } break; case CollectModel_StoreVideo: { BookWCDetailVC * vc = [BookWCDetailVC initBookWCDetailVC]; vc.Id = model.CollectionDataId; [self.navigationController pushViewController:vc animated:YES]; } break; case CollectModel_Teacher: { BookTeacherDetailVC * vc = [BookTeacherDetailVC initBookTeacherDetailVC]; vc.Id = model.CollectionDataId; [self.navigationController pushViewController:vc animated:YES]; } break; case CollectModel_financeCount:{ CountDataVC *vc = [CountDataVC initCountDataVC]; vc.index = 0; vc.titleStr = @"财务统计"; [self.navigationController pushViewController:vc animated:YES]; }break; case CollectModel_affairsCount:{ CountDataVC *vc = [CountDataVC initCountDataVC]; vc.index = 1; vc.titleStr = @"人事统计"; [self.navigationController pushViewController:vc animated:YES]; }break; case CollectModel_publishCount:{ CountDataVC *vc = [CountDataVC initCountDataVC]; vc.index = 2; vc.titleStr = @"出版统计"; [self.navigationController pushViewController:vc animated:YES]; }break; default: { MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC]; vc.Id = model.CollectionDataId; vc.type = CollectModel_Toipc; [self.navigationController pushViewController:vc animated:YES]; } break; } } -(void)back1{ for (NSInteger i = (self.navigationController.viewControllers.count - 1); i > 0 ;i --) { if ([self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"CommonHomeVC")]) { [self.navigationController popToViewController:self.navigationController.viewControllers[i] animated:YES]; return; } } } - (NSMutableArray *)listArray{ if (!_listArray) { _listArray = [NSMutableArray new]; } return _listArray; } @end