Files
yuyin_ios/SweetParty/主类/RCMic/Room/Box/本期奖池/BJBoxPoolAlert.m
2025-08-14 15:37:40 +08:00

392 lines
12 KiB
Objective-C
Executable File

//
// RoomGiftPoolAlert.m
//
//
// Created by ybb on 2021/5/6.
// Copyright © 2021 . All rights reserved.
//
#import "BJBoxPoolAlert.h"
#import "RoomBoxRecordCell.h"
#import "XiamuFooter.h"
#import "XiamuTipView.h"
@interface BJBoxPoolAlert () <UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>
@property (nonatomic, strong) UIView *mainView;
@property (nonatomic, strong) UIImageView *bgImg;
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) NSMutableArray *models; //礼物数组
//关于网络请求
@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) NSInteger poolType;
@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 BJBoxPoolAlert
- (NSMutableArray *)models {
if (!_models) {
_models = NSMutableArray.array;
}
return _models;
}
- (XiamuFooter *)footerView {
if (!_footerView) {
_footerView = [[XiamuFooter alloc] initWithFrame:CGRectMake(0, 0, _collectionView.width, 40)];
_footerView.hidden = YES;
}
return _footerView;
}
#pragma mark -
- (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;
if (self.poolType == 4 || self.poolType == 5 || self.poolType == 6) {
color = HEXCOLOR(0xFFFFFF);
_mainView = [[UIView alloc] initWithFrame:CGRectMake((APPW-_mainW)/2, APPH-_mainH, _mainW, _mainH)];
}else if (self.poolType == 21){
color = kWhiteColor;
_mainView = [[UIView alloc] initWithFrame:CGRectMake((APPW-_mainW)/2, APPH-_mainH, _mainW, _mainH)];
}else {
color = HEXCOLOR(0xFFFFFF);
_mainView = [[UIView alloc] initWithFrame:CGRectMake((APPW-_mainW)/2, APPH-_mainH, _mainW, _mainH)];
}
_mainView.backgroundColor = UIColor.clearColor;
[self addSubview:_mainView];
[ControlCreator createImageView:_mainView rect:_mainView.bounds imageName:self.bgImgName backguoundColor:nil];
}
- (void)initCollecionView {
if (_collectionView) {
return;
}
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake((_mainView.width-_contentX*2)/3.0, 140);
layout.minimumInteritemSpacing = 0;
layout.minimumLineSpacing = 0;
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(_contentX, _contentTop, _mainView.width-_contentX*2, _mainView.height-_contentTop-_contentBottom) collectionViewLayout:layout];
_collectionView.delegate = self;
_collectionView.dataSource = self;
_collectionView.backgroundColor = UIColor.clearColor;
_collectionView.showsVerticalScrollIndicator = NO;
NSString *cellId = NSStringFromClass(RoomBoxRecordCell.class);
[_collectionView registerNib:[UINib nibWithNibName:cellId bundle:nil] forCellWithReuseIdentifier:cellId];
[_collectionView registerClass:UICollectionReusableView.class forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"foot"];
[_mainView addSubview:_collectionView];
}
- (void)initMJrefresh {
__weak typeof(self) weakSelf = self;
MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
[weakSelf loadFirst];
}];
_collectionView.mj_header = header;
}
- (void)initTipView {
if (_tipsView) {
return;
}
_tipsView = [[XiamuTipView alloc]initWithFrame:CGRectMake(0, 0, APPW-30-80, 250)];
[self.collectionView addSubview:_tipsView];
__weak typeof(self) weakSelf = self;
_tipsView.block = ^{
if (weakSelf.isNetError) {
[weakSelf loadFirst];
}
};
}
- (void)showOnView:(UIView *)parent WithType:(NSInteger)type {
self.poolType = type;
if (type == 4 || type == 5 || type == 6) {
CGFloat x = 0;
CGFloat w = ScreenWidth-x*2;
CGFloat h = w/375*500;
self.mainW = w;
self.mainH = h;
self.contentX = 20;
self.contentTop = 90;
self.contentBottom = 40;
self.bgImgName = @"zhuan_bg_pool";
}else if (type == 21) {
CGFloat x = 0;
CGFloat w = ScreenWidth-x*2;
CGFloat h = w/375*531;
self.mainW = w;
self.mainH = h;
self.contentX = 15;
self.contentTop = 100;
self.contentBottom = 24;
self.bgImgName = @"sec_zhuan_bg_pool";
}else if (type == 100) {
CGFloat x = 12;
CGFloat w = ScreenWidth-x*2;
CGFloat h = w/350*427;
self.mainW = w;
self.mainH = h;
self.contentX = 17;
self.contentTop = 105;
self.contentBottom = 25;
self.bgImgName = @"zxy_pool_bg";
}else if(type == 777){
CGFloat x = 0;
CGFloat w = ScreenWidth - x*2;
CGFloat h = w/375*580;
self.mainW = w;
self.mainH = h;
self.contentX = 30;
self.contentTop = 115;
self.contentBottom = 50;
self.bgImgName = @"stake_bg_pool";
}else {
CGFloat x = 0;
CGFloat w = ScreenWidth - x*2;
CGFloat h = w/375*480;
self.mainW = w;
self.mainH = h;
self.contentX = 15;
self.contentTop = 80;
self.contentBottom = 50;
self.bgImgName = @"bg_explore_pool";
}
[self initMainView];
[self initCollecionView];
[self initMJrefresh];
//[self initTipView];
[parent addSubview:self];
[_collectionView.mj_header beginRefreshing];
}
#pragma mark - action
- (void)backAction {
[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.models.count==0) {
[self.tipsView stateNoResult];
[self.footerView stateHide];
}
}
if (_isNetError) {
[self.footerView stateNetError];
if (_isLoadFirst) {
[self.tipsView stateNoNet];
[self.footerView stateHide];
[self.models removeAllObjects];
[_collectionView 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 = @{@"tid":@(_poolType)};
NSMutableDictionary *paras = [NSMutableDictionary dictionary];
[paras addEntriesFromDictionary:dict];
NSString *urlStr = @"/api/box/get_box_list";
if (self.poolType == 100) {
urlStr = @"/api/Sprite/get_monster_box_list";
}
if (self.poolType == 777) {
urlStr = @"/api/monster/get_monster_box_list";
}
// [SVProgressHUD showWithStatus:nil];
[RCMicHTTP postWithURLString:urlStr 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.collectionView.mj_header endRefreshing];
}];
}
- (void)checkRequestResult:(NSArray *)listArr {
if ([listArr isKindOfClass:NSArray.class]) {
if (_isLoadFirst) {
[self.models removeAllObjects];
}
NSArray *models = [BJBoxPoolModel mj_objectArrayWithKeyValuesArray:listArr];
[self.models addObjectsFromArray:models];
[_collectionView reloadData];
self.isNoMoreData = YES;
_pageIndex ++;
}
}
#pragma mark ====================== 代理方法 ======================
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
return CGSizeMake(APPW, 40);
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
if ([kind isEqualToString:UICollectionElementKindSectionFooter]) {
UICollectionReusableView *foot = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"foot" forIndexPath:indexPath];
NSInteger footTag = 1001;
UIView *subview = [foot viewWithTag:footTag];
if (subview) {
[subview removeFromSuperview];
}
self.footerView.tag = footTag;
[foot addSubview:self.footerView];
return foot;
}
return nil;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.models.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellId = NSStringFromClass(RoomBoxRecordCell.class);
RoomBoxRecordCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellId forIndexPath:indexPath];
BJBoxPoolModel *model = self.models[indexPath.item];
cell.poolModel = model;
if (self.poolType == 4 || self.poolType == 5 || self.poolType == 6) {
cell.bjImg.image = ImageNamed(@"zhuan_gift_bg");
cell.labelTop.textColor = HEXCOLOR(0xFFFFFF);
cell.labelBot.textColor = HEXCOLOR(0xFFFFFF);
}else if (self.poolType == 100) {
cell.bjImg.image = ImageNamed(@"zxy_gift_bg");
cell.labelTop.textColor = HEXCOLOR(0xFFFFFF);
cell.labelBot.textColor = HEXCOLOR(0xFFFFFF);
}else if (self.poolType == 777) {
cell.bjImg.image = ImageNamed(@"stake_gift_bg");
cell.labelTop.textColor = HEXCOLOR(0xFFFFFF);
cell.labelBot.textColor = HEXCOLOR(0xFFFFFF);
}else {
cell.bjImg.image = ImageNamed(@"box_gift_bg");
cell.labelTop.textColor = HEXCOLOR(0xFFFFFF);
cell.labelBot.textColor = HEXCOLOR(0xFFFFFF);
}
return cell;
}
@end