猎豆优选

LDFindSearchResultViewController.m 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. //
  2. // LDFindSearchResultViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by xiaoxi on 2018/2/1.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "LDFindSearchResultViewController.h"
  9. #import "LDGoodCollectionCell.h"
  10. #import "LDChildGoodModel.h"
  11. #import "LDGoodListViewController.h"
  12. #import "LDFindRequestViewModel.h"
  13. #import "LDCollectionView.h"
  14. #import "LDGoodHorzitolCollectionCell.h"
  15. #import "LDSearchNoDataView.h"
  16. #import "LDSearchTitleView.h"
  17. #import "SelectView.h"
  18. #import "AdPopModel.h"
  19. #import "LDSearchSpecialView.h"
  20. #import "AdJumpManager.h"
  21. #import "LDTodayHorizontalGoodCell.h"
  22. #import "LDSectionAllGoodView.h"
  23. static NSString *const cellID = @"LDGoodCollectionCell";
  24. static NSString *const HorzitolCellId = @"LDGoodHorzitolCollectionCell";
  25. static NSString *const collectionViewHeaderTop = @"top";
  26. static NSString *const collectionViewHeaderMiddle = @"middle";
  27. static NSString *const collectionViewHeaderAllgood = @"allgood";
  28. static NSString *const collectionViewSpecailHeader = @"specailHeader";
  29. //static BOOL isNoData = NO;
  30. static CGFloat selectedViewHeight = 80.f;
  31. typedef enum : NSUInteger {
  32. ResultCellTypeVertical,
  33. ResultCellTypeHorzitol,
  34. } ResultCellType;
  35. @interface LDFindSearchResultViewController ()
  36. <
  37. UICollectionViewDelegate,
  38. UICollectionViewDataSource,
  39. UICollectionViewDelegateFlowLayout,
  40. UIGestureRecognizerDelegate,
  41. YHSearchNoDataViewDelegate,
  42. NY_SelectViewDelegate
  43. >
  44. {
  45. NSString *_type; //1->默认 2->销量由高到低 3->价格由高到低 4->价格由低到高 5-综合筛选
  46. NSString *_maxPrice; //最高价格
  47. NSString *_minPrice; //最低价格
  48. NSInteger page;
  49. NSInteger guessYouLikePage;
  50. NSInteger _is_has_coupon;
  51. BOOL isNoData;
  52. }
  53. @property (nonatomic, strong) UICollectionView *collectionView;
  54. @property (nonatomic, strong) NSMutableArray *goodsArr;
  55. @property (nonatomic, strong) SelectView *selectedView;
  56. @property (nonatomic, assign) ResultCellType cellType;
  57. @property (nonatomic, strong) NSArray *filtrateArray;
  58. @property (nonatomic, strong) NSDictionary *special_search;
  59. @property (nonatomic, strong) AdPopModel *adModel;
  60. //大淘客的数据
  61. @property (nonatomic, strong) NSMutableArray *yorkerArray;
  62. @end
  63. @implementation LDFindSearchResultViewController
  64. - (void)viewDidLoad {
  65. [super viewDidLoad];
  66. [self requesFiltrateParam];
  67. [self configDefauleParamKey];
  68. [self initNavBar];
  69. [self initSubviews];
  70. }
  71. - (void)viewWillAppear:(BOOL)animated {
  72. [super viewWillAppear:animated];
  73. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
  74. self.navigationItem.hidesBackButton = YES;
  75. self.navigationController.navigationBar.hidden = NO;
  76. }
  77. - (void)viewWillDisappear:(BOOL)animated {
  78. [super viewWillDisappear:animated];
  79. self.navigationController.navigationBar.hidden = self.hiddenNavigationWhenPop;
  80. [LoadingView dismiss];
  81. }
  82. - (void)willMoveToParentViewController:(UIViewController *)parent {
  83. [super willMoveToParentViewController:parent];
  84. //处理侧滑手势
  85. if (!parent) {
  86. [self.navigationController setNavigationBarHidden:NO animated:NO];
  87. self.selectedView.y = 0;
  88. if (self.special_search) {
  89. self.collectionView.y = 0;
  90. self.collectionView.height = kScreenHeight-NavBarHeight;
  91. }else {
  92. self.collectionView.y = selectedViewHeight;
  93. self.collectionView.height = kScreenHeight-NavBarHeight-selectedViewHeight;
  94. }
  95. }
  96. }
  97. - (void)didReceiveMemoryWarning {
  98. [super didReceiveMemoryWarning];
  99. }
  100. - (void)configDefauleParamKey {
  101. page = 1;
  102. guessYouLikePage = 1;
  103. _type = @"1";
  104. _minPrice = @"0";
  105. _maxPrice = @"-1";
  106. }
  107. - (void)initNavBar {
  108. self.view.backgroundColor = [UIColor YHColorWithHex:0xf5f4f4];
  109. if ([self respondsToSelector:@selector(setAutomaticallyAdjustsScrollViewInsets:)]) {
  110. self.automaticallyAdjustsScrollViewInsets = YES;
  111. }
  112. UIView *statusBarBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, KStatusBarHeight)];
  113. statusBarBgView.backgroundColor = [UIColor whiteColor];
  114. // [self.view addSubview:statusBarBgView];
  115. UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
  116. [button setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
  117. [button setImageEdgeInsets:UIEdgeInsetsMake(0, -10, 0, 0)];
  118. [button addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  119. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
  120. UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
  121. [rightBtn setImage:[UIImage imageNamed:@"Vertical_items"] forState:UIControlStateNormal];
  122. [rightBtn setImage:[UIImage imageNamed:@"Horizontal_items"] forState:UIControlStateSelected];
  123. [rightBtn addTarget:self action:@selector(switchItemsType:) forControlEvents:UIControlEventTouchUpInside];
  124. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
  125. NSNumber *cellType = [[NSUserDefaults standardUserDefaults] objectForKey:@"ResultCellType"];
  126. if (cellType) {
  127. self.cellType = cellType.integerValue;
  128. }else {
  129. self.cellType = ResultCellTypeHorzitol;
  130. }
  131. rightBtn.selected = self.cellType==ResultCellTypeHorzitol?YES:NO;
  132. self.navigationController.interactivePopGestureRecognizer.delegate = (id<UIGestureRecognizerDelegate>)self;
  133. LDSearchTitleView *titleView = [[LDSearchTitleView alloc] initWithFrame:CGRectMake(0, 0, FITSIZE(270), 32) searchName:self.searchName click:^{
  134. [self backAction];
  135. }];
  136. titleView.closeBlock = ^{
  137. [self backAction];
  138. self.searchBar.text = nil;
  139. };
  140. self.navigationController.navigationBar.translucent = NO;
  141. self.navigationItem.titleView = titleView;
  142. }
  143. - (void)backAction {
  144. [self.navigationController popViewControllerAnimated:NO];
  145. }
  146. - (void)switchItemsType:(UIButton *)sender {
  147. sender.selected = !sender.selected;
  148. self.cellType = sender.selected ? ResultCellTypeHorzitol:ResultCellTypeVertical;
  149. [[NSUserDefaults standardUserDefaults] setObject:@(self.cellType) forKey:@"ResultCellType"];
  150. [[NSUserDefaults standardUserDefaults] synchronize];
  151. [self.collectionView reloadData];
  152. }
  153. - (void)initSubviews {
  154. [self.view addSubview:self.collectionView];
  155. // [self.view addSubview:self.selectedView];
  156. [LoadingView show];
  157. }
  158. #pragma mark - request
  159. /**
  160. 加载筛选范围
  161. */
  162. - (void)requesFiltrateParam {
  163. NSString *urlString = [NSString stringWithFormat:@"%@/api/categoryNew/priceSection", BaseURL];
  164. [LDHttp post:urlString params:nil success:^(id json) {
  165. self.filtrateArray = json[@"data"];
  166. [self requestVoucherFindIsRefresh:NO switchButton:nil];
  167. } failure:^(NSError *error) {
  168. }];
  169. }
  170. - (void)requestVoucherFindIsRefresh:(BOOL)refresh switchButton:(UIButton *)switchButton{
  171. NSDictionary *param = @{@"page":@(page),
  172. @"keyword":self.searchName,
  173. @"sort":_type,
  174. @"min_price":_minPrice,
  175. @"max_price":_maxPrice,
  176. @"is_has_coupon":@(_is_has_coupon)
  177. };
  178. NSString *urlString = [NSString stringWithFormat:@"%@/api/v2/goods/search", BaseURL];
  179. [LDHttp post:urlString params:param success:^(id json) {
  180. [self.view addSubview:self.selectedView];
  181. NSArray *arr = [NSArray yy_modelArrayWithClass:[LDChildGoodModel class] json:json[@"data"]];
  182. NSArray *haoArr = [NSArray yy_modelArrayWithClass:[LDChildGoodModel class] json:json[@"haoLists"]];
  183. self.special_search = json[@"special"];
  184. self.adModel = [AdPopModel yy_modelWithJSON:json[@"special"]];
  185. if (refresh) {
  186. [self.goodsArr removeAllObjects];
  187. [self.collectionView reloadData];
  188. [self.yorkerArray removeAllObjects];
  189. }
  190. //首先判断special_search有没有数据,如果没有再去判断商品列表
  191. if (self.special_search != nil) {
  192. self.selectedView.hidden = YES;
  193. self.collectionView.y = 0;
  194. self.collectionView.height = SCREEN_HEIGHT-NavBarHeight;
  195. [self.collectionView.mj_footer endRefreshingWithNoMoreData];
  196. if (page == 1) {
  197. [self requestGuessYouLike];
  198. }
  199. [self.collectionView reloadData];
  200. }else {
  201. if (arr.count > 0) {
  202. [self.collectionView.mj_footer endRefreshing];
  203. [self.goodsArr addObjectsFromArray:arr];
  204. if (self.yorkerArray.count ==0 ) {
  205. [self.yorkerArray addObjectsFromArray:haoArr];
  206. }
  207. [self.collectionView reloadData];
  208. if (page == 1) {
  209. isNoData = NO;
  210. self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  211. page ++;
  212. [self requestVoucherFindIsRefresh:NO switchButton:nil];
  213. }];
  214. self.collectionView.footRefreshState = MJFooterRefreshStateNormal;
  215. }
  216. }
  217. else {
  218. [self.collectionView.mj_footer endRefreshingWithNoMoreData];
  219. if (page == 1) {
  220. isNoData = YES;
  221. [self requestGuessYouLike];
  222. }
  223. }
  224. }
  225. [self.collectionView reloadData];
  226. [LoadingView dismiss];
  227. switchButton.selected = !switchButton.selected;
  228. [self.collectionView.mj_header endRefreshing];
  229. } failure:^(NSError *error) {
  230. [self.collectionView.mj_footer endRefreshing];
  231. [LoadingView dismiss];
  232. [MBProgressHUD showMessage:@"该商品未参加优惠券和返佣推广活动,建议亲换个店铺试试"];
  233. }];
  234. }
  235. - (void)requestGuessYouLike {
  236. [LDFindRequestViewModel requestGuessYouLikeParamPage:guessYouLikePage success:^(NSArray *array) {
  237. if (array.count > 0) {
  238. [self.goodsArr addObjectsFromArray:array];
  239. [self.collectionView reloadData];
  240. if (guessYouLikePage == 1) {
  241. kWeak(self);
  242. _collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  243. guessYouLikePage ++;
  244. [selfWeak requestGuessYouLike];
  245. }];
  246. }
  247. }
  248. [self.collectionView.mj_footer endRefreshing];
  249. } failure:^(NSError *error) {
  250. [self.collectionView.mj_footer endRefreshing];
  251. [LoadingView dismiss];
  252. [MBProgressHUD showMessage:@"加载失败"];
  253. }];
  254. }
  255. #pragma mark - SearchNoDataViewDelegate
  256. - (void)yh_SearchNoDataViewDidRefresh {
  257. [self.goodsArr removeAllObjects];
  258. [self requestVoucherFindIsRefresh:YES switchButton:nil];
  259. }
  260. #pragma mark - collectionView
  261. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  262. return 3;
  263. }
  264. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  265. if (section == 1 ) {
  266. return self.yorkerArray.count;
  267. }
  268. if (section == 2) {
  269. return self.goodsArr.count;
  270. }
  271. return 0;
  272. }
  273. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  274. LDChildGoodModel *model =[[LDChildGoodModel alloc]init];
  275. if (indexPath.section == 1) {
  276. model = self.yorkerArray[indexPath.item];
  277. }else if (indexPath.section == 2){
  278. model =self.goodsArr[indexPath.item];
  279. }
  280. if (self.cellType == ResultCellTypeVertical) {
  281. LDGoodCollectionCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
  282. cell.model = model;
  283. return cell;
  284. }else {
  285. LDTodayHorizontalGoodCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:HorzitolCellId forIndexPath:indexPath];
  286. cell.model = model;
  287. return cell;
  288. }
  289. }
  290. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  291. LDChildGoodModel *model =[[LDChildGoodModel alloc]init];
  292. if (indexPath.section == 1) {
  293. model = self.yorkerArray[indexPath.item];
  294. }else if (indexPath.section == 2){
  295. model =self.goodsArr[indexPath.item];
  296. }
  297. //详情
  298. LDGoodDetailViewController *detailVC = [[LDGoodDetailViewController alloc] init];
  299. DetailRequestModel *requestModel = [[DetailRequestModel alloc] initWithChildModel:model];
  300. detailVC.requestModel = requestModel;
  301. NSString *action;
  302. if (indexPath.section == 1) {
  303. action = HaoListsSearchAction;
  304. }else {
  305. action = searchAction;
  306. }
  307. LDEventModel *evevtModel = [[LDEventModel alloc] initWithOrigin:model.origin category_id:@"0" source:action];
  308. detailVC.eventModel = evevtModel;
  309. [self.navigationController pushViewController:detailVC animated:YES];
  310. }
  311. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
  312. UICollectionReusableView *view = nil;
  313. if (indexPath.section == 2) {
  314. if (self.yorkerArray.count !=0) {
  315. LDSectionAllGoodView *sectionview =[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionViewHeaderAllgood forIndexPath:indexPath];
  316. return sectionview;
  317. }
  318. UICollectionReusableView *guessYouLikeView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionViewHeaderMiddle forIndexPath:indexPath];
  319. view = guessYouLikeView;
  320. return view;
  321. }
  322. if (indexPath.section == 0) {
  323. if (self.special_search != nil) {
  324. LDSearchSpecialView *searchSpecial =[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionViewSpecailHeader forIndexPath:indexPath];
  325. searchSpecial.model = self.adModel;
  326. searchSpecial.tapImgBlock = ^(AdPopModel * _Nonnull model) {
  327. [AdJumpManager jumpToPageWithModel:model ParentViewControll:self];
  328. };
  329. return searchSpecial;
  330. }else {
  331. LDSearchNoDataView *noData = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionViewHeaderTop forIndexPath:indexPath];
  332. noData.delegate = self;
  333. noData.hidden = !isNoData;
  334. view = noData;
  335. return view;
  336. }
  337. }
  338. else {
  339. UICollectionReusableView *guessYouLikeView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionViewHeaderMiddle forIndexPath:indexPath];
  340. UIImageView *middleImageView = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth/2-FITSIZE(99)/2, FITSIZE(14), FITSIZE(99), FITSIZE(12))];
  341. middleImageView.backgroundColor = [UIColor clearColor];
  342. middleImageView.image = [UIImage imageNamed:@"guess_like_gray"];
  343. guessYouLikeView.clipsToBounds = YES;
  344. [guessYouLikeView addSubview:middleImageView];
  345. view = guessYouLikeView;
  346. }
  347. return view;
  348. }
  349. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  350. LDChildGoodModel *model = self.goodsArr[indexPath.row];
  351. if (self.cellType == ResultCellTypeVertical) {
  352. CGFloat width = (SCREEN_WIDTH-5)/2;
  353. CGFloat height = width + 135;
  354. if (![AccountTool isLogin] && ![model.red_active_status boolValue]) {
  355. height = width +112;
  356. }
  357. CGSize itemSize = CGSizeMake(width, height);
  358. return itemSize;
  359. }else {
  360. return CGSizeMake(SCREEN_WIDTH, 147);
  361. }
  362. }
  363. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
  364. if (self.cellType == ResultCellTypeVertical) {
  365. return 5;
  366. }else {
  367. return 1;
  368. }
  369. }
  370. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
  371. if (section == 2 ) {
  372. if (self.yorkerArray.count == 0) {
  373. return CGSizeMake(0, 0);
  374. }
  375. return CGSizeMake(kScreenWidth, FITSIZE(52));
  376. }
  377. if (self.special_search != nil) {
  378. if (section == 0) {
  379. return CGSizeMake(kScreenWidth, FITSIZE(157));
  380. }
  381. else {
  382. return CGSizeMake(kScreenWidth, FITSIZE(40));
  383. }
  384. }
  385. if (isNoData) {
  386. if (section == 0) {
  387. return CGSizeMake(kScreenWidth, FITSIZE(264));
  388. }
  389. else {
  390. return CGSizeMake(kScreenWidth, FITSIZE(40));
  391. }
  392. }
  393. else {
  394. if (section == 0) {
  395. return CGSizeMake(kScreenWidth, 0.1);
  396. }
  397. else {
  398. return CGSizeMake(kScreenWidth, 0.1);
  399. }
  400. }
  401. }
  402. #pragma mark NY_SelectViewDelegate
  403. //筛选确定点击
  404. - (void)filtrateViewMakeSureFromValue:(NSString *)fromValue toValue:(NSString *)toValue {
  405. [self.collectionView scrollToTop];
  406. _minPrice = fromValue;
  407. _maxPrice = toValue;
  408. page = 1;
  409. [self requestVoucherFindIsRefresh:YES switchButton:nil];
  410. }
  411. //仅显示优惠券
  412. - (void)selectItme:(SelectView *)selectView onlyTicketClick:(UIButton *)switchBtn {
  413. _is_has_coupon = switchBtn.selected ? 0 : 1;
  414. [self requestVoucherFindIsRefresh:YES switchButton:switchBtn];
  415. }
  416. //上方条件选择
  417. -(void)selectTopButton:(SelectView *)selectView withIndex:(NSInteger)index withButtonType:(ButtonClickType)type1{
  418. [self.collectionView scrollToTop];
  419. //价格
  420. if (index == 2&&type1) {
  421. switch (type1) {
  422. case ButtonClickTypeNormal:
  423. //正常价格
  424. {
  425. NSLog(@"上边按钮的正常价格");
  426. }
  427. break;
  428. case ButtonClickTypeUp:
  429. //价格升序排列
  430. {
  431. NSLog(@"上边按钮的价格升序排列");
  432. _type = @"3";
  433. }
  434. break;
  435. case ButtonClickTypeDown:
  436. //价格降序排列
  437. {
  438. NSLog(@"上边按钮的价格降序排列");
  439. _type = @"4";
  440. }
  441. break;
  442. default:
  443. break;
  444. }
  445. }else if (index == 0){//综合
  446. NSLog(@"上边按钮的综合");
  447. _type = @"1";
  448. }else if (index == 1){//销量
  449. NSLog(@"上边按钮的销量");
  450. _type = @"2";
  451. }else{//筛选
  452. NSLog(@"上边按钮的筛选");
  453. }
  454. [self requestVoucherFindIsRefresh:YES switchButton:nil];
  455. }
  456. //排序选择
  457. -(void)selectItme:(SelectView *)selectView sortDic:(NSDictionary *)selectDic
  458. {
  459. _type = selectDic[@"type"];
  460. [self requestVoucherFindIsRefresh:YES switchButton:nil];
  461. }
  462. #pragma mark - scrollView
  463. - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  464. {
  465. //scrollView已经有拖拽手势,直接拿到scrollView的拖拽手势
  466. UIPanGestureRecognizer *pan = scrollView.panGestureRecognizer;
  467. //获取到拖拽的速度 >0 向下拖动 <0 向上拖动
  468. CGFloat velocity = [pan velocityInView:scrollView].y;
  469. if (velocity <- 10) {
  470. //向上拖动,隐藏导航栏
  471. [self.navigationController setNavigationBarHidden:YES animated:YES];
  472. if (self.special_search != nil) {
  473. self.collectionView.height = kScreenHeight-KStatusBarHeight;
  474. self.collectionView.y = KStatusBarHeight;
  475. }else {
  476. self.collectionView.height = kScreenHeight-NavBarHeight-selectedViewHeight+NavBarHeight;
  477. self.collectionView.y = self.selectedView.height+KStatusBarHeight;
  478. }
  479. self.selectedView.y = KStatusBarHeight;
  480. }else if (velocity > 10) {
  481. //向下拖动,显示导航栏
  482. [self.navigationController setNavigationBarHidden:NO animated:YES];
  483. if (self.special_search != nil) {
  484. self.collectionView.height = kScreenHeight-NavBarHeight;
  485. self.collectionView.y = 0;
  486. }else {
  487. self.collectionView.height = kScreenHeight-NavBarHeight-selectedViewHeight;
  488. self.collectionView.y = selectedViewHeight;
  489. }
  490. self.selectedView.y = 0;
  491. }else if(velocity == 0){
  492. //停止拖拽
  493. }
  494. }
  495. #pragma mark - lazy
  496. - (UICollectionView *)collectionView {
  497. if (!_collectionView) {
  498. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  499. flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
  500. flowLayout.minimumLineSpacing = 5;
  501. flowLayout.minimumInteritemSpacing = 5;
  502. _collectionView = [[LDCollectionView alloc] initWithFrame:CGRectMake(0, selectedViewHeight, kScreenWidth, kScreenHeight-NavBarHeight-selectedViewHeight) collectionViewLayout:flowLayout];
  503. _collectionView.delegate = self;
  504. _collectionView.dataSource = self;
  505. [_collectionView registerClass:[LDGoodCollectionCell class] forCellWithReuseIdentifier:cellID];
  506. [_collectionView registerClass:[LDTodayHorizontalGoodCell class] forCellWithReuseIdentifier:HorzitolCellId];
  507. [_collectionView registerClass:[LDSearchSpecialView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionViewSpecailHeader];
  508. [_collectionView registerClass:[LDSearchNoDataView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionViewHeaderTop];
  509. [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionViewHeaderMiddle];
  510. [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionViewHeaderMiddle];
  511. [_collectionView registerClass:[LDSectionAllGoodView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:collectionViewHeaderAllgood];
  512. MJRefreshGifHeader *header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
  513. page = 1;
  514. [self requestVoucherFindIsRefresh:YES switchButton:nil];
  515. }];
  516. header.lastUpdatedTimeLabel.hidden = YES;
  517. header.stateLabel.hidden = YES;
  518. //正在刷新的图片
  519. NSArray *imgArr = @[[UIImage imageNamed:@"ant1"],[UIImage imageNamed:@"ant2"]];
  520. [header setImages:imgArr duration:0.3 forState:MJRefreshStateRefreshing];
  521. [header setImages:@[[UIImage imageNamed:@"ant1"]] duration:1 forState:MJRefreshStateWillRefresh];
  522. [header setImages:@[[UIImage imageNamed:@"ant1"]] duration:1 forState:MJRefreshStatePulling];
  523. _collectionView.mj_header = header;
  524. if (@available(iOS 11.0, *)) {
  525. _collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  526. }
  527. }
  528. return _collectionView;
  529. }
  530. - (SelectView *)selectedView {
  531. if (!_selectedView) {
  532. _selectedView = [[SelectView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, selectedViewHeight) withArr:self.filtrateArray];
  533. UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, -KStatusBarHeight, SCREEN_WIDTH, KStatusBarHeight)];
  534. bgView.backgroundColor = [UIColor whiteColor];
  535. [_selectedView addSubview:bgView];
  536. _selectedView.delegate = self;
  537. }
  538. return _selectedView;
  539. }
  540. - (NSMutableArray *)goodsArr {
  541. if (!_goodsArr) {
  542. _goodsArr = [NSMutableArray array];
  543. }
  544. return _goodsArr;
  545. }
  546. - (NSMutableArray *)yorkerArray {
  547. if (!_yorkerArray) {
  548. _yorkerArray = [NSMutableArray array];
  549. }
  550. return _yorkerArray;
  551. }
  552. @end