// // YOUPAIHRGuildCenterSearchVC.m // VQU // // Created by xiaohaoran on 2021/11/3. // Copyright © 2021 MS. All rights reserved. // #import "YOUPAIHRPersonnelManagementVC.h" #import "YOUPAIHRPersonnelManagementCell.h" #import "YOUPAIHRGuildCenterDetailVC.h" #import "UIScrollView+LZRefresh.h" #import "YOUPAIHRPersonnelManagementModel.h" #import "YOUPAIHRAddManagementVC.h" #import "BRPickerView.h" @interface YOUPAIHRPersonnelManagementVC () @property(nonatomic,strong)UISearchBar* youpaipsearchBar; @property(nonatomic,strong)UITableView *youpaiptableView; @property (nonatomic, strong) NSMutableArray *youpaipdataSource; @property (nonatomic, assign) NSInteger youpaipselectIndex; @end @implementation YOUPAIHRPersonnelManagementVC - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [self.view endEditing:YES]; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self youpaifgetData]; } - (void)viewDidLoad { [super viewDidLoad]; self.title = @"人员管理"; [self youpaifsetSearchUI]; [self youpaiptableView]; [self youpaifsetRightBtn]; } -(void)youpaifgetData{ @weakify(self); [LCHttpHelper requestWithURLString:ChatRoom_ManManagementList parameters:@{@"usercode":self.youpaipsearchBar.text,@"room_id":@(self.youpaiproom_id)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) {//成功 if (self.youpaipdataSource!= nil) { [self.youpaipdataSource removeAllObjects]; } NSArray *list = [YOUPAIHRPersonnelManagementModel mj_objectArrayWithKeyValuesArray:dict[@"data"]]; [self.youpaipdataSource addObjectsFromArray:list]; [self.youpaiptableView reloadData]; if (self.youpaipdataSource.count != 0) { [self.youpaiptableView lz_hideEmptyView]; }else{ [self.youpaiptableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"未搜索到相关结果~"]; } } } failure:^(NSError *error) { }]; } - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{ [searchBar resignFirstResponder]; //判断空格 if ([[searchBar.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]length]==0) { searchBar.text = @""; }else{ @weakify(self); [LCHttpHelper requestWithURLString:ChatRoom_ManManagementList parameters:@{@"usercode":searchBar.text,@"room_id":@(self.youpaiproom_id)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) {//成功 if (self.youpaipdataSource!= nil) { [self.youpaipdataSource removeAllObjects]; } NSArray *list = [YOUPAIHRPersonnelManagementModel mj_objectArrayWithKeyValuesArray:dict[@"data"]]; [self.youpaipdataSource addObjectsFromArray:list]; [self.youpaiptableView reloadData]; if (self.youpaipdataSource.count != 0) { [self.youpaiptableView lz_hideEmptyView]; }else{ [self.youpaiptableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_home_data"] content:@"暂无数据"]; } } } failure:^(NSError *error) { }]; } } - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{ NSLog(@"%@",searchText); NSLog(@"%@",searchBar.text); if ([searchBar.text isEqualToString:@""]) { [self youpaifgetData]; }else{ NSLog(@"aaa"); } } -(void)youpaifsetRightBtn{ // 退出 UIButton *rightBtn = [UIButton buttonWithType:(UIButtonTypeCustom)]; rightBtn.frame = CGRectMake(0, 0, 60, 22); UIBarButtonItem *right = [[UIBarButtonItem alloc]initWithCustomView:rightBtn]; [rightBtn setTitle:@"添加管理" forState:UIControlStateNormal]; [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [rightBtn addTarget:self action:@selector(addManageAction) forControlEvents:(UIControlEventTouchUpInside)]; self.navigationItem.rightBarButtonItem = right; rightBtn.titleLabel.font = [UIFont systemFontOfSize:14]; } -(void)addManageAction{ YOUPAIHRAddManagementVC *vc = [YOUPAIHRAddManagementVC new]; vc.youpaiproom_id = self.youpaiproom_id; [self.navigationController pushViewController:vc animated:YES]; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 68; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.youpaipdataSource.count; } -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ YOUPAIHRPersonnelManagementCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HRPersonnelManagementID" forIndexPath:indexPath];; if (cell == nil) { cell = [[YOUPAIHRPersonnelManagementCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HRPersonnelManagementID"]; } [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; cell.backgroundColor = LCBkgColor; YOUPAIHRPersonnelManagementModel *model = self.youpaipdataSource[indexPath.row]; cell.youpaipmodel = model; @weakify(self); [cell setYoupaipdidClickBlock:^(YOUPAIHRPersonnelManagementModel * _Nonnull model) { @strongify(self); [self youpaifclearStatus:model]; }]; return cell; } //解除 -(void)youpaifclearStatus:(YOUPAIHRPersonnelManagementModel*)model{ NSString *youpaipIDStr; if ([model.youpaipidentity isEqualToString:@"host"]) { youpaipIDStr = @"主持"; }else if ([model.youpaipidentity isEqualToString:@"manager"]){ youpaipIDStr = @"管理"; } NSMutableArray *actionArray = [NSMutableArray new]; @weakify(self); ZCAlertAction* action = [ZCAlertAction actionWithTitle:[NSString stringWithFormat:@"解除%@身份",youpaipIDStr] andblock:^{//删除动态 @strongify(self); [LCHttpHelper requestWithURLString:ChatRoom_UpdateManManagement parameters:@{@"usercode":model.youpaipusercode,@"room_id":@(self.youpaiproom_id),@"is_set":@(1),@"identity":model.youpaipidentity} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) {//成功 [self youpaifgetData]; } } failure:^(NSError *error) { }]; }]; [actionArray addObject:action]; ZCAlertSheetView* alertSheet = [[ZCAlertSheetView alloc]initWithTitle:nil andShowCancelButton:YES andAction:actionArray]; alertSheet.alertWindow.hidden = NO; [alertSheet show]; } - (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(0); make.width.mas_equalTo(KScreenWidth-70); 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-70, 44)]; [search setSearchFieldBackgroundImage:[UIImage imageWithColor:HexColorFromRGB(0x4F4B5B) size:CGSizeMake(KScreenWidth-70, 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:[YOUPAIHRPersonnelManagementCell class] forCellReuseIdentifier:@"HRPersonnelManagementID"]; } return _youpaiptableView; } -(void)youpaifcancelButtonClick{ [self.youpaipsearchBar resignFirstResponder]; if (self.youpaipsearchBar.text.length>0) { self.youpaipsearchBar.text = @""; }else{ [self.navigationController popViewControllerAnimated:YES]; } } -(NSMutableArray *)youpaipdataSource{ if (_youpaipdataSource == nil) { _youpaipdataSource = [NSMutableArray new]; } return _youpaipdataSource; } @end