// // YOUPAIHRCoinDetailVC.m // VQU // // Created by xiaohaoran on 2021/10/19. // Copyright © 2021 MS. All rights reserved. // #import "YOUPAIHRCoinDetailVC.h" #import "YOUPAIHRCoinDetailCell.h" #import "YOUPAIHRCoinDetailModel.h" @interface YOUPAIHRCoinDetailVC (){ int ispage; int nextpage; } @property(nonatomic,strong)UITableView *youpaiptableView; @property(nonatomic,strong)NSMutableArray *youpaipdataArr;//数据源 @end @implementation YOUPAIHRCoinDetailVC - (void)viewDidLoad { [super viewDidLoad]; self.title = @"贵族币明细"; self.view.backgroundColor = LCBkgColor; [self youpaiptableView]; [self youpaifRefreshUI]; } -(void)youpaifRefreshUI{ nextpage = 1; self.view.tag = 1; @weakify(self); self.youpaiptableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{ @strongify(self); self->nextpage = 1; [self youpaifgetNobleCoinLog]; }]; // 上拉刷新 self.youpaiptableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{ @strongify(self); if (self->nextpage< self->ispage) { self.view.tag = 2; self->nextpage = self->nextpage+1; [self youpaifgetNobleCoinLog]; }else { [self.youpaiptableView.mj_footer endRefreshing]; [self.youpaiptableView.mj_footer endRefreshingWithNoMoreData]; } }]; [self.youpaiptableView.mj_header beginRefreshing]; } #pragma mark UITableViewDelegate&UITableViewDataSource -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 75; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.youpaipdataArr.count; } -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ YOUPAIHRCoinDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HRCoinDetailID"]; if (cell == nil) { cell = [[YOUPAIHRCoinDetailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HRCoinDetailID"]; } YOUPAIHRCoinDetailModel *model = self.youpaipdataArr[indexPath.row]; cell.youpaipmodel = model; cell.backgroundColor = LCBkgColor; [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; return cell; } -(UITableView *)youpaiptableView{ if (!_youpaiptableView) { _youpaiptableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain]; [self.view addSubview:_youpaiptableView]; [_youpaiptableView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.top.mas_equalTo(NavBarHeight); make.bottom.mas_equalTo(-SafeHeight); make.right.mas_equalTo(0); }]; _youpaiptableView.separatorStyle = UITableViewCellSeparatorStyleNone; _youpaiptableView.showsVerticalScrollIndicator = NO; _youpaiptableView.showsHorizontalScrollIndicator = NO; _youpaiptableView.delegate = self; _youpaiptableView.dataSource = self; _youpaiptableView.backgroundColor = LCBkgColor; [_youpaiptableView registerClass:[YOUPAIHRCoinDetailCell class] forCellReuseIdentifier:@"HRCoinDetailID"]; _youpaiptableView.tableFooterView = [UIView new]; if (@available(iOS 15.0, *)) { _youpaiptableView.sectionHeaderTopPadding = 0; } } return _youpaiptableView; } #pragma 获取数据 -(void)youpaifgetNobleCoinLog{ [LCHttpHelper requestWithURLString:GetNobleCoinLog parameters:@{@"page":[NSString stringWithFormat:@"%d",nextpage]} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 [self.youpaiptableView.mj_header endRefreshing]; NSDictionary *dic = dict[@"data"]; NSMutableArray *arrM = [NSMutableArray new]; if (self.view.tag == 1) { NSArray *arr = dic[@"list"]; if (arr.count<=0) { [self.youpaipdataArr removeAllObjects]; [self.youpaiptableView reloadData]; return ; } [arr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { YOUPAIHRCoinDetailModel *noticModel = [YOUPAIHRCoinDetailModel mj_objectWithKeyValues:obj]; [self.youpaipdataArr addObject:noticModel]; [arrM addObject:noticModel]; }]; if (self->nextpage == 1) { self.youpaipdataArr = arrM; self->nextpage = [dict[@"data"][@"page"] intValue]; self->ispage = [dict[@"data"][@"total_page"] intValue]; [self.youpaiptableView reloadData]; } }else{ NSArray *arr = dic[@"list"]; if (arr.count<=0) { return ; } [arr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { YOUPAIHRCoinDetailModel *noticModel = [YOUPAIHRCoinDetailModel mj_objectWithKeyValues:obj]; [self.youpaipdataArr addObject:noticModel]; }]; self->nextpage = [dict[@"data"][@"page"] intValue]; self->ispage = [dict[@"data"][@"total_page"] intValue]; [self.youpaiptableView reloadData]; [self.youpaiptableView.mj_header endRefreshing]; [self.youpaiptableView.mj_footer endRefreshing]; } } } failure:^(NSError *error) { [self.youpaiptableView.mj_header endRefreshing]; [self.youpaiptableView.mj_footer endRefreshing]; }]; } -(NSMutableArray *)youpaipdataArr{ if (_youpaipdataArr == nil) { _youpaipdataArr = [NSMutableArray new]; } return _youpaipdataArr; } @end