口袋优选

KBClassifyViewController.m 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. //
  2. // KBClassifyViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/4/28.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBClassifyViewController.h"
  9. #import "KBClassifyLeftView.h"
  10. #import "KBClassifyRightView.h"
  11. #import "KBCategoryModel.h"
  12. #import "KBSecondCategoryModel.h"
  13. #import "KBGoodListViewController.h"
  14. #import "KBClassifyListController.h"
  15. #import "KBFindNavBarStaticView.h"
  16. #import "PYSearchViewController.h"
  17. #import "KBFindSearchResultViewController.h"
  18. #import "KBFindRequestViewModel.h"
  19. #import "AdJumpManager.h"
  20. #import "AdJumpManager.h"
  21. #import "CreatSearchManager.h"
  22. @interface KBClassifyViewController ()<YHFindNavBarStaticViewDelegate,PYSearchViewControllerDelegate>
  23. {
  24. }
  25. @property (nonatomic, strong) KBClassifyLeftView *leftView; //类别
  26. @property (nonatomic, strong) KBClassifyRightView *rightView;//详单
  27. @property (nonatomic, strong) NSMutableArray *dataArr;
  28. @property (nonatomic, strong) NSArray *secondDataArr;
  29. @property (nonatomic, strong) KBFindNavBarStaticView *navBarStaticView;
  30. @property (nonatomic, strong) NSMutableArray *everyoneSearchArr;
  31. @property (nonatomic, strong) NSString *classifyName;
  32. @property (nonatomic, strong) NSArray *hotSearchModelArray;
  33. @property (nonatomic, strong) NSString *firstCategoryId;
  34. @end
  35. @implementation KBClassifyViewController
  36. - (void)viewWillDisappear:(BOOL)animated {
  37. [super viewWillDisappear:animated];
  38. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
  39. // [SVProgressHUD dismiss];
  40. }
  41. - (void)viewDidAppear:(BOOL)animated {
  42. [super viewDidAppear:animated];
  43. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
  44. }
  45. - (void)viewWillAppear:(BOOL)animated {
  46. [super viewWillAppear:animated];
  47. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
  48. }
  49. - (void)viewDidLoad {
  50. [super viewDidLoad];
  51. [self creatNavBar];
  52. [self createView];
  53. [self requestData];
  54. [self requestEveryoneSearch];
  55. }
  56. - (void)creatNavBar {
  57. [self.navigationBar addSubview:self.navBarStaticView];
  58. UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  59. [leftBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
  60. [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  61. [self.navigationBar setCustomLeftButtons:@[leftBtn]];
  62. [self.navigationBar setShowNavigationBarBottomLine:YES];
  63. self.view.backgroundColor = [UIColor whiteColor];
  64. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeSex) name:ChangeSex object:nil];
  65. }
  66. - (void)backAction {
  67. [self.navigationController popViewControllerAnimated:YES];
  68. }
  69. - (void)createView {
  70. [self createLeftView];
  71. [self createRightView];
  72. }
  73. - (void)changeSex {
  74. [self createLeftView];
  75. [self createRightView];
  76. [self refreshData];
  77. }
  78. - (void)createLeftView{
  79. self.leftView = [[KBClassifyLeftView alloc]initWithFrame:CGRectMake(0, NavBarHeight, 92*SCREEN_MUTI, SCREEN_HEIGHT - NavBarHeight)];
  80. __weak typeof(self) weakSelf = self;
  81. self.leftView.selectRowBlock = ^(NSInteger index) {
  82. KBCategoryModel *model = weakSelf.dataArr[index];
  83. weakSelf.secondDataArr = model.itemList;
  84. weakSelf.rightView.dataSource = model.itemList;
  85. weakSelf.rightView.model = model.adv;
  86. weakSelf.classifyName = model.name;
  87. weakSelf.firstCategoryId = model.Id;
  88. };
  89. [self.view addSubview:self.leftView];
  90. }
  91. - (void)createRightView{
  92. self.rightView = [[KBClassifyRightView alloc]initWithFrame:CGRectMake(92*SCREEN_MUTI, NavBarHeight, SCREEN_WIDTH - 92*SCREEN_MUTI, SCREEN_HEIGHT -NavBarHeight)];
  93. __weak typeof(self) weakSelf = self;
  94. self.rightView.selectItemBlock = ^(NSInteger index) {
  95. KBClassifyListController *list = [[KBClassifyListController alloc] init];
  96. KBSecondCategoryModel *model = weakSelf.secondDataArr[index];
  97. list.firstCategoryId = weakSelf.firstCategoryId;
  98. list.cate_id = model.Id;
  99. list.name = model.name;
  100. [weakSelf.navigationController pushViewController:list animated:YES];
  101. NSString *tagStr = [NSString stringWithFormat:@"%@-%@",weakSelf.classifyName,model.name];
  102. [MobClick event:Classify label:tagStr];
  103. };
  104. self.rightView.selectHeader = ^(AdPopModel *model) {
  105. [AdJumpManager jumpToPageWithModel:model ParentViewControll:weakSelf];
  106. };
  107. [self.view addSubview:self.rightView];
  108. }
  109. - (void)requestData {
  110. [SVProgressHUD show];
  111. NSString *urlString = [NSString stringWithFormat:@"%@/api/v2/category/list", BaseURL];
  112. [KBCacheHttp get:urlString params:nil success:^(id json, BOOL isCache) {
  113. [self.dataArr removeAllObjects];
  114. NSArray *arr = [NSArray yy_modelArrayWithClass:[KBCategoryModel class] json:json[@"data"]];
  115. [self.dataArr addObjectsFromArray:arr];
  116. self.leftView.dataArray = arr;
  117. KBCategoryModel *model = arr.firstObject;
  118. self.classifyName = model.name;
  119. self.secondDataArr = model.itemList;
  120. self.rightView.dataSource = model.itemList;
  121. // self.rightView.bannerImgUrl=model.adModel;
  122. self.rightView.model=model.adv;
  123. self.firstCategoryId = model.Id;
  124. [SVProgressHUD dismiss];
  125. } failure:^(NSError *error) {
  126. [SVProgressHUD dismiss];
  127. }];
  128. }
  129. - (void)requestEveryoneSearch {
  130. NSString *urlString = [NSString stringWithFormat:@"%@/api/v2/goods/everyoneSearch", BaseURL];
  131. [KBCacheHttp get:urlString params:nil success:^(id json, BOOL isCache) {
  132. [self.everyoneSearchArr removeAllObjects];
  133. self.hotSearchModelArray = [NSArray yy_modelArrayWithClass:[HotSearchModel class] json:json];
  134. for (HotSearchModel *model in self.hotSearchModelArray) {
  135. [self.everyoneSearchArr addObject:model.name];
  136. }
  137. } failure:^(NSError *error) {
  138. }];
  139. }
  140. - (void)refreshData {
  141. [self.dataArr removeAllObjects];
  142. [self requestData];
  143. }
  144. #pragma mark - navBarView
  145. - (void)yh_FindNavBarStaticViewClickSearch {
  146. [self createSearchViewControllerWith:nil];
  147. }
  148. #pragma mark - -------------search -----------
  149. - (void)createSearchViewControllerWith:(NSString *)text {
  150. CreatSearchManager *manager = [CreatSearchManager shareManager];
  151. [manager createSearchViewControllerWith:text viewController:self];
  152. // return;
  153. //
  154. // PYSearchViewController *searchViewController = [PYSearchViewController searchViewControllerWithHotSearches:@[] searchBarPlaceholder:@"输入商品名或粘贴淘宝标题"];
  155. // searchViewController.searchHistoryStyle = PYSearchHistoryStyleARCBorderTag;
  156. // searchViewController.hotSearchStyle = PYHotSearchStyleARCBorderTag;
  157. // searchViewController.searchTextField.font = [UIFont systemFontOfSize:13];
  158. // searchViewController.delegate = self;
  159. // searchViewController.searchBar.text = text;
  160. //
  161. // [self getHotSearchToSearchViewController:searchViewController];
  162. //
  163. // UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:searchViewController];
  164. // [self presentViewController:nav animated:NO completion:^{
  165. //
  166. // }];
  167. //
  168. // searchViewController.didSearchBlock = ^(PYSearchViewController *searchViewController, UISearchBar *searchBar, NSString *searchText) {
  169. // [MobClick event:search_count label:Search_Normal];
  170. // //处理搜索点击事件
  171. // KBFindSearchResultViewController *resultVC = [[KBFindSearchResultViewController alloc] init];
  172. // resultVC.searchBar = searchBar;
  173. // resultVC.searchName = searchText;
  174. // [nav pushViewController:resultVC animated:NO];
  175. //
  176. // };
  177. }
  178. /**
  179. 加载热搜词汇
  180. */
  181. - (void)getHotSearchToSearchViewController:(PYSearchViewController *)searchViewController {
  182. searchViewController.hotSearchModelArray = self.hotSearchModelArray;
  183. searchViewController.hotSearches = self.everyoneSearchArr;
  184. }
  185. #pragma mark - PYSearchViewControllerDelegate
  186. /**
  187. 输入完成时触发
  188. */
  189. - (void)searchViewController:(PYSearchViewController *)searchViewController searchTextDidChange:(UISearchBar *)seachBar searchText:(NSString *)searchText
  190. {
  191. if (searchText.length) {
  192. [KBHttp get:SearchAdvice params:@{@"name":searchText} success:^(id json) {
  193. NSArray *list = json[@"data"];
  194. searchViewController.searchSuggestions = list;
  195. } failure:^(NSError *error) {
  196. }];
  197. }
  198. }
  199. /**
  200. 点击建议
  201. */
  202. - (void)searchViewController:(PYSearchViewController *)searchViewController
  203. didSelectSearchSuggestionAtIndex:(NSInteger)index
  204. searchText:(NSString *)searchText {
  205. KBFindSearchResultViewController *resultVC = [[KBFindSearchResultViewController alloc] init];
  206. resultVC.searchName = searchText;
  207. resultVC.searchBar = searchViewController.searchBar;
  208. [searchViewController.navigationController pushViewController:resultVC animated:NO];
  209. }
  210. /**
  211. 点击热搜
  212. */
  213. - (void)searchViewController:(PYSearchViewController *)searchViewController
  214. didSelectHotSearchAtIndex:(NSInteger)index
  215. searchText:(NSString *)searchText {
  216. KBFindSearchResultViewController *resultVC = [[KBFindSearchResultViewController alloc] init];
  217. resultVC.searchName = searchText;
  218. resultVC.searchBar = searchViewController.searchBar;
  219. [searchViewController.navigationController pushViewController:resultVC animated:NO];
  220. [MobClick event:search_count label:Search_Hot_String];
  221. }
  222. /**
  223. 点击历史
  224. */
  225. - (void)searchViewController:(PYSearchViewController *)searchViewController
  226. didSelectSearchHistoryAtIndex:(NSInteger)index
  227. searchText:(NSString *)searchText {
  228. KBFindSearchResultViewController *resultVC = [[KBFindSearchResultViewController alloc] init];
  229. resultVC.searchName = searchText;
  230. resultVC.searchBar = searchViewController.searchBar;
  231. [searchViewController.navigationController pushViewController:resultVC animated:NO];
  232. [MobClick event:search_count label:Search_History_String];
  233. }
  234. #pragma mark -----
  235. - (KBFindNavBarStaticView *)navBarStaticView {
  236. if (!_navBarStaticView) {
  237. _navBarStaticView = [[KBFindNavBarStaticView alloc] initWithFrame:CGRectMake(60, 0, kScreenWidth-60, NavBarHeight-1)];
  238. _navBarStaticView.backgroundColor = [UIColor whiteColor];
  239. _navBarStaticView.delegate = self;
  240. }
  241. return _navBarStaticView;
  242. }
  243. - (NSMutableArray *)dataArr {
  244. if (!_dataArr) {
  245. _dataArr = [NSMutableArray array];
  246. }
  247. return _dataArr;
  248. }
  249. - (NSMutableArray *)everyoneSearchArr {
  250. if (!_everyoneSearchArr) {
  251. _everyoneSearchArr = [NSMutableArray array];
  252. }
  253. return _everyoneSearchArr;
  254. }
  255. - (void)didReceiveMemoryWarning {
  256. [super didReceiveMemoryWarning];
  257. // Dispose of any resources that can be recreated.
  258. }
  259. /*
  260. #pragma mark - Navigation
  261. // In a storyboard-based application, you will often want to do a little preparation before navigation
  262. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  263. // Get the new view controller using [segue destinationViewController].
  264. // Pass the selected object to the new view controller.
  265. }
  266. */
  267. @end