// // QXAddDirectView.m // IsLandVoice // // Created by 启星 on 2025/3/6. // #import "QXAddDirectView.h" #import "QXAddDirectCell.h" #import "QXMineNetwork.h" @interface QXAddDirectView() @property (nonatomic,strong)UIView *bgView; @property (nonatomic,strong)UILabel *titleLabel; @property (nonatomic,strong)UIView *seachBgView; @property (nonatomic,strong)UIImageView *searchImageView; @property (nonatomic,strong)UITextField *textField; @property (nonatomic,strong)UITableView*tableView; @property (nonatomic,strong)NSMutableArray*dataArray; @end @implementation QXAddDirectView - (instancetype)init { self = [super init]; if (self) { self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); [self createViews]; } return self; } -(void)createViews{ UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)]; tap.delegate = self; [self addGestureRecognizer:tap]; self.backgroundColor = [UIColor clearColor]; self.bgView = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH, SCREEN_HEIGHT-ScaleWidth(429), SCREEN_WIDTH, ScaleWidth(429))]; self.bgView.backgroundColor = [UIColor whiteColor]; [self.bgView addRoundedCornersWithRadius:16 byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)]; [self addSubview:self.bgView]; self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, 16, 300, 24)]; self.titleLabel.text = @"添加主持"; self.titleLabel.font = [UIFont boldSystemFontOfSize:16]; self.titleLabel.textColor = [UIColor colorWithHexString:@"#333333"]; [self.bgView addSubview:self.titleLabel]; self.seachBgView = [[UIView alloc] initWithFrame:CGRectMake(16, self.titleLabel.bottom+12, SCREEN_WIDTH-16*2, 35)]; self.seachBgView.backgroundColor = [UIColor colorWithHexString:@"#EFF2F8"]; self.seachBgView.layer.masksToBounds = YES; self.seachBgView.layer.cornerRadius = 17.5; [self.bgView addSubview:self.seachBgView]; self.searchImageView = [[UIImageView alloc] initWithFrame:CGRectMake(8, 5.5, 24, 24)]; self.searchImageView.image = [UIImage imageNamed:@"room_song_search"]; [self.seachBgView addSubview:self.searchImageView]; self.textField = [[UITextField alloc] initWithFrame:CGRectMake(self.searchImageView.right+6, 0, self.seachBgView.width-self.searchImageView.right-6-8, 35)]; self.textField.placeholder = @"请输入ID/用户名搜索"; self.textField.font = [UIFont systemFontOfSize:14]; [self.textField addTarget:self action:@selector(textDidChange:) forControlEvents:(UIControlEventEditingChanged)]; self.textField.returnKeyType = UIReturnKeyDone; self.textField.delegate = self; self.textField.textColor = [UIColor colorWithHexString:@"#333333"]; [self.seachBgView addSubview:self.textField]; self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.seachBgView.bottom+12, self.width, self.bgView.height-12-self.seachBgView.bottom) style:(UITableViewStylePlain)]; if (@available(iOS 15.0, *)) { self.tableView.sectionHeaderTopPadding = 0; } else { // Fallback on earlier versions } self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.tableFooterView = [UIView new]; self.tableView.delegate = self; self.tableView.dataSource = self; [self.bgView addSubview:self.tableView]; } -(void)textDidChange:(UITextField*)textField{ //发起网络请求 MJWeakSelf // [self.adpter qx_searchUserWithKeyword:textField.text completion:^(BOOL success, NSArray * _Nullable results) { // [weakSelf.dataArray removeAllObjects]; // [weakSelf.dataArray addObjectsFromArray:results]; // [weakSelf.tableView reloadData]; // }]; [QXMineNetwork searchApiWithType:1 search:textField.text successBlock:^(NSDictionary * _Nonnull dict) { [weakSelf.dataArray removeAllObjects]; NSArray *arr = [NSArray yy_modelArrayWithClass:[QXSearchModel class] json:dict]; [weakSelf.dataArray addObjectsFromArray:arr]; [weakSelf.tableView reloadData]; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { }]; } #pragma mark - UITextFieldDelegate -(BOOL)textFieldShouldReturn:(UITextField *)textField{ [textField resignFirstResponder]; return YES; } -(void)textFieldDidBeginEditing:(UITextField *)textField{ [UIView animateWithDuration:0.3 animations:^{ self.bgView.y = kSafeAreaTop+90; } completion:^(BOOL finished) { }]; } -(void)textFieldDidEndEditing:(UITextField *)textField{ [UIView animateWithDuration:0.3 animations:^{ self.bgView.y = SCREEN_HEIGHT-ScaleWidth(429); } completion:^(BOOL finished) { }]; } #pragma mark - QXAddDirectCellDelegate -(void)addDirectWithUser:(QXSearchModel *)user{ [QXMineNetwork roomAddOrDeleteManagerIsAdd:YES type:1 roomId:self.roomId user_id:user.id successBlock:^(NSDictionary * _Nonnull dict) { showToast(@"添加成功"); } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { showToast(msg); }]; } -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{ return touch.view == self; } #pragma mark - UITableViewDelegate,UITableViewDataSource -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.dataArray.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ QXAddDirectCell *cell = [QXAddDirectCell cellWithTableView:tableView]; QXSearchModel *model = self.dataArray[indexPath.row]; cell.user = model; cell.delegate = self; return cell; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 52; } -(void)resetView{ } -(void)showInView:(UIView *)view{ [self resetView]; [view addSubview:self]; [UIView animateWithDuration:0.3 animations:^{ self.bgView.x = 0; }]; } -(void)hide{ [UIView animateWithDuration:0.3 animations:^{ self.bgView.y = SCREEN_HEIGHT; } completion:^(BOOL finished) { [self removeFromSuperview]; }]; } -(NSMutableArray *)dataArray{ if (!_dataArray) { _dataArray = [NSMutableArray array]; } return _dataArray; } @end