猎豆优选

LDSimilarGoodsController.m 5.4KB

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