YXMessageDetailViewController.m 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. //
  2. // YXMessageDetailViewController.m
  3. // Temperature
  4. //
  5. // Created by TC on 2025/3/25.
  6. //
  7. #import "YXMessageDetailViewController.h"
  8. #import "YXMsgDetailTableViewCell.h"
  9. #import "YXMsgListModel.h"
  10. #import "RDSControlWebVC.h"
  11. #import "RDSRootControl.h"
  12. @interface YXMessageDetailViewController ()<UITableViewDataSource,UITableViewDelegate>
  13. @property (weak, nonatomic) UITableView *tableView;
  14. @property (strong, nonatomic) NSMutableArray *dataArray;
  15. @property (strong, nonatomic) UILabel *emptyLabel;
  16. @end
  17. @implementation YXMessageDetailViewController
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. self.view.backgroundColor = [UIColor colorWithHexString:@"#F9F9F9"];
  21. if ([self.type isEqualToString:@"1"]) {
  22. self.navigationItem.title = @"系统消息";
  23. } else if ([self.type isEqualToString:@"2"]){
  24. self.navigationItem.title = @"设备消息";
  25. } else if ([self.type isEqualToString:@"3"]){
  26. self.navigationItem.title = @"活动消息";
  27. }
  28. self.dataArray = [[NSMutableArray alloc]initWithCapacity:5];
  29. [self addRightItem];
  30. [self createTableView];
  31. [self p_getDetailList];
  32. }
  33. -(void)p_getDetailList
  34. {
  35. RDS_WEAKSELF(weakSelf)
  36. [RDSDemoApiHelper rds_getMessageListWithType:self.type Success:^(id responseObject) {
  37. if ([responseObject[@"code"] intValue] == 9999) {
  38. [RDSRootControl shareControl].isLoginSuccess = NO;
  39. TheDataManager.token = @"";
  40. }
  41. if ([responseObject[@"code"] intValue] == 0) {
  42. NSDictionary *dataDic = responseObject[@"data"];
  43. NSArray *listArray = dataDic[@"list"];
  44. weakSelf.dataArray = [YXMsgListModel mj_objectArrayWithKeyValuesArray:listArray];
  45. [weakSelf.tableView reloadData];
  46. if (weakSelf.dataArray.count == 0) {
  47. weakSelf.emptyLabel.hidden = NO;
  48. }else{
  49. weakSelf.emptyLabel.hidden = YES;
  50. }
  51. } else{
  52. [RDSHudShower showBottomToast:responseObject[@"message"]];
  53. }
  54. } failure:^(NSError *error) {
  55. }];
  56. }
  57. -(void)addRightItem
  58. {
  59. UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  60. [rightBtn setTitle:@"全部已读" forState:UIControlStateNormal];
  61. [rightBtn addTarget:self action:@selector(rightBtnAction:) forControlEvents:UIControlEventTouchUpInside];
  62. [rightBtn setTitleColor:[UIColor colorWithHexString:@"#267AFF"] forState:UIControlStateNormal];
  63. rightBtn.titleLabel.font = [UIFont systemFontOfSize:16];
  64. UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];
  65. self.navigationItem.rightBarButtonItem = rightItem;
  66. }
  67. -(void)rightBtnAction:(UIButton *)btn
  68. {
  69. RDS_WEAKSELF(weakSelf)
  70. [RDSDemoApiHelper rds_readAllMessageWithType:self.type success:^(id responseObject) {
  71. if ([responseObject[@"code"] intValue] == 9999) {
  72. [RDSRootControl shareControl].isLoginSuccess = NO;
  73. TheDataManager.token = @"";
  74. }
  75. if ([responseObject[@"code"] intValue] == 0) {
  76. [weakSelf p_getDetailList];
  77. } else{
  78. [RDSHudShower showBottomToast:responseObject[@"message"]];
  79. }
  80. } failure:^(NSError *error) {
  81. }];
  82. }
  83. -(UILabel *)emptyLabel
  84. {
  85. if (_emptyLabel == nil) {
  86. _emptyLabel = [[UILabel alloc]init];
  87. _emptyLabel.text = @"暂无数据";
  88. _emptyLabel.font = [UIFont systemFontOfSize:20];
  89. _emptyLabel.textColor = [UIColor colorWithHexString:@"333333"];
  90. _emptyLabel.textAlignment = NSTextAlignmentCenter;
  91. _emptyLabel.hidden = YES;
  92. [self.view addSubview:_emptyLabel];
  93. [_emptyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  94. make.width.equalTo(@200);
  95. make.centerX.equalTo(@0);
  96. make.height.equalTo(@50);
  97. make.centerY.equalTo(@-30);
  98. }];
  99. }
  100. return _emptyLabel;
  101. }
  102. -(void)createTableView
  103. {
  104. UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - kNavHeight - kTabbarHeight) style:UITableViewStyleGrouped];
  105. tableView.delegate = self;
  106. tableView.dataSource = self;
  107. tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  108. [tableView registerNib:[UINib nibWithNibName:@"YXMsgDetailTableViewCell" bundle:nil] forCellReuseIdentifier:@"msgDetailCellID"];
  109. tableView.backgroundColor = [UIColor colorWithHexString:@"#F9F9F9"];
  110. [self.view addSubview:tableView];
  111. self.tableView = tableView;
  112. }
  113. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  114. {
  115. return 1;
  116. }
  117. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  118. {
  119. return self.dataArray.count;
  120. }
  121. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  122. {
  123. YXMsgDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"msgDetailCellID" forIndexPath:indexPath];
  124. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  125. YXMsgListModel *model = self.dataArray[indexPath.row];
  126. cell.titleLabel.text = model.title;
  127. cell.detailLabel.text = model.content;
  128. cell.timeLabel.text = model.created_at;
  129. if ([model.status integerValue] == 1) {
  130. cell.colorView.hidden = NO;
  131. }else{
  132. cell.colorView.hidden = YES;
  133. }
  134. return cell;
  135. }
  136. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  137. {
  138. YXMsgListModel *model = self.dataArray[indexPath.row];
  139. RDSControlWebVC *webVc = [[RDSControlWebVC alloc]init];
  140. webVc.requestURL = model.detail_url;
  141. [self.navigationController pushViewController:webVc animated:YES];
  142. }
  143. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  144. {
  145. UIView *headerView = [[UIView alloc]init];
  146. return headerView;
  147. }
  148. -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  149. {
  150. UIView *footerView = [[UIView alloc]init];
  151. return footerView;
  152. }
  153. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  154. {
  155. return 10;
  156. }
  157. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  158. {
  159. return 0.01;
  160. }
  161. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  162. {
  163. return 85;
  164. }
  165. /*
  166. #pragma mark - Navigation
  167. // In a storyboard-based application, you will often want to do a little preparation before navigation
  168. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  169. // Get the new view controller using [segue destinationViewController].
  170. // Pass the selected object to the new view controller.
  171. }
  172. */
  173. @end