// // QXExpansionViewController.m // QXLive // // Created by 启星 on 2025/5/27. // #import "QXExpansionViewController.h" #import "QXExpansionCell.h" #import "UIButton+QX.h" #import "QXMenuPopView.h" #import "QXDynamicNetwork.h" #import "QXUserHomePageViewController.h" #import "QXExpansionAppStoreView.h" @interface QXExpansionViewController () @property (strong, nonatomic) UILabel *titleLabel; @property (strong, nonatomic) UIButton *sortBtn; @property (strong, nonatomic) UITableView *tableView; @property (strong, nonatomic) NSString *type; @property (strong, nonatomic) QXExpansionAppStoreView *appStoreView; @end @implementation QXExpansionViewController -(UIView *)listView{ return self.view; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccess) name:noticeUserLogin object:nil]; } - (void)initSubViews{ self.page = 1; self.bgImageHidden = YES; self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, 12, 100, 24)]; self.titleLabel.font = [UIFont systemFontOfSize:16]; self.titleLabel.textColor = RGB16(0xffffff); self.titleLabel.text = QXText(@"扩列交友"); [self.view addSubview:self.titleLabel]; self.sortBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-75-13, 0, 75, 48)]; [self.sortBtn setImage:[[UIImage imageNamed:@"arrow_bottom"] imageByTintColor:RGB16(0xffffff)] forState:(UIControlStateNormal)]; if ([QXGlobal shareGlobal].loginModel.sex.integerValue == 1) { [self.sortBtn setTitle:QXText(@"只看女生") forState:(UIControlStateNormal)]; self.type = @"2"; }else{ [self.sortBtn setTitle:QXText(@"只看男生") forState:(UIControlStateNormal)]; self.type = @"1"; } [self.sortBtn setTitleColor:RGB16(0xffffff) forState:(UIControlStateNormal)]; self.sortBtn.titleLabel.font = [UIFont systemFontOfSize:12]; [self.sortBtn qx_layoutButtonNOSizeToFitWithEdgeInsetsStyle:(QXButtonEdgeInsetsStyleRight) imageTitleSpace:3]; [self.sortBtn addTarget:self action:@selector(sortAction) forControlEvents:(UIControlEventTouchUpInside)]; [self.view addSubview:self.sortBtn]; [self.view addSubview:self.tableView]; self.appStoreView.hidden = YES; [self.view addSubview:self.appStoreView]; MJWeakSelf self.appStoreView.userBlock = ^(QXUserHomeModel * _Nonnull user) { if (!QXGlobal.shareGlobal.isLogin) { [[QXGlobal shareGlobal] logOut]; return; } if (user == nil) { return; } QXUserHomePageViewController *vc = [[QXUserHomePageViewController alloc] init]; vc.user_id = user.user_id; [weakSelf.navigationController pushViewController:vc animated:YES]; }; } -(void)loginSuccess{ [self getData]; } - (void)getData{ MJWeakSelf [QXDynamicNetwork expansionListWithPage:self.page type:self.type successBlock:^(NSArray * _Nonnull list, BOOL isAppStore) { if (weakSelf.page == 1) { [weakSelf.dataArray removeAllObjects]; } if (isAppStore) { self.appStoreView.hidden = NO; [self.sortBtn setTitleColor:RGB16(0xFFEB9D) forState:(UIControlStateNormal)]; [self.sortBtn setImage:[[UIImage imageNamed:@"arrow_bottom"] imageByTintColor:RGB16(0xFFEB9D)] forState:(UIControlStateNormal)]; self.sortBtn.top = ScaleWidth(71); self.tableView.hidden = YES; self.appStoreView.users = list; self.titleLabel.hidden = YES; }else{ [self.sortBtn setTitleColor:RGB16(0xffffff) forState:(UIControlStateNormal)]; [self.sortBtn setImage:[[UIImage imageNamed:@"arrow_bottom"] imageByTintColor:RGB16(0xffffff)] forState:(UIControlStateNormal)]; self.sortBtn.top = 0; self.tableView.hidden = NO; self.appStoreView.hidden = YES; self.titleLabel.hidden = NO; } [weakSelf.dataArray addObjectsFromArray:list]; [weakSelf.tableView.mj_header endRefreshing]; if (list.count == 0) { weakSelf.tableView.mj_footer.state = MJRefreshStateNoMoreData; }else{ [weakSelf.tableView.mj_footer endRefreshing]; } [self.tableView reloadData]; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { [weakSelf.tableView.mj_header endRefreshing]; [weakSelf.tableView.mj_footer endRefreshing]; }]; } -(void)sortAction{ QXMenuPopView *menuView = [[QXMenuPopView alloc] initWithPoint:CGPointMake(self.sortBtn.centerX, NavContentHeight+self.sortBtn.bottom-10)]; menuView.dataArray = @[QXText(@"只看女生"),QXText(@"只看男生"),QXText(@"查看全部")]; menuView.delegate = self; [menuView showInView:KEYWINDOW]; } -(void)didSelectedIndex:(NSInteger)index menuTitle:(NSString *)menuTitle{ QXLOG(@"选择了%@",menuTitle); if ([menuTitle isEqualToString:QXText(@"只看女生")]) { self.page = 1; self.type = @"2"; [self getData]; }else if ([menuTitle isEqualToString:QXText(@"只看男生")]) { self.page = 1; self.type = @"1"; [self getData]; }else{ self.page = 1; self.type = @"0"; [self getData]; } [self.sortBtn setTitle:menuTitle forState:(UIControlStateNormal)]; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.dataArray.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ QXExpansionCell *cell = [tableView dequeueReusableCellWithIdentifier:@"QXExpansionCell" forIndexPath:indexPath]; cell.selectionStyle = NO; QXUserHomeModel *model = self.dataArray[indexPath.row]; cell.model = model; return cell; } -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{ QXExpansionCell *eCell = (QXExpansionCell *)cell; [eCell nameStartAnimate]; } -(void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{ QXExpansionCell *eCell = (QXExpansionCell *)cell; [eCell nameStopAnimate]; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ QXUserHomeModel *model = self.dataArray[indexPath.row]; NSArray *imgArr; if (model.home_bgimages.length > 0) { imgArr = [model.home_bgimages componentsSeparatedByString:@","]; } // NSArray * CGFloat itemH = 94; if (imgArr.count == 1) { itemH = (SCREEN_WIDTH-15-15-15)/2 + 94+10; }else if(imgArr.count > 1){ if (imgArr.count > 3) { itemH = (SCREEN_WIDTH-16*2-12*2-10*2)/3*2+10+94+ScaleWidth(10); }else{ itemH = (SCREEN_WIDTH-16*2-12*2-10*2)/3+94+ScaleWidth(10); } }else{ itemH = 94; } return itemH; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ QXUserHomeModel *model = self.dataArray[indexPath.row]; QXUserHomePageViewController *vc = [[QXUserHomePageViewController alloc] init]; vc.user_id = model.user_id; [self.navigationController pushViewController:vc animated:YES]; } -(UITableView *)tableView{ if (!_tableView) { self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.titleLabel.bottom+12, SCREEN_WIDTH, self.view.height-TabbarContentHeight-self.titleLabel.bottom-12) style:UITableViewStylePlain]; self.tableView.backgroundColor = [UIColor clearColor]; self.tableView.delegate = self; self.tableView.dataSource = self; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; [self.tableView registerNib:[UINib nibWithNibName:@"QXExpansionCell" bundle:nil] forCellReuseIdentifier:@"QXExpansionCell"]; self.tableView.estimatedRowHeight = 94; MJWeakSelf _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ weakSelf.page = 1; [weakSelf getData]; }]; _tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{ weakSelf.page++; [weakSelf getData]; }]; self.tableView.hidden = NO; } return _tableView; } -(QXExpansionAppStoreView *)appStoreView{ if (!_appStoreView) { _appStoreView = [[QXExpansionAppStoreView alloc] initWithFrame:self.tableView.bounds]; } return _appStoreView; } @end