《省钱达人》与《猎豆优选》UI相同版。域名tbk

DRClassifyViewController.m 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. //
  2. // DRClassifyViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/4/28.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRClassifyViewController.h"
  9. #import "DRClassifyLeftView.h"
  10. #import "DRClassifyRightView.h"
  11. #import "DRCategoryModel.h"
  12. #import "DRSecondCategoryModel.h"
  13. #import "DRGoodListViewController.h"
  14. #import "DRClassifyListController.h"
  15. #import "DRFindNavBarStaticView.h"
  16. #import "PYSearchViewController.h"
  17. #import "DRFindSearchResultViewController.h"
  18. #import "DRFindRequestViewModel.h"
  19. @interface DRClassifyViewController ()<YHFindNavBarStaticViewDelegate,PYSearchViewControllerDelegate>
  20. {
  21. }
  22. @property (nonatomic, strong) DRClassifyLeftView *leftView; //类别
  23. @property (nonatomic, strong) DRClassifyRightView *rightView;//详单
  24. @property (nonatomic, strong) NSMutableArray *dataArr;
  25. @property (nonatomic, strong) NSArray *secondDataArr;
  26. @property (nonatomic, strong) DRFindNavBarStaticView *navBarStaticView;
  27. @property (nonatomic, strong) NSMutableArray *everyoneSearchArr;
  28. @property (nonatomic, strong) NSString *classifyName;
  29. @property (nonatomic, strong) NSString *firstCategoryId;
  30. @end
  31. @implementation DRClassifyViewController
  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 = [[DRClassifyLeftView alloc]initWithFrame:CGRectMake(0, NavBarHeight, 92*SCREEN_MUTI, SCREEN_HEIGHT - NavBarHeight)];
  77. __weak typeof(self) weakSelf = self;
  78. self.leftView.selectRowBlock = ^(NSInteger index) {
  79. DRCategoryModel *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 = [[DRClassifyRightView 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. DRClassifyListController *list = [[DRClassifyListController alloc] init];
  92. DRSecondCategoryModel *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. [DRCacheHttp get:urlString params:nil success:^(id json, BOOL isCache) {
  106. [self.dataArr removeAllObjects];
  107. NSArray *arr = [NSArray yy_modelArrayWithClass:[DRCategoryModel class] json:json[@"data"]];
  108. [self.dataArr addObjectsFromArray:arr];
  109. self.leftView.dataArray = arr;
  110. DRCategoryModel *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. [DRFindRequestViewModel 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. [self presentViewController:nav animated:NO completion:^{
  149. for (int i = 0; i < searchViewController.hotSearchTags.count; i++) {
  150. UILabel *tag = searchViewController.hotSearchTags[i];
  151. NSDictionary *dic = self.everyoneSearchArr[i];
  152. if ([dic[@"color"] boolValue]) {
  153. tag.layer.borderColor = [UIColor homeRedColor].CGColor;
  154. tag.textColor = [UIColor homeRedColor];
  155. }
  156. }
  157. }];
  158. searchViewController.didSearchBlock = ^(PYSearchViewController *searchViewController, UISearchBar *searchBar, NSString *searchText) {
  159. [MobClick event:search_count label:Search_Normal];
  160. //处理搜索点击事件
  161. DRFindSearchResultViewController *resultVC = [[DRFindSearchResultViewController alloc] init];
  162. resultVC.searchBar = searchBar;
  163. resultVC.searchName = searchText;
  164. [nav pushViewController:resultVC animated:NO];
  165. };
  166. }
  167. /**
  168. 加载热搜词汇
  169. */
  170. - (void)getHotSearchToSearchViewController:(PYSearchViewController *)searchViewController {
  171. NSMutableArray *hotSearch = [NSMutableArray array];
  172. for (NSDictionary *dic in self.everyoneSearchArr) {
  173. [hotSearch addObject:dic[@"name"]];
  174. }
  175. searchViewController.hotSearches = hotSearch;
  176. }
  177. #pragma mark - PYSearchViewControllerDelegate
  178. /**
  179. 输入完成时触发
  180. */
  181. - (void)searchViewController:(PYSearchViewController *)searchViewController searchTextDidChange:(UISearchBar *)seachBar searchText:(NSString *)searchText
  182. {
  183. if (searchText.length) {
  184. [DRHttp get:SearchAdvice params:@{@"name":searchText} success:^(id json) {
  185. NSArray *list = json[@"data"];
  186. searchViewController.searchSuggestions = list;
  187. } failure:^(NSError *error) {
  188. }];
  189. }
  190. }
  191. /**
  192. 点击建议
  193. */
  194. - (void)searchViewController:(PYSearchViewController *)searchViewController
  195. didSelectSearchSuggestionAtIndex:(NSInteger)index
  196. searchText:(NSString *)searchText {
  197. DRFindSearchResultViewController *resultVC = [[DRFindSearchResultViewController alloc] init];
  198. resultVC.searchName = searchText;
  199. resultVC.searchBar = searchViewController.searchBar;
  200. [searchViewController.navigationController pushViewController:resultVC animated:NO];
  201. }
  202. /**
  203. 点击热搜
  204. */
  205. - (void)searchViewController:(PYSearchViewController *)searchViewController
  206. didSelectHotSearchAtIndex:(NSInteger)index
  207. searchText:(NSString *)searchText {
  208. DRFindSearchResultViewController *resultVC = [[DRFindSearchResultViewController alloc] init];
  209. resultVC.searchName = searchText;
  210. resultVC.searchBar = searchViewController.searchBar;
  211. [searchViewController.navigationController pushViewController:resultVC animated:NO];
  212. [MobClick event:search_count label:Search_Hot_String];
  213. }
  214. /**
  215. 点击历史
  216. */
  217. - (void)searchViewController:(PYSearchViewController *)searchViewController
  218. didSelectSearchHistoryAtIndex:(NSInteger)index
  219. searchText:(NSString *)searchText {
  220. DRFindSearchResultViewController *resultVC = [[DRFindSearchResultViewController alloc] init];
  221. resultVC.searchName = searchText;
  222. resultVC.searchBar = searchViewController.searchBar;
  223. [searchViewController.navigationController pushViewController:resultVC animated:NO];
  224. [MobClick event:search_count label:Search_History_String];
  225. }
  226. #pragma mark -----
  227. - (DRFindNavBarStaticView *)navBarStaticView {
  228. if (!_navBarStaticView) {
  229. _navBarStaticView = [[DRFindNavBarStaticView alloc] initWithFrame:CGRectMake(60, 0, kScreenWidth-60, NavBarHeight-2)];
  230. _navBarStaticView.backgroundColor = [UIColor whiteColor];
  231. _navBarStaticView.delegate = self;
  232. }
  233. return _navBarStaticView;
  234. }
  235. - (NSMutableArray *)dataArr {
  236. if (!_dataArr) {
  237. _dataArr = [NSMutableArray array];
  238. }
  239. return _dataArr;
  240. }
  241. - (NSMutableArray *)everyoneSearchArr {
  242. if (!_everyoneSearchArr) {
  243. _everyoneSearchArr = [NSMutableArray array];
  244. }
  245. return _everyoneSearchArr;
  246. }
  247. - (void)didReceiveMemoryWarning {
  248. [super didReceiveMemoryWarning];
  249. // Dispose of any resources that can be recreated.
  250. }
  251. /*
  252. #pragma mark - Navigation
  253. // In a storyboard-based application, you will often want to do a little preparation before navigation
  254. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  255. // Get the new view controller using [segue destinationViewController].
  256. // Pass the selected object to the new view controller.
  257. }
  258. */
  259. @end