// // LMWeekStarViewController.m // SweetParty // // Created by Xmac on 2024/8/6. // #import "LMWeekStarViewController.h" #import "LMWeekLastCollectionViewCell.h" #import "LMWeekListTableViewCell.h" #import "LMWeekListHeaderView.h" @interface LMWeekStarViewController () @property (weak, nonatomic) IBOutlet UITableView *currentTableView; @property (weak, nonatomic) IBOutlet UICollectionView *lastWeekTopItemView; @property (nonatomic, strong) LMWeekListHeaderView *headerView; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *topLayout; @property (nonatomic, strong) NSMutableArray *lastWeekDataArr; @property (nonatomic, strong) NSMutableArray *currentListDataArr; @property (weak, nonatomic) IBOutlet UILabel *meInfoisRank; @property (weak, nonatomic) IBOutlet UIImageView *meInfoHeaderPic; @property (weak, nonatomic) IBOutlet UILabel *meInfoNicknameLabel; @property (weak, nonatomic) IBOutlet UILabel *meInfoDeffNumLabel; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *heightConstraint; @end @implementation LMWeekStarViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. self.navTitle = @"周星榜"; [self.customNavBar styleClear]; self.customNavBar.titleLab.textColor = kWhiteColor; [self.customNavBar.left0Btn setImage:ImageNamed(@"whiteBack") forState:(UIControlStateNormal)]; self.view.backgroundColor = HEXCOLOR(0x390780); UIButton *btn = [UIButton buttonWithType:(UIButtonTypeCustom)]; [btn setImage:ImageNamed(@"week_home_yiwen") forState:(UIControlStateNormal)]; [self.customNavBar addSubview:btn]; [btn buttonAddTaget:^(UIButton *btn) { [UIViewController goWebWithUrl:[VERSION_HTTPS_SERVER stringByAppendingString:@"index.php/index/index/page_show?id=20"]]; } forControlEvents:(UIControlEventTouchUpInside)]; [btn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(-15); make.width.height.mas_equalTo(30); make.top.mas_equalTo(yb_StatusBar_H+7); }]; [self setupUI]; [self requestGiftLastWeekRank]; } - (void)setupUI { self.topLayout.constant = yb_NavigationBar_H; [self.currentTableView registerNib:[UINib nibWithNibName:@"LMWeekListTableViewCell" bundle:nil] forCellReuseIdentifier:LMWeekListTableViewCellID]; self.currentTableView.tableHeaderView = self.headerView; UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; flowLayout.itemSize = CGSizeMake((APPW-30)/4, 140); flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal; flowLayout.minimumLineSpacing = 0; self.lastWeekTopItemView.collectionViewLayout = flowLayout; self.lastWeekTopItemView.delegate = self; self.lastWeekTopItemView.dataSource = self; [self.lastWeekTopItemView registerNib:[UINib nibWithNibName:@"LMWeekLastCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:LMWeekLastCollectionViewCellID]; } - (void)setmeInfoWithDict:(NSDictionary *)myinfo { NSInteger is_top_rank = [myinfo safeIntForKey:@"is_top_rank"];//1 已上榜 2未上榜 if (is_top_rank == 1){ self.meInfoisRank.text = @"已上榜"; self.meInfoDeffNumLabel.hidden = YES; }else{ self.meInfoisRank.text = @"未上榜"; self.meInfoDeffNumLabel.text = [NSString stringWithFormat:@"距上榜还差%@个",[myinfo safeStringForKey:@"diff_num"]]; self.meInfoDeffNumLabel.hidden = NO; } self.meInfoNicknameLabel.text = [myinfo safeStringForKey:@"nick_name"]; [self.meInfoHeaderPic sd_setImageWithURL:[NSURL URLWithString:[myinfo safeStringForKey:@"head_pic"]] placeholderImage:kDefaultUserIcon]; } #pragma mark ——————— 网络请求 ——————— - (void)requestGiftLastWeekRank { [BJHttpTool BJ_Last_week_rankWithParameters:@{} success:^(id response) { self.lastWeekDataArr = [LMLastWeekRankListModel mj_objectArrayWithKeyValuesArray:response[@"data"]]; [self.lastWeekTopItemView reloadData]; if (self.lastWeekDataArr.count > 0) { self.heightConstraint.constant = 200; }else { self.heightConstraint.constant = 55; } } failure:^(NSError *error) { }]; } - (void)requestGiftCurrentWeekRankListWithGid:(NSString *)gid { [BJHttpTool BJ_Now_week_rankWithParameters:@{@"gid":gid} success:^(id response) { NSDictionary *data = [response safeDictionaryForKey:@"data"]; self.currentListDataArr = [LMCurrentWeekGiftRankListModel mj_objectArrayWithKeyValuesArray:[data safeArrayForKey:@"list"]]; [self.currentTableView reloadData]; NSDictionary *myinfo = [data safeDictionaryForKey:@"my_user_info"]; [self setmeInfoWithDict:myinfo]; } failure:^(NSError *error) { }]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.currentListDataArr.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { LMWeekListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:LMWeekListTableViewCellID forIndexPath:indexPath]; cell.model = self.currentListDataArr[indexPath.row]; cell.rankLabel.text = [NSString stringWithFormat:@"%02ld",indexPath.row+1]; if (indexPath.row < 3){ NSString *rankiconStr = [NSString stringWithFormat:@"week_rank_%ld",indexPath.row+1]; cell.rankIcon.image = ImageNamed(rankiconStr); cell.rankIcon.hidden = NO; cell.rankLabel.hidden = YES; // if (indexPath.row == 0){ // cell.receiveHeaderPic.layer.borderColor = HEXCOLOR(0xF9A920).CGColor; // }else if (indexPath.row == 1){ // cell.receiveHeaderPic.layer.borderColor = HEXCOLOR(0xAEBAC3).CGColor; // }else if (indexPath.row == 2){ // cell.receiveHeaderPic.layer.borderColor = HEXCOLOR(0xF36745).CGColor; // } }else{ cell.receiveHeaderPic.layer.borderColor = kClearColor.CGColor; cell.rankIcon.hidden = YES; cell.rankLabel.hidden = NO; } return cell; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.lastWeekDataArr.count; } - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { LMWeekLastCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:LMWeekLastCollectionViewCellID forIndexPath:indexPath]; cell.model = self.lastWeekDataArr[indexPath.row]; return cell; } - (LMWeekListHeaderView *)headerView { if (!_headerView){ _headerView = LoadNib(@"LMWeekListHeaderView"); _headerView.frame = CGRectMake(0, 0, APPW-30, 110); WEAK_SELF; _headerView.updateListBlock = ^(NSString * _Nonnull gid) { [weakSelf requestGiftCurrentWeekRankListWithGid:gid]; }; } return _headerView; } - (NSMutableArray *)lastWeekDataArr { if (!_lastWeekDataArr){ _lastWeekDataArr = [NSMutableArray array]; } return _lastWeekDataArr; } - (NSMutableArray *)currentListDataArr { if (!_currentListDataArr){ _currentListDataArr = [NSMutableArray array]; } return _currentListDataArr; } @end