猎豆优选

LDClassifyViewController.m 11KB

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