// // RoomCharmView.m // DingDangApp // // Created by apple on 2023/5/31. // #import "RoomCharmView.h" #import "WLBlockTableView.h" #import "RoomOnlineUserListCell.h" #import "RoomMicroModel.h" @interface RoomCharmView () @property (nonatomic,strong) UILabel *titleLabel; @property (nonatomic,strong) WLBlockTableView *listView; @property (nonatomic,strong) NSMutableArray *dataSource; @property (nonatomic,assign) NSInteger page; ///麦上用户 @property (nonatomic,strong) NSMutableArray *onMicroArray; @end @implementation RoomCharmView - (void)initView{ [super initView]; self.page =1; [self titleLabel]; [self listViewBlock]; [[AppMessageManager shareManager].delegate addDelegate:self delegateQueue:dispatch_get_main_queue()]; UILongPressGestureRecognizer *longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)]; longPressGestureRecognizer.minimumPressDuration = 1.0; [self.listView addGestureRecognizer:longPressGestureRecognizer]; } - (void)longPress:(UILongPressGestureRecognizer *)gesture{ if(gesture.state == UIGestureRecognizerStateBegan){ CGPoint tapPoint = [gesture locationInView:self.listView]; NSIndexPath *tapIndexPath = [self.listView indexPathForRowAtPoint:tapPoint]; if(tapIndexPath){ RoomUserInfoModel *model = self.dataSource[tapIndexPath.row]; NSInteger roomAuth = [self.roomInfoModel.room_auth integerValue]; if(roomAuth ==2|| roomAuth ==3 || roomAuth ==5){ UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"清除" message:@"用户魅力值" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *cancelaction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil]; UIAlertAction *sendaction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [[AppMessageManager shareManager] sendCleanSelectUserCharmMessage:self.roomID userID:[ToolsObject getUserModel].user_id toUserID:model.user_id]; }]; [alertVC addAction:cancelaction]; [alertVC addAction:sendaction]; [[ToolsObject getCurrentViewController] presentViewController:alertVC animated:YES completion:nil]; } } } } //移除房间用户 刷新列表 - (void)sendRoomReloadUserMessage:(id)data{ if ([data isKindOfClass:[NSDictionary class]]) { NSDictionary * dataDict = data; NSString * user_id = dataDict[@"user_id"]; NSString * mic_id = dataDict[@"mic_id"]; BOOL is_join = dataDict[@"is_join"]; __block NSMutableArray * tempArr = @[].mutableCopy; [tempArr addObjectsFromArray:self.dataSource]; if (is_join) { [tempArr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if ([obj isKindOfClass:[RoomUserInfoModel class]]) { RoomUserInfoModel * model = obj; if ([model.user_id isEqualToString:user_id]) { model.mic_id = mic_id; } } }]; [self.listView reloadData]; } } } //房间刷新麦序 清空麦序消息 - (void)sendRoomReloadMicroList:(id)data{ if ([data isKindOfClass:[NSDictionary class]]){ NSDictionary * dataDic = data; NSString * user_id = dataDic[@"user_id"]; NSString * room_auth = dataDic[@"room_auth"]; [self.dataSource enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if ([obj isKindOfClass:[RoomUserInfoModel class]]) { RoomUserInfoModel * model = obj; if ([model.user_id isEqualToString:user_id]) { model.room_auth = room_auth; *stop = YES; } } }]; [self.listView reloadData]; return; } if ([data isKindOfClass:[NSNumber class]]) { BOOL isUsers = data; if (isUsers) { NSDictionary * dataDic = data; NSString * user_id = dataDic[@"user_id"]; NSMutableArray * dataArr = @[].mutableCopy; [dataArr addObjectsFromArray:self.dataSource]; WeakSelf(ws); [dataArr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if ([obj isKindOfClass:[RoomUserInfoModel class]]) { RoomUserInfoModel * model = obj; if ([model.user_id isEqualToString:user_id]) { [ws.dataSource removeObject:model]; *stop = YES; } } }]; [self.listView reloadData]; } return; } } - (void)setRoomInfoModel:(RoomInfoModel *)roomInfoModel{ _roomInfoModel = roomInfoModel; [self requestData]; } - (void)requestData{ if([ToolsObject isBlankString:self.roomID].length ==0){ [ToolsObject addPopVieToText:@"未获取房间信息"]; [self dismiss]; return; } NSMutableDictionary *params = [[NSMutableDictionary alloc] init]; [params setObject:self.roomID forKey:@"room_id"]; [params setValue:self.userID forKey:@"mic_user_id"]; [params setObject:@(self.page) forKey:@"page"]; WeakSelf(ws); /// /room/charm/sum/list NSString *url = [DDEncryptManager dd_aesDecryptWithText:@"Pq2vDcKFwQQ/cCRUB+vx++7JHaHqMlZzGbz2ZXgaqQo="]; [NetworkRequest requestPOST:url parameters:params block:^(BaseResponse * _Nonnull response) { if(response.code ==200){ NSArray * dataArray = [NSArray yy_modelArrayWithClass:RoomUserInfoModel.class json:response.data[@"record"]].mutableCopy; BOOL next = [[response.data objectForKey:@"next"] boolValue]; if(ws.page ==1){ ws.dataSource = [NSMutableArray arrayWithArray:dataArray]; }else{ [ws.dataSource addObjectsFromArray:dataArray]; } // if(next ==NO){ // self.listView.mj_footer.state = MJRefreshStateNoMoreData; // self.listView.mj_footer.userInteractionEnabled = NO; // }else{ // self.listView.mj_footer.userInteractionEnabled = YES; // } [ws.listView baseReloadData]; } }]; } - (void)listViewBlock{ WeakSelf(ws); [self.listView addMJHeader:^{ ws.page =1; [ws requestData]; }]; [self.listView addMJFooter:^{ ws.page ++; [ws requestData]; }]; self.listView.numberOfRowsInSectionBlock = ^NSInteger(UITableView * _Nonnull tableView, NSInteger section) { return ws.dataSource.count; }; self.listView.heightForRowAtIndexPathBlock = ^CGFloat(UITableView * _Nonnull tableView, NSIndexPath * _Nonnull indexPath) { return KAdaptedHeight(70); }; self.listView.cellForRowAtIndexPathBlock = ^UITableViewCell * _Nonnull(UITableView * _Nonnull tableView, NSIndexPath * _Nonnull indexPath) { RoomOnlineUserListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RoomOnlineUserListCell" forIndexPath:indexPath]; if (cell == nil) { cell = [[RoomOnlineUserListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"RoomOnlineUserListCell"]; } RoomUserInfoModel *cellModel = ws.dataSource[indexPath.row]; cell.model = cellModel; cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.onMicLabel.hidden = NO; cell.onMicLabel.text = cellModel.total_price; return cell ; }; self.listView.didSelectRowAtIndexPathBlock = ^(UITableView * _Nonnull tableView, NSIndexPath * _Nonnull indexPath) { RoomUserInfoModel *cellModel = ws.dataSource[indexPath.row]; [ws dismiss]; if(ws.backSetUserBlock){ ws.backSetUserBlock(cellModel); } }; } - (UILabel *)titleLabel{ if (!_titleLabel) { _titleLabel = [[UILabel alloc] init]; _titleLabel.textColor = KRGB(34); _titleLabel.text = @"魅力值列表"; _titleLabel.font = KFontMedium(18); _titleLabel.textAlignment = NSTextAlignmentCenter; [self addSubview:_titleLabel]; [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.mas_equalTo(self).mas_offset(0); make.top.mas_equalTo(self.mas_top).mas_offset(KAdaptedHeight(12)); make.height.mas_equalTo(KAdaptedHeight(25)); }]; } return _titleLabel; } - (WLBlockTableView *)listView{ if (!_listView) { _listView = [[WLBlockTableView alloc] init]; _listView.rowHeight = KAdaptedHeight(70); _listView.backgroundColor = [UIColor clearColor]; [_listView registerClass:[RoomOnlineUserListCell class] forCellReuseIdentifier:@"RoomOnlineUserListCell"]; [self addSubview:_listView]; [_listView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.titleLabel.mas_bottom).mas_offset(KAdaptedHeight(13)); make.left.right.bottom.mas_equalTo(self).mas_offset(0); }]; } return _listView; } - (NSMutableArray*)dataSource{ if (!_dataSource) { _dataSource = [[NSMutableArray alloc] init]; } return _dataSource; } - (NSMutableArray*)onMicroArray{ if (!_onMicroArray) { _onMicroArray = [[NSMutableArray alloc] init]; } return _onMicroArray; } @end