168 lines
6.7 KiB
Objective-C
168 lines
6.7 KiB
Objective-C
//
|
|
// QXBackpackSubViewController.m
|
|
// QXLive
|
|
//
|
|
// Created by 启星 on 2025/5/16.
|
|
//
|
|
|
|
#import "QXBackpackSubViewController.h"
|
|
#import "QXGiftCell.h"
|
|
#import "QXBackpackRecordCell.h"
|
|
#import "QXMineNetwork.h"
|
|
|
|
@interface QXBackpackSubViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
|
|
@property (nonatomic,strong)UICollectionView *collectionView;
|
|
@end
|
|
|
|
@implementation QXBackpackSubViewController
|
|
-(UIView *)listView{
|
|
return self.view;
|
|
}
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
// Do any additional setup after loading the view.
|
|
}
|
|
- (void)initSubViews{
|
|
self.page = 1;
|
|
self.bgImageHidden = YES;
|
|
if (self.type == 0) {
|
|
[self getBagList];
|
|
self.collectionView.frame = CGRectMake(0, 12, SCREEN_WIDTH, SCREEN_HEIGHT-NavContentHeight-44-10);
|
|
}else{
|
|
[self getGiftRecordListIsIncome:self.type == 1];
|
|
[self.collectionView addRoundedCornersWithRadius:16];
|
|
self.collectionView.backgroundColor = [UIColor whiteColor];
|
|
self.collectionView.frame = CGRectMake(16, 12, SCREEN_WIDTH-32, SCREEN_HEIGHT-NavContentHeight-44-10);
|
|
}
|
|
[self.view addSubview:self.collectionView];
|
|
}
|
|
-(void)getBagList{
|
|
MJWeakSelf
|
|
[QXMineNetwork getBagListSuccessBlock:^(NSArray * _Nonnull list) {
|
|
[weakSelf.dataArray removeAllObjects];
|
|
[weakSelf.dataArray addObjectsFromArray:list];
|
|
[weakSelf.collectionView reloadData];
|
|
[weakSelf.collectionView.mj_header endRefreshing];
|
|
[weakSelf.collectionView.mj_footer endRefreshing];
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
[weakSelf.collectionView.mj_header endRefreshing];
|
|
[weakSelf.collectionView.mj_footer endRefreshing];
|
|
}];
|
|
}
|
|
|
|
-(void)getGiftRecordListIsIncome:(BOOL)isIncom{
|
|
MJWeakSelf
|
|
if (isIncom) {
|
|
[QXMineNetwork getBagIncomeListWithPage:self.page successBlock:^(NSArray * _Nonnull list) {
|
|
if (self.page == 1) {
|
|
[self.dataArray removeAllObjects];
|
|
}
|
|
if (list.count == 0) {
|
|
weakSelf.collectionView.mj_footer.state = MJRefreshStateNoMoreData;
|
|
}else{
|
|
[weakSelf.collectionView.mj_footer endRefreshing];
|
|
}
|
|
[weakSelf.dataArray addObjectsFromArray:list];
|
|
[weakSelf.collectionView reloadData];
|
|
[weakSelf.collectionView.mj_header endRefreshing];
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
[weakSelf.collectionView.mj_header endRefreshing];
|
|
[weakSelf.collectionView.mj_footer endRefreshing];
|
|
}];
|
|
}else{
|
|
[QXMineNetwork getBagOutcomeListWithPage:self.page successBlock:^(NSArray * _Nonnull list) {
|
|
if (self.page == 1) {
|
|
[self.dataArray removeAllObjects];
|
|
}
|
|
if (list.count == 0) {
|
|
weakSelf.collectionView.mj_footer.state = MJRefreshStateNoMoreData;
|
|
}else{
|
|
[weakSelf.collectionView.mj_footer endRefreshing];
|
|
}
|
|
[weakSelf.dataArray addObjectsFromArray:list];
|
|
[weakSelf.collectionView reloadData];
|
|
|
|
[weakSelf.collectionView.mj_header endRefreshing];
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
[weakSelf.collectionView.mj_header endRefreshing];
|
|
[weakSelf.collectionView.mj_footer endRefreshing];
|
|
}];
|
|
}
|
|
|
|
}
|
|
|
|
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
|
|
return self.dataArray.count;
|
|
}
|
|
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
if (self.type == 0) {
|
|
QXGiftCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXGiftCell" forIndexPath:indexPath];
|
|
cell.roomGiftModel = self.dataArray[indexPath.row];
|
|
cell.cellType = QXGiftCellTypeBackpack;
|
|
return cell;
|
|
}else{
|
|
QXBackpackRecordCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXBackpackRecordCell" forIndexPath:indexPath];
|
|
if (indexPath.row == (self.dataArray.count - 1)) {
|
|
cell.lineView.hidden = YES;
|
|
}else{
|
|
cell.lineView.hidden = NO;
|
|
}
|
|
cell.model = self.dataArray[indexPath.row];
|
|
return cell;
|
|
}
|
|
}
|
|
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
if (self.type == 0) {
|
|
CGFloat width = (SCREEN_WIDTH-15*2-22*2)/3;
|
|
return CGSizeMake(width, width/100*136);
|
|
}else{
|
|
return CGSizeMake(SCREEN_WIDTH-32, 67);
|
|
}
|
|
}
|
|
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
|
|
if (self.type == 0) {
|
|
return 22;
|
|
}
|
|
return 0;
|
|
}
|
|
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
|
|
if (self.type == 0) {
|
|
return 22;
|
|
}
|
|
return 0;
|
|
}
|
|
-(UICollectionView *)collectionView{
|
|
if (!_collectionView) {
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
|
layout.minimumLineSpacing = 22;
|
|
layout.minimumInteritemSpacing = 22;
|
|
layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15);
|
|
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 12, SCREEN_WIDTH, SCREEN_HEIGHT-NavContentHeight-44-10) collectionViewLayout:layout];
|
|
_collectionView.delegate = self;
|
|
_collectionView.dataSource = self;
|
|
_collectionView.backgroundColor = [UIColor clearColor];
|
|
[_collectionView registerNib:[UINib nibWithNibName:@"QXGiftCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"QXGiftCell"];
|
|
[_collectionView registerNib:[UINib nibWithNibName:@"QXBackpackRecordCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"QXBackpackRecordCell"];
|
|
MJWeakSelf
|
|
_collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
|
|
weakSelf.page = 1;
|
|
if (weakSelf.type == 0) {
|
|
[weakSelf getBagList];
|
|
}else{
|
|
[weakSelf getGiftRecordListIsIncome:self.type == 1];
|
|
}
|
|
}];
|
|
_collectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
|
|
weakSelf.page++;
|
|
if (weakSelf.type == 0) {
|
|
[weakSelf getBagList];
|
|
}else{
|
|
[weakSelf getGiftRecordListIsIncome:self.type == 1];
|
|
}
|
|
}];
|
|
}
|
|
return _collectionView;
|
|
}
|
|
|
|
@end
|