// // QXSystemNoticeViewController.m // QXLive // // Created by 启星 on 2025/5/28. // #import "QXSystemNoticeViewController.h" #import "QXSystemNoticeCell.h" #import "QXSystemMessageCell.h" #import "QXSystemMessageHandleCell.h" #import "QXMessageServices.h" #import "AppDelegate.h" @interface QXSystemNoticeViewController () @property (nonatomic,strong)UITableView *tableView; @property (nonatomic,assign)CGFloat rowHeight; @end @implementation QXSystemNoticeViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.navigationController setNavigationBarHidden:NO animated:YES]; } -(void)setNavgationItems{ [super setNavgationItems]; if (self.type == 0) { self.navigationItem.title = QXText(@"官方公告"); }else{ self.navigationItem.title = QXText(@"系统消息"); } } - (void)initSubViews{ self.page = 1; if (self.type == 0) { self.rowHeight = 280; }else{ self.rowHeight = 91; } [self.view addSubview:self.tableView]; [self getMessageList]; } -(void)getMessageList{ MJWeakSelf [QXMessageServices getMessageListWithPage:self.page type:self.type == 0?@"2":@"1" successBlock:^(NSArray * _Nonnull list) { if (weakSelf.page == 1) { [weakSelf.dataArray removeAllObjects]; } [weakSelf.dataArray addObjectsFromArray:list]; [weakSelf.tableView reloadData]; if (list.count == 0) { weakSelf.tableView.mj_footer.state = MJRefreshStateNoMoreData; }else{ [weakSelf.tableView.mj_footer endRefreshing]; } [weakSelf.tableView.mj_header endRefreshing]; AppDelegate *appdelegate = (AppDelegate*)[UIApplication sharedApplication].delegate; appdelegate.tabbarVC.systemUnreadNumber = 0; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { [weakSelf.tableView.mj_header endRefreshing]; [weakSelf.tableView.mj_footer endRefreshing]; }]; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.dataArray.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ if (self.type == 0) { QXSystemNoticeCell *cell = [QXSystemNoticeCell cellWithTableView:tableView]; cell.model = self.dataArray[indexPath.row]; return cell; }else{ QXMessageListModel *model = self.dataArray[indexPath.row]; if (model.type.intValue == 6) { QXSystemMessageHandleCell *cell = [QXSystemMessageHandleCell cellWithTableView:tableView]; cell.model = model; cell.delegate = self; return cell; }else{ QXSystemMessageCell *cell = [QXSystemMessageCell cellWithTableView:tableView]; cell.model = model; return cell; } } } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ QXMessageListModel *model = self.dataArray[indexPath.row]; if (model.room_id.integerValue > 0) { [[QXGlobal shareGlobal] joinRoomWithRoomId:model.room_id isRejoin:NO navagationController:self.navigationController]; }else{ if ([model.url hasPrefix:@"http"] || [model.url hasPrefix:@"https"]) { QXBaseWebViewController *vc = [[QXBaseWebViewController alloc] init]; vc.urlStr = model.url; [self.navigationController pushViewController:vc animated:YES]; } } } -(void)handleInviteIsAgree:(BOOL)isAgree message:(nonnull QXMessageListModel *)message{ MJWeakSelf [QXMessageServices guildInviteApplyHandleWithApplyId:message.id type:isAgree?@"1":@"2" successBlock:^(NSDictionary * _Nonnull dict) { showToast(@"操作成功"); weakSelf.page = 1; [weakSelf getMessageList]; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { showToast(msg); }]; } -(UITableView *)tableView{ if (!_tableView) { _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavContentHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavContentHeight) style:(UITableViewStylePlain)]; _tableView.dataSource = self; _tableView.delegate = self; _tableView.backgroundColor = [UIColor clearColor]; _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; _tableView.rowHeight = UITableViewAutomaticDimension; _tableView.estimatedRowHeight = self.rowHeight; MJWeakSelf _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ weakSelf.page = 1; [weakSelf getMessageList]; }]; _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{ weakSelf.page++; [weakSelf getMessageList]; }]; } return _tableView; } @end