酷店

KDPProjectListVC.m 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //
  2. // KDPProjectListVC.m
  3. // KuDianProject
  4. //
  5. // Created by 学丽 on 2019/7/10.
  6. // Copyright © 2019 KDP. All rights reserved.
  7. //
  8. #import "KDPProjectListVC.h"
  9. @interface KDPProjectListVC ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,DZNEmptyDataSetDelegate,DZNEmptyDataSetSource>
  10. @property(nonatomic,strong)UICollectionView *listview;
  11. @property(nonatomic,assign)NSInteger pageNum;
  12. @property(nonatomic,strong)NSMutableArray *dataArray;
  13. @end
  14. @implementation KDPProjectListVC
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. self.pageNum=1;
  18. [self.navBar addleftReturnButton:self selector:@selector(returnClickBtn)];
  19. self.view.backgroundColor=[UIColor whiteColor];
  20. [self.view addSubview:self.listview];
  21. [self.listview mas_makeConstraints:^(MASConstraintMaker *make) {
  22. make.left.mas_equalTo(0);
  23. make.top.mas_equalTo(KDNavBarHeight);
  24. make.height.mas_equalTo(SCREEN_HEIGHT-KDNavBarHeight);
  25. make.width.mas_equalTo(SCREEN_WIDTH);
  26. }];
  27. [self goodListProject];
  28. }
  29. -(void)goodListProject
  30. {
  31. [LoadingView show];
  32. NSDictionary *dics =@{@"page":@(self.pageNum),@"id":self.projectID,@"type":self.type,@"start_price":@"",@"end_price":@"",@"start_tk_rate":@""};
  33. [KDPNetworkRequestHTTP postURL:projectGoodURL params:dics success:^(id _Nonnull json) {
  34. [LoadingView dismiss];
  35. if (self.pageNum == 1) {
  36. [self.dataArray removeAllObjects];
  37. }
  38. NSArray *array =[NSArray yy_modelArrayWithClass:[KDPGoodsModel class] json:json[@"data"]];
  39. [self.listview.mj_header endRefreshing];
  40. [self.listview.mj_footer endRefreshing];
  41. if (array.count == 0) {
  42. [self.listview.mj_footer endRefreshingWithNoMoreData];
  43. }
  44. [self.dataArray addObjectsFromArray:array];
  45. [self.listview reloadData];
  46. } failure:^(NSError * _Nonnull error) {
  47. [LoadingView dismiss];
  48. }];
  49. }
  50. #pragma mark---CollectDelegate&&DataSource
  51. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  52. {
  53. KDPRecommendGoodCell *recommC=[collectionView dequeueReusableCellWithReuseIdentifier:@"recomm" forIndexPath:indexPath];
  54. recommC.model=self.dataArray[indexPath.row];
  55. return recommC;
  56. }
  57. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  58. {
  59. return self.dataArray.count;
  60. }
  61. -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  62. {
  63. return 1;
  64. }
  65. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  66. {
  67. return CGSizeMake(SCREEN_WIDTH, 121);
  68. }
  69. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  70. {
  71. KDPGoodDetailVC *goodDetail=[[KDPGoodDetailVC alloc]init];
  72. goodDetail.model=self.dataArray[indexPath.row];
  73. [self.navigationController pushViewController:goodDetail animated:YES];
  74. }
  75. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView{
  76. return [UIImage imageNamed:@"no_order"];
  77. }
  78. - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{
  79. return YES;
  80. }
  81. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView{
  82. return [[NSAttributedString alloc] initWithString:@"还没有记录" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x333333],NSFontAttributeName:FONT_SYS(12)}];
  83. }
  84. - (CGFloat )spaceHeightForEmptyDataSet:(UIScrollView *)scrollView{
  85. return 30;
  86. }
  87. -(void)returnClickBtn
  88. {
  89. [self.navigationController popViewControllerAnimated:YES];
  90. }
  91. -(void)viewWillAppear:(BOOL)animated
  92. {
  93. [super viewWillAppear:animated];
  94. self.navigationController.navigationBar.hidden=YES;
  95. self.tabBarController.tabBar.hidden=YES;
  96. }
  97. -(void)viewWillDisappear:(BOOL)animated
  98. {
  99. [super viewWillDisappear:animated];
  100. self.tabBarController.tabBar.hidden=NO;
  101. }
  102. -(UICollectionView *)listview
  103. {
  104. if (!_listview) {
  105. UICollectionViewFlowLayout *layout =[[UICollectionViewFlowLayout alloc]init];
  106. layout.minimumLineSpacing=0;
  107. layout.minimumInteritemSpacing=0;
  108. _listview=[[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) collectionViewLayout:layout];
  109. _listview.showsVerticalScrollIndicator=NO;
  110. _listview.backgroundColor=[UIColor whiteColor];
  111. _listview.delegate=self;
  112. if (@available(iOS 11.0, *)) {
  113. _listview.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  114. } else {
  115. self.automaticallyAdjustsScrollViewInsets = NO;
  116. }
  117. _listview.dataSource=self;
  118. [_listview registerClass:[KDPRecommendGoodCell class] forCellWithReuseIdentifier:@"recomm"];
  119. _listview.mj_header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{
  120. self.pageNum = 1;
  121. [self goodListProject];
  122. }];
  123. _listview.emptyDataSetDelegate = self;
  124. _listview.emptyDataSetSource = self;
  125. _listview.mj_footer=[MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  126. self.pageNum++;
  127. [self goodListProject];
  128. }];
  129. }
  130. return _listview;
  131. }
  132. -(NSMutableArray *)dataArray
  133. {
  134. if (!_dataArray) {
  135. _dataArray=[NSMutableArray array];
  136. }
  137. return _dataArray;
  138. }
  139. @end