酷店

KDPSupplyListViewController.m 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. //
  2. // KDPSupplyListViewController.m
  3. // KuDianProject
  4. //
  5. // Created by admin on 2019/7/11.
  6. // Copyright © 2019 KDP. All rights reserved.
  7. //
  8. #import "KDPSupplyListViewController.h"
  9. #import "KDPSupplyContentReusableView.h"
  10. #import "KDPRecommendGoodCell.h"
  11. #import "KDPScreenViewController.h"
  12. @interface KDPSupplyListViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,DZNEmptyDataSetDelegate,DZNEmptyDataSetSource>
  13. @property (nonatomic, strong) UICollectionView *collectionView;
  14. @property (nonatomic, strong) NSMutableArray *dataSource;
  15. @property (nonatomic, assign) NSInteger page;
  16. @property (nonatomic, strong) NSMutableDictionary *params;
  17. @end
  18. @implementation KDPSupplyListViewController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. // Do any additional setup after loading the view.
  22. [self setupNav];
  23. [self.view addSubview:self.collectionView];
  24. [self requestGoodData];
  25. }
  26. - (void)setupNav{
  27. self.navBar.backgroundColor = [UIColor whiteColor];
  28. UIButton *returnBtn =[[UIButton alloc]initWithFrame:CGRectMake(15, KDNavBarHeight - 13-18, 11, 18)];
  29. [returnBtn addTarget:self action:@selector(returnClickBtn) forControlEvents:UIControlEventTouchUpInside];
  30. [returnBtn setImage:[UIImage imageNamed:@"return_black"] forState:UIControlStateNormal];
  31. returnBtn.adjustsImageWhenHighlighted = NO;
  32. [self.navBar addSubview:returnBtn];
  33. self.navBar.navTitleLabel.textColor = [UIColor colorWithHex:0x333333];
  34. self.navBar.navTitleLabel.text = self.mode.name;
  35. }
  36. - (void)requestGoodData{
  37. if (![KDPAccountTool isLogin]) {
  38. return;
  39. }
  40. [self.params setValue:[NSString stringWithFormat:@"%ld",(long)self.page] forKey:@"page"];
  41. [LoadingView showInView:self.view];
  42. NSString *getGoodUrl = [NSString stringWithFormat:@"%@api/goods/search",KDURL];
  43. [KDPNetworkRequestHTTP postURL:getGoodUrl params:self.params success:^(id _Nonnull json) {
  44. [LoadingView dismiss];
  45. NSArray *dataArr = [NSArray yy_modelArrayWithClass:[KDPGoodsModel class] json:json[@"data"]];
  46. if (self.page == 1) {
  47. [self.dataSource removeAllObjects];
  48. }
  49. if (dataArr.count > 0) {
  50. [self.dataSource addObjectsFromArray:dataArr];
  51. } else{
  52. [self.collectionView.mj_footer endRefreshingWithNoMoreData];
  53. }
  54. [self.collectionView.mj_footer endRefreshing];
  55. [self.collectionView.mj_header endRefreshing];
  56. [self.collectionView reloadData];
  57. } failure:^(NSError * _Nonnull error) {
  58. [LoadingView dismiss];
  59. }];
  60. }
  61. - (void)returnClickBtn{
  62. [self.navigationController popViewControllerAnimated:YES];
  63. }
  64. - (void)viewWillAppear:(BOOL)animated{
  65. [super viewWillAppear:animated];
  66. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
  67. }
  68. - (void)viewWillDisappear:(BOOL)animated{
  69. [super viewWillDisappear:animated];
  70. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
  71. }
  72. - (UICollectionView *)collectionView{
  73. if (!_collectionView) {
  74. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  75. flowLayout.itemSize = CGSizeMake(SCREEN_WIDTH, 130);
  76. flowLayout.minimumLineSpacing = 0;
  77. flowLayout.minimumInteritemSpacing = 0;
  78. flowLayout.sectionHeadersPinToVisibleBounds = YES;
  79. _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, KDNavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-KDNavBarHeight) collectionViewLayout:flowLayout];
  80. _collectionView.showsVerticalScrollIndicator = NO;
  81. _collectionView.showsHorizontalScrollIndicator = NO;
  82. [_collectionView registerClass:[KDPRecommendGoodCell class] forCellWithReuseIdentifier:NSStringFromClass([KDPRecommendGoodCell class])];
  83. [_collectionView registerClass:[KDPSupplyContentReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass([KDPSupplyContentReusableView class])];
  84. _collectionView.backgroundColor = [UIColor whiteColor];
  85. _collectionView.delegate = self;
  86. _collectionView.dataSource = self;
  87. _collectionView.emptyDataSetDelegate = self;
  88. _collectionView.emptyDataSetSource = self;
  89. _collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  90. self.page = 1;
  91. [self requestGoodData];
  92. }];
  93. if (@available(iOS 11.0, *)) {
  94. _collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  95. } else {
  96. self.automaticallyAdjustsScrollViewInsets = NO;
  97. }
  98. _collectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  99. self.page ++;
  100. [self requestGoodData];
  101. }];
  102. }
  103. return _collectionView;
  104. }
  105. - (NSMutableArray *)dataSource{
  106. if (!_dataSource) {
  107. _dataSource = [NSMutableArray array];
  108. }
  109. return _dataSource;
  110. }
  111. - (NSMutableDictionary *)params{
  112. if (!_params) {
  113. _params = [NSMutableDictionary dictionaryWithDictionary:@{@"page":@(self.page),@"id":self.mode.Id,@"type":self.mode.type,@"start_price":@"",@"end_price":@"",@"start_tk_rate":@""}];
  114. }
  115. return _params;
  116. }
  117. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
  118. KDPSupplyContentReusableView *reusAbleView;
  119. if (kind == UICollectionElementKindSectionHeader) {
  120. reusAbleView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass([KDPSupplyContentReusableView class]) forIndexPath:indexPath];
  121. reusAbleView.layer.borderColor = [UIColor colorWithHex:0xf4f4f4].CGColor;
  122. reusAbleView.layer.borderWidth = 0.5;
  123. WeakSelf(weakSelf);
  124. __weak KDPSupplyContentReusableView *weakReusAbleView = reusAbleView;
  125. reusAbleView.changeBlock = ^(BOOL isPrice) {
  126. KDPScreenViewController *screenVC = [[KDPScreenViewController alloc] initWithPrice:isPrice];
  127. screenVC.params = weakSelf.params;
  128. screenVC.resetBlock = ^(BOOL isPrice) {
  129. if (isPrice == YES) {
  130. [weakReusAbleView changeScreeWithStyle:KDPSupplyContentButtonStylePrice Color:[UIColor colorWithHex:0x333333] text:@"价格筛选"];
  131. [self.params setValue:@"" forKey:@"start_price"];
  132. [self.params setValue:@"" forKey:@"end_price"];
  133. } else{
  134. [weakReusAbleView changeScreeWithStyle:KDPSupplyContentButtonStyleProfit Color:[UIColor colorWithHex:0x333333] text:@"利润筛选"];
  135. [self.params setValue:@"" forKey:@"start_tk_rate"];
  136. }
  137. [weakSelf.collectionView.mj_header beginRefreshing];
  138. };
  139. screenVC.profitBlock = ^(NSString *baseScale) {
  140. if (!baseScale.length) {
  141. [weakReusAbleView changeScreeWithStyle:KDPSupplyContentButtonStyleProfit Color:[UIColor colorWithHex:0x333333] text:[NSString stringWithFormat:@"利润筛选"]];
  142. [self.params setValue:@"" forKey:@"start_tk_rate"];
  143. } else{
  144. [weakReusAbleView changeScreeWithStyle:KDPSupplyContentButtonStyleProfit Color:[UIColor baseColor] text:[NSString stringWithFormat:@"佣金%@%%以上",baseScale]];
  145. [self.params setValue:baseScale forKey:@"start_tk_rate"];
  146. }
  147. [weakSelf.collectionView.mj_header beginRefreshing];
  148. };
  149. screenVC.priceBlock = ^(NSString *minPrice, NSString *maxPrice) {
  150. if (minPrice.length != 0 || maxPrice.length != 0) {
  151. if (minPrice.length == 0) {
  152. minPrice = @"0";
  153. }
  154. NSString *price=[NSString stringWithFormat:@"价格%@-%@元",minPrice,maxPrice];
  155. if (maxPrice.integerValue == 0 || [maxPrice intValue] <= [minPrice intValue]) {
  156. price=[NSString stringWithFormat:@"价格%@元以上",minPrice];
  157. maxPrice = @"";
  158. }
  159. [weakReusAbleView changeScreeWithStyle:KDPSupplyContentButtonStylePrice Color:[UIColor baseColor] text:price];
  160. } else{
  161. [weakReusAbleView changeScreeWithStyle:KDPSupplyContentButtonStylePrice Color:[UIColor colorWithHex:0x333333] text:@"价格筛选"];
  162. }
  163. [weakSelf.params setValue:minPrice forKey:@"start_price"];
  164. [weakSelf.params setValue:maxPrice forKey:@"end_price"];
  165. [weakSelf.collectionView.mj_header beginRefreshing];
  166. };
  167. CWLateralSlideConfiguration *conf = [CWLateralSlideConfiguration configurationWithDistance:0 maskAlpha:0.7 scaleY:1 direction:CWDrawerTransitionFromRight backImage:nil];
  168. conf.distance=SCREEN_WIDTH/3*2;
  169. [weakSelf cw_showDrawerViewController:screenVC animationType:0 configuration:conf];
  170. };
  171. return reusAbleView;
  172. }
  173. return reusAbleView;
  174. }
  175. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
  176. if (section == 0) {
  177. return CGSizeMake(SCREEN_WIDTH, 33);
  178. }
  179. return CGSizeZero;
  180. }
  181. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  182. return 1;
  183. }
  184. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  185. return self.dataSource.count;
  186. }
  187. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  188. KDPRecommendGoodCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([KDPRecommendGoodCell class]) forIndexPath:indexPath];
  189. cell.model = self.dataSource[indexPath.row];
  190. return cell;
  191. }
  192. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView{
  193. return [UIImage imageNamed:@"no_order"];
  194. }
  195. - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{
  196. return YES;
  197. }
  198. - (CGFloat)spaceHeightForEmptyDataSet:(UIScrollView *)scrollView{
  199. return 50;
  200. }
  201. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView{
  202. return [[NSAttributedString alloc] initWithString:@"还没有记录" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x333333],NSFontAttributeName:FONT_SYS(12)}];
  203. }
  204. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  205. KDPGoodDetailVC *detailVC = [[KDPGoodDetailVC alloc] init];
  206. detailVC.model = self.dataSource[indexPath.row];
  207. [self.navigationController pushViewController:detailVC animated:YES];
  208. }
  209. @end