CommomSearchVC.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. //
  2. // CommomSearchVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/1/17.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "CommomSearchVC.h"
  9. #import "CommonListCell.h"
  10. #import "MyFavoriteVC.h"
  11. #import "CommonNoteVC.h"
  12. #import "OtherFavoriteVC.h"
  13. #import "OtherNoteBookVC.h"
  14. #import "DownFileViewController.h"
  15. #import "WorkFlowDetailsController.h"
  16. #import "MyApprovalPageDetail.h"
  17. #import "CountDataVC.h"
  18. #import "CommomSearchVC.h"
  19. #import "MyFavoriteVC.h"
  20. #import "NoteBookVC.h"
  21. #import "OtherFavoriteVC.h"
  22. #import "OtherNoteBookVC.h"
  23. #import "DownFileViewController.h"
  24. #import "WorkFlowDetailsController.h"
  25. #import "MyApprovalPageDetail.h"
  26. #import "CountDataVC.h"
  27. #import "CommomSearchVC.h"
  28. #import "NoteBookShareVC.h"
  29. #import "MyTDGroupViewController.h"
  30. #import "TDGroupInfoListVC.h"
  31. #import "MailListVC.h"
  32. #import "ShareListVC.h"
  33. @interface CommomSearchVC ()<UITableViewDelegate,UITableViewDataSource>
  34. @property (nonatomic, copy) NSMutableArray *listArray;
  35. @end
  36. @implementation CommomSearchVC
  37. - (void)viewDidLoad {
  38. [super viewDidLoad];
  39. self.fd_prefersNavigationBarHidden = YES;
  40. self.view.backgroundColor = RGB(255, 255, 255);
  41. self.tableView.delegate = self;
  42. self.tableView.dataSource = self;
  43. // [self.topNavSearch setBarPlaceholder:@"姓名/手机号/邮箱"];
  44. if (self.IsAddUser) {
  45. [self.cancelBtn setAttributedTitle:[[NSAttributedString alloc] initWithString:@"确定" attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang SC" size: 15],NSForegroundColorAttributeName: UIColorHex(#3979D3)}] forState:UIControlStateNormal];
  46. WS(weakSelf);
  47. NSMutableArray * array = [NSMutableArray array];
  48. [self.cancelBtn setAction:^{
  49. for (SelectModel *model in weakSelf.listArray) {
  50. if (model.hadSelected) {
  51. [array addObject:model];
  52. }
  53. }
  54. if (array.count > 0) {
  55. [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFI_ChaoSongRen object:nil userInfo:@{@"selectPeople":array}];
  56. [weakSelf back1];
  57. }
  58. }];
  59. }
  60. self.historySearchType = HistorySearchType_Common;
  61. [self addObserver:self forKeyPath:@"searchText" options:NSKeyValueObservingOptionNew context:nil];
  62. }
  63. - (void)dealloc
  64. {
  65. [[NSNotificationCenter defaultCenter] removeObserver:self];
  66. }
  67. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
  68. {
  69. id obj = [change objectForKey:@"new"];
  70. NSString * text = @"";
  71. if ([obj isKindOfClass:[NSString class]]) {
  72. text = obj;
  73. }else{
  74. text = [obj stringValue];
  75. }
  76. if (text.length > 0) {
  77. [self getData:text];
  78. }
  79. }
  80. - (void)getData:(NSString *)searchKey
  81. {
  82. [self.listArray removeAllObjects];
  83. WS(weakSelf);
  84. SHOWLOADING
  85. [[HttpManager sharedHttpManager] POSTUrl:Host(API_Collection_List) parameters:@{@"FolderId":@(0),@"Page":@(1),@"PerPage":@(99999999),@"VisitUserId":@(0),@"SearchKey":searchKey} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  86. REMOVESHOW
  87. MyFavoriteModel *listModel = [[MyFavoriteModel alloc] initWithDictionary:responseObject error:nil];
  88. [weakSelf.listArray addObjectsFromArray:listModel.Items];
  89. for (MyFavoriteSubModel *model in weakSelf.listArray) {
  90. if (model.CollectionType == CollectModel_Text) {
  91. model.CollectionType = CollectModel_Aritle;
  92. }
  93. }
  94. dispatch_async(dispatch_get_main_queue(), ^{
  95. [weakSelf.tableView reloadData];
  96. });
  97. } failure:^(NSError * _Nonnull error) {
  98. REMOVESHOW
  99. }];
  100. }
  101. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  102. {
  103. return self.listArray.count;
  104. }
  105. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  106. {
  107. return UITableViewAutomaticDimension;
  108. }
  109. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  110. {
  111. CommonListCell *cell = [CommonListCell configCell1:tableView indexPath:indexPath];
  112. MyFavoriteSubModel * model = [self.listArray objectAtIndex:indexPath.row];
  113. [cell setCellData:model withText:self.searchText];
  114. return cell;
  115. }
  116. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  117. {
  118. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  119. MyFavoriteSubModel * model = [self.listArray objectAtIndex:indexPath.row];
  120. switch (model.CollectionType) {
  121. case CollectModel_Aritle:{
  122. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  123. vc.type = CollectModel_Aritle;
  124. vc.Id = model.CollectionDataId;
  125. [self.navigationController pushViewController:vc animated:YES];
  126. }break;
  127. case CollectModel_Toipc:
  128. {
  129. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  130. vc.type = CollectModel_Toipc;
  131. vc.Id = model.CollectionDataId;
  132. [self.navigationController pushViewController:vc animated:YES];
  133. }break;
  134. case CollectModel_NewTopic:
  135. {
  136. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  137. vc.type = CollectModel_NewTopic;
  138. vc.Id = model.CollectionDataId;
  139. [self.navigationController pushViewController:vc animated:YES];
  140. }break;
  141. case CollectModel_Collect:{
  142. }break;
  143. case CollectModel_NoteBook:{
  144. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  145. vc.type = CollectModel_NoteBook;
  146. vc.Id = model.CollectionDataId;
  147. vc.isNoteBook = YES;
  148. [self.navigationController pushViewController:vc animated:YES];
  149. }break;
  150. case CollectModel_CollectFile:{
  151. if (model.SourceUserId == [AppUserModel sharedAppUserModel].Id || model.SourceUserId == 0) {
  152. MyFavoriteVC * vc = [MyFavoriteVC initMyFavoriteVC];
  153. vc.listType = model.CollectionDataId == 0 ? MyFavoriteListLevelTypeA : MyFavoriteListLevelTypeB;
  154. vc.FolderId = model.CollectionDataId;
  155. vc.myTitle = model.Title;
  156. [self.navigationController pushViewController:vc animated:YES];
  157. }else{
  158. OtherFavoriteVC * vc = [OtherFavoriteVC initOtherFavoriteVC];
  159. vc.listType = model.CollectionDataId == 0 ? MyFavoriteListLevelTypeA : MyFavoriteListLevelTypeB;
  160. vc.FolderId = model.CollectionDataId;
  161. vc.CollectionDataId = model.CollectionDataId;
  162. vc.CollectionType = model.CollectionType;
  163. vc.Author = model.Data.Author;
  164. vc.myTitle = model.Title;
  165. vc.VisitUserId = model.SourceUserId;
  166. [self.navigationController pushViewController:vc animated:YES];
  167. }
  168. }break;
  169. case CollectModel_NoteFile: {
  170. if (model.SourceUserId == [AppUserModel sharedAppUserModel].Id || model.SourceUserId == 0) {
  171. NoteBookVC * vc = [NoteBookVC initNoteBookVC];
  172. vc.listType = model.CollectionDataId == 0 ? MyFavoriteListLevelTypeA : MyFavoriteListLevelTypeB;
  173. vc.FolderId = model.CollectionDataId;
  174. vc.myTitle = model.Title;
  175. [self.navigationController pushViewController:vc animated:YES];
  176. }else{
  177. OtherNoteBookVC * vc = [OtherNoteBookVC initOtherNoteBookVC];
  178. vc.listType = model.CollectionDataId == 0 ? MyFavoriteListLevelTypeA : MyFavoriteListLevelTypeB;
  179. vc.FolderId = model.CollectionDataId;
  180. vc.CollectionDataId = model.CollectionDataId;
  181. vc.CollectionType = model.CollectionType;
  182. vc.Author = model.Data.Author;
  183. vc.myTitle = model.Title;
  184. vc.VisitUserId = model.SourceUserId;
  185. [self.navigationController pushViewController:vc animated:YES];
  186. }
  187. }break;
  188. case CollectModel_TopicBooK:{
  189. if (model.SourceUserId == [AppUserModel sharedAppUserModel].Id || model.SourceUserId == 0) {
  190. NoteBookVC * vc = [NoteBookVC initNoteBookVC];
  191. vc.listType = MyFavoriteListLevelTypeA;
  192. vc.FolderId = model.CollectionDataId;
  193. vc.TypeValue = 1;
  194. vc.myTitle = model.Title;
  195. [self.navigationController pushViewController:vc animated:YES];
  196. }else{
  197. OtherNoteBookVC * vc = [OtherNoteBookVC initOtherNoteBookVC];
  198. vc.listType = MyFavoriteListLevelTypeA ;
  199. vc.FolderId = model.CollectionDataId;
  200. vc.CollectionDataId = model.CollectionDataId;
  201. vc.CollectionType = model.CollectionType;
  202. vc.Author = model.Data.Author;
  203. vc.TypeValue = 1;
  204. vc.myTitle = model.Title;
  205. vc.VisitUserId = model.SourceUserId;
  206. [self.navigationController pushViewController:vc animated:YES];
  207. }
  208. }break;
  209. case CollectModel_TopicSubBooK:{
  210. if (model.SourceUserId == [AppUserModel sharedAppUserModel].Id || model.SourceUserId == 0) {
  211. NoteBookVC * vc = [NoteBookVC initNoteBookVC];
  212. vc.listType = MyFavoriteListLevelTypeB;
  213. vc.FolderId = model.CollectionDataId;
  214. vc.TypeValue = 1;
  215. vc.myTitle = model.Title;
  216. [self.navigationController pushViewController:vc animated:YES];
  217. }else{
  218. OtherNoteBookVC * vc = [OtherNoteBookVC initOtherNoteBookVC];
  219. vc.listType = MyFavoriteListLevelTypeB;
  220. vc.FolderId = model.CollectionDataId;
  221. vc.CollectionDataId = model.CollectionDataId;
  222. vc.CollectionType = model.CollectionType;
  223. vc.Author = model.Data.Author;
  224. vc.TypeValue = 1;
  225. vc.myTitle = model.Title;
  226. vc.VisitUserId = model.SourceUserId;
  227. [self.navigationController pushViewController:vc animated:YES];
  228. }
  229. }break;
  230. case CollectModel_Notice:{
  231. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  232. vc.type = CollectModel_Notice;
  233. vc.Id = model.CollectionDataId;
  234. [self.navigationController pushViewController:vc animated:YES];
  235. }break;
  236. case CollectModel_InterMail:{
  237. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  238. vc.type = CollectModel_InterMail;
  239. vc.Id = model.CollectionDataId;
  240. [self.navigationController pushViewController:vc animated:YES];
  241. }break;
  242. case CollectModel_file:{
  243. FlowAttachmentsModel *wMdoel = [[FlowAttachmentsModel alloc]init];
  244. wMdoel.Url = model.Data.File;
  245. wMdoel.MinUrl = model.Data.File;
  246. wMdoel.Title = model.Data.FileName;
  247. wMdoel.SoureId = model.Data.Id;
  248. wMdoel.SoureTypeId = CollectModel_file;
  249. wMdoel.Size = model.Data.FileSize;
  250. DownFileViewController *downFileViewController = [[DownFileViewController alloc]init];
  251. downFileViewController.model = wMdoel;
  252. [self.navigationController pushViewController:downFileViewController animated:YES];
  253. }break;
  254. case CollectModel_meetDetail:
  255. {
  256. WorkFlowDetailsController * vc = [[WorkFlowDetailsController alloc] initWithId:model.CollectionDataId];
  257. [self.navigationController pushViewController:vc animated:YES];
  258. }
  259. break;
  260. case CollectModel_work:
  261. {
  262. MyApprovalPageDetail * vc = [[MyApprovalPageDetail alloc]init];
  263. vc.pageType = Type_ONEC;
  264. vc.indexId = model.CollectionDataId;
  265. vc.title = model.Data.Title;
  266. vc.TodoId = model.CollectionDataId;
  267. [self.navigationController pushViewController:vc animated:YES];
  268. }
  269. case CollectModel_meetMian:{
  270. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  271. vc.Id = model.CollectionDataId;
  272. vc.type = CollectModel_meetMian;
  273. [self.navigationController pushViewController:vc animated:YES];
  274. }break;
  275. case CollectModel_financeCount:{
  276. CountDataVC *vc = [CountDataVC initCountDataVC];
  277. vc.index = 0;
  278. vc.titleStr = @"财务统计";
  279. [self.navigationController pushViewController:vc animated:YES];
  280. }break;
  281. case CollectModel_affairsCount:{
  282. CountDataVC *vc = [CountDataVC initCountDataVC];
  283. vc.index = 1;
  284. vc.titleStr = @"人事统计";
  285. [self.navigationController pushViewController:vc animated:YES];
  286. }break;
  287. case CollectModel_publishCount:{
  288. CountDataVC *vc = [CountDataVC initCountDataVC];
  289. vc.index = 2;
  290. vc.titleStr = @"出版统计";
  291. [self.navigationController pushViewController:vc animated:YES];
  292. }break;
  293. default:
  294. {
  295. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  296. vc.Id = model.CollectionDataId;
  297. vc.type = CollectModel_Toipc;
  298. [self.navigationController pushViewController:vc animated:YES];
  299. }
  300. break;
  301. }
  302. }
  303. -(void)back1{
  304. for (NSInteger i = (self.navigationController.viewControllers.count - 1); i > 0 ;i --) {
  305. if ([self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"CommonHomeVC")]) {
  306. [self.navigationController popToViewController:self.navigationController.viewControllers[i] animated:YES];
  307. return;
  308. }
  309. }
  310. }
  311. - (NSMutableArray *)listArray{
  312. if (!_listArray) {
  313. _listArray = [NSMutableArray new];
  314. }
  315. return _listArray;
  316. }
  317. @end