YOUPAIZYSearchVC.m 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925
  1. //
  2. // YOUPAIZYSearchVC.m
  3. // VQU
  4. //
  5. // Created by Elaine on 2020/12/16.
  6. // Copyright © 2020 leo. All rights reserved.
  7. //
  8. #import "YOUPAIZYSearchVC.h"
  9. #import "YOUPAILCOnlineCell.h"
  10. #import "YOUPAILZUserShowVC.h"
  11. #import "YOUPAIZYLabelView.h"
  12. #import "YOUPAIZYLabelModel.h"
  13. #import "YOUPAIHRSearchHeaderView.h"
  14. #import "YOUPAIHRSearchModel.h"
  15. #import "YOUPAIHRSearchLiveRoomCell.h"
  16. #import "YOUPAIHRSearchResultVC.h"
  17. #import "YOUPAILZChatRoomPasswordWindow.h"
  18. #import "YOUPAILZChatRoomVC.h"
  19. #import "UIViewController+TFPresent.h"
  20. #import "YOUPAIHRSearchBannerCell.h"
  21. typedef enum : NSUInteger {
  22. SearchCellType_List,//用户
  23. SearchCellType_talkData,//语聊
  24. SearchCellType_liveData,//直播
  25. SearchCellType_bannerData,//图片
  26. } SearchCellType;
  27. @interface HRSearchHomeModel : NSObject
  28. // 类型
  29. @property (nonatomic, assign) SearchCellType youpaiptype;
  30. @end
  31. @implementation HRSearchHomeModel
  32. @end
  33. @interface YOUPAIZYSearchVC ()<UISearchBarDelegate,UITableViewDelegate,UITableViewDataSource,ZYLabelViewDelegate,UIScrollViewDelegate>
  34. @property(nonatomic,strong)UISearchBar* searchBar;
  35. @property(nonatomic,strong)NSMutableArray* youpaipcontBtnArray;
  36. @property(nonatomic,strong)NSMutableArray* youpaipsexBtnArray;
  37. @property(nonatomic,strong)NSMutableArray* youpaippersonArray;
  38. @property(nonatomic,strong)NSString* currentString;
  39. @property(nonatomic,assign)NSInteger currentType; //0全部 1虾约号 2昵称
  40. @property(nonatomic,assign)NSInteger gender; //0全部 1女生 2男生
  41. @property(nonatomic,assign)NSInteger currentPage;//代表当前页码
  42. @property(nonatomic,strong)NSMutableArray* youpaiplabelArray;//标签
  43. @property(nonatomic,assign)CGFloat youpaiplabelViewHeight;
  44. @property(nonatomic,assign)NSInteger youpaiptotalPage;
  45. @property(nonatomic,strong)NSMutableArray *youpaiphotUserArray;//热搜
  46. @property (nonatomic, strong) NSMutableArray *youpaiphistoryArray;//历史记录
  47. //=====结果//
  48. @property(nonatomic,strong)NSMutableArray *youpaipListArray;//用户数组
  49. @property(nonatomic,strong)NSMutableArray *youpaiptalkDataArray;//语聊数组
  50. @property(nonatomic,strong)NSMutableArray *youpaipliveDataArr;//直播数组
  51. @property(nonatomic,strong)NSMutableArray *youpaipbannerArr;//图片数组
  52. @property(nonatomic,strong)YOUPAIHRSearchModel* model;
  53. @property(nonatomic,strong)youpaipbannerModel *bannerModel;
  54. @end
  55. @implementation YOUPAIZYSearchVC
  56. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  57. [self.view endEditing:YES];
  58. }
  59. - (void)youpaifsetupTableView{
  60. self.tableView.frame = CGRectMake(0, NavBarHeight, KScreenWidth, KScreenHeight-NavBarHeight);
  61. self.tableView.showsVerticalScrollIndicator = NO;
  62. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  63. self.tableView.backgroundColor = LCWhiteColor;
  64. self.tableView.delegate = self;
  65. self.tableView.dataSource= self;
  66. self.isAllowScroll = NO;
  67. [self.view addSubview:self.tableView];
  68. self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(youpaifloadNewData)];
  69. MJRefreshAutoNormalFooter* normalFooter = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(youpaifloadMoreData)];
  70. [normalFooter setTitle:@"正在加载..." forState:(MJRefreshStateRefreshing)];
  71. [normalFooter setTitle:@"" forState:(MJRefreshStateNoMoreData)];
  72. self.tableView.mj_footer = normalFooter;
  73. self.tableView.mj_footer.automaticallyHidden = YES;
  74. self.tableView.tableHeaderView = [self youpaiftableHeaderView];
  75. }
  76. - (void)youpaifloadNewData{
  77. self.tableView.mj_footer.hidden = YES;
  78. [self.tableView.mj_footer endRefreshing];//先结束上拉,假如有的话
  79. self.currentPage = 1;
  80. if (self.youpaipisSearch) {
  81. [self.tableView.mj_header endRefreshing];
  82. return;
  83. }
  84. [LCHttpHelper requestWithURLString:HomeOnlineActive parameters:@{@"page":@(self.currentPage),@"gender":@(self.gender)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  85. NSDictionary* dict = (NSDictionary*)responseObject;
  86. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  87. if (code==0) {//成功
  88. [self.youpaiphotUserArray removeAllObjects];
  89. NSArray* array = [[[dict objectForKey:@"data"]objectForKey:@"list"]objectForKey:@"list"];
  90. NSMutableArray* modelArray = [YOUPAILCOnlineModel mj_objectArrayWithKeyValuesArray:array];
  91. NSMutableArray* tempArray = [NSMutableArray arrayWithArray:(NSArray*)modelArray];
  92. [self.youpaiphotUserArray addObjectsFromArray:tempArray];
  93. self.youpaiptotalPage = [[[[dict objectForKey:@"data"]objectForKey:@"list"]objectForKey:@"total_page"]integerValue];
  94. self.currentPage = [[[[dict objectForKey:@"data"]objectForKey:@"list"]objectForKey:@"page"]integerValue];
  95. [self.tableView reloadData];
  96. if (self.currentPage>=self.youpaiptotalPage) {
  97. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  98. self.tableView.mj_footer.hidden = YES;
  99. }
  100. [self.tableView.mj_header endRefreshing];
  101. }else{
  102. [self.tableView.mj_header endRefreshing];
  103. }
  104. } failure:^(NSError *error) {
  105. [self.tableView.mj_header endRefreshing];
  106. }];
  107. }
  108. - (void)youpaifloadMoreData{
  109. [self.tableView.mj_header endRefreshing];
  110. self.tableView.mj_footer.hidden = YES;
  111. [self.tableView.mj_footer endRefreshing];
  112. self.currentPage+=1;
  113. if (self.youpaipisSearch) {//搜索
  114. [LCHttpHelper requestWithURLString:HomeSearch parameters:@{@"text":self.currentString,@"type":@(self.currentType),@"page":@(self.currentPage+1)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  115. NSDictionary* dict = (NSDictionary*)responseObject;
  116. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  117. if (code==0) {//成功
  118. if (self.youpaiptalkDataArray.count>0) {
  119. [self.youpaiptalkDataArray removeAllObjects];
  120. }
  121. if (self.youpaipliveDataArr.count>0) {
  122. [self.youpaipliveDataArr removeAllObjects];
  123. }
  124. if (self.youpaipListArray.count>0) {
  125. [self.youpaipListArray removeAllObjects];
  126. }
  127. if (self.youpaipbannerArr.count>0) {
  128. [self.youpaipbannerArr removeAllObjects];
  129. }
  130. YOUPAIHRSearchModel* model = [YOUPAIHRSearchModel mj_objectWithKeyValues:[dict objectForKey:@"data"]];
  131. youpaipbannerModel *model1 = [youpaipbannerModel mj_objectWithKeyValues:model.youpaipbannerData];
  132. self.model = model;
  133. [self.youpaiptalkDataArray addObjectsFromArray:model.youpaiptalkData];
  134. [self.youpaipliveDataArr addObjectsFromArray:model.youpaipliveData];
  135. [self.youpaipListArray addObjectsFromArray:model.youpaiplist];
  136. if (model1.youpaipkey.length>0) {
  137. [self.youpaipbannerArr addObject:model1];
  138. }
  139. // if (self.youpaiptalkDataArray.count<=0&self.youpaipliveDataArr.count<=0&self.youpaipListArray.count<=0) {
  140. // [ZCHUDHelper showTitle:@""];
  141. // }else{
  142. // [self youpaifupdateShowCells];
  143. // }
  144. self.currentPage = [[[dict objectForKey:@"data"] objectForKey:@"page"]integerValue];
  145. NSInteger youpaiptotalPage = [[[dict objectForKey:@"data"] objectForKey:@"total_page"]integerValue];
  146. if (self.currentPage>=youpaiptotalPage) {
  147. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  148. self.tableView.mj_footer.hidden = YES;
  149. }
  150. }
  151. [self.tableView.mj_footer endRefreshing];
  152. } failure:^(NSError *error) {
  153. [self.tableView.mj_footer endRefreshing];
  154. }];
  155. }else{
  156. [LCHttpHelper requestWithURLString:HomeOnlineActive parameters:@{@"page":@(self.currentPage),@"gender":@(self.gender)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  157. NSDictionary* dict = (NSDictionary*)responseObject;
  158. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  159. if (code==0) {//成功
  160. NSArray* array = [[[dict objectForKey:@"data"]objectForKey:@"list"]objectForKey:@"list"];
  161. NSMutableArray* modelArray = [YOUPAILCOnlineModel mj_objectArrayWithKeyValuesArray:array];
  162. NSMutableArray* tempArray = [NSMutableArray arrayWithArray:(NSArray*)modelArray];
  163. [self.youpaiphotUserArray addObjectsFromArray:tempArray];
  164. self.youpaiptotalPage = [[[[dict objectForKey:@"data"]objectForKey:@"list"]objectForKey:@"total_page"]integerValue];
  165. self.currentPage = [[[[dict objectForKey:@"data"]objectForKey:@"list"]objectForKey:@"page"]integerValue];
  166. [self.tableView reloadData];
  167. if (self.currentPage>=self.youpaiptotalPage) {
  168. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  169. self.tableView.mj_footer.hidden = YES;
  170. }
  171. [self.tableView.mj_header endRefreshing];
  172. }else{
  173. [self.tableView.mj_header endRefreshing];
  174. }
  175. } failure:^(NSError *error) {
  176. [self.tableView.mj_header endRefreshing];
  177. }];
  178. }
  179. }
  180. -(UIView *)youpaiftableHeaderView
  181. {
  182. UIView *tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0,0,KScreenWidth, self.youpaiplabelViewHeight)];
  183. YOUPAIHRSearchHeaderView *labelView = [[YOUPAIHRSearchHeaderView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, self.youpaiplabelViewHeight) youpaiphistoryArray:self.youpaiphistoryArray];
  184. self.youpaiplabelViewHeight = labelView.youpaipcollectionView.collectionViewLayout.collectionViewContentSize.height;
  185. tableHeaderView.frame = CGRectMake(0,0,KScreenWidth, self.youpaiplabelViewHeight+44);
  186. labelView = [[YOUPAIHRSearchHeaderView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, self.youpaiplabelViewHeight+44) youpaiphistoryArray:self.youpaiphistoryArray];
  187. @weakify(self);
  188. [labelView setYoupaiptapAction:^(NSString * _Nonnull str) {
  189. @strongify(self);
  190. [self youpaifsearchDidclikTag:str];
  191. }];
  192. [tableHeaderView addSubview:labelView];
  193. if (self.youpaiphistoryArray.count<=0) {
  194. return [UIView new];
  195. }else{
  196. return tableHeaderView;
  197. }
  198. }
  199. -(void)youpaifsearchDidclikTag:(NSString*)keyword{
  200. self.searchBar.text = keyword;
  201. self.currentString = keyword;
  202. self.youpaipisSearch = YES;
  203. // NSLog(@"%@",@{@"type":@(self.currentType),@"page":@(1),@"label_id":self.youpaiplabel_id});
  204. [LCHttpHelper requestWithURLString:HomeSearch parameters:@{@"type":@(self.currentType),@"page":@(1),@"text":keyword} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  205. NSDictionary* dict = (NSDictionary*)responseObject;
  206. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  207. if (code==0) {//成功
  208. [self.youpaippersonArray removeAllObjects];
  209. if (self.youpaiptalkDataArray.count>0) {
  210. [self.youpaiptalkDataArray removeAllObjects];
  211. }
  212. if (self.youpaipliveDataArr.count>0) {
  213. [self.youpaipliveDataArr removeAllObjects];
  214. }
  215. if (self.youpaipListArray.count>0) {
  216. [self.youpaipListArray removeAllObjects];
  217. }
  218. if (self.youpaipbannerArr.count>0) {
  219. [self.youpaipbannerArr removeAllObjects];
  220. }
  221. YOUPAIHRSearchModel* model = [YOUPAIHRSearchModel mj_objectWithKeyValues:[dict objectForKey:@"data"]];
  222. youpaipbannerModel *model1 = [youpaipbannerModel mj_objectWithKeyValues:model.youpaipbannerData];
  223. self.model = model;
  224. [self.youpaiptalkDataArray addObjectsFromArray:model.youpaiptalkData];
  225. [self.youpaipliveDataArr addObjectsFromArray:model.youpaipliveData];
  226. [self.youpaipListArray addObjectsFromArray:model.youpaiplist];
  227. if (model1.youpaipkey.length>0) {
  228. [self.youpaipbannerArr addObject:model1];
  229. }
  230. [self youpaifupdateShowCells];
  231. NSInteger youpaiptotalPage = [[[dict objectForKey:@"data"]objectForKey:@"total_page"]integerValue];
  232. self.currentPage = [[[dict objectForKey:@"data"]objectForKey:@"page"]integerValue];
  233. if (self.youpaiptalkDataArray.count == 0&&self.youpaipliveDataArr.count == 0&&self.youpaipListArray.count == 0&&self.youpaipbannerArr.count == 0) {
  234. [self.tableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"没有搜到相关结果,换个词试试~"];
  235. self.tableView.tableHeaderView = [UIView new];
  236. }else{
  237. [self.tableView lz_hideEmptyView];
  238. }
  239. if (self.currentPage>=youpaiptotalPage) {
  240. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  241. self.tableView.mj_footer.hidden = YES;
  242. }
  243. }
  244. [self.tableView.mj_footer endRefreshing];
  245. } failure:^(NSError *error) {
  246. [self.tableView.mj_footer endRefreshing];
  247. }];
  248. }
  249. - (void)viewWillAppear:(BOOL)animated{
  250. [super viewWillAppear:animated];
  251. // [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:HexColorFromRGB(0xffffff) size:CGSizeMake(KScreenWidth, NavBarHeight)] forBarMetrics:UIBarMetricsDefault];
  252. if (@available(iOS 13.0, *)) {
  253. [self.searchBar.searchTextField becomeFirstResponder];
  254. } else {
  255. UITextField *searchField = [self.searchBar valueForKey:@"_searchField"];
  256. [searchField becomeFirstResponder];
  257. }
  258. }
  259. - (void)viewWillDisappear:(BOOL)animated{
  260. [super viewWillDisappear:animated];
  261. }
  262. - (void)viewDidLoad {
  263. [super viewDidLoad];
  264. self.youpaiplabelViewHeight = 0.0;
  265. self.youpaiplabelArray = [NSMutableArray array];
  266. self.youpaiphotUserArray = [NSMutableArray array];
  267. self.youpaippersonArray = [NSMutableArray array];
  268. self.youpaipListArray = [NSMutableArray array];
  269. self.youpaiptalkDataArray = [NSMutableArray array];
  270. self.youpaipliveDataArr = [NSMutableArray array];
  271. self.youpaipbannerArr = [NSMutableArray array];
  272. self.currentPage = 1;
  273. self.currentType = 0;
  274. self.gender = [LCSaveModel getUserModel].youpaipuserinfo.youpaipgender == 1 ? 2 : 1 ;//女生搜显示男生(无标签),男生搜显示女生(有标签)
  275. self.youpaipcontBtnArray = [NSMutableArray array];
  276. self.youpaipsexBtnArray = [NSMutableArray array];
  277. [self youpaifsetupNav];
  278. [self youpaifsetupTableView];
  279. // self.tableView.hidden = YES;
  280. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(youpaifchangeHisHeaderViewStatus) name:@"changeHisHeaderView" object:nil];
  281. [self.tableView.mj_header beginRefreshing];
  282. }
  283. -(void)youpaifchangeHisHeaderViewStatus{
  284. [self.youpaiphistoryArray removeAllObjects];
  285. self.tableView.tableHeaderView = [UIView new];
  286. }
  287. -(void)dealloc{
  288. [[NSNotificationCenter defaultCenter]removeObserver:self];;
  289. }
  290. - (void)youpaifsetupNav{
  291. UISearchBar* search = [[UISearchBar alloc]initWithFrame:CGRectMake(10, 0, KScreenWidth-80, 44.0f)];
  292. [search setImage:[UIImage imageNamed:@"vqu_images_H_search_icon"]
  293. forSearchBarIcon:UISearchBarIconSearch
  294. state:UIControlStateNormal];
  295. search.tintColor = ZYPinkColor;
  296. [search setSearchFieldBackgroundImage:[UIImage imageWithColor:LZF7F8FAColor size:CGSizeMake(KScreenWidth-80, 38.0f)] forState:UIControlStateNormal];
  297. UITextField *searchField = [search valueForKey:@"searchField"];
  298. if (searchField) {
  299. searchField.frame = CGRectMake(16,8,search.frame.size.width-16,38);
  300. [searchField setBackgroundColor:HexColorFromRGB(0x4F4B5B)];
  301. searchField.layer.cornerRadius = 19.0f;
  302. searchField.layer.masksToBounds = YES;
  303. searchField.font = LCFont(14);
  304. searchField.textColor = LZ273145Color;
  305. NSMutableAttributedString* placeholder = [[NSMutableAttributedString alloc]initWithString:@"搜索花舞号/昵称"];
  306. [placeholder addAttribute:NSFontAttributeName value:LCFont(14) range:NSMakeRange(0, placeholder.length)];
  307. [placeholder addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0xD3D1D7) range:NSMakeRange(0, placeholder.length)];
  308. searchField.attributedPlaceholder = placeholder;
  309. }
  310. search.delegate = self;
  311. self.searchBar = search;
  312. UIBarButtonItem* item = [[UIBarButtonItem alloc]initWithCustomView:search];
  313. UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
  314. target:nil action:nil];
  315. negativeSpacer.width = 5;
  316. self.navigationItem.leftBarButtonItems = @[item];
  317. self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(youpaifbackVC) title:@"取消" font:LCFont15 titleColor:HexColorFromRGB(0x9F9DA5) highlightedColor:HexColorFromRGB(0x9F9DA5) titleEdgeInsets:UIEdgeInsetsZero];
  318. }
  319. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  320. if (self.youpaipisSearch) {
  321. HRSearchHomeModel* model = self.youpaippersonArray[indexPath.section];
  322. if (model.youpaiptype == SearchCellType_talkData ||model.youpaiptype == SearchCellType_liveData) {
  323. return 84;
  324. }else if(model.youpaiptype == SearchCellType_List){
  325. return 68;
  326. }else if(model.youpaiptype == SearchCellType_bannerData){
  327. return 116;
  328. }
  329. else{
  330. return 0;
  331. }
  332. }
  333. return 68;
  334. }
  335. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  336. if (self.youpaipisSearch) {
  337. if (self.youpaippersonArray.count>0) {
  338. return self.youpaippersonArray.count;
  339. }
  340. }else{
  341. return 1;
  342. }
  343. return 0;
  344. }
  345. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  346. if (self.youpaipisSearch) {
  347. if (self.youpaippersonArray.count>0) {
  348. HRSearchHomeModel* model = self.youpaippersonArray[section];
  349. if (model.youpaiptype == SearchCellType_talkData) {
  350. return self.youpaiptalkDataArray.count;
  351. }else if (model.youpaiptype == SearchCellType_liveData){
  352. return self.youpaipliveDataArr.count;
  353. }else if (model.youpaiptype == SearchCellType_List){
  354. return self.youpaipListArray.count;
  355. }else if (model.youpaiptype == SearchCellType_bannerData){
  356. return self.youpaipbannerArr.count;
  357. }
  358. else{
  359. return 0;
  360. }
  361. }else{
  362. return 0;
  363. }
  364. }
  365. return self.youpaiphotUserArray.count;
  366. }
  367. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  368. if (self.youpaipisSearch) {
  369. if (self.youpaippersonArray.count>0) {
  370. HRSearchHomeModel* model = self.youpaippersonArray[indexPath.section];
  371. switch (model.youpaiptype) {
  372. case SearchCellType_bannerData:
  373. {
  374. YOUPAIHRSearchBannerCell* cell = [[YOUPAIHRSearchBannerCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"YOUPAIHRSearchBannerCell"];
  375. if (self.youpaipbannerArr.count>0) {
  376. youpaipbannerModel *talmodel = self.youpaipbannerArr[indexPath.row];
  377. self.bannerModel = talmodel;
  378. cell.model= talmodel;
  379. }
  380. cell.backgroundColor = LCBkgColor;
  381. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  382. return cell;
  383. }
  384. break;
  385. case SearchCellType_talkData:
  386. {
  387. YOUPAIHRSearchLiveRoomCell* cell = [[YOUPAIHRSearchLiveRoomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"YOUPAIHRSearchLiveRoomCell"];
  388. if (self.youpaiptalkDataArray.count>0) {
  389. talkDataModel *talmodel = self.youpaiptalkDataArray[indexPath.row];
  390. cell.youpaipmodel = talmodel;
  391. }
  392. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  393. return cell;
  394. }
  395. break;
  396. case SearchCellType_liveData:
  397. {
  398. YOUPAIHRSearchLiveRoomCell* cell = [[YOUPAIHRSearchLiveRoomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"YOUPAIHRSearchLiveRoomCell"];
  399. if (self.youpaipliveDataArr.count>0) {
  400. talkDataModel *talmodel = self.youpaipliveDataArr[indexPath.row];
  401. cell.youpaipmodel = talmodel;
  402. }
  403. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  404. return cell;
  405. }
  406. break;
  407. case SearchCellType_List:
  408. {
  409. YOUPAILCOnlineCell* cell = [[YOUPAILCOnlineCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UserListCell"];
  410. if (self.youpaipListArray.count>0) {
  411. YOUPAILCOnlineModel* listmodel =self.youpaipListArray[indexPath.row];
  412. cell.youpaiponlineModel = listmodel;
  413. }
  414. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  415. return cell;
  416. }
  417. break;
  418. default:
  419. break;
  420. }
  421. }else{
  422. return nil;
  423. }
  424. }else{
  425. YOUPAILCOnlineCell* cell = [[YOUPAILCOnlineCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UserListCell"];
  426. if (self.youpaiphotUserArray.count>0) {
  427. YOUPAILCOnlineModel* model =self.youpaiphotUserArray[indexPath.row];
  428. cell.youpaiponlineModel = model;
  429. }
  430. // [cell bottomLineforViewHeight:74];
  431. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  432. return cell;
  433. }
  434. return nil;
  435. }
  436. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  437. {
  438. if (self.youpaipisSearch) {
  439. if (self.youpaippersonArray.count>0) {
  440. HRSearchHomeModel *model = self.youpaippersonArray[section];
  441. UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, 44)];
  442. headerView.backgroundColor = LCWhiteColor;
  443. //title
  444. UILabel *titleLabel = [UILabel new];
  445. [headerView addSubview:titleLabel];
  446. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  447. make.left.mas_equalTo(14);
  448. make.centerY.mas_equalTo(0);
  449. }];
  450. titleLabel.textColor = LZ273145Color;
  451. titleLabel.font = LCBoldFont(14);
  452. //数量
  453. UIButton *rightBtn = [UIButton new];
  454. [headerView addSubview:rightBtn];
  455. [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  456. make.right.mas_equalTo(-14);
  457. make.centerY.mas_equalTo(0);
  458. }];
  459. [rightBtn setImage:[UIImage imageNamed:@"vqu_images_chatroom_search_more"] forState:UIControlStateNormal];
  460. rightBtn.titleLabel.font = [UIFont systemFontOfSize:12];
  461. [rightBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  462. [rightBtn setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];
  463. if (model.youpaiptype == SearchCellType_talkData) {
  464. titleLabel.text = @"相关聊天室";
  465. [rightBtn setTitle:[NSString stringWithFormat:@"全部房间(%ld)",self.model.youpaiptalkDataTotalNums] forState:UIControlStateNormal];
  466. [rightBtn addTarget:self action:@selector(youpaiftalkDataRightBtnClick) forControlEvents:UIControlEventTouchUpInside];
  467. }else if (model.youpaiptype == SearchCellType_liveData){
  468. titleLabel.text = @"相关直播间";
  469. [rightBtn setTitle:[NSString stringWithFormat:@"全部房间(%ld)",self.model.youpaipliveDataTotalNums] forState:UIControlStateNormal];
  470. [rightBtn addTarget:self action:@selector(youpaifliveDataRightBtnClick) forControlEvents:UIControlEventTouchUpInside];
  471. }else if(model.youpaiptype == SearchCellType_List){
  472. titleLabel.text = @"相关用户";
  473. rightBtn.hidden = YES;
  474. }else if(model.youpaiptype == SearchCellType_bannerData){
  475. // self.tableView.tableHeaderView = [UIView new];
  476. return [UIView new];
  477. }
  478. return headerView;
  479. }else{
  480. return [UIView new];
  481. }
  482. }else{
  483. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,0,KScreenWidth,54)];
  484. view.backgroundColor = LCWhiteColor;
  485. UILabel* tipLabel = [[UILabel alloc]initWithFrame:CGRectMake(16,19,100,17)];
  486. tipLabel.textColor = [UIColor blackColor];
  487. tipLabel.font = LCBoldFont(16);
  488. tipLabel.text = @"热搜榜";
  489. [view addSubview:tipLabel];
  490. return view;
  491. }
  492. return nil;
  493. }
  494. #pragma mark 头部右边3个按钮事件
  495. //聊天室
  496. -(void)youpaiftalkDataRightBtnClick{
  497. YOUPAIHRSearchResultVC *vc = [YOUPAIHRSearchResultVC new];
  498. vc.type = 1;
  499. vc.keyword = self.currentString;
  500. [self.navigationController pushViewController:vc animated:YES];
  501. }
  502. //直播间
  503. -(void)youpaifliveDataRightBtnClick{
  504. YOUPAIHRSearchResultVC *vc = [YOUPAIHRSearchResultVC new];
  505. vc.type = 2;
  506. vc.keyword = self.currentString;
  507. [self.navigationController pushViewController:vc animated:YES];
  508. }
  509. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  510. {
  511. if (self.youpaipbannerArr.count>0) {
  512. return 0;
  513. }else{
  514. return 54.0f;
  515. }
  516. }
  517. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  518. if (self.youpaipisSearch) {
  519. HRSearchHomeModel *model = self.youpaippersonArray[indexPath.section];
  520. if (model.youpaiptype == SearchCellType_talkData) {
  521. UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  522. cell.userInteractionEnabled = NO;
  523. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  524. cell.userInteractionEnabled = YES;
  525. });
  526. talkDataModel *model1 = self.youpaiptalkDataArray[indexPath.row];
  527. NSString *roomId = [NSString stringWithFormat:@"%@",@(model1.youpaiproom_id)];
  528. if ([[YOUPAILZChatRoomManager shareManager].chatroomModel.youpaiproom_id isEqual:roomId] && [YOUPAILZChatRoomManager shareManager].chatroomController != nil) {
  529. [[YOUPAILZChatRoomManager shareManager] youpaifshowChatRoom];
  530. return;
  531. }
  532. [self youpaifshowPasswordWindowWithRoomId:[NSString stringWithFormat:@"%ld",(long)model1.youpaiproom_id] youpaipis_comein_room_hide:0];
  533. }else if (model.youpaiptype == SearchCellType_liveData){
  534. YOUPAIHRSearchResultVC *vc = [YOUPAIHRSearchResultVC new];
  535. vc.type = 2;
  536. vc.keyword = self.currentString;
  537. [self.navigationController pushViewController:vc animated:YES];
  538. }else if (model.youpaiptype == SearchCellType_bannerData){
  539. ZCBaseWebVC* baseWeb = [[ZCBaseWebVC alloc]init];
  540. baseWeb.contentUrl = self.bannerModel.youpaiplink_url;
  541. [self.navigationController pushViewController:baseWeb animated:YES];
  542. [LCHttpHelper requestWithURLString:HomeSearchSearch_stats parameters:@{@"key":self.bannerModel.youpaipkey} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  543. NSDictionary* dict = (NSDictionary*)responseObject;
  544. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  545. if (code==0) {//成功
  546. }
  547. } failure:^(NSError *error) {
  548. }];
  549. }
  550. else {
  551. ListModel* model =self.youpaipListArray[indexPath.row];
  552. YOUPAILZUserShowVC *userShow = [[YOUPAILZUserShowVC alloc] init];
  553. userShow.youpaipuserId = model.youpaipuserid;
  554. [self.navigationController pushViewController:userShow animated:YES];
  555. }
  556. }else{
  557. YOUPAILCOnlineModel* model =self.youpaiphotUserArray[indexPath.row];
  558. YOUPAILZUserShowVC *userShow = [[YOUPAILZUserShowVC alloc] init];
  559. userShow.youpaipuserId = model.youpaipuserid;
  560. [self.navigationController pushViewController:userShow animated:YES];
  561. }
  562. }
  563. - (void)youpaifshowPasswordWindowWithRoomId:(NSString *)roomId youpaipis_comein_room_hide:(NSInteger)youpaipis_comein_room_hide{
  564. @weakify(self);
  565. [LCHttpHelper requestWithURLString:GetRoomStatus parameters:@{@"room_id":roomId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  566. @strongify(self);
  567. NSDictionary* dict = (NSDictionary*)responseObject;
  568. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  569. if (code==0) {
  570. NSDictionary *data = [dict objectForKey:@"data"];
  571. if ([[data objectForKey:@"pwd"] integerValue] == 1) { // 有密码
  572. YOUPAILZChatRoomPasswordWindow *window = [[YOUPAILZChatRoomPasswordWindow alloc] init];
  573. [window setYoupaippasswordBlock:^(NSString * _Nonnull password, YOUPAILZChatRoomPasswordWindow * _Nonnull window) {
  574. @strongify(self);
  575. [self youpaifgoChatRoomVCWithPwd:password RoomId:roomId youpaipis_comein_room_hide:youpaipis_comein_room_hide window:window];
  576. }];
  577. [self TFPresentVC:window completion:^{}];
  578. }else{
  579. [self youpaifgoChatRoomVCWithPwd:@"" RoomId:roomId youpaipis_comein_room_hide:youpaipis_comein_room_hide window:nil];
  580. }
  581. }
  582. } failure:^(NSError *error) {
  583. }];
  584. }
  585. /// 加入语聊房
  586. /// @param pwd 密码
  587. /// @param roomId 房间号
  588. /// @param youpaipis_comein_room_hide 是否悄悄进房
  589. /// @param window 密码框
  590. - (void)youpaifgoChatRoomVCWithPwd:(NSString *)pwd RoomId:(NSString *)roomId youpaipis_comein_room_hide:(NSInteger)youpaipis_comein_room_hide window:(YOUPAILZChatRoomPasswordWindow *)window{
  591. [ZCHUDHelper show];
  592. @weakify(self);
  593. [LCHttpHelper requestWithURLString:JoinTalk parameters:@{@"room_id":roomId,@"pwd":pwd,@"is_comein_room_hide":@(youpaipis_comein_room_hide)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  594. [ZCHUDHelper dismiss];
  595. @strongify(self);
  596. NSDictionary* dict = (NSDictionary*)responseObject;
  597. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  598. if (code==0) {
  599. if (window != nil) {
  600. [window dismissViewControllerAnimated:YES completion:^{}];
  601. }
  602. [[YOUPAILZChatRoomManager shareManager] youpaifleaveChannel];
  603. YOUPAILZChatRoomModel *youpaipchatroomModel = [YOUPAILZChatRoomModel mj_objectWithKeyValues:dict[@"data"]];
  604. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  605. YOUPAILZChatRoomVC *vc = [[YOUPAILZChatRoomVC alloc] init];
  606. vc.youpaipchatroomModel = youpaipchatroomModel;
  607. [self.navigationController pushViewController:vc animated:YES];
  608. [YOUPAILZChatRoomManager shareManager].chatroomModel = vc.youpaipchatroomModel;
  609. [YOUPAILZChatRoomManager shareManager].chatroomController = vc;
  610. // });
  611. }else{
  612. if (window != nil) {
  613. [window youpaifshowHUDWithTitle:[dict objectForKey:@"message"]];
  614. }else{
  615. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  616. }
  617. }
  618. } failure:^(NSError *error) {
  619. [ZCHUDHelper dismiss];
  620. }];
  621. }
  622. -(void)youpaifbackVC{
  623. [self.searchBar resignFirstResponder];
  624. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  625. [self popEffectDismiss];
  626. });
  627. }
  628. - (void)youpaifcancelClick{
  629. self.searchBar.text = @"";
  630. [self searchBar:self.searchBar textDidChange:@""];
  631. }
  632. - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{
  633. [self.searchBar resignFirstResponder];
  634. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  635. [self popEffectDismiss];
  636. });
  637. }
  638. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
  639. [searchBar resignFirstResponder];
  640. //判断空格
  641. if ([[searchBar.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]length]==0) {
  642. searchBar.text = @"";
  643. self.youpaipisSearch = NO;
  644. self.youpaipisLabelSearch = NO;
  645. self.tableView.tableHeaderView = [self youpaiftableHeaderView];
  646. }else{
  647. self.youpaipisSearch = YES;
  648. self.youpaipisLabelSearch = NO;
  649. self.currentString = searchBar.text;
  650. [self youpaifsetHistoryArrWithStr:searchBar.text];
  651. [LCHttpHelper requestWithURLString:HomeSearch parameters:@{@"text":self.currentString,@"type":@(self.currentType),@"page":@(1)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  652. NSDictionary* dict = (NSDictionary*)responseObject;
  653. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  654. if (code==0) {//成功
  655. [self.youpaippersonArray removeAllObjects];
  656. if (self.youpaiptalkDataArray.count>0) {
  657. [self.youpaiptalkDataArray removeAllObjects];
  658. }
  659. if (self.youpaipliveDataArr.count>0) {
  660. [self.youpaipliveDataArr removeAllObjects];
  661. }
  662. if (self.youpaipListArray.count>0) {
  663. [self.youpaipListArray removeAllObjects];
  664. }
  665. if (self.youpaipbannerArr.count>0) {
  666. [self.youpaipbannerArr removeAllObjects];
  667. }
  668. YOUPAIHRSearchModel* model = [YOUPAIHRSearchModel mj_objectWithKeyValues:[dict objectForKey:@"data"]];
  669. youpaipbannerModel *model1 = [youpaipbannerModel mj_objectWithKeyValues:model.youpaipbannerData];
  670. self.model = model;
  671. [self.youpaiptalkDataArray addObjectsFromArray:model.youpaiptalkData];
  672. [self.youpaipliveDataArr addObjectsFromArray:model.youpaipliveData];
  673. [self.youpaipListArray addObjectsFromArray:model.youpaiplist];
  674. if (model1.youpaipkey.length>0) {
  675. [self.youpaipbannerArr addObject:model1];
  676. }
  677. [self youpaifupdateShowCells];
  678. NSInteger youpaiptotalPage = [[[dict objectForKey:@"data"]objectForKey:@"total_page"]integerValue];
  679. self.currentPage = [[[dict objectForKey:@"data"]objectForKey:@"page"]integerValue];
  680. self.tableView.tableHeaderView = [UIView new];
  681. if (self.youpaiptalkDataArray.count == 0&&self.youpaipliveDataArr.count == 0&&self.youpaipListArray.count == 0&&self.youpaipbannerArr.count == 0) {
  682. [self.tableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"没有搜到相关结果,换个词试试~"];
  683. }else{
  684. [self.tableView lz_hideEmptyView];
  685. }
  686. if (self.currentPage>=youpaiptotalPage) {
  687. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  688. self.tableView.mj_footer.hidden = YES;
  689. }
  690. }
  691. } failure:^(NSError *error) {
  692. }];
  693. }
  694. }
  695. - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
  696. NSLog(@"%@",searchText);
  697. NSLog(@"%@",searchBar.text);
  698. if ([searchBar.text isEqualToString:@""]) {
  699. // self.tableView.hidden = YES;
  700. [self.youpaippersonArray removeAllObjects];
  701. self.currentPage = 1;
  702. self.currentString = @"";
  703. self.youpaipisSearch = NO;
  704. [self.tableView lz_hideEmptyView];
  705. self.tableView.tableHeaderView = [self youpaiftableHeaderView];
  706. [self.tableView.mj_header beginRefreshing];
  707. }else{
  708. // self.youpaipisSearch = YES;
  709. // self.youpaipisLabelSearch = NO;
  710. }
  711. }
  712. #pragma mark ZYLabelViewDelegate 标签搜索
  713. -(void)youpaifclickLabel:(YOUPAIZYLabelModel *)labelModel
  714. {
  715. NSLog(@"%@",labelModel.youpaipname);
  716. NSLog(@"%@",labelModel.youpaiptag_id);
  717. self.youpaiplabel_id = labelModel.youpaiptag_id;
  718. self.youpaiplabel_name = labelModel.youpaipname;
  719. self.searchBar.text = self.youpaiplabel_name;
  720. NSLog(@"%@",@{@"type":@(self.currentType),@"page":@(1),@"label_id":self.youpaiplabel_id});
  721. [LCHttpHelper requestWithURLString:HomeSearch parameters:@{@"type":@(self.currentType),@"page":@(1),@"label_id":self.youpaiplabel_id} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  722. NSDictionary* dict = (NSDictionary*)responseObject;
  723. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  724. if (code==0) {//成功
  725. [self.youpaiphotUserArray removeAllObjects];
  726. NSMutableArray* tempArray = [YOUPAILCOnlineModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"]objectForKey:@"list"]];
  727. [self.youpaiphotUserArray addObjectsFromArray:tempArray];
  728. self.currentPage = [[[dict objectForKey:@"data"] objectForKey:@"page"]integerValue];
  729. NSInteger youpaiptotalPage = [[[dict objectForKey:@"data"] objectForKey:@"total_page"]integerValue];
  730. [self.tableView reloadData];
  731. if (self.currentPage>=youpaiptotalPage) {
  732. [self.tableView.mj_footer endRefreshingWithNoMoreData];
  733. self.tableView.mj_footer.hidden = YES;
  734. }
  735. }
  736. [self.tableView.mj_footer endRefreshing];
  737. } failure:^(NSError *error) {
  738. [self.tableView.mj_footer endRefreshing];
  739. }];
  740. }
  741. -(void)youpaifupdateShowCells{
  742. @synchronized (self) {
  743. [self.youpaippersonArray removeAllObjects];
  744. if (self.youpaipbannerArr.count) {
  745. HRSearchHomeModel *model = [HRSearchHomeModel new];
  746. model.youpaiptype = SearchCellType_bannerData;
  747. [self.youpaippersonArray addObject:model];
  748. }
  749. // if (self.youpaiptalkDataArray.count) {
  750. // HRSearchHomeModel *model = [HRSearchHomeModel new];
  751. // model.youpaiptype = SearchCellType_talkData;
  752. //
  753. // [self.youpaippersonArray addObject:model];
  754. // }
  755. // if (self.youpaipliveDataArr.count) {
  756. // HRSearchHomeModel *model = [HRSearchHomeModel new];
  757. // model.youpaiptype = SearchCellType_liveData;
  758. //
  759. // [self.youpaippersonArray addObject:model];
  760. // }
  761. if (self.youpaipListArray.count) {
  762. HRSearchHomeModel *model = [HRSearchHomeModel new];
  763. model.youpaiptype = SearchCellType_List;
  764. [self.youpaippersonArray addObject:model];
  765. }
  766. [self.tableView reloadData];
  767. }
  768. }
  769. - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
  770. [self.searchBar endEditing:YES];
  771. }
  772. - (void)youpaifsetHistoryArrWithStr:(NSString *)str
  773. {
  774. for (int i = 0; i < _youpaiphistoryArray.count; i++) {
  775. if ([_youpaiphistoryArray[i] isEqualToString:str]) {
  776. [_youpaiphistoryArray removeObjectAtIndex:i];
  777. break;
  778. }
  779. }
  780. [_youpaiphistoryArray insertObject:str atIndex:0];
  781. [NSKeyedArchiver archiveRootObject:_youpaiphistoryArray toFile:KHistorySearchPath];
  782. }
  783. - (NSMutableArray *)youpaiphistoryArray
  784. {
  785. if (!_youpaiphistoryArray) {
  786. _youpaiphistoryArray = [NSKeyedUnarchiver unarchiveObjectWithFile:KHistorySearchPath];
  787. if (!_youpaiphistoryArray) {
  788. self.youpaiphistoryArray = [NSMutableArray array];
  789. }
  790. }
  791. return _youpaiphistoryArray;
  792. }
  793. @end