Files
yuyin_ios/SweetParty/主类/Homepage/Controller/SPHomepageVC.m
2025-08-08 11:05:33 +08:00

325 lines
11 KiB
Objective-C
Executable File

//
// SPHomepageVC.m
// SweetParty
//
// Created by bj_szd on 2022/6/2.
//
#import "SPHomepageVC.h"
#import "SPHomepageHeader.h"
#import "SPHomepageInfoView.h"
#import "SPHomepageGiftView.h"
#import "SPTrendListCell.h"
#import "SPTrendDetailVC.h"
#import "SPHomepagePhotoView.h"
#import "YYHomepageGiftVC.h"
@interface SPHomepageVC ()
@property (nonatomic, strong) SPHomepageHeader *headerView;
@property (nonatomic, strong) SPHomepageInfoView *infoView;
//@property (nonatomic, strong) SPHomepageGiftView *giftView;
@property (nonatomic, strong) SPHomepagePhotoView *photoView;
@property (nonatomic, strong) UIButton *blackBtn;
@property (nonatomic, strong) UIButton *focusBtn;
@property (nonatomic, strong) UIButton *msgBtn;
@property (nonatomic, assign) NSInteger currentIndex;
@property (nonatomic, strong) SPHomepageModel *model;
@end
@implementation SPHomepageVC
- (void)viewDidLoad {
[super viewDidLoad];
[self showNaviBarWithTitle:@""];
[self onChangeNaviWhiteStyle];
[self.naviView.backBtn setImage:ImageNamed(@"whiteBack") forState:UIControlStateNormal];
self.naviView.hidden = YES;
[self createUI];
[self fetchHomepageData];
[self fetchData];
}
- (void)fetchHomepageData {
NSDictionary *params = @{@"from_id":C_string(self.userId)};
[[AFNetworkRequset shared] postRequestWithParams:params Path:@"api/player/player_home_page" Loading:NO Hud:NO Success:^(id _Nonnull responseDic) {
SPHomepageModel *model = [SPHomepageModel mj_objectWithKeyValues:responseDic[@"data"]];
self.model = model;
self.focusBtn.selected = model.is_follow == 2;
self.blackBtn.selected = model.is_black == 1;
self.headerView.model = model;
CGFloat headerH = 420;
if ([model.user_room_visitor.rid integerValue] > 0) {
headerH = 480;
}else{
headerH = 420;
}
self.headerView.frame = CGRectMake(0, 0, ScreenWidth, headerH);
self.tableView.tableHeaderView = self.headerView;
// self.giftView.model = model;
// CGFloat itemH = 125;
// NSInteger lines = model.receive_gift_list.count%3 == 0 ? model.receive_gift_list.count/3 : model.receive_gift_list.count/3+1;
// self.giftView.frame = CGRectMake(0, 0, ScreenWidth, itemH*lines+20);
[self onChangeIndex];
} Failure:^(id _Nonnull errorData) {
}];
}
- (void)fetchData {
NSDictionary *params = @{@"from_id":C_string(self.userId), @"page":@(self.page), @"page_limit":@(10)};
[AFNetworkRequset.shared postRequestWithParams:params Path:@"api/user_zone/get_user_zone_list" Loading:YES Hud:NO Success:^(id _Nonnull responseDic) {
if (self.page == 1) {
[self.dataArray removeAllObjects];
[self.tableView reloadData];
}
[self endRefresh];
NSArray *arr = [SPTrendListModel mj_objectArrayWithKeyValuesArray:responseDic[@"data"]];
[self.dataArray addObjectsFromArray:arr];
[self.tableView reloadData];
if (arr.count > 0) {
[self endFooterRefreshWithMore];
}else {
[self endFooterRefreshWithNoMore];
}
//
// if (self.dataArray.count <= 0) {
// [self showNoContentView];
// } else {
// [self hideNoContentView];
// }
} Failure:^(id _Nonnull errorData) {
}];
}
- (void)refreshFetchData {
self.page = 1;
[self fetchData];
}
- (void)fetchMoreData {
self.page ++;
[self fetchData];
}
-(void)createUI {
[self.tableView registerNib:[UINib nibWithNibName:@"SPTrendListCell" bundle:nil] forCellReuseIdentifier:@"SPTrendListCell"];
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 152;
self.tableView.backgroundColor = kClearColor;
self.view.backgroundColor = kWhiteColor;
UIImageView *bgImgV = [[UIImageView alloc] initWithImage:ImageNamed(@"home_bg")];
[self.view addSubview:bgImgV];
[self.view sendSubviewToBack:bgImgV];
[bgImgV mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.equalTo(self.view);
make.height.mas_equalTo(ScreenWidth/375*812);
}];
BOOL isSelf = NO;
if ([self.userId integerValue] == [BJUserManager.userInfo.uid integerValue]) {
isSelf = YES;
}
CGFloat tabBottomCon = isSelf ? SAFE_AREA_INSERTS_BOTTOM : (79+SAFE_AREA_INSERTS_BOTTOM);
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.equalTo(self.view);
make.bottom.equalTo(self.view).offset(-tabBottomCon);
}];
UIButton *msgBtn = [ControlCreator createButton:nil rect:CGRectZero text:@"" font:YBBoldFont(14) color:HEXCOLOR(0x333333) backguoundColor:nil imageName:@"homepage_chat" target:self action:@selector(onMsg)];
// msgBtn.layer.masksToBounds = YES;
// msgBtn.layer.cornerRadius = 20;
// [msgBtn setJianBianWithCGSize:CGSizeMake(150, 49)];
[self.view addSubview:msgBtn];
self.msgBtn = msgBtn;
UIButton *focusBtn = [ControlCreator createButton:nil rect:CGRectZero text:@"" font:YBBoldFont(14) color:mainDeepColor backguoundColor:nil imageName:@"homepage_focus_nor" target:self action:@selector(onFocus)];
[focusBtn setImage:ImageNamed(@"homepage_focus_sel") forState:UIControlStateSelected];
// [focusBtn setTitle:@"已关注" forState:UIControlStateSelected];
// focusBtn.layer.masksToBounds = YES;
// focusBtn.layer.cornerRadius = 20;
// focusBtn.layer.borderWidth = 1;
// focusBtn.layer.borderColor = mainDeepColor.CGColor;
[self.view addSubview:focusBtn];
self.focusBtn = focusBtn;
[focusBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.view).offset(15);
make.bottom.equalTo(self.view).offset(-SAFE_AREA_INSERTS_BOTTOM);
make.size.mas_equalTo(CGSizeMake(135, 44));
}];
[msgBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.view).offset(-15);
make.centerY.equalTo(focusBtn);
make.size.mas_equalTo(CGSizeMake(195, 44));
}];
msgBtn.hidden = focusBtn.hidden = isSelf;
self.blackBtn = [ControlCreator createButton:self.view rect:CGRectMake(ScreenWidth-50-12, 60, 50, 30) text:@"加入黑名单" font:YBMediumFont(12) color:kWhiteColor backguoundColor:nil imageName:nil target:self action:@selector(onBlack)];
[self.blackBtn setTitle:@"移除黑名单" forState:UIControlStateSelected];
self.blackBtn.hidden = isSelf;
// WEAK_SELF
// [[RCCoreClient sharedCoreClient] getBlacklistStatus:C_string(self.userId) success:^(int bizStatus) {
// //bizStatus 0表示已经在黑名单中
// RCMicMainThread(^{
// if (isSelf) {
// weakSelf.blackBtn.hidden = YES;
// }else {
// weakSelf.blackBtn.hidden = bizStatus == 0;
// }
// });
// } error:^(RCErrorCode status) {
//
// }];
}
- (void)onBlack {
NSString *urlStr = self.model.is_black == 1 ? @"/api/user_tencent/remove_blacklist" : @"/api/user_tencent/add_blacklist";
NSDictionary *params = @{@"user_id":minStr(self.userId)};
[[AFNetworkRequset shared] postRequestWithParams:params Path:urlStr Loading:YES Hud:YES Success:^(id _Nonnull responseDic) {
if (self.model.is_black == 1) {
self.model.is_black = 2;
self.blackBtn.selected = NO;
}else {
self.model.is_black = 1;
self.blackBtn.selected = YES;
}
} Failure:^(id _Nonnull errorData) {
}];
}
- (void)onMsg {
TXSingleChatVC *vc = [[TXSingleChatVC alloc] init];
vc.userId = self.userId;
vc.titleStr = self.model.nick_name;
[self.navigationController pushViewController:vc animated:YES];
}
- (void)onFocus {
NSDictionary *params = @{@"follow_uid":self.userId};
NSString *urlStr = self.model.is_follow == 2 ? @"api/user/unfollow_user" : @"api/user/follow_user";
[[AFNetworkRequset shared] postRequestWithParams:params Path:urlStr Loading:YES Hud:YES Success:^(id _Nonnull responseDic) {
self.model.is_follow = self.model.is_follow == 2 ? 1 : 2;
self.focusBtn.selected = self.model.is_follow == 2;
} Failure:^(id _Nonnull errorData) {
}];
}
- (void)onChangeIndex {
if (self.currentIndex == 0) {
self.infoView.model = self.model;
self.tableView.tableFooterView = self.infoView;
}else if (self.currentIndex == 1) {
self.tableView.tableFooterView = nil;
}else if (self.currentIndex == 2) {
// self.giftView.model = self.model;
// self.tableView.tableFooterView = self.giftView;
YYHomepageGiftVC *giftvc = [[YYHomepageGiftVC alloc] init];
[self addChildViewController:giftvc];
// self.photoView.model = self.model;
// self.tableView.tableFooterView = self.photoView;
giftvc.model = self.model;
giftvc.view.frame = CGRectMake(0, 0, APPW, 600);
self.tableView.tableFooterView = giftvc.view;
}
[self.tableView reloadData];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.currentIndex == 1 ? self.dataArray.count : 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
SPTrendListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SPTrendListCell" forIndexPath:indexPath];
cell.selectionStyle = NO;
SPTrendListModel *model = self.dataArray[indexPath.row];
cell.model = model;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
SPTrendListModel *model = self.dataArray[indexPath.row];
SPTrendDetailVC *vc = [[SPTrendDetailVC alloc] init];
vc.zid = model.zid;
WEAK_SELF
vc.onDeleteBlock = ^(NSString * _Nonnull zid) {
[weakSelf.dataArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
SPTrendListModel *topicObj = obj;
if ([topicObj.zid isEqualToString:zid]) {
[weakSelf.dataArray removeObject:topicObj];
}
}];
[weakSelf.tableView reloadData];
};
[self.navigationController pushViewController:vc animated:YES];
}
- (SPHomepageHeader *)headerView {
if (!_headerView) {
_headerView = [[NSBundle mainBundle] loadNibNamed:@"SPHomepageHeader" owner:self options:nil].firstObject;
WEAK_SELF
_headerView.onSelectIndexBlock = ^(NSInteger index) {
weakSelf.currentIndex = index;
[weakSelf onChangeIndex];
};
}
return _headerView;
}
- (SPHomepageInfoView *)infoView {
if (!_infoView) {
_infoView = [[NSBundle mainBundle] loadNibNamed:@"SPHomepageInfoView" owner:self options:nil].firstObject;
_infoView.frame = CGRectMake(0, 0, ScreenWidth, 700);
}
return _infoView;
}
//- (SPHomepageGiftView *)giftView {
// if (!_giftView) {
// _giftView = [[SPHomepageGiftView alloc] initWithFrame:CGRectZero];
// }
// return _giftView;
//}
- (SPHomepagePhotoView *)photoView {
if (!_photoView) {
CGFloat itemH = (ScreenWidth-20*2-12*2)/2 + 12;
_photoView = [[SPHomepagePhotoView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, itemH*3)];
}
return _photoView;
}
@end