123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- //
- // KBClassifyViewController.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/4/28.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "KBClassifyViewController.h"
- #import "KBClassifyLeftView.h"
- #import "KBClassifyRightView.h"
- #import "KBCategoryModel.h"
- #import "KBSecondCategoryModel.h"
- #import "KBGoodListViewController.h"
- #import "KBClassifyListController.h"
- #import "KBFindNavBarStaticView.h"
- #import "PYSearchViewController.h"
- #import "KBFindSearchResultViewController.h"
- #import "KBFindRequestViewModel.h"
- #import "AdJumpManager.h"
- #import "AdJumpManager.h"
- #import "CreatSearchManager.h"
- @interface KBClassifyViewController ()<YHFindNavBarStaticViewDelegate,PYSearchViewControllerDelegate>
- {
-
- }
- @property (nonatomic, strong) KBClassifyLeftView *leftView; //类别
- @property (nonatomic, strong) KBClassifyRightView *rightView;//详单
- @property (nonatomic, strong) NSMutableArray *dataArr;
- @property (nonatomic, strong) NSArray *secondDataArr;
- @property (nonatomic, strong) KBFindNavBarStaticView *navBarStaticView;
- @property (nonatomic, strong) NSMutableArray *everyoneSearchArr;
- @property (nonatomic, strong) NSString *classifyName;
- @property (nonatomic, strong) NSArray *hotSearchModelArray;
- @property (nonatomic, strong) NSString *firstCategoryId;
- @end
- @implementation KBClassifyViewController
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
- // [SVProgressHUD dismiss];
- }
- - (void)viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
- [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self creatNavBar];
- [self createView];
- [self requestData];
- [self requestEveryoneSearch];
- }
- - (void)creatNavBar {
-
- [self.navigationBar addSubview:self.navBarStaticView];
- UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
- [leftBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
- [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
- [self.navigationBar setCustomLeftButtons:@[leftBtn]];
- [self.navigationBar setShowNavigationBarBottomLine:YES];
- self.view.backgroundColor = [UIColor whiteColor];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeSex) name:ChangeSex object:nil];
-
-
-
- }
- - (void)backAction {
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)createView {
- [self createLeftView];
- [self createRightView];
- }
- - (void)changeSex {
- [self createLeftView];
- [self createRightView];
- [self refreshData];
- }
- - (void)createLeftView{
- self.leftView = [[KBClassifyLeftView alloc]initWithFrame:CGRectMake(0, NavBarHeight, 92*SCREEN_MUTI, SCREEN_HEIGHT - NavBarHeight)];
- __weak typeof(self) weakSelf = self;
- self.leftView.selectRowBlock = ^(NSInteger index) {
- KBCategoryModel *model = weakSelf.dataArr[index];
- weakSelf.secondDataArr = model.itemList;
- weakSelf.rightView.dataSource = model.itemList;
- weakSelf.rightView.model = model.adv;
- weakSelf.classifyName = model.name;
- weakSelf.firstCategoryId = model.Id;
- };
- [self.view addSubview:self.leftView];
- }
- - (void)createRightView{
- self.rightView = [[KBClassifyRightView alloc]initWithFrame:CGRectMake(92*SCREEN_MUTI, NavBarHeight, SCREEN_WIDTH - 92*SCREEN_MUTI, SCREEN_HEIGHT -NavBarHeight)];
- __weak typeof(self) weakSelf = self;
- self.rightView.selectItemBlock = ^(NSInteger index) {
- KBClassifyListController *list = [[KBClassifyListController alloc] init];
- KBSecondCategoryModel *model = weakSelf.secondDataArr[index];
- list.firstCategoryId = weakSelf.firstCategoryId;
- list.cate_id = model.Id;
- list.name = model.name;
- [weakSelf.navigationController pushViewController:list animated:YES];
-
- NSString *tagStr = [NSString stringWithFormat:@"%@-%@",weakSelf.classifyName,model.name];
- [MobClick event:Classify label:tagStr];
-
- };
- self.rightView.selectHeader = ^(AdPopModel *model) {
- [AdJumpManager jumpToPageWithModel:model ParentViewControll:weakSelf];
- };
- [self.view addSubview:self.rightView];
- }
- - (void)requestData {
-
- [SVProgressHUD show];
- NSString *urlString = [NSString stringWithFormat:@"%@/api/v2/category/list", BaseURL];
-
- [KBCacheHttp get:urlString params:nil success:^(id json, BOOL isCache) {
- [self.dataArr removeAllObjects];
- NSArray *arr = [NSArray yy_modelArrayWithClass:[KBCategoryModel class] json:json[@"data"]];
- [self.dataArr addObjectsFromArray:arr];
- self.leftView.dataArray = arr;
- KBCategoryModel *model = arr.firstObject;
- self.classifyName = model.name;
- self.secondDataArr = model.itemList;
- self.rightView.dataSource = model.itemList;
- // self.rightView.bannerImgUrl=model.adModel;
- self.rightView.model=model.adv;
- self.firstCategoryId = model.Id;
- [SVProgressHUD dismiss];
- } failure:^(NSError *error) {
- [SVProgressHUD dismiss];
- }];
-
-
- }
- - (void)requestEveryoneSearch {
- NSString *urlString = [NSString stringWithFormat:@"%@/api/v2/goods/everyoneSearch", BaseURL];
-
- [KBCacheHttp get:urlString params:nil success:^(id json, BOOL isCache) {
- [self.everyoneSearchArr removeAllObjects];
-
- self.hotSearchModelArray = [NSArray yy_modelArrayWithClass:[HotSearchModel class] json:json];
- for (HotSearchModel *model in self.hotSearchModelArray) {
- [self.everyoneSearchArr addObject:model.name];
- }
- } failure:^(NSError *error) {
-
- }];
- }
- - (void)refreshData {
- [self.dataArr removeAllObjects];
- [self requestData];
- }
- #pragma mark - navBarView
- - (void)yh_FindNavBarStaticViewClickSearch {
- [self createSearchViewControllerWith:nil];
- }
- #pragma mark - -------------search -----------
- - (void)createSearchViewControllerWith:(NSString *)text {
-
- CreatSearchManager *manager = [CreatSearchManager shareManager];
- [manager createSearchViewControllerWith:text viewController:self];
- // return;
- //
- // PYSearchViewController *searchViewController = [PYSearchViewController searchViewControllerWithHotSearches:@[] searchBarPlaceholder:@"输入商品名或粘贴淘宝标题"];
- // searchViewController.searchHistoryStyle = PYSearchHistoryStyleARCBorderTag;
- // searchViewController.hotSearchStyle = PYHotSearchStyleARCBorderTag;
- // searchViewController.searchTextField.font = [UIFont systemFontOfSize:13];
- // searchViewController.delegate = self;
- // searchViewController.searchBar.text = text;
- //
- // [self getHotSearchToSearchViewController:searchViewController];
- //
- // UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:searchViewController];
- // [self presentViewController:nav animated:NO completion:^{
- //
- // }];
- //
- // searchViewController.didSearchBlock = ^(PYSearchViewController *searchViewController, UISearchBar *searchBar, NSString *searchText) {
- // [MobClick event:search_count label:Search_Normal];
- // //处理搜索点击事件
- // KBFindSearchResultViewController *resultVC = [[KBFindSearchResultViewController alloc] init];
- // resultVC.searchBar = searchBar;
- // resultVC.searchName = searchText;
- // [nav pushViewController:resultVC animated:NO];
- //
- // };
- }
- /**
- 加载热搜词汇
- */
- - (void)getHotSearchToSearchViewController:(PYSearchViewController *)searchViewController {
-
- searchViewController.hotSearchModelArray = self.hotSearchModelArray;
- searchViewController.hotSearches = self.everyoneSearchArr;
- }
- #pragma mark - PYSearchViewControllerDelegate
- /**
- 输入完成时触发
- */
- - (void)searchViewController:(PYSearchViewController *)searchViewController searchTextDidChange:(UISearchBar *)seachBar searchText:(NSString *)searchText
- {
-
- if (searchText.length) {
- [KBHttp 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 {
- KBFindSearchResultViewController *resultVC = [[KBFindSearchResultViewController 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 {
- KBFindSearchResultViewController *resultVC = [[KBFindSearchResultViewController 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 {
- KBFindSearchResultViewController *resultVC = [[KBFindSearchResultViewController alloc] init];
- resultVC.searchName = searchText;
- resultVC.searchBar = searchViewController.searchBar;
- [searchViewController.navigationController pushViewController:resultVC animated:NO];
- [MobClick event:search_count label:Search_History_String];
- }
- #pragma mark -----
- - (KBFindNavBarStaticView *)navBarStaticView {
- if (!_navBarStaticView) {
- _navBarStaticView = [[KBFindNavBarStaticView alloc] initWithFrame:CGRectMake(60, 0, kScreenWidth-60, NavBarHeight-1)];
- _navBarStaticView.backgroundColor = [UIColor whiteColor];
- _navBarStaticView.delegate = self;
- }
- return _navBarStaticView;
- }
- - (NSMutableArray *)dataArr {
- if (!_dataArr) {
- _dataArr = [NSMutableArray array];
- }
- return _dataArr;
- }
- - (NSMutableArray *)everyoneSearchArr {
- if (!_everyoneSearchArr) {
- _everyoneSearchArr = [NSMutableArray array];
- }
- return _everyoneSearchArr;
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|