// // QXIntimateViewController.m // QXLive // // Created by 启星 on 2025/11/20. // #import "QXIntimateViewController.h" #import "QXIntimateCpCell.h" #import "QXIntimateListCell.h" #import "QXIntimateNoCpCell.h" #import "QXMineNetwork.h" #import "QXButton.h" #import "QXMoreIntimateViewController.h" #import "QXIntimateMoreListCell.h" #import "QXHeartBeatSpaceViewController.h" #import "QXUserHomePageViewController.h" @interface QXIntimateViewController () @property (nonatomic,strong)UITableView *tableView; @property (nonatomic,strong)QXRoomBestFriendModel *model; @end @implementation QXIntimateViewController - (void)viewDidLoad { self.isNoChangeBgImage = YES; [super viewDidLoad]; // Do any additional setup after loading the view. } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.navigationController setNavigationBarHidden:NO animated:YES]; } -(void)setNavgationItems{ [super setNavgationItems]; } - (void)initSubViews{ self.page = 1; [self updateBgImage:@"mine_intimate_bg"]; [self updateBackImage:[UIImage imageNamed:@"mine_intimate_back"]]; UIImageView *titleImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mine_intimate_title_img"]]; [self.view addSubview:titleImageView]; [titleImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.view); make.width.mas_equalTo(ScaleWidth(178)); make.height.mas_equalTo(ScaleWidth(68)); make.top.mas_equalTo(NavContentHeight); }]; [self.view addSubview:self.tableView]; } -(void)setUserId:(NSString *)userId{ _userId = userId; self.page = 1; [self getList]; } -(void)getList{ MJWeakSelf [QXMineNetwork userBestFriendsListWithUserId:self.userId page:self.page successBlock:^(QXRoomBestFriendModel * _Nonnull model) { weakSelf.model = model; if (weakSelf.page == 1) { [weakSelf.dataArray removeAllObjects]; } [weakSelf.dataArray addObjectsFromArray:model.no_cp]; [weakSelf.tableView reloadData]; if (model.no_cp.count == 0) { weakSelf.tableView.mj_footer.state = MJRefreshStateNoMoreData; }else{ [weakSelf.tableView.mj_footer endRefreshing]; } [weakSelf.tableView.mj_header endRefreshing]; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { }]; } -(void)moreAction:(QXButton*)btn{ QXRoomBestFriendListModel *md = btn.object; QXMoreIntimateViewController *vc = [[QXMoreIntimateViewController alloc] init]; vc.userId = self.userId; vc.relation_id = md.relation_list.firstObject.relation_id; vc.relation_name = md.relation_name; [self.navigationController pushViewController:vc animated:YES]; } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ if (self.model == nil) { return 0; }else{ return 1+self.dataArray.count; } } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 1; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.section == 0) { if (self.model.cp) { QXIntimateCpCell *cell = [QXIntimateCpCell cellWithTableView:tableView]; cell.userId = self.userId; cell.model = self.model.cp; cell.delegate = self; return cell; }else{ QXIntimateNoCpCell *cell = [QXIntimateNoCpCell cellWithTableView:tableView]; return cell; } }else{ QXRoomBestFriendListModel *md = self.dataArray[indexPath.section-1]; if (md.relation_list.count > 1) { QXIntimateListCell*cell = [QXIntimateListCell cellWithTableView:tableView]; cell.userId = self.userId; if (self.dataArray.count>0) { QXRoomBestFriendListModel *md = self.dataArray[indexPath.section-1]; cell.model = md; } return cell; }else{ MJWeakSelf QXIntimateMoreListCell *cell = [QXIntimateMoreListCell cellWithTableView:tableView]; cell.userId = self.userId; QXRoomBestFriendListModel *md = self.dataArray[indexPath.section-1]; cell.model = md.relation_list.firstObject; cell.delegate = self; cell.deleteSuccessBlock = ^(QXRelationshipListModel * _Nonnull model) { weakSelf.page = 1; [weakSelf getList]; }; return cell; } } } -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 50)]; UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mine_intimate_title_bg"]]; UILabel *titleLabel = [[UILabel alloc] init]; titleLabel.font = [UIFont boldSystemFontOfSize:16]; titleLabel.textColor = RGB16(0xffffff); QXButton *btn = [[QXButton alloc] init]; [btn setTitle:@"更多>>" forState:(UIControlStateNormal)]; [btn setTitleColor:RGB16(0xE973FC) forState:(UIControlStateNormal)]; btn.titleLabel.font = [UIFont systemFontOfSize:12]; [btn addTarget:self action:@selector(moreAction:) forControlEvents:(UIControlEventTouchUpInside)]; [header addSubview:btn]; [header addSubview:imageView]; [header addSubview:titleLabel]; [imageView mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(132); make.height.mas_equalTo(36); make.centerX.centerY.equalTo(header); }]; [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(header); make.centerY.equalTo(header).offset(2); }]; [btn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-23); make.top.bottom.equalTo(header); make.width.mas_equalTo(40); }]; if (section == 0) { titleLabel.text = @"心动"; btn.hidden = YES; }else{ QXRoomBestFriendListModel *md = self.dataArray[section-1]; titleLabel.text = md.relation_name; if (md.relation_list.count>1) { btn.hidden = NO; btn.object = md; }else{ btn.hidden = YES; } } return header; } -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 50; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.section == 0) { if (self.model.cp) { return ScaleWidth(100); }else{ return ScaleWidth(36); } }else{ QXRoomBestFriendListModel *md = self.dataArray[indexPath.section-1]; if (md.relation_list.count == 1) { return ScaleWidth(92)+18; }else{ if (md.relation_list.count == 0) { return 0; }else{ return ScaleWidth(125); } } } } -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{ UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 15)]; return footer; } -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ return 15; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ // if (indexPath.section == 0) { // if (self.model.cp) { // QXHeartBeatSpaceViewController *vc = [[QXHeartBeatSpaceViewController alloc] init]; // vc.userId = self.userId; // [self.navigationController pushViewController:vc animated:YES]; // } // } } -(void)didClickHeaderCardViewWithUserId:(NSString *)userId{ if (self.model.cp) { QXHeartBeatSpaceViewController *vc = [[QXHeartBeatSpaceViewController alloc] init]; vc.userId = self.userId; [self.navigationController pushViewController:vc animated:YES]; } } -(void)didClickHeaderViewUserId:(NSString *)userId{ QXUserHomePageViewController *vc = [[QXUserHomePageViewController alloc] init]; vc.user_id = userId; [self.navigationController pushViewController:vc animated:YES]; } - (void)didClickHeaderWithUserId:(NSString *)userId{ QXUserHomePageViewController *vc = [[QXUserHomePageViewController alloc] init]; vc.user_id = userId; [self.navigationController pushViewController:vc animated:YES]; } -(UITableView *)tableView{ if (!_tableView) { _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavContentHeight+ScaleWidth(68), SCREEN_WIDTH, SCREEN_HEIGHT -NavContentHeight-ScaleWidth(68)) style:(UITableViewStyleGrouped)]; _tableView.dataSource = self; _tableView.delegate = self; _tableView.backgroundColor = [UIColor clearColor]; _tableView.tableFooterView = [UIView new]; _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; if (@available(iOS 15.0, *)) { _tableView.sectionHeaderTopPadding = 0; } else { // Fallback on earlier versions } MJWeakSelf _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ weakSelf.page = 1; [weakSelf getList]; }]; _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{ weakSelf.page++; [weakSelf getList]; }]; } return _tableView; } @end