Files
yuyin_ios/SweetParty/主类/音悦新增/盲盒巡乐会/SPBlindXunlehuiRankAlert.m
2025-08-08 11:05:33 +08:00

247 lines
7.0 KiB
Objective-C

//
// SPBlindXunlehuiRankAlert.m
// SweetParty
//
// Created by yons on 2024/11/21.
//
#import "SPBlindXunlehuiRankAlert.h"
#import "BJBoxRankCell.h"
#import "XiamuFooter.h"
#import "XiamuTipView.h"
@interface SPBlindXunlehuiRankAlert ()<UITableViewDataSource, UITableViewDelegate, JXCategoryViewDelegate>
@property (weak, nonatomic) IBOutlet UIView *categoryBgView;
@property (nonatomic, strong) JXCategoryTitleView *categoryView;
@property (nonatomic, strong) NSArray *titles;
@property (weak, nonatomic) IBOutlet UITableView *mainTableV;
@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, assign) NSInteger time_type;
//关于网络请求
@property (nonatomic, assign) BOOL isLoadFirst;
@property (nonatomic, assign) BOOL isOnRequesting, isNoMoreData, isNetError;
@property (nonatomic, strong) XiamuFooter *footerView;
@property (nonatomic, strong) XiamuTipView *tipsView;
@property (nonatomic, assign) NSInteger pageIndex;
@property (weak, nonatomic) IBOutlet UIView *clearView;
@end
@implementation SPBlindXunlehuiRankAlert
- (void)awakeFromNib {
[super awakeFromNib];
self.titles = @[@"日榜", @"周榜"];
self.time_type = 1;
[self creatUI];
[self loadFirst];
WEAK_SELF
[self.clearView dg_Tapped:^{
[weakSelf removeFromSuperview];
}];
}
- (void)initMJrefresh {
__weak typeof(self) weakSelf = self;
MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
[weakSelf loadFirst];
}];
_mainTableV.mj_header = header;
}
- (void)setIsOnRequesting:(BOOL)isOnRequesting {
_isOnRequesting = isOnRequesting;
if (isOnRequesting) {
_isNetError = NO;
[self.footerView stateLoading];
return;
}
if (_isNoMoreData) {
[self.footerView stateNoMore];
if (self.dataArray.count==0) {
[self.tipsView stateNoResult];
[self.footerView stateHide];
}
}
if (_isNetError) {
[self.footerView stateNetError];
if (_isLoadFirst) {
[self.tipsView stateNoNet];
[self.footerView stateHide];
[self.dataArray removeAllObjects];
[_mainTableV reloadData];
}
}
}
- (void)loadFirst {
if (_isOnRequesting) {
return;
}
_pageIndex = 1;
_isLoadFirst = YES;
self.isNoMoreData = NO;
[self loadListData];
}
- (void)loadMore {
if (_isOnRequesting) {
return;
}
if (_isNoMoreData) {
return;
}
_isLoadFirst = NO;
[self loadListData];
}
- (void)loadListData {
[self.tipsView stateHide];
self.isNetError = NO;
__weak typeof(self) weakSelf = self;
self.isOnRequesting = YES;
NSDictionary *dict = @{@"page":@(self.pageIndex).stringValue,
@"page_limit":@"30",
@"time_type":@(self.time_type)
};
NSMutableDictionary *paras = [NSMutableDictionary dictionary];
[paras addEntriesFromDictionary:dict];
// [SVProgressHUD showWithStatus:nil];
[RCMicHTTP postWithURLString:@"/api/blind_box/get_blind_box_rank" parameters:paras response:^(RCMicHTTPResult *result) {
[SVProgressHUD dismiss];
if (result.success) {
if (result.errorCode == 200 && [result.content isKindOfClass:NSArray.class]) {
[self checkRequestResult:result.content];
}else {
[SVProgressHUD showInfoWithStatus:result.message];
self.isNetError = YES;
}
}else {
[SVProgressHUD showInfoWithStatus:@"网络错误"];
self.isNetError = YES;
}
weakSelf.isOnRequesting = NO;
[weakSelf.mainTableV.mj_header endRefreshing];
}];
}
- (void)checkRequestResult:(NSArray *)listArr {
if ([listArr isKindOfClass:NSArray.class]) {
if (_isLoadFirst) {
[self.dataArray removeAllObjects];
}
if (listArr.count == 0 ) {
self.isNoMoreData = YES;
}
NSArray *models = [BJBoxRankModel mj_objectArrayWithKeyValuesArray:listArr];
[self.dataArray addObjectsFromArray:models];
[_mainTableV reloadData];
_pageIndex ++;
}
}
- (void)creatUI {
[self.categoryBgView addSubview:self.categoryView];
[self.categoryView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(0);
}];
self.mainTableV.delegate = self;
self.mainTableV.dataSource = self;
self.mainTableV.rowHeight = 60;
self.mainTableV.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.mainTableV registerNib:[UINib nibWithNibName:@"BJBoxRankCell" bundle:nil] forCellReuseIdentifier:@"BJBoxRankCell"];
[self initMJrefresh];
}
#pragma mark -UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
BJBoxRankCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BJBoxRankCell"];
cell.orderLab.textColor = cell.nicknameLab.textColor = HEXCOLOR(0xFFFFFF);
BJBoxRankModel *model = self.dataArray[indexPath.row];
cell.model = model;
cell.orderLab.text = [NSString stringWithFormat:@"%ld", indexPath.row+1];
return cell;
}
#pragma mark -JXCategoryViewDelegate
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
self.time_type = index + 1;
[self loadFirst];
}
// 分页菜单视图
- (JXCategoryTitleView *)categoryView {
if (!_categoryView) {
_categoryView = [[JXCategoryTitleView alloc] init];
_categoryView.delegate = self;
_categoryView.titleFont = YBMediumFont(14);
_categoryView.titleSelectedFont = YBMediumFont(14);
_categoryView.titleColor = HEXCOLOR(0xFDFDFD);
_categoryView.titleSelectedColor = HEXCOLOR(0xFFFFFF);
_categoryView.cellWidth = 148/2;
_categoryView.cellSpacing = 0;
_categoryView.contentEdgeInsetLeft = 0;
_categoryView.contentEdgeInsetRight = 0;
_categoryView.titles = self.titles;
JXCategoryIndicatorBackgroundView *backgroundView = [[JXCategoryIndicatorBackgroundView alloc] init];
backgroundView.indicatorHeight = 30;
backgroundView.indicatorWidthIncrement = 0;
backgroundView.indicatorCornerRadius = 14;
backgroundView.indicatorColor = [UIColor bm_colorGradientChangeWithSize:CGSizeMake(148/2, 30) direction:FXGradientChangeDirectionVertical startColor:HEXCOLOR(0xDB5CEA) endColor:HEXCOLOR(0xEA958F)];
// backgroundView.layer.borderWidth = 1;
// backgroundView.layer.borderColor = HEXCOLOR(0xFFFFFF).CGColor;
_categoryView.indicators = @[backgroundView];
}
return _categoryView;
}
- (IBAction)closeAction:(id)sender {
[self removeFromSuperview];
}
- (NSMutableArray *)dataArray {
if (!_dataArray) {
_dataArray = NSMutableArray.array;
}
return _dataArray;
}
@end