猎豆优选

LDHistoryViewController.m 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. //
  2. // LDHistoryViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/6/11.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LDHistoryViewController.h"
  9. #import "LDGoodHorzitolCollectionCell.h"
  10. #import "LDChildGoodModel.h"
  11. #import "LDHistoryHeaderView.h"
  12. #import "LDNoDataView.h"
  13. static NSString *KHorizontalCellId = @"KHorizontalCellId";
  14. static NSString *KHeaderId = @"KHeaderId";
  15. @interface LDHistoryViewController ()<UICollectionViewDelegate, UICollectionViewDataSource>
  16. {
  17. NSInteger _page;
  18. }
  19. @property (nonatomic, strong) UICollectionView *collectionView;
  20. @property (nonatomic, strong) NSMutableArray *historyDataArr;
  21. @property (nonatomic, strong) LDNoDataView *noDataView;
  22. @end
  23. @implementation LDHistoryViewController
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. [self configCollectionView];
  27. [self requestData];
  28. }
  29. - (void)configCollectionView {
  30. _page = 1;
  31. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
  32. self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight-40) collectionViewLayout:flowLayout];
  33. flowLayout.minimumInteritemSpacing = 2;
  34. [self.collectionView registerClass:[LDGoodHorzitolCollectionCell class] forCellWithReuseIdentifier:KHorizontalCellId];
  35. [self.collectionView registerClass:[LDHistoryHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KHeaderId];
  36. self.collectionView.backgroundColor = [UIColor whiteColor];
  37. self.collectionView.showsVerticalScrollIndicator = NO;
  38. self.collectionView.delegate = self;
  39. self.collectionView.dataSource = self;
  40. self.collectionView.bounces = YES;
  41. // self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  42. //
  43. // }];
  44. [self.view addSubview:self.collectionView];
  45. [self.collectionView addSubview:self.noDataView];
  46. }
  47. - (void)requestData {
  48. NSString *url = [NSString stringWithFormat:@"%@/api/v2/brower/recordList",BaseURL];
  49. [LDHttp post:url params:nil success:^(id json) {
  50. NSArray *array = json[@"data"];
  51. for (NSArray *childArr in array) {
  52. NSArray *list = [NSArray yy_modelArrayWithClass:[LDChildGoodModel class] json:childArr];
  53. [self.historyDataArr addObject:list];
  54. }
  55. [self setNoDataView];
  56. [self.collectionView reloadData];
  57. } failure:^(NSError *error) {
  58. }];
  59. }
  60. - (void)setNoDataView {
  61. if (self.historyDataArr.count > 0) {
  62. NSArray *list = self.historyDataArr.firstObject;
  63. self.noDataView.hidden = list.count > 0;
  64. }else {
  65. self.noDataView.hidden = NO;
  66. }
  67. }
  68. #pragma mark ============ UICollectionView Delegate && DataSource ==========
  69. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  70. {
  71. NSArray *arr = self.historyDataArr[section];
  72. return arr.count;
  73. }
  74. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  75. return self.historyDataArr.count;
  76. }
  77. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  78. return CGSizeMake(SCREEN_WIDTH, 140);
  79. }
  80. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
  81. return 1;
  82. }
  83. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
  84. {
  85. return CGSizeMake(SCREEN_WIDTH, 40);
  86. }
  87. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
  88. {
  89. return CGSizeMake(0, 0);
  90. }
  91. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  92. {
  93. LDChildGoodModel *model = self.historyDataArr[indexPath.section][indexPath.row];
  94. LDGoodHorzitolCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:KHorizontalCellId forIndexPath:indexPath];
  95. cell.model = model;
  96. return cell;
  97. }
  98. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
  99. LDHistoryHeaderView *header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KHeaderId forIndexPath:indexPath];
  100. LDChildGoodModel *model = self.historyDataArr[indexPath.section][indexPath.row];
  101. [header setDateWith:model.add_time];
  102. return header;
  103. }
  104. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  105. LDGoodDetailViewController *detail = [[LDGoodDetailViewController alloc] init];
  106. LDChildGoodModel *model = self.historyDataArr[indexPath.section][indexPath.row];
  107. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithId:model.goods_id
  108. is_coupon:model.is_coupon
  109. coupon_price:model.coupon_price
  110. price:model.price
  111. discount_price:model.discount_price
  112. commission_rate:model.commission_rate
  113. coupon_start_time:model.coupon_start_time
  114. coupon_end_time:model.coupon_end_time
  115. coupon_id:model.coupon_id];
  116. detail.requestModel = requestModel;
  117. LDEventModel *evevtModel = [[LDEventModel alloc] initWithOrigin:@"0" category_id:@"0" source:collectAction];
  118. detail.eventModel = evevtModel;
  119. [self.navigationController pushViewController:detail animated:YES];
  120. }
  121. - (NSMutableArray *)historyDataArr {
  122. if (!_historyDataArr) {
  123. _historyDataArr = [NSMutableArray array];
  124. }
  125. return _historyDataArr;
  126. }
  127. - (LDNoDataView *)noDataView {
  128. if (!_noDataView) {
  129. _noDataView = [[LDNoDataView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 264)];
  130. _noDataView.hidden = YES;
  131. _noDataView.center = self.collectionView.center;
  132. }
  133. return _noDataView;
  134. }
  135. - (void)didReceiveMemoryWarning {
  136. [super didReceiveMemoryWarning];
  137. // Dispose of any resources that can be recreated.
  138. }
  139. /*
  140. #pragma mark - Navigation
  141. // In a storyboard-based application, you will often want to do a little preparation before navigation
  142. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  143. // Get the new view controller using [segue destinationViewController].
  144. // Pass the selected object to the new view controller.
  145. }
  146. */
  147. @end