Files

290 lines
8.0 KiB
Mathematica
Raw Permalink Normal View History

2025-08-08 11:05:33 +08:00
//
// BJBoxRecordAlert.m
//
//
// Created by ybb on 2021/5/6.
// Copyright © 2021 . All rights reserved.
//
#import "ZXYRankView.h"
#import "ZXYRankCell.h"
#import "XiamuFooter.h"
#import "XiamuTipView.h"
@interface ZXYRankView () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UIView *mainView;
@property (nonatomic, strong) UIImageView *bgImg;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataArray; //
//
@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 (nonatomic, assign) CGFloat mainW;
@property (nonatomic, assign) CGFloat mainH;
@property (nonatomic, assign) CGFloat contentX;
@property (nonatomic, assign) CGFloat contentTop;
@property (nonatomic, assign) CGFloat contentBottom;
@property (nonatomic, copy) NSString *bgImgName;
@end
@implementation ZXYRankView
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:UIScreen.mainScreen.bounds]) {
self.backgroundColor = [kBlackColor colorWithAlphaComponent:0.3];
[ControlCreator createButton:self rect:self.bounds text:@"" font:nil color:nil backguoundColor:UIColor.clearColor imageName:nil target:self action:@selector(backAction:)];
}
return self;
}
- (void)initMainView {
if (_mainView) {
return;
}
UIColor *color;
color = HEXCOLOR(0xFFFFFF);
_mainView = [[UIView alloc] initWithFrame:CGRectMake((APPW-_mainW)/2, (APPH-_mainH)/2, _mainW, _mainH)];
_mainView.backgroundColor = UIColor.clearColor;
[self addSubview:_mainView];
[ControlCreator createImageView:_mainView rect:_mainView.bounds imageName:self.bgImgName backguoundColor:nil];
// UIButton *closeBtn = [ControlCreator createButton:self rect:CGRectZero text:@"" font:nil color:nil backguoundColor:nil imageName:@"hd_box_close" target:self action:@selector(backAction:)];
// [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
// make.centerX.mas_equalTo(0);
// make.top.equalTo(_mainView.mas_bottom).offset(15);
// }];
}
- (void)initTableView {
if (_tableView) {
return;
}
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(_contentX, _contentTop, _mainView.width-_contentX*2, _mainView.height-_contentTop-20-_contentBottom)];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.backgroundColor = UIColor.clearColor;
_tableView.showsVerticalScrollIndicator = NO;
_tableView.separatorStyle = NO;
NSString *cellId = NSStringFromClass(ZXYRankCell.class);
[_tableView registerNib:[UINib nibWithNibName:cellId bundle:nil] forCellReuseIdentifier:cellId];
[_mainView addSubview:_tableView];
}
- (void)initMJrefresh {
__weak typeof(self) weakSelf = self;
MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
[weakSelf loadFirst];
}];
_tableView.mj_header = header;
}
- (void)initTipView {
if (_tipsView) {
return;
}
_tipsView = [[XiamuTipView alloc]initWithFrame:CGRectMake(0, 0, _tableView.width, 250)];
[self.tableView addSubview:_tipsView];
__weak typeof(self) weakSelf = self;
_tipsView.block = ^{
if (weakSelf.isNetError) {
[weakSelf loadFirst];
}
};
}
- (NSMutableArray *)dataArray {
if (!_dataArray) {
_dataArray = NSMutableArray.array;
}
return _dataArray;
}
- (XiamuFooter *)footerView {
if (!_footerView) {
_footerView = [[XiamuFooter alloc] initWithFrame:CGRectMake(0, 0, _tableView.width, 40)];
_footerView.hidden = YES;
}
return _footerView;
}
- (void)showOnView:(UIView *)parent {
CGFloat x = 12;
CGFloat w = ScreenWidth-x*2;
CGFloat h = w/350*465;
self.mainW = w;
self.mainH = h;
self.contentX = 22;
self.contentTop = 100;
self.contentBottom = 25;
self.bgImgName = @"zxy_rank_bg";
[self initMainView];
[self initTableView];
[self initMJrefresh];
// [self initTipView];
[parent addSubview:self];
[_tableView.mj_header beginRefreshing];
}
#pragma mark - action
- (void)backAction:(id)sender {
[self removeFromSuperview];
}
#pragma mark - data
- (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];
[_tableView 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":@"20",
};
NSMutableDictionary *paras = [NSMutableDictionary dictionary];
[paras addEntriesFromDictionary:dict];
// [SVProgressHUD showWithStatus:nil];
[RCMicHTTP postWithURLString:@"/api/Sprite/get_user_monster_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.tableView.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 *arr = [DDCaiAllRecordModel mj_objectArrayWithKeyValuesArray:listArr];
[self.dataArray addObjectsFromArray:arr];
[_tableView reloadData];
_pageIndex ++;
}
}
#pragma mark - table view
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.dataArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 70;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellId = NSStringFromClass(ZXYRankCell.class);
ZXYRankCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];
cell.selectionStyle = NO;
DDCaiAllRecordModel *model = self.dataArray[indexPath.row];
cell.model = model;
return cell;
}
//- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
// if (indexPath.item+6>self.dataArray.count && !self.isNoMoreData) {
// [self loadMore];
// }
//}
@end