ReplayMeVC.m 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. //
  2. // ReplayMeVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/6/11.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "ReplayMeVC.h"
  9. #import "MyTDGroupView.h"
  10. #import "ReplayMeCell.h"
  11. #import "ShowBtn.h"
  12. #import "YCMenuView.h"
  13. #import "ReplayMeLikeVC.h"
  14. #import "ReplayMeSearchVC.h"
  15. #import "ReplyModel.h"
  16. @interface ReplayMeVC ()<UITableViewDelegate,UITableViewDataSource>
  17. @property (weak, nonatomic) IBOutlet UIView *navBar;
  18. @property (weak, nonatomic) IBOutlet UIView *HeadView;
  19. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  20. @property (strong, nonatomic) ShowBtn *titleBtn;
  21. @property (strong, nonatomic) MyTDGroupView *SearchView;
  22. @property (strong, nonatomic) NSMutableArray *taskActionArray;
  23. @property (strong, nonatomic) NSMutableArray *dataArray;
  24. @property (assign, nonatomic) BOOL replayMe;
  25. @property (assign, nonatomic) NSInteger PraiseCount;
  26. @end
  27. @implementation ReplayMeVC
  28. +(ReplayMeVC *)initReplayMeVC{
  29. ReplayMeVC *controller = [StoryboardManager.shared.Source instantiateViewControllerWithIdentifier:@"ReplayMeVC"];
  30. return controller;
  31. }
  32. - (ShowBtn *)titleBtn
  33. {
  34. if (!_titleBtn) {
  35. _titleBtn = [ShowBtn new];
  36. }
  37. return _titleBtn;
  38. }
  39. - (MyTDGroupView *)SearchView
  40. {
  41. if (!_SearchView) {
  42. _SearchView = [[MyTDGroupView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 36)];
  43. }
  44. return _SearchView;
  45. }
  46. - (void)autoSizeBtn:(NSString *)title
  47. {
  48. [self.titleBtn setLabelTitle:title];
  49. }
  50. - (void)viewWillAppear:(BOOL)animated
  51. {
  52. [super viewWillAppear:animated];
  53. [self getData];
  54. }
  55. - (void)getData
  56. {
  57. [self.dataArray removeAllObjects];
  58. NSDictionary * paraDict = @{@"KeyWord":@"",
  59. @"TypeValue":self.replayMe ? @(0) : @(1),
  60. };
  61. WS(weakSelf);
  62. SHOWLOADING
  63. [[HttpManager sharedHttpManager] POSTUrl:Host(API_APP_Reply_List) parameters:paraDict responseStyle:JOSN success:^(id _Nonnull responseObject) {
  64. REMOVESHOW
  65. if ([responseObject isKindOfClass:[NSDictionary class]]) {
  66. for (NSDictionary * dict in responseObject[@"Item"]) {
  67. ReplyModel * model = [ReplyModel modelWithDictionary:dict];
  68. [weakSelf.dataArray addObject:model];
  69. }
  70. weakSelf.PraiseCount = [responseObject[@"PraiseCount"] integerValue];
  71. }
  72. dispatch_async(dispatch_get_main_queue(), ^{
  73. [weakSelf.tableView reloadData];
  74. });
  75. } failure:^(NSError * _Nonnull error) {
  76. REMOVESHOW
  77. }];
  78. }
  79. - (void)viewDidLoad {
  80. [super viewDidLoad];
  81. self.fd_prefersNavigationBarHidden = YES;
  82. self.tableView.delegate = self;
  83. self.tableView.dataSource = self;
  84. [self.HeadView addSubview:self.SearchView];
  85. [self.SearchView mas_makeConstraints:^(MASConstraintMaker *make) {
  86. make.top.mas_offset(6);
  87. make.left.right.mas_equalTo(self.HeadView);
  88. make.height.mas_offset(36);
  89. }];
  90. WS(weakSelf);
  91. [self.SearchView.button setAction:^{
  92. ReplayMeSearchVC * vc = [[ReplayMeSearchVC alloc] init];
  93. vc.IsReplyMe = weakSelf.replayMe;
  94. [weakSelf.navigationController pushViewController:vc animated:YES];
  95. }];
  96. [self.navBar addSubview:self.titleBtn];
  97. [self.titleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  98. make.center.mas_equalTo(self.navBar);
  99. }];
  100. if (self.replayMe) {
  101. [self autoSizeBtn:@"我回复的"];
  102. }else{
  103. [self autoSizeBtn:@"回复我的"];
  104. }
  105. [self.titleBtn setAction:^{
  106. [weakSelf.titleBtn show];
  107. NSMutableArray *menuDataSourceArray = [weakSelf getMenuDataSource:weakSelf.taskActionArray];
  108. YCMenuView *view = [YCMenuView menuWithActions:menuDataSourceArray width:105 relyonView:weakSelf.titleBtn];
  109. view.menuColor = UIColorHex(0xFFFFFF);
  110. view.separatorColor = UIColorHex(0xEAEAEA);
  111. view.textColor = UIColorHex(0x666666);
  112. view.textFont = [UIFont systemFontOfSize:16.0];
  113. view.menuCellHeight = 45;
  114. view.maxDisplayCount = 10;
  115. view.offset = - 6;
  116. [view show];
  117. }];
  118. }
  119. -(NSMutableArray *)dataArray{
  120. if(!_dataArray){
  121. _dataArray = [NSMutableArray array];
  122. }
  123. return _dataArray;
  124. }
  125. -(NSMutableArray *)taskActionArray{
  126. if(!_taskActionArray){
  127. _taskActionArray = [[NSMutableArray alloc] initWithObjects:@"回复我的",@"我回复的", nil];
  128. }
  129. return _taskActionArray;
  130. }
  131. -(NSMutableArray *)getMenuDataSource:(NSMutableArray *)titleArray{
  132. NSMutableArray *menuDataSourceArray = [[NSMutableArray alloc] init];
  133. for(int i = 0;i < titleArray.count;i ++){
  134. NSString *titleStr = [titleArray objectAtIndex:i];
  135. WS(weakSelf);
  136. YCMenuAction *actionMenu = [YCMenuAction actionWithTitle:titleStr image:nil handler:^(YCMenuAction *action) {
  137. [weakSelf.titleBtn dismiss];
  138. [weakSelf autoSizeBtn:titleStr];
  139. if([@"回复我的" isEqualToString:action.title]){
  140. weakSelf.replayMe = NO;
  141. }else{
  142. weakSelf.replayMe = YES;
  143. }
  144. [weakSelf getData];
  145. }];
  146. [menuDataSourceArray addObject:actionMenu];
  147. }
  148. return menuDataSourceArray;
  149. }
  150. #pragma mark -UITableViewDelegate
  151. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  152. {
  153. return self.dataArray.count;
  154. }
  155. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  156. {
  157. if (!self.replayMe) {
  158. return 45.f;
  159. }else{
  160. return 0.01f;
  161. }
  162. }
  163. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  164. {
  165. return 0.01f;
  166. }
  167. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  168. {
  169. UIView * view = [UIView new];
  170. if (!self.replayMe) {
  171. UILabel * label = [UILabel new];
  172. label.font = Kfont(16);
  173. label.textColor = UIColorHex(0x0a0a0a);
  174. label.text = @"收到的赞";
  175. [view addSubview:label];
  176. [label mas_makeConstraints:^(MASConstraintMaker *make) {
  177. make.left.mas_offset(15);
  178. make.centerY.mas_equalTo(view);
  179. }];
  180. UIImageView * imgv = [UIImageView new];
  181. imgv.image = IMG(@"right_img");
  182. [view addSubview:imgv];
  183. [imgv mas_makeConstraints:^(MASConstraintMaker *make) {
  184. make.right.mas_offset(-15);
  185. make.centerY.mas_equalTo(view);
  186. }];
  187. UILabel * redL = [UILabel new];
  188. redL.font = Kfont(11);
  189. redL.textColor = UIColorHex(0xFFFFFF);
  190. redL.backgroundColor = [UIColor redColor];
  191. redL.hidden = self.PraiseCount == 0 ? YES : NO;
  192. redL.text = [NSString stringWithFormat:@"%ld",self.PraiseCount];
  193. redL.textAlignment = NSTextAlignmentCenter;
  194. [view addSubview:redL];
  195. [redL mas_makeConstraints:^(MASConstraintMaker *make) {
  196. make.right.mas_equalTo(imgv.mas_left).offset(-8);
  197. make.centerY.mas_equalTo(view);
  198. make.size.mas_offset(CGSizeMake(16, 16));
  199. }];
  200. redL.layer.cornerRadius = 8.f;
  201. redL.layer.masksToBounds = YES;
  202. UIView * lineV = [UIView new];
  203. lineV.backgroundColor = LINEBGCOLOR;
  204. [view addSubview:lineV];
  205. [lineV mas_makeConstraints:^(MASConstraintMaker *make) {
  206. make.left.bottom.right.mas_equalTo(view);
  207. make.height.mas_offset(0.5);
  208. }];
  209. WS(weakSelf);
  210. UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) {
  211. ReplayMeLikeVC * vc = [ReplayMeLikeVC initReplayMeLikeVC];
  212. [weakSelf.navigationController pushViewController:vc animated:YES];
  213. }];
  214. [view addGestureRecognizer:tap];
  215. }
  216. return view;
  217. }
  218. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  219. {
  220. return [UIView new];
  221. }
  222. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  223. {
  224. return UITableViewAutomaticDimension;
  225. }
  226. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  227. {
  228. ReplyModel * model = [self.dataArray objectAtIndex:indexPath.row];
  229. if (model.IsComment) {
  230. ReplayMeCell * cell = [ReplayMeCell configCell0:tableView indexPath:indexPath];
  231. cell.redV.hidden = model.IsRead;
  232. [cell setDataCommentModel:model];
  233. return cell;
  234. }else{
  235. ReplayMeCell * cell = [ReplayMeCell configCell1:tableView indexPath:indexPath];
  236. cell.redV.hidden = model.IsRead;
  237. [cell setDataModel:model];
  238. return cell;
  239. }
  240. }
  241. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  242. {
  243. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  244. ReplyModel * model = [self.dataArray objectAtIndex:indexPath.row];
  245. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  246. model.IsRead = YES;
  247. vc.type = model.TypeValue;
  248. vc.Id = model.SourceId;
  249. [self.navigationController pushViewController:vc animated:YES];
  250. }
  251. @end