《省钱达人》与《猎豆优选》UI相同版。域名tbk

DRNewsListViewController.m 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. //
  2. // DRNewsListViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/12/12.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRNewsListViewController.h"
  9. #import "DRGoodCollectionCell.h"
  10. #import "DRGoodDetailViewController.h"
  11. static NSString *cellID = @"DRGoodCollectionCell";
  12. @interface DRNewsListViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
  13. {
  14. NSInteger _page;
  15. NSInteger _type;
  16. BOOL _changeType;
  17. ActivityIndicatorView *_indicatorView;
  18. }
  19. @property (nonatomic, strong) UICollectionView *collectionView;
  20. @property (nonatomic, strong) NSMutableArray *goodsArr;
  21. @end
  22. @implementation DRNewsListViewController
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. [self configParam];
  26. [self configNavigationBar];
  27. [self configCollectionView];
  28. [self initHUD];
  29. [self loadCategoryGoodsList];
  30. }
  31. - (void)viewWillAppear:(BOOL)animated {
  32. [super viewWillAppear:animated];
  33. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
  34. self.navigationController.navigationBar.hidden = YES;
  35. }
  36. - (void)viewWillDisappear:(BOOL)animated {
  37. [super viewWillDisappear:animated];
  38. [_indicatorView stopAnimating];
  39. }
  40. #pragma mark - HUD
  41. - (void)initHUD {
  42. ActivityIndicatorView *indicatorView = [ActivityIndicatorView showInView:self.view frame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight)];
  43. _indicatorView = indicatorView;
  44. [_indicatorView startAnimating];
  45. }
  46. - (void)configParam {
  47. _page = 1;
  48. _type = 1; //默认请求推荐的数据
  49. }
  50. - (void)configNavigationBar {
  51. self.view.backgroundColor = [UIColor whiteColor];
  52. [self.navigationBar setNavTitle:@"猎豆头条"];
  53. self.navigationBar.showNavigationBarBottomLine = YES;
  54. UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  55. [leftBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
  56. [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  57. [self.navigationBar setCustomLeftButtons:@[leftBtn]];
  58. [self.navigationBar setShowNavigationBarBottomLine:YES];
  59. }
  60. - (void)configCollectionView {
  61. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
  62. flowLayout.minimumLineSpacing = 5;
  63. flowLayout.minimumInteritemSpacing = 0;
  64. flowLayout.headerReferenceSize = CGSizeMake(0, 0);
  65. self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight) collectionViewLayout:flowLayout];
  66. [self.collectionView registerClass:[DRGoodCollectionCell class] forCellWithReuseIdentifier:cellID];
  67. self.collectionView.backgroundColor = [UIColor YHColorWithHex:0xf6f6f6];
  68. self.collectionView.showsVerticalScrollIndicator = NO;
  69. self.collectionView.delegate = self;
  70. self.collectionView.dataSource = self;
  71. self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  72. [self loadMoreData];
  73. }];
  74. [self.view addSubview: self.collectionView];
  75. }
  76. - (void)backAction {
  77. [self.navigationController popViewControllerAnimated:YES];
  78. }
  79. /**
  80. 上拉加载
  81. */
  82. - (void)loadMoreData {
  83. _page++;
  84. _changeType = NO;
  85. [self loadCategoryGoodsList];
  86. }
  87. /**
  88. 加载下部商品列表
  89. */
  90. - (void)loadCategoryGoodsList {
  91. NSDictionary *para = @{@"page":@(_page)};
  92. NSString *url = [NSString stringWithFormat:@"%@/api/v2/message_push/LieDouHeadlinesList",BaseURL];
  93. [DRHttp post:url params:para success:^(id json) {
  94. if (_changeType) {
  95. [self.goodsArr removeAllObjects];
  96. }
  97. NSArray *list = [NSArray yy_modelArrayWithClass:[DRChildGoodModel class] json:json[@"data"]];
  98. if (list.count > 0) {
  99. [self.collectionView.mj_footer endRefreshing];
  100. }else {
  101. [self.collectionView.mj_footer endRefreshingWithNoMoreData];
  102. }
  103. [self.goodsArr addObjectsFromArray:list];
  104. [self.collectionView reloadData];
  105. [_indicatorView stopAnimating];
  106. } failure:^(NSError *error) {
  107. [self.collectionView.mj_footer endRefreshing];
  108. [_indicatorView stopAnimating];
  109. [MBProgressHUD showMessage:@"加载失败"];
  110. }];
  111. }
  112. #pragma mark =============== YHTypeButtonActionDelegate =============
  113. - (void)didClickTypeButtonAction:(UIButton *)button withIndex:(NSInteger)index {
  114. _type = index + 1;
  115. _changeType = YES;
  116. [self loadCategoryGoodsList];
  117. [self.collectionView setContentOffset:CGPointMake(0, 0) animated:YES];
  118. }
  119. #pragma mark ============ UICollectionView Delegate && DataSource ==========
  120. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  121. {
  122. return self.goodsArr.count;
  123. }
  124. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  125. DRChildGoodModel *model = self.goodsArr[indexPath.row];
  126. CGFloat width = (SCREEN_WIDTH-5)/2;
  127. CGFloat height = width + 112;
  128. if (model.commission_price.length > 0) {
  129. }
  130. return CGSizeMake(width, height);
  131. }
  132. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
  133. {
  134. return CGSizeMake(0, 0);
  135. }
  136. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
  137. {
  138. return CGSizeMake(0, 0);
  139. }
  140. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  141. {
  142. DRGoodCollectionCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
  143. DRChildGoodModel *model = self.goodsArr[indexPath.row];
  144. cell.model = model;
  145. return cell;
  146. }
  147. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  148. DRChildGoodModel *model = self.goodsArr[indexPath.row];
  149. //详情
  150. DRGoodDetailViewController *detailVC = [[DRGoodDetailViewController alloc] init];
  151. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithChildModel:model];
  152. detailVC.requestModel = requestModel;
  153. // DREventModel *evevtModel = [[DREventModel alloc] initWithOrigin:model.origin category_id:@"0" source:ListAction];
  154. // detailVC.eventModel = evevtModel;
  155. [self.navigationController pushViewController:detailVC animated:YES];
  156. }
  157. #pragma mark -------------
  158. - (NSMutableArray *)goodsArr {
  159. if (!_goodsArr) {
  160. _goodsArr = [NSMutableArray array];
  161. }
  162. return _goodsArr;
  163. }
  164. @end