123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- //
- // CreatSearchManager.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/7/24.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "CreatSearchManager.h"
- #import "LDFindSearchResultViewController.h"
- #import "PYSearch.h"
- @interface CreatSearchManager ()<PYSearchViewControllerDelegate, PYSearchViewControllerDataSource>
- {
- PYSearchViewController *searchVc;
- }
- @property (nonatomic, strong) NSMutableArray *everyOneSearch;
- @property (nonatomic, strong) NSArray *hotSearchModelArray;
- @end
- @implementation CreatSearchManager
- - (void)loadHotText {
- NSString *urlString = [NSString stringWithFormat:@"%@/api/v2/goods/everyoneSearch", BaseURL];
-
- [LDCacheHttp get:urlString params:nil success:^(id json, BOOL isCache) {
- [self.everyOneSearch removeAllObjects];
- // for (NSDictionary *dic in json) {
- // [self.everyOneSearch addObject:dic];
- // }
- self.hotSearchModelArray = [NSArray yy_modelArrayWithClass:[HotSearchModel class] json:json];
- for (HotSearchModel *model in self.hotSearchModelArray) {
- [self.everyOneSearch addObject:model.name];
- }
- } failure:^(NSError *error) {
-
- }];
- }
- - (void)createSearchViewControllerWith:(NSString *)text viewController:(UIViewController *)vc{
-
- [self loadHotText];
-
- PYSearchViewController *searchViewController = [PYSearchViewController searchViewControllerWithHotSearches:@[] searchBarPlaceholder:text];
- searchVc = searchViewController;
- // searchViewController.swapHotSeachWithSearchHistory = YES;
- searchViewController.searchHistoryStyle = PYSearchHistoryStyleARCBorderTag;
- searchViewController.hotSearchStyle = PYHotSearchStyleARCBorderTag;
- searchViewController.searchTextField.font = [UIFont systemFontOfSize:13];
- searchViewController.searchTextField.enablesReturnKeyAutomatically = NO;
- searchViewController.delegate = self;
- [self getHotSearchToSearchViewController:searchViewController];
-
- UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:searchViewController];
- LDFindSearchResultViewController *resultVC = [[LDFindSearchResultViewController alloc] init];
- resultVC.searchBar = searchViewController.searchBar;
- resultVC.searchName = text;
- searchViewController.searchBar.text = text;
- searchViewController.searchSuggestions = nil;
- [nav pushViewController:resultVC animated:NO];
- nav.modalPresentationStyle = UIModalPresentationFullScreen;
- [vc presentViewController:nav animated:NO completion:^{
-
-
- }];
-
- searchViewController.didSearchBlock = ^(PYSearchViewController *searchViewController, UISearchBar *searchBar, NSString *searchText) {
- //处理搜索点击事件
- [MobClick event:search_count label:Search_Normal];
- LDFindSearchResultViewController *resultVC = [[LDFindSearchResultViewController alloc] init];
- resultVC.searchBar = searchBar;
- resultVC.searchName = searchText;
- if (searchText.length == 0) {
- searchBar.text = searchBar.placeholder;
- resultVC.searchName = searchBar.placeholder;
- }
- searchViewController.searchSuggestions = nil;
- [nav pushViewController:resultVC animated:NO];
- };
- }
- /**
- 加载热门搜索
- */
- - (void)getHotSearchToSearchViewController:(PYSearchViewController *)searchViewController {
-
- searchViewController.hotSearchModelArray = self.hotSearchModelArray;
- searchViewController.hotSearches = self.everyOneSearch;
- }
- #pragma mark - PYSearchViewControllerDelegate
- /**
- 输入完成时触发
- */
- - (void)searchViewController:(PYSearchViewController *)searchViewController searchTextDidChange:(UISearchBar *)seachBar searchText:(NSString *)searchText
- {
-
- if (searchText.length) {
- [LDHttp get:SearchAdvice params:@{@"name":searchText} success:^(id json) {
- NSArray *list = json[@"data"];
- searchViewController.searchSuggestions = list;
- } failure:^(NSError *error) {
-
- }];
-
- }
- }
- /**
- 点击建议
- */
- - (void)searchViewController:(PYSearchViewController *)searchViewController
- didSelectSearchSuggestionAtIndex:(NSInteger)index
- searchText:(NSString *)searchText {
- LDFindSearchResultViewController *resultVC = [[LDFindSearchResultViewController alloc] init];
- resultVC.searchName = searchText;
- resultVC.searchBar = searchViewController.searchBar;
- [searchViewController.navigationController pushViewController:resultVC animated:NO];
- }
- /**
- 点击热搜
- */
- - (void)searchViewController:(PYSearchViewController *)searchViewController
- didSelectHotSearchAtIndex:(NSInteger)index
- searchText:(NSString *)searchText {
- LDFindSearchResultViewController *resultVC = [[LDFindSearchResultViewController alloc] init];
- resultVC.searchName = searchText;
- resultVC.searchBar = searchViewController.searchBar;
- [searchViewController.navigationController pushViewController:resultVC animated:NO];
- [MobClick event:search_count label:Search_Hot_String];
- }
- /**
- 点击历史
- */
- - (void)searchViewController:(PYSearchViewController *)searchViewController
- didSelectSearchHistoryAtIndex:(NSInteger)index
- searchText:(NSString *)searchText {
- LDFindSearchResultViewController *resultVC = [[LDFindSearchResultViewController alloc] init];
- resultVC.searchName = searchText;
- resultVC.searchBar = searchViewController.searchBar;
- [searchViewController.navigationController pushViewController:resultVC animated:NO];
-
- [MobClick event:search_count label:Search_History_String];
- }
- - (NSMutableArray *)everyOneSearch {
- if (!_everyOneSearch) {
- _everyOneSearch = [NSMutableArray array];
- }
- return _everyOneSearch;
- }
- @end
|