177 lines
7.2 KiB
Objective-C
177 lines
7.2 KiB
Objective-C
//
|
|
// DDMyInformationGiftWallViewController.m
|
|
// DingDangApp
|
|
//
|
|
// Created by apple on 2023/5/29.
|
|
//
|
|
|
|
#import "DDMyInformationGiftWallViewController.h"
|
|
#import "DDMyInfoGiftWallView.h"
|
|
#import "DDMyInfoGiftWallCollectionViewCell.h"
|
|
#import "DDGiftWallModel.h"
|
|
#import "Api+DDMineApi.h"
|
|
@interface DDMyInformationGiftWallViewController ()
|
|
|
|
@end
|
|
|
|
@implementation DDMyInformationGiftWallViewController
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
// Do any additional setup after loading the view.
|
|
self.giftCount = 0;
|
|
self.pageNum = 1;
|
|
[self.view addSubview:self.giftWallCollectionView];
|
|
[self.giftWallCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(0, 0, 0, 0));
|
|
}];
|
|
[self requestGiftWall];
|
|
}
|
|
|
|
-(void)requestGiftWall
|
|
{
|
|
WeakSelf(weakSelf)
|
|
[Api getUserGiftWall:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
|
[weakSelf.giftWallCollectionView.mj_header endRefreshing];
|
|
[weakSelf.giftWallCollectionView.mj_footer endRefreshing];
|
|
if(code == 200){
|
|
if (weakSelf.pageNum == 1) {
|
|
[weakSelf.giftListArr removeAllObjects];
|
|
}
|
|
NSArray *list = [DDGiftWallModel DD_ModelsWithArray:data.data];
|
|
[weakSelf.giftListArr addObjectsFromArray:list];
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
[weakSelf.giftWallCollectionView.mj_header endRefreshing];
|
|
[weakSelf.giftWallCollectionView.mj_footer endRefreshing];
|
|
[weakSelf.giftWallCollectionView reloadData];
|
|
|
|
weakSelf.giftCount =list.count;
|
|
|
|
|
|
});
|
|
}
|
|
} uid:self.user_id giftType:@"1"];
|
|
|
|
return;
|
|
NSMutableDictionary *requestDict = [NSMutableDictionary dictionary];
|
|
if ([ToolsObject IsNullWithObject:self.user_id]) {
|
|
[requestDict setObject:[ToolsObject getUserModel].user_id forKey:@"user_id"];
|
|
}else{
|
|
[requestDict setObject:self.user_id forKey:@"user_id"];
|
|
}
|
|
[requestDict setObject:@(self.pageNum) forKey:@"page_number"];
|
|
[requestDict setObject:@(15) forKey:@"current_page"];
|
|
|
|
[NetworkRequest requestPOST:@"/my/gift/list" parameters:requestDict block:^(BaseResponse * _Nonnull response) {
|
|
if (response.code == 200) {
|
|
if ([ToolsObject IsNullWithObject:response.data]) {
|
|
[weakSelf.giftWallCollectionView.mj_header endRefreshing];
|
|
[weakSelf.giftWallCollectionView.mj_footer endRefreshing]; return;
|
|
}
|
|
|
|
if (weakSelf.pageNum == 1) {
|
|
[weakSelf.giftListArr removeAllObjects];
|
|
}
|
|
[weakSelf.giftListArr addObjectsFromArray:[NSArray yy_modelArrayWithClass:DDGiftWallModel.class json:response.data[@"record"]]];
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
[weakSelf.giftWallCollectionView.mj_header endRefreshing];
|
|
[weakSelf.giftWallCollectionView.mj_footer endRefreshing];
|
|
[weakSelf.giftWallCollectionView reloadData];
|
|
if ([response.data[@"count"]integerValue]==0) {
|
|
}else{
|
|
weakSelf.giftCount =[response.data[@"count"]integerValue];
|
|
|
|
}
|
|
});
|
|
if ([response.data[@"next"]integerValue] == 0) {
|
|
[weakSelf.giftWallCollectionView.mj_footer endRefreshingWithNoMoreData];
|
|
}
|
|
}else{
|
|
[weakSelf.giftWallCollectionView.mj_header endRefreshing];
|
|
[weakSelf.giftWallCollectionView.mj_footer endRefreshing];
|
|
}
|
|
}];
|
|
}
|
|
-(UICollectionViewFlowLayout *)flowLayout
|
|
{
|
|
if (!_flowLayout) {
|
|
_flowLayout = [[UICollectionViewFlowLayout alloc]init];
|
|
CGFloat itemWidth = (kWidth-8*3-32)/4;
|
|
_flowLayout.itemSize = CGSizeMake(itemWidth, itemWidth*1.38);
|
|
_flowLayout.sectionInset = UIEdgeInsetsMake(0,16,0,16);
|
|
_flowLayout.minimumLineSpacing = 8;
|
|
_flowLayout.minimumInteritemSpacing = 12;
|
|
_flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
|
|
}
|
|
return _flowLayout;
|
|
}
|
|
- (UICollectionView *)giftWallCollectionView {
|
|
if (!_giftWallCollectionView) {
|
|
_giftWallCollectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:self.flowLayout];
|
|
_giftWallCollectionView.delegate = self;
|
|
_giftWallCollectionView.dataSource = self;
|
|
_giftWallCollectionView.showsHorizontalScrollIndicator = NO;
|
|
_giftWallCollectionView.alwaysBounceVertical= YES;
|
|
_giftWallCollectionView.backgroundColor = [UIColor whiteColor];
|
|
[_giftWallCollectionView registerClass:[DDMyInfoGiftWallCollectionViewCell class] forCellWithReuseIdentifier:@"DDMyInfoGiftWallCollectionViewCell"];
|
|
[_giftWallCollectionView registerClass:[DDMyInfoGiftWallView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"DDMyInfoGiftWallView"];
|
|
|
|
WeakSelf(weakSelf)
|
|
_giftWallCollectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
|
|
weakSelf.pageNum ++;
|
|
[weakSelf requestGiftWall];
|
|
}];
|
|
}
|
|
return _giftWallCollectionView;
|
|
}
|
|
|
|
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
|
|
{
|
|
return 1;
|
|
}
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
|
|
{
|
|
return self.giftListArr.count;
|
|
}
|
|
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
|
|
|
|
return CGSizeMake(kWidth, 48);
|
|
}
|
|
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
UICollectionReusableView *reusableview = nil;
|
|
|
|
if(kind == UICollectionElementKindSectionHeader){
|
|
|
|
DDMyInfoGiftWallView * headerView= [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"DDMyInfoGiftWallView" forIndexPath:indexPath];
|
|
headerView.numString =[NSString stringWithFormat:@"%ld",self.giftCount];
|
|
reusableview = headerView;
|
|
return reusableview;
|
|
|
|
}
|
|
reusableview = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"UICollectionReusableHeaderView" forIndexPath:indexPath];
|
|
|
|
return reusableview;
|
|
}
|
|
|
|
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
DDMyInfoGiftWallCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"DDMyInfoGiftWallCollectionViewCell" forIndexPath:indexPath];
|
|
if (indexPath.row < self.giftListArr.count){
|
|
cell.model = self.giftListArr[indexPath.row];
|
|
}
|
|
return cell;
|
|
}
|
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
|
|
}
|
|
-(NSMutableArray *)giftListArr
|
|
{
|
|
if (!_giftListArr) {
|
|
_giftListArr = [NSMutableArray array];
|
|
}
|
|
return _giftListArr;
|
|
}
|
|
@end
|