Files
yuyin_ios/SweetParty/主类/RCMic/Room/BaoMaiView/BJRoomBaomaiAlert.m
2025-08-08 11:05:33 +08:00

420 lines
14 KiB
Objective-C
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// RoomFluctuationOfWheatView.m
// QiaoYuYueWan
//
// Created by feifei on 2019/9/2.
// Copyright © 2019 QiaoYuYueWan. All rights reserved.
//
#import "BJRoomBaomaiAlert.h"
#import "BJRoomBaomaiCell.h"
#import "YYXQPickTimeAlert.h"
@interface BJRoomBaomaiAlert ()<UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate>
@property (nonatomic, strong) RCMicRoomViewModel *roomModel;
@property (nonatomic, strong) UIView *mainView;
@property (nonatomic, strong) UILabel *titelLB;
@property (nonatomic, strong) UITextField *searchTF;
@property (nonatomic, strong) UIButton *searchBtn;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, assign) BOOL haveSearchTf; //是否有搜索框
@property (nonatomic, assign) BOOL isSearching; //当前正在展示搜索出来的结果只有一个section
@property (nonatomic, strong) NSMutableArray<BJRoomBaomaiModel *> *mic_user;
@property (nonatomic, strong) NSMutableArray<BJRoomBaomaiModel *> *room_user;
@property (nonatomic, strong) NSMutableArray<BJRoomBaomaiModel *> *searchArry;
@end
@implementation BJRoomBaomaiAlert
- (NSMutableArray<BJRoomBaomaiModel *> *)mic_user {
if (!_mic_user) {
_mic_user = NSMutableArray.array;
}
return _mic_user;
}
- (NSMutableArray<BJRoomBaomaiModel *> *)room_user {
if (!_room_user) {
_room_user = NSMutableArray.array;
}
return _room_user;
}
- (NSMutableArray<BJRoomBaomaiModel *> *)searchArry {
if (!_searchArry) {
_searchArry = NSMutableArray.array;
}
return _searchArry;
}
#pragma mark - Intial
- (instancetype)initWithRoomModel:(RCMicRoomViewModel *)viewModel {
if (self = [super initWithFrame:UIScreen.mainScreen.bounds]) {
self.roomModel = viewModel;
self.backgroundColor = HEXCOLORA(0x000000, 0.5);
[self setUpUI];
}
return self;
}
- (void)setUpUI {
//返回按钮
UIButton *clearBtn = [UIButton buttonWithType:UIButtonTypeCustom];
clearBtn.frame = self.bounds;
clearBtn.backgroundColor = UIColor.clearColor;
[clearBtn setTitle:@"" forState:UIControlStateNormal];
[clearBtn addTarget:self action:@selector(removeAction) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:clearBtn];
//主图
self.mainView.frame = CGRectMake(0, APPH-400-yb_HomeIndicator_H, APPW, 400+yb_HomeIndicator_H); //有效高度 400+底部间距
[self addSubview:self.mainView];
self.titelLB.frame = CGRectMake(0, 15, APPW, 20);
[self.mainView addSubview:self.titelLB];
self.searchTF.frame = CGRectMake(22, _titelLB.bottom+14, APPW-44-80, 35);
[self.mainView addSubview:self.searchTF];
self.searchBtn.frame = CGRectMake(_searchTF.right+30, 0, 50, 30);
self.searchBtn.centerY = _searchTF.centerY;
[self.mainView addSubview:self.searchBtn];
self.tableView.frame = CGRectMake(0, _searchTF.bottom, APPW, 400-_searchTF.bottom);
[self.mainView addSubview:self.tableView];
}
- (void)showOnView:(UIView *)parent haveSearchTf:(BOOL)haveSearch {
_haveSearchTf = haveSearch;
[parent addSubview:self];
//设置动画前的状态
_searchTF.hidden = haveSearch==NO;
if (haveSearch) {
_searchTF.hidden = _searchBtn.hidden = NO;
_titelLB.text = @"抱麦";
self.tableView.frame = CGRectMake(0, _searchTF.bottom, APPW, 400-_searchTF.bottom);
}else {
_titelLB.text = @"成员";
_searchTF.hidden = _searchBtn.hidden = YES;
self.tableView.frame = CGRectMake(0, _titelLB.bottom, APPW, 400-_titelLB.bottom);
}
_mainView.y = APPH;
[self layoutIfNeeded];
//动画
[UIView animateWithDuration:0.2 animations:^{
self.mainView.y = APPH-400-yb_HomeIndicator_H;
}];
//请求数据
[self loadListData];
}
- (void)loadListData {
NSDictionary *dict = @{@"rid":C_string(_roomModel.roomInfo.roomId),
@"page":C_string(@"1"),
@"page_limit":C_string(@"999"),
};
NSMutableDictionary *paras = [NSMutableDictionary dictionary];
[paras addEntriesFromDictionary:dict];
//uid 参数
_isSearching = _searchTF.text.length > 0;
if (_searchTF.text.length > 0) {
[paras setObject:_searchTF.text forKey:@"uid"];
}
// [SVProgressHUD showWithStatus:nil];
[RCMicHTTP postWithURLString:@"/api/room/get_room_user_list" parameters:paras response:^(RCMicHTTPResult *result) {
// [SVProgressHUD dismiss];
if (result.success) {
if (result.errorCode == 200 && [result.content isKindOfClass:NSDictionary.class]) {
[self checkResult:result.content];
}else {
[SVProgressHUD showInfoWithStatus:result.message];
}
}else {
[SVProgressHUD showInfoWithStatus:@"网络错误"];
}
}];
}
- (void)checkResult:(NSDictionary *)result {
[self.searchArry removeAllObjects];
if (_isSearching) {
// NSArray *upArr = [result safeArrayForKey:@"micro_user_list"];
// if (upArr.count > 0) {
// NSArray *models = [BJRoomBaomaiModel mj_objectArrayWithKeyValuesArray:upArr];
// [self.searchArry addObjectsFromArray:models];
// }
NSArray *downArr = [result safeArrayForKey:@"unmicro_user_list"];
if (downArr.count > 0) {
NSArray *models = [BJRoomBaomaiModel mj_objectArrayWithKeyValuesArray:downArr];
[self.searchArry addObjectsFromArray:models];
}
}
else {
[self.mic_user removeAllObjects];
[self.room_user removeAllObjects];
NSArray *upArr = [result safeArrayForKey:@"micro_user_list"];
if (upArr.count > 0) {
NSArray *models = [BJRoomBaomaiModel mj_objectArrayWithKeyValuesArray:upArr];
[self.mic_user addObjectsFromArray:models];
}
NSArray *downArr = [result safeArrayForKey:@"unmicro_user_list"];
if (downArr.count > 0) {
NSArray *models = [BJRoomBaomaiModel mj_objectArrayWithKeyValuesArray:downArr];
[self.room_user addObjectsFromArray:models];
}
}
[self.tableView reloadData];
}
#pragma mark - action
- (void)removeAction {
[self removeFromSuperview];
}
- (void)tfValueChanged {
NSLog(@"%@", _searchTF.text);
if (_searchTF.text.length == 0) {
_isSearching = NO;
[_tableView reloadData];
}
}
- (void)inviteUserWith:(BJRoomBaomaiModel *)model {
__weak typeof(self) weakSelf = self;
[_roomModel bj_inviteParticipant:model.uid error:^(BOOL isOk) {
if (isOk) {
// [SVProgressHUD showInfoWithStatus:@"上麦成功"];
V2TIMMessage *message = [[V2TIMManager sharedInstance] createCustomMessage:[@(BJIMMsgType_BeUpMic).stringValue mj_JSONData]];
[[V2TIMManager sharedInstance] sendMessage:message
receiver:model.uid
groupID:nil
priority:V2TIM_PRIORITY_DEFAULT
onlineUserOnly:YES
offlinePushInfo:nil
progress:nil
succ:^{
// 单聊自定义消息发送成功
} fail:^(int code, NSString *desc) {
// 单聊自定义消息发送失败
}];
[weakSelf loadListData];
}
}];
}
- (void)xq_baomaiWith:(BJRoomBaomaiModel *)model time:(NSString *)time {
NSDictionary *params = @{@"uid":model.uid, @"rid":C_string(self.roomModel.roomInfo.roomId), @"micro_id":C_string(GVUSER.position), @"time":time};
[[AFNetworkRequset shared] postRequestWithParams:params Path:@"/api/room/room_owner_up_micro" Loading:YES Hud:YES Success:^(id _Nonnull responseDic) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self removeFromSuperview];
});
} Failure:^(id _Nonnull errorData) {
}];
}
- (void)doSearch {
if (_searchTF.text.length > 0) {
[self loadListData];
}
[self endEditing:YES];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[self doSearch];
return YES;
}
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
if (_isSearching) {
return 1;
}
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (_isSearching) {
return self.searchArry.count;
}else{
if (section == 0) {
return self.mic_user.count;
}else if (section == 1) {
return self.room_user.count;
}
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
BJRoomBaomaiCell *cell = [BJRoomBaomaiCell cellWithTableView:tableView];
cell.timeLabel.hidden = YES;
if (_haveSearchTf) {
if (indexPath.section == 0) {
cell.quDingButton.hidden = YES;
}else {
cell.quDingButton.hidden = NO;
}
}else {
cell.quDingButton.hidden = YES;
}
//定model
BJRoomBaomaiModel *model;
if (_isSearching) {
model = self.searchArry[indexPath.row];
}else{
if (indexPath.section == 0) {
model = self.mic_user[indexPath.row];
}else{
model = self.room_user[indexPath.row];
}
}
cell.model = model;
__weak typeof(self) weakSelf = self;
cell.quDingButtonClickBlock = ^(BJRoomBaomaiModel *model) {
NSLog(@"------------------%@", GVUSER.position);
if (weakSelf.roomModel.roomInfo.is_blind_date == 1 && [GVUSER.position integerValue] < 6) {
YYXQPickTimeAlert *view = LoadNib(@"YYXQPickTimeAlert");
view.frame = [UIScreen mainScreen].bounds;
[KEYWINDOW addSubview:view];
view.onConfirmBlock = ^(NSString * _Nonnull time) {
[weakSelf xq_baomaiWith:model time:time];
};
}else {
[weakSelf inviteUserWith:model];
}
// [weakSelf inviteUserWith:model];
};
return cell;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *headerView = [ControlCreator createView:nil rect:CGRectMake(0, 0, ScreenViewWidth, 40) backguoundColor:[UIColor whiteColor]];
UILabel *headerLB = [ControlCreator createLabel:headerView rect:CGRectMake(12, 10, ScreenViewWidth, 20) text:@"" font:Font(14) color:mainViceColor backguoundColor:[UIColor clearColor] align:NSTextAlignmentLeft lines:1];
if (_isSearching) {
return nil;
}
if (section == 0) {
headerLB.text = NSStringFormat(@"麦上用户%ld/8", (long)self.mic_user.count);
}else{
headerLB.text = NSStringFormat(@"麦下用户%ld人", (long)self.room_user.count);
}
return headerView;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//定model
BJRoomBaomaiModel *model;
if (_isSearching) {
model = self.searchArry[indexPath.row];
}else{
if (indexPath.section == 0) {
model = self.mic_user[indexPath.row];
}else{
model = self.room_user[indexPath.row];
}
}
if (self.onClickUserBlock) {
self.onClickUserBlock(model.uid);
}
}
#pragma mark Table view delegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 90;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
if (_isSearching) {
return 0.001;
}
return 40;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.00001;
}
#pragma mark - getter methodsb
- (UIView *)mainView{
if (!_mainView) {
_mainView = [ControlCreator createView:nil rect:CGRectZero backguoundColor:[UIColor whiteColor]];
_mainView.layer.masksToBounds = YES;
_mainView.layer.cornerRadius = 7;
}
return _mainView;
}
- (UILabel *)titelLB{
if (!_titelLB) {
_titelLB = [ControlCreator createLabel:nil rect:CGRectZero text:@"抱麦" font:Font(15) color:[UIColor blackColor] backguoundColor:[UIColor clearColor] align:NSTextAlignmentCenter lines:1];
}
return _titelLB;
}
- (UITextField *)searchTF{
if (!_searchTF) {
_searchTF = [ControlCreator createTextField:nil rect:CGRectMake(0, 0, 0, 0) placeholder:@"输入用户ID" placeholderColor:nil text:@"" font:Font(12) color:mainViceColor backguoundColor:MHColorFromHexString(@"#F8F8F8")];
_searchTF.layer.masksToBounds = YES;
_searchTF.layer.cornerRadius = 17.5;
_searchTF.keyboardType = UIKeyboardTypeNumberPad;
UIView *leftTFView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 35)];
leftTFView.backgroundColor = [UIColor clearColor];
_searchTF.leftView = leftTFView;
_searchTF.leftViewMode = UITextFieldViewModeAlways;
[_searchTF addTarget:self action:@selector(tfValueChanged) forControlEvents:UIControlEventEditingChanged];
_searchTF.delegate = self;
}
return _searchTF;
}
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
_tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
_tableView.dataSource = self;
_tableView.delegate = self;
_tableView.backgroundView = nil;
_tableView.showsVerticalScrollIndicator = NO;
_tableView.backgroundColor = [UIColor whiteColor];
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.separatorColor=[UIColor clearColor];
}
return _tableView;
}
- (UIButton *)searchBtn {
if (!_searchBtn) {
_searchBtn = [ControlCreator createButton:nil rect:CGRectZero text:@"确定" font:YBFont(14) color:UIColor.whiteColor backguoundColor:MLControlsColor imageName:nil target:self action:@selector(doSearch)];
_searchBtn.layer.masksToBounds = YES;
_searchBtn.layer.cornerRadius = 15;
}
return _searchBtn;
}
@end