// // YXMessageDetailViewController.m // Temperature // // Created by TC on 2025/3/25. // #import "YXMessageDetailViewController.h" #import "YXMsgDetailTableViewCell.h" #import "YXMsgListModel.h" #import "RDSControlWebVC.h" #import "RDSRootControl.h" @interface YXMessageDetailViewController () @property (weak, nonatomic) UITableView *tableView; @property (strong, nonatomic) NSMutableArray *dataArray; @property (strong, nonatomic) UILabel *emptyLabel; @end @implementation YXMessageDetailViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor colorWithHexString:@"#F9F9F9"]; if ([self.type isEqualToString:@"1"]) { self.navigationItem.title = @"系统消息"; } else if ([self.type isEqualToString:@"2"]){ self.navigationItem.title = @"设备消息"; } else if ([self.type isEqualToString:@"3"]){ self.navigationItem.title = @"活动消息"; } self.dataArray = [[NSMutableArray alloc]initWithCapacity:5]; [self addRightItem]; [self createTableView]; [self p_getDetailList]; } -(void)p_getDetailList { RDS_WEAKSELF(weakSelf) [RDSDemoApiHelper rds_getMessageListWithType:self.type Success:^(id responseObject) { if ([responseObject[@"code"] intValue] == 9999) { [RDSRootControl shareControl].isLoginSuccess = NO; TheDataManager.token = @""; } if ([responseObject[@"code"] intValue] == 0) { NSDictionary *dataDic = responseObject[@"data"]; NSArray *listArray = dataDic[@"list"]; weakSelf.dataArray = [YXMsgListModel mj_objectArrayWithKeyValuesArray:listArray]; [weakSelf.tableView reloadData]; if (weakSelf.dataArray.count == 0) { weakSelf.emptyLabel.hidden = NO; }else{ weakSelf.emptyLabel.hidden = YES; } } else{ [RDSHudShower showBottomToast:responseObject[@"message"]]; } } failure:^(NSError *error) { }]; } -(void)addRightItem { UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [rightBtn setTitle:@"全部已读" forState:UIControlStateNormal]; [rightBtn addTarget:self action:@selector(rightBtnAction:) forControlEvents:UIControlEventTouchUpInside]; [rightBtn setTitleColor:[UIColor colorWithHexString:@"#267AFF"] forState:UIControlStateNormal]; rightBtn.titleLabel.font = [UIFont systemFontOfSize:16]; UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:rightBtn]; self.navigationItem.rightBarButtonItem = rightItem; } -(void)rightBtnAction:(UIButton *)btn { RDS_WEAKSELF(weakSelf) [RDSDemoApiHelper rds_readAllMessageWithType:self.type success:^(id responseObject) { if ([responseObject[@"code"] intValue] == 9999) { [RDSRootControl shareControl].isLoginSuccess = NO; TheDataManager.token = @""; } if ([responseObject[@"code"] intValue] == 0) { [weakSelf p_getDetailList]; } else{ [RDSHudShower showBottomToast:responseObject[@"message"]]; } } failure:^(NSError *error) { }]; } -(UILabel *)emptyLabel { if (_emptyLabel == nil) { _emptyLabel = [[UILabel alloc]init]; _emptyLabel.text = @"暂无数据"; _emptyLabel.font = [UIFont systemFontOfSize:20]; _emptyLabel.textColor = [UIColor colorWithHexString:@"333333"]; _emptyLabel.textAlignment = NSTextAlignmentCenter; _emptyLabel.hidden = YES; [self.view addSubview:_emptyLabel]; [_emptyLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.width.equalTo(@200); make.centerX.equalTo(@0); make.height.equalTo(@50); make.centerY.equalTo(@-30); }]; } return _emptyLabel; } -(void)createTableView { UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - kNavHeight - kTabbarHeight) style:UITableViewStyleGrouped]; tableView.delegate = self; tableView.dataSource = self; tableView.separatorStyle = UITableViewCellSeparatorStyleNone; [tableView registerNib:[UINib nibWithNibName:@"YXMsgDetailTableViewCell" bundle:nil] forCellReuseIdentifier:@"msgDetailCellID"]; tableView.backgroundColor = [UIColor colorWithHexString:@"#F9F9F9"]; [self.view addSubview:tableView]; self.tableView = tableView; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.dataArray.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { YXMsgDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"msgDetailCellID" forIndexPath:indexPath]; cell.selectionStyle = UITableViewCellSelectionStyleNone; YXMsgListModel *model = self.dataArray[indexPath.row]; cell.titleLabel.text = model.title; cell.detailLabel.text = model.content; cell.timeLabel.text = model.created_at; if ([model.status integerValue] == 1) { cell.colorView.hidden = NO; }else{ cell.colorView.hidden = YES; } return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { YXMsgListModel *model = self.dataArray[indexPath.row]; RDSControlWebVC *webVc = [[RDSControlWebVC alloc]init]; webVc.requestURL = model.detail_url; [self.navigationController pushViewController:webVc animated:YES]; } -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *headerView = [[UIView alloc]init]; return headerView; } -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { UIView *footerView = [[UIView alloc]init]; return footerView; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 10; } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 0.01; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 85; } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end