新UI马甲包

HCSimilarGoodsController.m 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. //
  2. // HCSimilarGoodsController.m
  3. // hc
  4. //
  5. // Created by hc on 2018/2/2.
  6. // Copyright © 2018年 hc. All rights reserved.
  7. //
  8. #import "HCSimilarGoodsController.h"
  9. #import "HCGoodCollectionCell.h"
  10. #import "HCGoodDetailViewController.h"
  11. static NSString *cellID = @"HCGoodCollectionCell";
  12. @interface HCSimilarGoodsController ()<UICollectionViewDelegate,UICollectionViewDataSource>
  13. {
  14. }
  15. @property (nonatomic, strong) UICollectionView *collectionView;
  16. @property (nonatomic, strong) NSMutableArray *goodsArr;
  17. @end
  18. @implementation HCSimilarGoodsController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. [self configNavigationBar];
  22. [self configCollectionView];
  23. [self loadCategoryGoodsList];
  24. }
  25. - (void)configNavigationBar {
  26. self.view.backgroundColor = [UIColor whiteColor];
  27. [self.navigationBar setNavTitle:@"相似推荐"];
  28. self.navigationBar.showNavigationBarBottomLine = YES;
  29. UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  30. [leftBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
  31. [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  32. [self.navigationBar setCustomLeftButtons:@[leftBtn]];
  33. [self.navigationBar setShowNavigationBarBottomLine:YES];
  34. }
  35. - (void)configCollectionView {
  36. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
  37. CGFloat width = (SCREEN_WIDTH-5)/2;
  38. flowLayout.minimumLineSpacing = 5;
  39. flowLayout.minimumInteritemSpacing = 0;
  40. flowLayout.headerReferenceSize = CGSizeMake(0, 0);
  41. self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight) collectionViewLayout:flowLayout];
  42. [self.collectionView registerClass:[HCGoodCollectionCell class] forCellWithReuseIdentifier:cellID];
  43. self.collectionView.backgroundColor = [UIColor YHColorWithHex:0xf6f6f6];
  44. self.collectionView.showsVerticalScrollIndicator = NO;
  45. self.collectionView.delegate = self;
  46. self.collectionView.dataSource = self;
  47. [self.view addSubview: self.collectionView];
  48. }
  49. - (void)backAction {
  50. [self.navigationController popViewControllerAnimated:YES];
  51. }
  52. /**
  53. 加载下部商品列表
  54. */
  55. - (void)loadCategoryGoodsList {
  56. NSDictionary *para = @{@"goods_id":self.goods_id};
  57. [HCHttp post:SimilarGoods params:para success:^(id json) {
  58. NSArray *list = [NSArray yy_modelArrayWithClass:[HCChildGoodModel class] json:json];
  59. [self.goodsArr addObjectsFromArray:list];
  60. [self.collectionView reloadData];
  61. if (self.goodsArr.count == 0) {
  62. [SVProgressHUD showInfoWithStatus:@"暂无数据"];
  63. }
  64. } failure:^(NSError *error) {
  65. [SVProgressHUD showInfoWithStatus:@"暂无数据"];
  66. }];
  67. }
  68. #pragma mark ============ UICollectionView Delegate && DataSource ==========
  69. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  70. {
  71. return self.goodsArr.count;
  72. }
  73. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  74. CGFloat width = (SCREEN_WIDTH-5)/2;
  75. CGFloat height = width + 102;
  76. return CGSizeMake(width, height);
  77. }
  78. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
  79. {
  80. return CGSizeMake(0, 0);
  81. }
  82. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
  83. {
  84. return CGSizeMake(0, 0);
  85. }
  86. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  87. {
  88. HCGoodCollectionCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
  89. HCChildGoodModel *model = self.goodsArr[indexPath.row];
  90. cell.model = model;
  91. return cell;
  92. }
  93. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  94. HCChildGoodModel *model = self.goodsArr[indexPath.row];
  95. //详情
  96. HCGoodDetailViewController *detailVC = [[HCGoodDetailViewController alloc] init];
  97. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithChildModel:model];
  98. detailVC.requestModel = requestModel;
  99. HCEventModel *evevtModel = [[HCEventModel alloc] initWithOrigin:@"0" category_id:@"0" source:sameCouponAction];
  100. detailVC.eventModel = evevtModel;
  101. [self.navigationController pushViewController:detailVC animated:YES];
  102. }
  103. #pragma mark -------------
  104. - (NSMutableArray *)goodsArr {
  105. if (!_goodsArr) {
  106. _goodsArr = [NSMutableArray array];
  107. }
  108. return _goodsArr;
  109. }
  110. - (void)didReceiveMemoryWarning {
  111. [super didReceiveMemoryWarning];
  112. // Dispose of any resources that can be recreated.
  113. }
  114. /*
  115. #pragma mark - Navigation
  116. // In a storyboard-based application, you will often want to do a little preparation before navigation
  117. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  118. // Get the new view controller using [segue destinationViewController].
  119. // Pass the selected object to the new view controller.
  120. }
  121. */
  122. @end