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

DRHistoryViewController.m 7.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. //
  2. // DRHistoryViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/6/11.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRHistoryViewController.h"
  9. #import "DRGoodHorzitolCollectionCell.h"
  10. #import "DRGoodDetailViewController.h"
  11. #import "DRChildGoodModel.h"
  12. #import "DRHistoryHeaderView.h"
  13. #import "DRNoDataView.h"
  14. static NSString *KHorizontalCellId = @"KHorizontalCellId";
  15. static NSString *KHeaderId = @"KHeaderId";
  16. @interface DRHistoryViewController ()<UICollectionViewDelegate, UICollectionViewDataSource>
  17. {
  18. NSInteger _page;
  19. }
  20. @property (nonatomic, strong) UICollectionView *collectionView;
  21. @property (nonatomic, strong) NSMutableArray *historyDataArr;
  22. @property (nonatomic, strong) DRNoDataView *noDataView;
  23. @end
  24. @implementation DRHistoryViewController
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27. [self configCollectionView];
  28. [self requestData];
  29. }
  30. - (void)configCollectionView {
  31. _page = 1;
  32. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
  33. self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight-40) collectionViewLayout:flowLayout];
  34. flowLayout.minimumInteritemSpacing = 2;
  35. [self.collectionView registerClass:[DRGoodHorzitolCollectionCell class] forCellWithReuseIdentifier:KHorizontalCellId];
  36. [self.collectionView registerClass:[DRHistoryHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KHeaderId];
  37. self.collectionView.backgroundColor = [UIColor whiteColor];
  38. self.collectionView.showsVerticalScrollIndicator = NO;
  39. self.collectionView.delegate = self;
  40. self.collectionView.dataSource = self;
  41. self.collectionView.bounces = YES;
  42. // self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  43. //
  44. // }];
  45. [self.view addSubview:self.collectionView];
  46. [self.collectionView addSubview:self.noDataView];
  47. }
  48. - (void)requestData {
  49. NSString *url = [NSString stringWithFormat:@"%@/api/v2/brower/recordList",BaseURL];
  50. [DRHttp post:url params:nil success:^(id json) {
  51. NSArray *array = json[@"data"];
  52. for (NSArray *childArr in array) {
  53. NSArray *list = [NSArray yy_modelArrayWithClass:[DRChildGoodModel class] json:childArr];
  54. [self.historyDataArr addObject:list];
  55. }
  56. [self setNoDataView];
  57. [self.collectionView reloadData];
  58. } failure:^(NSError *error) {
  59. }];
  60. }
  61. - (void)setNoDataView {
  62. if (self.historyDataArr.count > 0) {
  63. NSArray *list = self.historyDataArr.firstObject;
  64. self.noDataView.hidden = list.count > 0;
  65. }else {
  66. self.noDataView.hidden = NO;
  67. }
  68. }
  69. #pragma mark ============ UICollectionView Delegate && DataSource ==========
  70. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  71. {
  72. NSArray *arr = self.historyDataArr[section];
  73. return arr.count;
  74. }
  75. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  76. return self.historyDataArr.count;
  77. }
  78. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  79. return CGSizeMake(SCREEN_WIDTH, 140);
  80. }
  81. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
  82. return 1;
  83. }
  84. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
  85. {
  86. return CGSizeMake(SCREEN_WIDTH, 40);
  87. }
  88. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
  89. {
  90. return CGSizeMake(0, 0);
  91. }
  92. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  93. {
  94. DRChildGoodModel *model = self.historyDataArr[indexPath.section][indexPath.row];
  95. DRGoodHorzitolCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:KHorizontalCellId forIndexPath:indexPath];
  96. cell.model = model;
  97. return cell;
  98. }
  99. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
  100. DRHistoryHeaderView *header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:KHeaderId forIndexPath:indexPath];
  101. DRChildGoodModel *model = self.historyDataArr[indexPath.section][indexPath.row];
  102. [header setDateWith:model.add_time];
  103. return header;
  104. }
  105. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  106. DRGoodDetailViewController *detail = [[DRGoodDetailViewController alloc] init];
  107. DRChildGoodModel *model = self.historyDataArr[indexPath.section][indexPath.row];
  108. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithId:model.goods_id
  109. is_coupon:model.is_coupon
  110. coupon_price:model.coupon_price
  111. price:model.price
  112. discount_price:model.discount_price
  113. commission_rate:model.commission_rate
  114. coupon_start_time:model.coupon_start_time
  115. coupon_end_time:model.coupon_end_time];
  116. detail.requestModel = requestModel;
  117. DREventModel *evevtModel = [[DREventModel 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. - (DRNoDataView *)noDataView {
  128. if (!_noDataView) {
  129. _noDataView = [[DRNoDataView 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