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

DRSimilarGoodsController.m 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. //
  2. // DRSimilarGoodsController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/2/2.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRSimilarGoodsController.h"
  9. #import "DRGoodCollectionCell.h"
  10. #import "DRGoodDetailViewController.h"
  11. static NSString *cellID = @"DRGoodCollectionCell";
  12. @interface DRSimilarGoodsController ()<UICollectionViewDelegate,UICollectionViewDataSource>
  13. {
  14. }
  15. @property (nonatomic, strong) UICollectionView *collectionView;
  16. @property (nonatomic, strong) NSMutableArray *goodsArr;
  17. @end
  18. @implementation DRSimilarGoodsController
  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:[DRGoodCollectionCell 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. [DRHttp post:SimilarGoods params:para success:^(id json) {
  58. NSArray *list = [NSArray yy_modelArrayWithClass:[DRChildGoodModel 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. DRChildGoodModel *model = self.goodsArr[indexPath.row];
  75. CGFloat width = (SCREEN_WIDTH-5)/2;
  76. CGFloat height = width + 112;
  77. if (model.commission_price.length > 0) {
  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. DRGoodCollectionCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
  92. DRChildGoodModel *model = self.goodsArr[indexPath.row];
  93. cell.model = model;
  94. return cell;
  95. }
  96. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  97. DRChildGoodModel *model = self.goodsArr[indexPath.row];
  98. //详情
  99. DRGoodDetailViewController *detailVC = [[DRGoodDetailViewController alloc] init];
  100. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithChildModel:model];
  101. detailVC.requestModel = requestModel;
  102. DREventModel *evevtModel = [[DREventModel 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