两折买改口袋样式

CreatSearchManager.m 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. //
  2. // CreatSearchManager.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/7/24.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "CreatSearchManager.h"
  9. #import "LZMFindSearchResultViewController.h"
  10. #import "PYSearch.h"
  11. @interface CreatSearchManager ()<PYSearchViewControllerDelegate, PYSearchViewControllerDataSource>
  12. {
  13. PYSearchViewController *searchVc;
  14. }
  15. @property (nonatomic, strong) NSMutableArray *everyOneSearch;
  16. @end
  17. @implementation CreatSearchManager
  18. - (void)loadHotText {
  19. NSString *urlString = [NSString stringWithFormat:@"%@/api/v2/goods/everyoneSearch", BaseURL];
  20. [LZMCacheHttp get:urlString params:nil success:^(id json, BOOL isCache) {
  21. [self.everyOneSearch removeAllObjects];
  22. for (NSDictionary *dic in json) {
  23. [self.everyOneSearch addObject:dic];
  24. }
  25. } failure:^(NSError *error) {
  26. }];
  27. }
  28. - (void)createSearchViewControllerWith:(NSString *)text viewController:(UIViewController *)vc{
  29. [self loadHotText];
  30. PYSearchViewController *searchViewController = [PYSearchViewController searchViewControllerWithHotSearches:@[] searchBarPlaceholder:text];
  31. searchVc = searchViewController;
  32. // searchViewController.swapHotSeachWithSearchHistory = YES;
  33. searchViewController.searchHistoryStyle = PYSearchHistoryStyleARCBorderTag;
  34. searchViewController.hotSearchStyle = PYHotSearchStyleARCBorderTag;
  35. searchViewController.searchTextField.font = [UIFont systemFontOfSize:13];
  36. searchViewController.searchTextField.enablesReturnKeyAutomatically = NO;
  37. searchViewController.delegate = self;
  38. [self getHotSearchToSearchViewController:searchViewController];
  39. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:searchViewController];
  40. if (text.length > 0) {
  41. LZMFindSearchResultViewController *resultVC = [[LZMFindSearchResultViewController alloc] init];
  42. resultVC.searchBar = searchViewController.searchBar;
  43. resultVC.searchName = text;
  44. searchViewController.searchBar.text = text;
  45. searchViewController.searchSuggestions = nil;
  46. [nav pushViewController:resultVC animated:NO];
  47. }
  48. [vc presentViewController:nav animated:NO completion:^{
  49. for (int i = 0; i < searchViewController.hotSearchTags.count; i++) {
  50. UILabel *tag = searchViewController.hotSearchTags[i];
  51. NSDictionary *dic = self.everyOneSearch[i];
  52. if ([dic[@"color"] boolValue]) {
  53. tag.layer.borderColor = [UIColor homeRedColor].CGColor;
  54. tag.textColor = [UIColor homeRedColor];
  55. }
  56. }
  57. }];
  58. searchViewController.didSearchBlock = ^(PYSearchViewController *searchViewController, UISearchBar *searchBar, NSString *searchText) {
  59. //处理搜索点击事件
  60. [MobClick event:search_count label:Search_Normal];
  61. LZMFindSearchResultViewController *resultVC = [[LZMFindSearchResultViewController alloc] init];
  62. resultVC.searchBar = searchBar;
  63. resultVC.searchName = searchText;
  64. if (searchText.length == 0) {
  65. searchBar.text = searchBar.placeholder;
  66. resultVC.searchName = searchBar.placeholder;
  67. }
  68. searchViewController.searchSuggestions = nil;
  69. [nav pushViewController:resultVC animated:NO];
  70. };
  71. }
  72. /**
  73. 加载热门搜索
  74. */
  75. - (void)getHotSearchToSearchViewController:(PYSearchViewController *)searchViewController {
  76. NSMutableArray *hotSearch = [NSMutableArray array];
  77. for (NSDictionary *dic in self.everyOneSearch) {
  78. [hotSearch addObject:dic[@"name"]];
  79. }
  80. searchViewController.hotSearches = hotSearch;
  81. }
  82. #pragma mark - PYSearchViewControllerDelegate
  83. /**
  84. 输入完成时触发
  85. */
  86. - (void)searchViewController:(PYSearchViewController *)searchViewController searchTextDidChange:(UISearchBar *)seachBar searchText:(NSString *)searchText
  87. {
  88. if (searchText.length) {
  89. [LZMHttp get:SearchAdvice params:@{@"name":searchText} success:^(id json) {
  90. NSArray *list = json[@"data"];
  91. searchViewController.searchSuggestions = list;
  92. } failure:^(NSError *error) {
  93. }];
  94. }
  95. }
  96. /**
  97. 点击建议
  98. */
  99. - (void)searchViewController:(PYSearchViewController *)searchViewController
  100. didSelectSearchSuggestionAtIndex:(NSInteger)index
  101. searchText:(NSString *)searchText {
  102. LZMFindSearchResultViewController *resultVC = [[LZMFindSearchResultViewController alloc] init];
  103. resultVC.searchName = searchText;
  104. resultVC.searchBar = searchViewController.searchBar;
  105. [searchViewController.navigationController pushViewController:resultVC animated:NO];
  106. }
  107. /**
  108. 点击热搜
  109. */
  110. - (void)searchViewController:(PYSearchViewController *)searchViewController
  111. didSelectHotSearchAtIndex:(NSInteger)index
  112. searchText:(NSString *)searchText {
  113. LZMFindSearchResultViewController *resultVC = [[LZMFindSearchResultViewController alloc] init];
  114. resultVC.searchName = searchText;
  115. resultVC.searchBar = searchViewController.searchBar;
  116. [searchViewController.navigationController pushViewController:resultVC animated:NO];
  117. [MobClick event:search_count label:Search_Hot_String];
  118. }
  119. /**
  120. 点击历史
  121. */
  122. - (void)searchViewController:(PYSearchViewController *)searchViewController
  123. didSelectSearchHistoryAtIndex:(NSInteger)index
  124. searchText:(NSString *)searchText {
  125. LZMFindSearchResultViewController *resultVC = [[LZMFindSearchResultViewController alloc] init];
  126. resultVC.searchName = searchText;
  127. resultVC.searchBar = searchViewController.searchBar;
  128. [searchViewController.navigationController pushViewController:resultVC animated:NO];
  129. [MobClick event:search_count label:Search_History_String];
  130. }
  131. - (NSMutableArray *)everyOneSearch {
  132. if (!_everyOneSearch) {
  133. _everyOneSearch = [NSMutableArray array];
  134. }
  135. return _everyOneSearch;
  136. }
  137. @end