YOUPAIHRCoinDetailVC.m 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. //
  2. // YOUPAIHRCoinDetailVC.m
  3. // VQU
  4. //
  5. // Created by xiaohaoran on 2021/10/19.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAIHRCoinDetailVC.h"
  9. #import "YOUPAIHRCoinDetailCell.h"
  10. #import "YOUPAIHRCoinDetailModel.h"
  11. @interface YOUPAIHRCoinDetailVC ()<UITableViewDelegate,UITableViewDataSource>{
  12. int ispage;
  13. int nextpage;
  14. }
  15. @property(nonatomic,strong)UITableView *youpaiptableView;
  16. @property(nonatomic,strong)NSMutableArray *youpaipdataArr;//数据源
  17. @end
  18. @implementation YOUPAIHRCoinDetailVC
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. self.title = @"贵族币明细";
  22. self.view.backgroundColor = LCBkgColor;
  23. [self youpaiptableView];
  24. [self youpaifRefreshUI];
  25. }
  26. -(void)youpaifRefreshUI{
  27. nextpage = 1;
  28. self.view.tag = 1;
  29. @weakify(self);
  30. self.youpaiptableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  31. @strongify(self);
  32. self->nextpage = 1;
  33. [self youpaifgetNobleCoinLog];
  34. }];
  35. // 上拉刷新
  36. self.youpaiptableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  37. @strongify(self);
  38. if (self->nextpage< self->ispage) {
  39. self.view.tag = 2;
  40. self->nextpage = self->nextpage+1;
  41. [self youpaifgetNobleCoinLog];
  42. }else
  43. {
  44. [self.youpaiptableView.mj_footer endRefreshing];
  45. [self.youpaiptableView.mj_footer endRefreshingWithNoMoreData];
  46. }
  47. }];
  48. [self.youpaiptableView.mj_header beginRefreshing];
  49. }
  50. #pragma mark UITableViewDelegate&UITableViewDataSource
  51. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  52. return 75;
  53. }
  54. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  55. return self.youpaipdataArr.count;
  56. }
  57. -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  58. YOUPAIHRCoinDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HRCoinDetailID"];
  59. if (cell == nil) {
  60. cell = [[YOUPAIHRCoinDetailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HRCoinDetailID"];
  61. }
  62. YOUPAIHRCoinDetailModel *model = self.youpaipdataArr[indexPath.row];
  63. cell.youpaipmodel = model;
  64. cell.backgroundColor = LCBkgColor;
  65. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  66. return cell;
  67. }
  68. -(UITableView *)youpaiptableView{
  69. if (!_youpaiptableView) {
  70. _youpaiptableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
  71. [self.view addSubview:_youpaiptableView];
  72. [_youpaiptableView mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.left.mas_equalTo(0);
  74. make.top.mas_equalTo(NavBarHeight);
  75. make.bottom.mas_equalTo(-SafeHeight);
  76. make.right.mas_equalTo(0);
  77. }];
  78. _youpaiptableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  79. _youpaiptableView.showsVerticalScrollIndicator = NO;
  80. _youpaiptableView.showsHorizontalScrollIndicator = NO;
  81. _youpaiptableView.delegate = self;
  82. _youpaiptableView.dataSource = self;
  83. _youpaiptableView.backgroundColor = LCBkgColor;
  84. [_youpaiptableView registerClass:[YOUPAIHRCoinDetailCell class] forCellReuseIdentifier:@"HRCoinDetailID"];
  85. _youpaiptableView.tableFooterView = [UIView new];
  86. if (@available(iOS 15.0, *)) {
  87. _youpaiptableView.sectionHeaderTopPadding = 0;
  88. }
  89. }
  90. return _youpaiptableView;
  91. }
  92. #pragma 获取数据
  93. -(void)youpaifgetNobleCoinLog{
  94. [LCHttpHelper requestWithURLString:GetNobleCoinLog parameters:@{@"page":[NSString stringWithFormat:@"%d",nextpage]} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  95. NSDictionary* dict = (NSDictionary*)responseObject;
  96. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  97. if (code==0) {//成功
  98. [self.youpaiptableView.mj_header endRefreshing];
  99. NSDictionary *dic = dict[@"data"];
  100. NSMutableArray *arrM = [NSMutableArray new];
  101. if (self.view.tag == 1) {
  102. NSArray *arr = dic[@"list"];
  103. if (arr.count<=0) {
  104. [self.youpaipdataArr removeAllObjects];
  105. [self.youpaiptableView reloadData];
  106. return ;
  107. }
  108. [arr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  109. YOUPAIHRCoinDetailModel *noticModel = [YOUPAIHRCoinDetailModel mj_objectWithKeyValues:obj];
  110. [self.youpaipdataArr addObject:noticModel];
  111. [arrM addObject:noticModel];
  112. }];
  113. if (self->nextpage == 1) {
  114. self.youpaipdataArr = arrM;
  115. self->nextpage = [dict[@"data"][@"page"] intValue];
  116. self->ispage = [dict[@"data"][@"total_page"] intValue];
  117. [self.youpaiptableView reloadData];
  118. }
  119. }else{
  120. NSArray *arr = dic[@"list"];
  121. if (arr.count<=0) {
  122. return ;
  123. }
  124. [arr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  125. YOUPAIHRCoinDetailModel *noticModel = [YOUPAIHRCoinDetailModel mj_objectWithKeyValues:obj];
  126. [self.youpaipdataArr addObject:noticModel];
  127. }];
  128. self->nextpage = [dict[@"data"][@"page"] intValue];
  129. self->ispage = [dict[@"data"][@"total_page"] intValue];
  130. [self.youpaiptableView reloadData];
  131. [self.youpaiptableView.mj_header endRefreshing];
  132. [self.youpaiptableView.mj_footer endRefreshing];
  133. }
  134. }
  135. } failure:^(NSError *error) {
  136. [self.youpaiptableView.mj_header endRefreshing];
  137. [self.youpaiptableView.mj_footer endRefreshing];
  138. }];
  139. }
  140. -(NSMutableArray *)youpaipdataArr{
  141. if (_youpaipdataArr == nil) {
  142. _youpaipdataArr = [NSMutableArray new];
  143. }
  144. return _youpaipdataArr;
  145. }
  146. @end