Files
mier_ios/SweetParty/主类/音悦新增/盲盒巡乐会/SPBlindXunlehuiRecordAlert.m
2025-08-11 10:43:19 +08:00

191 lines
5.0 KiB
Objective-C

//
// SPBlindXunlehuiRecordAlert.m
// SweetParty
//
// Created by yons on 2024/11/21.
//
#import "SPBlindXunlehuiRecordAlert.h"
#import "SPBlindXunlehuiRecordCell.h"
#import "XiamuFooter.h"
#import "XiamuTipView.h"
@interface SPBlindXunlehuiRecordAlert ()<UITableViewDataSource, UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *mainTableV;
//关于网络请求
@property (nonatomic, assign) BOOL isLoadFirst;
@property (nonatomic, assign) BOOL isOnRequesting, isNoMoreData, isNetError;
@property (nonatomic, strong) XiamuFooter *footerView;
@property (nonatomic, strong) XiamuTipView *tipsView;
@property (nonatomic, strong) NSMutableArray *dataArray;
@property (weak, nonatomic) IBOutlet UIView *clearView;
@property (nonatomic, assign) NSInteger pageIndex;
@end
@implementation SPBlindXunlehuiRecordAlert
- (void)awakeFromNib {
[super awakeFromNib];
[self creatUI];
[self loadFirst];
WEAK_SELF
[self.clearView dg_Tapped:^{
[weakSelf removeFromSuperview];
}];
}
- (void)creatUI {
self.mainTableV.delegate = self;
self.mainTableV.dataSource = self;
self.mainTableV.rowHeight = 135;
self.mainTableV.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.mainTableV registerNib:[UINib nibWithNibName:@"SPBlindXunlehuiRecordCell" bundle:nil] forCellReuseIdentifier:@"SPBlindXunlehuiRecordCell"];
[self initMJrefresh];
}
- (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",
};
NSMutableDictionary *paras = [NSMutableDictionary dictionary];
[paras addEntriesFromDictionary:dict];
// [SVProgressHUD showWithStatus:nil];
[RCMicHTTP postWithURLString:@"/api/blind_box/get_blind_box_win_log" 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 ++;
}
}
#pragma mark -UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
SPBlindXunlehuiRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SPBlindXunlehuiRecordCell"];
BJBoxRankModel *model = self.dataArray[indexPath.row];
cell.model = model;
cell.orderL.text = [NSString stringWithFormat:@"%ld", indexPath.row + 1];
return cell;
}
- (IBAction)closeAction:(id)sender {
[self removeFromSuperview];
}
- (NSMutableArray *)dataArray {
if (!_dataArray) {
_dataArray = NSMutableArray.array;
}
return _dataArray;
}
@end