猎豆优选

LDRankListViewController.m 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. //
  2. // LDRankListViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/7/12.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LDRankListViewController.h"
  9. #import "LDBuyLimitGoodModel.h"
  10. #import "LDRankGoodCollectionCell.h"
  11. static NSString *cellID = @"LDGoodCollectionCell";
  12. @interface LDRankListViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
  13. {
  14. NSInteger _page;
  15. ActivityIndicatorView *_indicatorView;
  16. }
  17. @property (nonatomic, strong) UICollectionView *collectionView;
  18. @property (nonatomic, strong) NSMutableArray *goodsArr;
  19. @end
  20. @implementation LDRankListViewController
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. [self configParam];
  24. [self configNavigationBar];
  25. [self configCollectionView];
  26. [self initHUD];
  27. [self loadCategoryGoodsList];
  28. }
  29. - (void)viewWillAppear:(BOOL)animated {
  30. [super viewWillAppear:animated];
  31. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
  32. self.navigationController.navigationBar.hidden = YES;
  33. }
  34. - (void)viewWillDisappear:(BOOL)animated {
  35. [super viewWillDisappear:animated];
  36. [_indicatorView stopAnimating];
  37. }
  38. #pragma mark - HUD
  39. - (void)initHUD {
  40. ActivityIndicatorView *indicatorView = [ActivityIndicatorView showInView:self.view frame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight)];
  41. _indicatorView = indicatorView;
  42. [_indicatorView startAnimating];
  43. }
  44. - (void)configParam {
  45. _page = 1;
  46. }
  47. - (void)configNavigationBar {
  48. self.view.backgroundColor = [UIColor whiteColor];
  49. if (self.name.length > 0) {
  50. [self.navigationBar setNavTitle:self.name];
  51. }else {
  52. [self.navigationBar setNavTitle:@"今日热卖榜"];
  53. }
  54. self.navigationBar.showNavigationBarBottomLine = YES;
  55. UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  56. [leftBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
  57. [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  58. [self.navigationBar setCustomLeftButtons:@[leftBtn]];
  59. [self.navigationBar setShowNavigationBarBottomLine:YES];
  60. }
  61. - (void)configCollectionView {
  62. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
  63. flowLayout.minimumLineSpacing = 5;
  64. flowLayout.minimumInteritemSpacing = 0;
  65. flowLayout.headerReferenceSize = CGSizeMake(0, 0);
  66. self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight) collectionViewLayout:flowLayout];
  67. [self.collectionView registerClass:[LDRankGoodCollectionCell class] forCellWithReuseIdentifier:cellID];
  68. self.collectionView.backgroundColor = [UIColor YHColorWithHex:0xf6f6f6];
  69. self.collectionView.showsVerticalScrollIndicator = NO;
  70. self.collectionView.delegate = self;
  71. self.collectionView.dataSource = self;
  72. self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  73. [self loadMoreData];
  74. }];
  75. [self.view addSubview: self.collectionView];
  76. }
  77. - (void)backAction {
  78. [self.navigationController popViewControllerAnimated:YES];
  79. }
  80. /**
  81. 上拉加载
  82. */
  83. - (void)loadMoreData {
  84. _page++;
  85. [self loadCategoryGoodsList];
  86. }
  87. /**
  88. 加载下部商品列表
  89. */
  90. - (void)loadCategoryGoodsList {
  91. NSDictionary *para = @{@"platform":@"2",
  92. @"page":@(_page),
  93. @"page_size":@"20",
  94. };
  95. NSString *url = [NSString stringWithFormat:@"%@/api/v2/goods/hotSaleList",BaseURL];
  96. [LDHttp post:url params:para success:^(id json) {
  97. NSArray *list = [NSArray yy_modelArrayWithClass:[LDBuyLimitGoodModel class] json:json[@"data"][@"list"]];
  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 ============ UICollectionView Delegate && DataSource ==========
  113. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  114. {
  115. return self.goodsArr.count;
  116. }
  117. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  118. LDBuyLimitGoodModel *model = self.goodsArr[indexPath.row];
  119. CGFloat width = (SCREEN_WIDTH-5)/2;
  120. CGFloat height = width + 112;
  121. if (model.commission_price.length > 0) {
  122. }
  123. return CGSizeMake(width, height);
  124. }
  125. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
  126. {
  127. return CGSizeMake(0, 0);
  128. }
  129. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
  130. {
  131. return CGSizeMake(0, 0);
  132. }
  133. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  134. {
  135. LDRankGoodCollectionCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
  136. LDBuyLimitGoodModel *model = self.goodsArr[indexPath.row];
  137. cell.model = model;
  138. return cell;
  139. }
  140. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  141. //详情
  142. LDBuyLimitGoodModel *model = self.goodsArr[indexPath.row];
  143. LDGoodDetailViewController *detailVC = [[LDGoodDetailViewController alloc] init];
  144. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithBuyLimitModel:model];
  145. detailVC.requestModel = requestModel;
  146. LDEventModel *evevtModel = [[LDEventModel alloc] initWithOrigin:model.origin category_id:@"0" source:HotSaleAction];
  147. detailVC.eventModel = evevtModel;
  148. [self.navigationController pushViewController:detailVC animated:YES];
  149. }
  150. #pragma mark -------------
  151. - (NSMutableArray *)goodsArr {
  152. if (!_goodsArr) {
  153. _goodsArr = [NSMutableArray array];
  154. }
  155. return _goodsArr;
  156. }
  157. - (void)didReceiveMemoryWarning {
  158. [super didReceiveMemoryWarning];
  159. // Dispose of any resources that can be recreated.
  160. }
  161. /*
  162. #pragma mark - Navigation
  163. // In a storyboard-based application, you will often want to do a little preparation before navigation
  164. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  165. // Get the new view controller using [segue destinationViewController].
  166. // Pass the selected object to the new view controller.
  167. }
  168. */
  169. @end