TDInterLeterSearchVC.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. //
  2. // TDInterLeterSearchVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/3/23.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "TDInterLeterSearchVC.h"
  9. #import "ChatMsgNoticeCell.h"
  10. #import "NSDate+Extension.h"
  11. @interface TDInterLeterSearchVC ()<UITableViewDelegate,UITableViewDataSource>
  12. @property (nonatomic, copy) NSMutableArray *listArray;
  13. @property (nonatomic, assign) NSUInteger currentPage ;
  14. @property (nonatomic, assign) NSUInteger totalPage ;
  15. @property (nonatomic, assign) NSUInteger totalRecord ;
  16. @end
  17. @implementation TDInterLeterSearchVC
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. self.fd_prefersNavigationBarHidden = YES;
  21. self.view.backgroundColor = RGB(255, 255, 255);
  22. self.tableView.delegate = self;
  23. self.tableView.dataSource = self;
  24. [self addRefresh];
  25. self.historySearchType = HistorySearchType_InterMail;
  26. [self addObserver:self forKeyPath:@"searchText" options:NSKeyValueObservingOptionNew context:nil];
  27. }
  28. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context
  29. {
  30. id obj = [change objectForKey:@"new"];
  31. NSString * text = @"";
  32. if ([obj isKindOfClass:[NSString class]]) {
  33. text = obj;
  34. }else{
  35. text = [obj stringValue];
  36. }
  37. if (text.length > 0) {
  38. [self headRefresh];
  39. }
  40. }
  41. - (void)addRefresh
  42. {
  43. WS(weakSelf);
  44. if (self.searchText.length > 0) {
  45. self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  46. [weakSelf headRefresh];
  47. }];
  48. self.tableView.mj_footer = [MJRefreshBackStateFooter footerWithRefreshingBlock:^{
  49. [weakSelf footerRefresh];
  50. }];
  51. }
  52. }
  53. - (void)removeRefresh
  54. {
  55. [self.tableView.mj_header endRefreshing];
  56. [self.tableView.mj_header removeFromSuperview];
  57. [self.tableView.mj_footer endRefreshing];
  58. [self.tableView.mj_footer removeFromSuperview];
  59. }
  60. - (void)headRefresh{
  61. self.currentPage = 1;
  62. [self.listArray removeAllObjects];
  63. [self getData:self.searchText];
  64. }
  65. - (void)footerRefresh{
  66. self.currentPage += 1;
  67. if (self.totalRecord == self.listArray.count) {
  68. self.currentPage --;
  69. return ;
  70. }
  71. [self getData:self.searchText];
  72. }
  73. - (void)getData:(NSString *)searchKey
  74. {
  75. NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
  76. NSUInteger deleteType = 0;
  77. switch (self.type) {
  78. case PageTypeFromTitleAll:
  79. {
  80. deleteType = 1;
  81. }
  82. break;
  83. case PageTypeFromTitleMy:
  84. {
  85. deleteType = 2;
  86. }
  87. break;
  88. case PageTypeFromTitleDraftBox:
  89. {
  90. deleteType = 3;
  91. }
  92. break;
  93. case PageTypeFromTitleDeleted:
  94. {
  95. deleteType = 4;
  96. }
  97. break;
  98. default:
  99. {
  100. deleteType = 5;
  101. }
  102. break;
  103. }
  104. [dict setObject:@(self.currentPage) forKey:@"Page"];
  105. [dict setObject:@"20" forKey:@"PerPage"];
  106. [dict setObject:@(deleteType) forKey:@"SearchType"];
  107. [dict setObject:searchKey forKey:@"Key"];
  108. [dict setObject:@(self.FolderId) forKey:@"FolderId"];
  109. WS(weakSelf);
  110. [[HttpManager sharedHttpManager] POSTUrl:Host(API_InterLetter) parameters:dict responseStyle:JOSN success:^(id _Nonnull responseObject) {
  111. NSLog(@"站内信返回数据%@",responseObject);
  112. InterLeterModel *listModel = [[InterLeterModel alloc] initWithDictionary:responseObject error:nil];
  113. [weakSelf.tableView.mj_header endRefreshing];
  114. [weakSelf.tableView.mj_footer endRefreshing];
  115. weakSelf.totalRecord = listModel.Total;
  116. [weakSelf.listArray addObjectsFromArray:listModel.Items];
  117. if (weakSelf.totalRecord == weakSelf.listArray.count) {
  118. [weakSelf.tableView.mj_footer resetNoMoreData];
  119. [weakSelf.tableView.mj_footer endRefreshingWithNoMoreData];
  120. }
  121. [weakSelf.tableView reloadData];
  122. } failure:^(NSError * _Nonnull error) {
  123. SHOWERROR([ZYCTool handerResultData:error]);
  124. [weakSelf.tableView.mj_header endRefreshing];
  125. [weakSelf.tableView.mj_footer endRefreshing];
  126. }];
  127. }
  128. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  129. {
  130. return self.listArray.count;
  131. }
  132. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  133. {
  134. return [ChatMsgNoticeCell configCell2Height];
  135. }
  136. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  137. {
  138. InterLeterSubModel *model = self.listArray[indexPath.row];
  139. switch (self.type) {
  140. case PageTypeFromTitleAll:{
  141. ChatMsgNoticeCell *cell = [ChatMsgNoticeCell configCell2:tableView indexPath:indexPath];
  142. cell.cell2UserImgView.image = [UIImage imageNamed:@"站内信图"];
  143. cell.cell2TitleLabel.attributedText = [ZYCTool checkOfString:model.Title withSearchText:self.searchText];
  144. [self setIntroLabelWithModel:model introLabel:cell.cell2IntroLabel unreadNumberLabel:cell.cell2UnReadNumberLbl];
  145. cell.cell2TimeLabel.text = [NSDate getTimeStringAutoShort2:model.CreatedDate];
  146. cell.IsTopImgV.hidden = !model.IsTop;
  147. cell.cell2RedBgView.hidden = model.IsRead;
  148. return cell;
  149. }
  150. break;
  151. case PageTypeFromTitleMy:
  152. {
  153. ChatMsgNoticeCell *cell = [ChatMsgNoticeCell configCell2:tableView indexPath:indexPath];
  154. cell.cell2UserImgView.image = [UIImage imageNamed:@"站内信图"];
  155. cell.cell2TitleLabel.attributedText = [ZYCTool checkOfString:model.Title withSearchText:self.searchText];
  156. [self setIntroLabelWithModel:model introLabel:cell.cell2IntroLabel unreadNumberLabel:cell.cell2UnReadNumberLbl];
  157. cell.cell2TimeLabel.text = [NSDate getTimeStringAutoShort2:model.CreatedDate];
  158. cell.cell2RedBgView.hidden = model.IsRead;
  159. return cell;
  160. }
  161. break;
  162. case PageTypeFromTitleDraftBox:
  163. {
  164. ChatMsgNoticeCell *cell = [ChatMsgNoticeCell configCell2:tableView indexPath:indexPath];
  165. cell.cell2UserImgView.image = [UIImage imageNamed:@"站内信图"];
  166. cell.cell2TitleLabel.attributedText = [ZYCTool checkOfString:model.Title withSearchText:self.searchText];
  167. cell.cell2UnReadNumberLbl.hidden = YES;
  168. if (model.MissiveType == 2) {
  169. cell.cell2IntroLabel.text = @"匿名";
  170. }else{
  171. if (model.EnjoyUser.length == 0) {
  172. cell.cell2IntroLabel.hidden = YES;
  173. }else{
  174. if (model.EnjoyUser.length > 13) {
  175. NSRange range1 = NSMakeRange(10, (model.EnjoyUser.length - 10));
  176. NSString *resultStr1 = [model.EnjoyUser stringByReplacingCharactersInRange:range1 withString:@"..."];
  177. cell.cell2IntroLabel.text = [NSString stringWithFormat:@"收件人:%@",resultStr1];
  178. }else{
  179. cell.cell2IntroLabel.text = [NSString stringWithFormat:@"收件人:%@",model.EnjoyUser];
  180. }
  181. }
  182. }
  183. cell.cell2EditBtn.hidden = NO;
  184. WS(weakSelf);
  185. [cell.cell2EditBtn setAction:^{
  186. NSLog(@"编辑草稿箱站内信");
  187. [weakSelf editorButtonHander:indexPath];
  188. }];
  189. cell.cell2RedBgView.hidden = model.IsRead;
  190. cell.cell2TimeLabel.hidden = YES;
  191. return cell;
  192. }
  193. break;
  194. case PageTypeFromTitleDeleted:
  195. {
  196. ChatMsgNoticeCell *cell = [ChatMsgNoticeCell configCell2:tableView indexPath:indexPath];
  197. cell.cell2UserImgView.image = [UIImage imageNamed:@"站内信图"];
  198. cell.cell2TitleLabel.attributedText = [ZYCTool checkOfString:model.Title withSearchText:self.searchText];
  199. [self setIntroLabelWithModel:model introLabel:cell.cell2IntroLabel unreadNumberLabel:cell.cell2UnReadNumberLbl];
  200. cell.cell2EditBtn.hidden = NO;
  201. cell.cell2RedBgView.hidden = YES;
  202. cell.cell2TimeLabel.hidden = YES;
  203. [cell.cell2EditBtn setTitle:@"恢复" forState:UIControlStateNormal];
  204. WS(weakSelf);
  205. [cell.cell2EditBtn setAction:^{
  206. NSLog(@"恢复已删除站内信");
  207. [weakSelf reDoDeleteFind:@[model].mutableCopy];
  208. }];
  209. return cell;
  210. }break;
  211. default:
  212. {
  213. ChatMsgNoticeCell *cell = [ChatMsgNoticeCell configCell2:tableView indexPath:indexPath];
  214. cell.cell2UserImgView.image = [UIImage imageNamed:@"站内信图"];
  215. cell.cell2TitleLabel.attributedText = [ZYCTool checkOfString:model.Title withSearchText:self.searchText];
  216. //cell.cell2IntroLabel.text = @"匿名";
  217. cell.IsTopImgV.hidden = !model.IsTop;
  218. [self setIntroLabelWithModel:model introLabel:cell.cell2IntroLabel unreadNumberLabel:cell.cell2UnReadNumberLbl];
  219. cell.cell2RedBgView.hidden = model.IsRead;
  220. return cell;
  221. }
  222. break;
  223. }
  224. }
  225. - (void)setIntroLabelWithModel:(InterLeterSubModel *)model introLabel:(UILabel *)introLabel unreadNumberLabel:(UILabel *)unreadNumberLabel {
  226. //判断是否匿名
  227. if (model.MissiveType == 2) {
  228. introLabel.text = @"匿名";
  229. unreadNumberLabel.text = nil;
  230. }else {
  231. if (model.IsAdmin == YES) {
  232. if (model.EnjoyUser.length > 10) {
  233. NSRange range1 = NSMakeRange(10, (model.EnjoyUser.length - 10));
  234. NSString *resultStr1 = [model.EnjoyUser stringByReplacingCharactersInRange:range1 withString:@"..."];
  235. introLabel.text = [NSString stringWithFormat:@"收件人:%@",resultStr1];
  236. }else{
  237. introLabel.text = [NSString stringWithFormat:@"收件人:%@",model.EnjoyUser];
  238. }
  239. }else {
  240. introLabel.text = model.SendName;
  241. }
  242. unreadNumberLabel.text = [NSString stringWithFormat:@"已读:%ld/%ld",(long)model.ReadCount,(long)model.AllCount];
  243. }
  244. }
  245. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  246. {
  247. InterLeterSubModel *model = self.listArray[indexPath.row];
  248. if (self.type == PageTypeFromTitleDraftBox) {
  249. [self editorButtonHander:indexPath];
  250. }else{
  251. MyTDTopicDetailVC *vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  252. vc.Id = model.MiddleId;
  253. vc.type = CollectModel_InterMail;
  254. [self.navigationController pushViewController:vc animated:YES];
  255. }
  256. }
  257. /// 恢复文件夹
  258. - (void)reDoDeleteFind:(NSMutableArray<InterLeterSubModel *>*)findModelArray{
  259. NSMutableArray *MiddleIds = [NSMutableArray array];
  260. for (InterLeterSubModel *model in findModelArray) {
  261. [MiddleIds addObject:@(model.Id)];
  262. }
  263. NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
  264. [dic setValue:MiddleIds forKey:@"MiddleIds"];
  265. [dic setValue:@(5) forKey:@"FolderType"];
  266. [dic setValue:@(0) forKey:@"IsDelete"];
  267. [dic setValue:@([AppUserModel sharedAppUserModel].Id) forKey:@"UserId"];
  268. SHOWLOADING
  269. WEAKSELF
  270. [[HttpManager sharedHttpManager] POSTUrl:Host(API_Find_DeleteRecord_Redo) parameters:dic responseStyle:DATA success:^(id _Nonnull responseObject) {
  271. STRONGSELF
  272. REMOVESHOW
  273. [strongSelf headRefresh];
  274. } failure:^(NSError * _Nonnull error) {
  275. SHOWERROR([ZYCTool handerResultData:error]);
  276. }];
  277. }
  278. - (void)editorButtonHander:(NSIndexPath *)indexPath{
  279. WS(weakSelf);
  280. InterLeterSubModel *model = self.listArray[indexPath.row];
  281. MyTDTopicCreateVC * vc = [MyTDTopicCreateVC initMyTDTopicCreateVC];
  282. vc.type = CollectModel_InterMail;
  283. vc.isEdit = YES;
  284. vc.Id = model.MiddleId;
  285. vc.upDateBlock = ^{
  286. [weakSelf headRefresh];
  287. };
  288. [self.navigationController pushViewController:vc animated:YES];
  289. }
  290. - (NSMutableArray *)listArray{
  291. if (!_listArray) {
  292. _listArray = [NSMutableArray new];
  293. }
  294. return _listArray;
  295. }
  296. @end