// // YOUPAIHRGuildCenterSearchVC.m // VQU // // Created by xiaohaoran on 2021/11/3. // Copyright © 2021 MS. All rights reserved. // #import "YOUPAIHRGuildCenterSearchVC.h" #import "YOUPAIHRGuildCenterSearchCell.h" #import "YOUPAIHRGuildCenterDetailVC.h" #import "YOUPAIHRGuildCenterSearchModel.h" @interface YOUPAIHRGuildCenterSearchVC () @property(nonatomic,strong)UISearchBar* youpaipsearchBar; @property(nonatomic,strong)UITableView *youpaiptableView; @property(nonatomic,strong)NSMutableArray *youpaipdataMutArr;//进来就有(待审核数据) @property(nonatomic,strong)NSMutableArray* youpaippersonArray;//搜索结果 @property(nonatomic,assign)NSInteger youpaipcurrentPage;//代表当前页码 @property(nonatomic,assign)NSInteger youpaiptotalPage; @property(nonatomic,assign)BOOL youpaipisSearch; @property(nonatomic,copy)NSString *youpaipcurrentString; @end @implementation YOUPAIHRGuildCenterSearchVC - (void)viewDidLoad { [super viewDidLoad]; self.title = @"加入公会"; [self youpaifsetSearchUI]; [self youpaiptableView]; self.youpaiptableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(youpaifloadNewData)]; MJRefreshAutoNormalFooter* normalFooter = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(youpaifloadMoreData)]; [normalFooter setTitle:@"正在加载..." forState:(MJRefreshStateRefreshing)]; [normalFooter setTitle:@"" forState:(MJRefreshStateNoMoreData)]; self.youpaiptableView.mj_footer = normalFooter; self.youpaiptableView.mj_footer.automaticallyHidden = YES; [self.youpaiptableView.mj_header beginRefreshing]; } - (void)youpaifloadNewData{ self.youpaiptableView.mj_footer.hidden = YES; [self.youpaiptableView.mj_footer endRefreshing];//先结束上拉,假如有的话 self.youpaipcurrentPage = 1; if (self.youpaipisSearch) { [self.youpaippersonArray removeAllObjects]; [LCHttpHelper requestWithURLString:ChatRoom_Guild_guildSearch parameters:@{@"keyword":self.youpaipcurrentString} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 [self.youpaippersonArray removeAllObjects]; YOUPAIHRGuildCenterSearchModel* model = [YOUPAIHRGuildCenterSearchModel mj_objectWithKeyValues:dict[@"data"]]; [self.youpaippersonArray addObject:model]; [self.youpaiptableView reloadData]; } [self.youpaiptableView.mj_footer endRefreshing]; if (self.youpaippersonArray.count != 0) { [self.youpaiptableView lz_hideEmptyView]; }else{ [self.youpaiptableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"暂无数据"]; } } failure:^(NSError *error) { [self.youpaiptableView.mj_footer endRefreshing]; }]; } [LCHttpHelper requestWithURLString:ChatRoom_Guild_search parameters:@{@"page":@(self.youpaipcurrentPage),@"number":@"15"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 [self.youpaipdataMutArr removeAllObjects]; NSArray* array = [[dict objectForKey:@"data"]objectForKey:@"list"]; NSMutableArray* modelArray = [YOUPAIHRGuildCenterSearchModel mj_objectArrayWithKeyValuesArray:array]; NSMutableArray* tempArray = [NSMutableArray arrayWithArray:(NSArray*)modelArray]; [self.youpaipdataMutArr addObjectsFromArray:tempArray]; self.youpaiptotalPage = [[[dict objectForKey:@"data"]objectForKey:@"total_page"]integerValue]; self.youpaipcurrentPage = [[[dict objectForKey:@"data"]objectForKey:@"page"]integerValue]; [self.youpaiptableView reloadData]; if (self.youpaipcurrentPage>=self.youpaiptotalPage) { [self.youpaiptableView.mj_footer endRefreshingWithNoMoreData]; self.youpaiptableView.mj_footer.hidden = YES; } [self.youpaiptableView.mj_header endRefreshing]; if (self.youpaipdataMutArr.count != 0) { [self.youpaiptableView lz_hideEmptyView]; }else{ [self.youpaiptableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"暂无数据"]; } }else{ [self.youpaiptableView.mj_header endRefreshing]; } } failure:^(NSError *error) { [self.youpaiptableView.mj_header endRefreshing]; }]; } - (void)youpaifloadMoreData{ [self.youpaiptableView.mj_header endRefreshing]; self.youpaiptableView.mj_footer.hidden = YES; [self.youpaiptableView.mj_footer endRefreshing]; self.youpaipcurrentPage+=1; if (self.youpaipisSearch) {//搜索 [self.youpaippersonArray removeAllObjects]; [LCHttpHelper requestWithURLString:ChatRoom_Guild_guildSearch parameters:@{@"keyword":self.youpaipcurrentString} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 [self.youpaippersonArray removeAllObjects]; YOUPAIHRGuildCenterSearchModel* model = [YOUPAIHRGuildCenterSearchModel mj_objectWithKeyValues:dict[@"data"]]; [self.youpaippersonArray addObject:model]; [self.youpaiptableView reloadData]; } [self.youpaiptableView.mj_footer endRefreshing]; if (self.youpaippersonArray.count != 0) { [self.youpaiptableView lz_hideEmptyView]; }else{ [self.youpaiptableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"暂无数据"]; } } failure:^(NSError *error) { [self.youpaiptableView.mj_footer endRefreshing]; }]; }else{ [LCHttpHelper requestWithURLString:ChatRoom_Guild_search parameters:@{@"page":@(self.youpaipcurrentPage),@"number":@"15"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 NSArray* array = [[dict objectForKey:@"data"]objectForKey:@"list"]; NSMutableArray* modelArray = [YOUPAIHRGuildCenterSearchModel mj_objectArrayWithKeyValuesArray:array]; NSMutableArray* tempArray = [NSMutableArray arrayWithArray:(NSArray*)modelArray]; [self.youpaipdataMutArr addObjectsFromArray:tempArray]; self.youpaiptotalPage = [[[dict objectForKey:@"data"] objectForKey:@"total_page"]integerValue]; self.youpaipcurrentPage = [[[dict objectForKey:@"data"]objectForKey:@"page"]integerValue]; [self.youpaiptableView reloadData]; if (self.youpaipcurrentPage>=self.youpaiptotalPage) { [self.youpaiptableView.mj_footer endRefreshingWithNoMoreData]; self.youpaiptableView.mj_footer.hidden = YES; } [self.youpaiptableView.mj_header endRefreshing]; }else{ [self.youpaiptableView.mj_header endRefreshing]; } if (self.youpaipdataMutArr.count != 0) { [self.youpaiptableView lz_hideEmptyView]; }else{ [self.youpaiptableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"暂无数据"]; } } failure:^(NSError *error) { [self.youpaiptableView.mj_header endRefreshing]; }]; } } -(void)youpaifbackVC{ [self.youpaipsearchBar resignFirstResponder]; } - (void)youpaifcancelClick{ self.youpaipsearchBar.text = @""; [self searchBar:self.youpaipsearchBar textDidChange:@""]; } - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{ [self.youpaipsearchBar resignFirstResponder]; } - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{ [searchBar resignFirstResponder]; //判断空格 if ([[searchBar.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]length]==0) { searchBar.text = @""; self.youpaipisSearch = NO; }else{ self.youpaipisSearch = YES; self.youpaipcurrentString = searchBar.text; [LCHttpHelper requestWithURLString:ChatRoom_Guild_guildSearch parameters:@{@"keyword":self.youpaipcurrentString} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 [self.youpaippersonArray removeAllObjects]; YOUPAIHRGuildCenterSearchModel* model = [YOUPAIHRGuildCenterSearchModel mj_objectWithKeyValues:dict[@"data"]]; if (model != nil) { [self.youpaippersonArray addObject:model]; } [self.youpaiptableView reloadData]; } [self.youpaiptableView.mj_footer endRefreshing]; if (self.youpaippersonArray.count != 0) { [self.youpaiptableView lz_hideEmptyView]; }else{ [self.youpaiptableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"暂无数据"]; } } failure:^(NSError *error) { [self.youpaiptableView.mj_footer endRefreshing]; }]; } } - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{ NSLog(@"%@",searchText); NSLog(@"%@",searchBar.text); if ([searchBar.text isEqualToString:@""]) { // self.tableView.hidden = YES; [self.youpaippersonArray removeAllObjects]; self.youpaipcurrentPage = 1; self.youpaipcurrentString = @""; self.youpaipisSearch = NO; [self.youpaiptableView.mj_header beginRefreshing]; }else{ } } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ // YOUPAIHRGuildCenterDetailVC *vc = [YOUPAIHRGuildCenterDetailVC new]; // [self.navigationController pushViewController:vc animated:YES]; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 68; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ if (self.youpaipisSearch) { return self.youpaippersonArray.count; } return self.youpaipdataMutArr.count; } -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ YOUPAIHRGuildCenterSearchCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HRGuildCenterSearchID" forIndexPath:indexPath];; if (cell == nil) { cell = [[YOUPAIHRGuildCenterSearchCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HRGuildCenterSearchID"]; } [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; cell.backgroundColor = LCBkgColor; YOUPAIHRGuildCenterSearchModel *model; if (self.youpaipisSearch) { model = self.youpaippersonArray[indexPath.row]; }else{ model = self.youpaipdataMutArr[indexPath.row]; } cell.youpaipmodel = model; @weakify(self); [cell setYoupaipjoinGuildBlock:^(YOUPAIHRGuildCenterSearchModel * _Nonnull model) { @strongify(self); [self youpaifguildJoin:model]; }]; return cell; } //申请加入 -(void)youpaifguildJoin:(YOUPAIHRGuildCenterSearchModel*)model{ [LCHttpHelper requestWithURLString:ChatRoom_guildJoin parameters:@{@"guild_id":[NSString stringWithFormat:@"%ld",model.youpaipid]} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 self.youpaipisSearch = NO; [self.youpaiptableView.mj_header beginRefreshing]; }else{ [ZCHUDHelper showTitle:dict[@"message"]]; } } failure:^(NSError *error) { }]; } - (void)youpaifsetSearchUI{ UIView *bgSearchView = [UIView new]; [self.view addSubview:bgSearchView]; [bgSearchView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.top.mas_equalTo(NavBarHeight+8); make.height.mas_equalTo(44); }]; bgSearchView.backgroundColor = LCBkgColor; UISearchBar* search = [[UISearchBar alloc]initWithFrame:CGRectZero]; [bgSearchView addSubview:search]; [search mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(10); make.width.mas_equalTo(KScreenWidth-80); make.top.mas_equalTo(0); make.bottom.mas_equalTo(0); }]; [search setImage:[UIImage imageNamed:@"vqu_images_H_search_icon"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal]; // search.tintColor = ZYPinkColor; search.backgroundImage = [UIImage imageWithColor:LCBkgColor size:CGSizeMake(KScreenWidth-80, 44)]; [search setSearchFieldBackgroundImage:[UIImage imageWithColor:HexColorFromRGB(0x4F4B5B) size:CGSizeMake(KScreenWidth-80, 38.0f)] forState:UIControlStateNormal]; // search.searchTextField.clearButtonMode = UITextFieldViewModeAlways; UITextField *searchField = [search valueForKey:@"searchField"]; if (searchField) { searchField.frame = CGRectMake(16,8,search.frame.size.width-16,38); [searchField setBackgroundColor:HexColorFromRGB(0x4F4B5B)]; searchField.layer.cornerRadius = 19.0f; searchField.layer.masksToBounds = YES; searchField.font = LCFont(14); searchField.textColor = [UIColor whiteColor]; NSMutableAttributedString* placeholder = [[NSMutableAttributedString alloc]initWithString:@"搜索公会ID"]; [placeholder addAttribute:NSFontAttributeName value:LCFont(14) range:NSMakeRange(0, placeholder.length)]; [placeholder addAttribute:NSForegroundColorAttributeName value:HexColorFromRGB(0x6C6B70) range:NSMakeRange(0, placeholder.length)]; searchField.attributedPlaceholder = placeholder; searchField.clearButtonMode = UITextFieldViewModeAlways; } search.delegate = self; self.youpaipsearchBar = search; //取消 UIButton *cancelBtn = [UIButton new]; [bgSearchView addSubview:cancelBtn]; [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(search.mas_right); make.right.mas_equalTo(0); make.top.mas_equalTo(0); make.bottom.mas_equalTo(0); }]; [cancelBtn setTitle:@"取消" forState:UIControlStateNormal]; [cancelBtn setTitleColor:HexColorFromRGB(0x9F9DA5) forState:UIControlStateNormal]; [cancelBtn addTarget:self action:@selector(youpaifcancelButtonClick) forControlEvents:UIControlEventTouchUpInside]; } -(UITableView *)youpaiptableView{ if (_youpaiptableView == nil) { _youpaiptableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain]; [self.view addSubview:_youpaiptableView]; [_youpaiptableView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(44+8+NavBarHeight); make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.bottom.mas_equalTo(-SafeHeight); }]; _youpaiptableView.delegate = self; _youpaiptableView.dataSource = self; _youpaiptableView.backgroundColor = [UIColor clearColor]; _youpaiptableView.separatorStyle = UITableViewCellSeparatorStyleNone; _youpaiptableView.showsVerticalScrollIndicator = NO; _youpaiptableView.showsHorizontalScrollIndicator = NO; if (@available(iOS 15.0, *)) { _youpaiptableView.sectionHeaderTopPadding = 0; } [_youpaiptableView registerClass:[YOUPAIHRGuildCenterSearchCell class] forCellReuseIdentifier:@"HRGuildCenterSearchID"]; } return _youpaiptableView; } -(void)youpaifcancelButtonClick{ [self.youpaipsearchBar resignFirstResponder]; if (self.youpaipsearchBar.text.length>0) { self.youpaipsearchBar.text = @""; }else{ [self.navigationController popViewControllerAnimated:YES]; } } -(NSMutableArray *)youpaipdataMutArr{ if(_youpaipdataMutArr == nil){ _youpaipdataMutArr = [NSMutableArray new]; } return _youpaipdataMutArr; } -(NSMutableArray *)youpaippersonArray{ if(_youpaippersonArray == nil){ _youpaippersonArray = [NSMutableArray new]; } return _youpaippersonArray; } @end