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

DRRankListViewController.m 6.9KB

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