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

DRClassifyListController.m 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. //
  2. // DRClassifyListController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/9.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRClassifyListController.h"
  9. #import "DRGoodCollectionCell.h"
  10. #import "DRGoodDetailViewController.h"
  11. #import "DRTypeButtonHeader.h"
  12. #import "DRGoodDetailViewController.h"
  13. #import "DRChildFilterView.h"
  14. static NSString *cellID = @"DRGoodCollectionCell";
  15. #define KHeaderBarHeight 80
  16. @interface DRClassifyListController ()
  17. <
  18. UICollectionViewDelegate,
  19. UICollectionViewDataSource,
  20. JC_SelectViewDelegate,
  21. UICollectionViewDelegateFlowLayout
  22. >
  23. {
  24. NSInteger _page;
  25. NSInteger _type;
  26. NSInteger _is_has_coupon;
  27. }
  28. @property (nonatomic, strong) UICollectionView *collectionView;
  29. @property (nonatomic, strong) NSMutableArray *goodsArr;
  30. @property (nonatomic, strong) DRChildFilterView *filterView;
  31. @end
  32. @implementation DRClassifyListController
  33. - (void)viewDidLoad {
  34. [super viewDidLoad];
  35. [self configNavigationBar];
  36. [self configParam];
  37. [self configCollectionView];
  38. [self loadCategoryGoodsList:NO switchButton:nil];
  39. }
  40. - (void)viewWillDisappear:(BOOL)animated {
  41. [super viewWillDisappear:animated];
  42. [SVProgressHUD dismiss];
  43. }
  44. #pragma mark - HUD
  45. - (void)configParam {
  46. _page = 1;
  47. _type = 1; //默认请求推荐的数据
  48. _is_has_coupon = 0;
  49. }
  50. - (void)configNavigationBar {
  51. self.view.backgroundColor = [UIColor whiteColor];
  52. [self.navigationBar setNavTitle:self.name];
  53. UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  54. [leftBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
  55. [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  56. [self.navigationBar setCustomLeftButtons:@[leftBtn]];
  57. [self.navigationBar setShowNavigationBarBottomLine:YES];
  58. }
  59. - (void)configCollectionView {
  60. self.filterView = [[DRChildFilterView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, KHeaderBarHeight) withArr:nil];
  61. self.filterView.delegate = self;
  62. [self.view addSubview:self.filterView];
  63. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
  64. flowLayout.minimumLineSpacing = 5;
  65. flowLayout.minimumInteritemSpacing = 0;
  66. flowLayout.headerReferenceSize = CGSizeMake(0, 0);
  67. self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, NavBarHeight+KHeaderBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight) collectionViewLayout:flowLayout];
  68. [self.collectionView registerClass:[DRGoodCollectionCell class] forCellWithReuseIdentifier:cellID];
  69. self.collectionView.backgroundColor = [UIColor YHColorWithHex:0xf6f6f6];
  70. self.collectionView.showsVerticalScrollIndicator = NO;
  71. self.collectionView.delegate = self;
  72. self.collectionView.dataSource = self;
  73. self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  74. [self loadMoreData];
  75. }];
  76. [self.view addSubview: self.collectionView];
  77. }
  78. - (void)backAction {
  79. [self.navigationController popViewControllerAnimated:YES];
  80. }
  81. #pragma mark ----
  82. #pragma mark JC_SelectViewDelegate
  83. //仅显示优惠券
  84. - (void)selectItme:(DRChildFilterView *)selectView onlyTicketClick:(UIButton *)switchBtn {
  85. _is_has_coupon = switchBtn.selected ? 0 : 1;
  86. [self loadCategoryGoodsList:YES switchButton:switchBtn];
  87. }
  88. //上方条件选择
  89. - (void)selectTopButton:(DRChildFilterView *)selectView withIndex:(NSInteger)index withButtonType:(JCButtonClickType )type1{
  90. [self.collectionView scrollToTop];
  91. //价格
  92. if (index == 2&&type1) {
  93. switch (type1) {
  94. case JCButtonClickTypeNormal:
  95. //正常价格
  96. {
  97. NSLog(@"上边按钮的正常价格");
  98. }
  99. break;
  100. case JCButtonClickTypeUp:
  101. //价格升序排列
  102. {
  103. NSLog(@"上边按钮的价格升序排列");
  104. _type = 3;
  105. }
  106. break;
  107. case JCButtonClickTypeDown:
  108. //价格降序排列
  109. {
  110. NSLog(@"上边按钮的价格降序排列");
  111. _type = 4;
  112. }
  113. break;
  114. default:
  115. break;
  116. }
  117. }else if (index == 0){//综合
  118. NSLog(@"上边按钮的综合");
  119. _type = 1;
  120. }else if (index == 1){//销量
  121. NSLog(@"上边按钮的销量");
  122. _type = 2;
  123. }else{//筛选
  124. NSLog(@"上边按钮的筛选");
  125. }
  126. _page = 1;
  127. [self.collectionView.mj_footer resetNoMoreData];
  128. [self loadCategoryGoodsList:YES switchButton:nil];
  129. }
  130. /**
  131. 上拉加载
  132. */
  133. - (void)loadMoreData {
  134. _page++;
  135. [self loadCategoryGoodsList:NO switchButton:nil];
  136. }
  137. /**
  138. 加载下部商品列表
  139. */
  140. - (void)loadCategoryGoodsList:(BOOL)refresh switchButton:(UIButton *)switchButton{
  141. if (![self.collectionView.mj_footer isRefreshing]) {
  142. [SVProgressHUD show];
  143. }
  144. NSDictionary *para = @{@"page":@(_page),
  145. @"category_id":self.firstCategoryId,
  146. @"sort":@(_type),
  147. @"sub_category_id":self.cate_id,
  148. @"stype":@"0",
  149. @"is_has_coupon":@(_is_has_coupon)
  150. };
  151. [DRHttp post:StocklistByCategoryId params:para success:^(id json) {
  152. if (refresh) [self.goodsArr removeAllObjects];
  153. NSArray *list = [NSArray yy_modelArrayWithClass:[DRChildGoodModel class] json:json[@"data"]];
  154. [self.goodsArr addObjectsFromArray:list];
  155. [self.collectionView reloadData];
  156. if (list.count > 0) {
  157. [self.collectionView.mj_footer endRefreshing];
  158. }else {
  159. [self.collectionView.mj_footer endRefreshingWithNoMoreData];
  160. }
  161. [SVProgressHUD dismiss];
  162. switchButton.selected = !switchButton.selected;
  163. } failure:^(NSError *error) {
  164. [self.collectionView.mj_footer endRefreshing];
  165. [SVProgressHUD dismiss];
  166. [MBProgressHUD showMessage:@"加载失败"];
  167. }];
  168. }
  169. #pragma mark - scrollView
  170. - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  171. {
  172. //scrollView已经有拖拽手势,直接拿到scrollView的拖拽手势
  173. UIPanGestureRecognizer *pan = scrollView.panGestureRecognizer;
  174. //获取到拖拽的速度 >0 向下拖动 <0 向上拖动
  175. CGFloat velocity = [pan velocityInView:scrollView].y;
  176. if (velocity <- 10) {
  177. //向上拖动,隐藏导航栏
  178. if (self.navigationBar.y == -NavBarHeight) {
  179. return;
  180. }
  181. [UIView animateWithDuration:0.15 animations:^{
  182. self.navigationBar.y = -NavBarHeight;
  183. self.filterView.y = KStatusBarHeight;
  184. self.collectionView.y = KStatusBarHeight + KHeaderBarHeight;
  185. self.collectionView.height = SCREEN_HEIGHT-KHeaderBarHeight-KStatusBarHeight;
  186. }];
  187. }else if (velocity > 10) {
  188. //向下拖动,显示导航栏
  189. if (self.navigationBar.y == 0) {
  190. return;
  191. }
  192. [UIView animateWithDuration:0.15 animations:^{
  193. self.navigationBar.y = 0;
  194. self.filterView.y = NavBarHeight;
  195. self.collectionView.y = NavBarHeight + KHeaderBarHeight;
  196. }];
  197. }else if(velocity == 0){
  198. //停止拖拽
  199. }
  200. }
  201. #pragma mark ============ UICollectionView Delegate && DataSource ==========
  202. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  203. {
  204. return self.goodsArr.count;
  205. }
  206. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  207. DRChildGoodModel *model = self.goodsArr[indexPath.row];
  208. CGFloat width = (SCREEN_WIDTH-5)/2;
  209. CGFloat height = width + 112;
  210. if (model.commission_price.length > 0) {
  211. }
  212. return CGSizeMake(width, height);
  213. }
  214. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
  215. {
  216. return CGSizeMake(0, 0);
  217. }
  218. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
  219. {
  220. return CGSizeMake(0, 0);
  221. }
  222. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  223. {
  224. DRGoodCollectionCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
  225. DRChildGoodModel *model = self.goodsArr[indexPath.row];
  226. cell.model = model;
  227. return cell;
  228. }
  229. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  230. DRChildGoodModel *model = self.goodsArr[indexPath.row];
  231. //详情
  232. DRGoodDetailViewController *detailVC = [[DRGoodDetailViewController alloc] init];
  233. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithChildModel:model];
  234. detailVC.requestModel = requestModel;
  235. if (self.isOtherPage) {
  236. DREventModel *evevtModel = [[DREventModel alloc] initWithOrigin:model.origin category_id:self.cate_id source:HomeClassifyAction];
  237. detailVC.eventModel = evevtModel;
  238. }else {
  239. DREventModel *evevtModel = [[DREventModel alloc] initWithOrigin:model.origin category_id:self.cate_id source:ListClassifyAction];
  240. detailVC.eventModel = evevtModel;
  241. }
  242. [self.navigationController pushViewController:detailVC animated:YES];
  243. }
  244. #pragma mark -------------
  245. - (NSMutableArray *)goodsArr {
  246. if (!_goodsArr) {
  247. _goodsArr = [NSMutableArray array];
  248. }
  249. return _goodsArr;
  250. }
  251. - (void)didReceiveMemoryWarning {
  252. [super didReceiveMemoryWarning];
  253. // Dispose of any resources that can be recreated.
  254. }
  255. /*
  256. #pragma mark - Navigation
  257. // In a storyboard-based application, you will often want to do a little preparation before navigation
  258. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  259. // Get the new view controller using [segue destinationViewController].
  260. // Pass the selected object to the new view controller.
  261. }
  262. */
  263. @end