// // YOUPAILZChatRoomSelectedSeatWindow.m // VQU // // Created by CY on 2021/11/6. // Copyright © 2021 MS. All rights reserved. // #import "YOUPAILZChatRoomSelectedSeatWindow.h" #import "YOUPAILZChatRoomSeatModel.h" #import "YOUPAILZChatRoomOthearSeatCell.h" @interface YOUPAILZChatRoomSelectedSeatWindow () @property (nonatomic, strong) NSMutableArray * youpaipnormalSeats; @property (nonatomic, strong) YOUPAILZChatRoomSeatModel *youpaipselectedSeatModel; @property (nonatomic,weak)UICollectionView *youpaipcollectonView; @property (nonatomic,weak)UIButton *youpaipconfirmBtn; @end @implementation YOUPAILZChatRoomSelectedSeatWindow - (void)dealloc{ [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)viewDidLoad { [super viewDidLoad]; self.baseView.hidden = YES; [self youpaifinitUI]; [self youpaifhandleSeatInfo]; [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(youpaifupdateSeat:) name:@"UpdateChatRoomSeat" object:nil]; } -(void)youpaifupdateSeat:(NSNotification *)notify{ self.youpaipnormalSeatJsons = notify.userInfo[@"seats"]; [self youpaifhandleSeatInfo]; } - (void)youpaifinitUI{ UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 415.0f + SafeHeight)]; bgV.backgroundColor = HexColorFromRGB(0x2A2935); [self.view addSubview:bgV]; [bgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.offset(0.0f); make.height.offset(415.0f + SafeHeight); }]; [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:bgV size:CGSizeMake(20.0f, 20.0f)]; UIView *navV = [[UIView alloc] init]; [bgV addSubview:navV]; [navV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.top.offset(0.0f); make.height.offset(49.0f); }]; UIButton *youpaipcloseBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [youpaipcloseBtn setImage:[UIImage imageNamed:@"vqu_images_nav_return_white"] forState:UIControlStateNormal]; [youpaipcloseBtn setImage:[UIImage imageNamed:@"vqu_images_nav_return_white"] forState:UIControlStateHighlighted]; [youpaipcloseBtn addTarget:self action:@selector(youpaifcloseBtnClick) forControlEvents:UIControlEventTouchUpInside]; [navV addSubview:youpaipcloseBtn]; [youpaipcloseBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(4.0f); make.centerY.equalTo(navV); make.size.mas_offset(CGSizeMake(44.0f, 44.0f)); }]; UILabel *titleL = [[UILabel alloc] init]; titleL.text = @"上麦"; titleL.textColor = [UIColor whiteColor]; titleL.font = LCBoldFont(17.0f); [navV addSubview:titleL]; [titleL mas_makeConstraints:^(MASConstraintMaker *make) { make.center.equalTo(navV); }]; UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical; flowLayout.minimumLineSpacing = 0.0f; flowLayout.minimumInteritemSpacing = 0.0f; flowLayout.sectionInset = UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f); flowLayout.itemSize = CGSizeMake(KScreenWidth / 4.0f, 114.0f); UICollectionView *youpaipotherSeatCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout]; youpaipotherSeatCollectionView.delegate = self; youpaipotherSeatCollectionView.dataSource = self; youpaipotherSeatCollectionView.showsVerticalScrollIndicator = NO; youpaipotherSeatCollectionView.showsHorizontalScrollIndicator = NO; youpaipotherSeatCollectionView.backgroundColor = [UIColor clearColor]; youpaipotherSeatCollectionView.clipsToBounds = NO; [youpaipotherSeatCollectionView registerClass:YOUPAILZChatRoomOthearSeatCell.class forCellWithReuseIdentifier:NSStringFromClass(YOUPAILZChatRoomOthearSeatCell.class)]; [bgV addSubview:youpaipotherSeatCollectionView]; self.youpaipcollectonView = youpaipotherSeatCollectionView; [youpaipotherSeatCollectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(navV.mas_bottom).offset(35.0f); make.left.right.offset(0.0f); make.height.offset(228.0f); }]; UIButton *youpaipconfirmBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [youpaipconfirmBtn addTarget:self action:@selector(youpaifconfirmBtnClick) forControlEvents:UIControlEventTouchUpInside]; [youpaipconfirmBtn setTitle:@"确定麦位" forState:0]; [youpaipconfirmBtn setTitleColor:HexColorFromRGB(0x9F9DA5) forState:0]; youpaipconfirmBtn.titleLabel.font = LCFont(16); if (self.youpaipplayType == 2) { [youpaipconfirmBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 80.0f, 48.0f) FromColors:@[HexColorFromRGB(0xFF7FDA),HexColorFromRGB(0xFF48B3)] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal]; }else{ [youpaipconfirmBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 80.0f, 48.0f) FromColors:@[HexColorFromRGB(0x4F4B5B),HexColorFromRGB(0x4F4B5B)] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal]; } youpaipconfirmBtn.layer.cornerRadius = 24.0f; youpaipconfirmBtn.clipsToBounds = YES; youpaipconfirmBtn.userInteractionEnabled = NO; [bgV addSubview:youpaipconfirmBtn]; self.youpaipconfirmBtn = youpaipconfirmBtn; [youpaipconfirmBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.left.offset(40.0f); make.right.offset(-40.0f); make.bottom.offset(-SafeHeight-32.0f); make.height.offset(48.0f); }]; } - (void)youpaifcloseBtnClick{ [self dismissViewControllerAnimated:YES completion:^{}]; } - (void)youpaifconfirmBtnClick{ NSInteger index = [self.youpaipnormalSeats indexOfObject:self.youpaipselectedSeatModel]; if (self.youpaipisInviation) { [LCHttpHelper requestWithURLString:InviteUpperSeat parameters:@{@"room_id":self.youpaiproomId,@"seat":@(index),@"op_uid":self.youpaipoperationUserId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 [ZCHUDHelper showTitle:@"邀请成功"]; } } failure:^(NSError *error) { }]; }else{ [LCHttpHelper requestWithURLString:HoldSeat parameters:@{@"room_id":self.youpaiproomId,@"op_uid":self.youpaipoperationUserId,@"seat":@(index)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { [[NSNotificationCenter defaultCenter]postNotificationName:@"ChatRoomConfirmSuccess" object:nil userInfo:@{@"userId":self.youpaipoperationUserId}]; } failure:^(NSError *error) { }]; } } - (void)youpaifhandleSeatInfo{ self.youpaipnormalSeats = [YOUPAILZChatRoomSeatModel mj_objectArrayWithKeyValuesArray:self.youpaipnormalSeatJsons]; if (self.youpaipnormalSeats.count != 0) { self.youpaipnormalSeats.lastObject.youpaipisSelected = NO; } for (YOUPAILZChatRoomSeatModel *seatModel in self.youpaipnormalSeats) { seatModel.youpaipisTalking = NO; if ([self.youpaipselectedSeatModel.youpaipseatName isEqual:seatModel.youpaipseatName]) { if (seatModel.youpaipseatState == LZChatRoomSeatStateWithFree) { seatModel.youpaipisSelected = YES; self.youpaipselectedSeatModel = seatModel; }else{ self.youpaipselectedSeatModel = nil; } } } [self.youpaipcollectonView reloadData]; [self youpaifreloadConfirmBtnStyle]; } - (void)youpaifreloadConfirmBtnStyle{ if (self.youpaipselectedSeatModel != nil) { [self.youpaipconfirmBtn setTitleColor:[UIColor whiteColor] forState:0]; if (self.youpaipplayType == 2) { [self.youpaipconfirmBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 80.0f, 48.0f) FromColors:@[HexColorFromRGB(0xFF7FDA),HexColorFromRGB(0xFF48B3)] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal]; }else{ [self.youpaipconfirmBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 80.0f, 48.0f) FromColors:@[HexColorFromRGB(0xFF0084),HexColorFromRGB(0xFF3A00)] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal]; } self.youpaipconfirmBtn.userInteractionEnabled = YES; }else{ [self.youpaipconfirmBtn setTitleColor:HexColorFromRGB(0x9F9DA5) forState:0]; [self.youpaipconfirmBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 80.0f, 48.0f) FromColors:@[HexColorFromRGB(0x4F4B5B),HexColorFromRGB(0x4F4B5B)] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal]; self.youpaipconfirmBtn.userInteractionEnabled = NO; } } #pragma mark - UICollectionViewDataSource - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return self.youpaipnormalSeats.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ YOUPAILZChatRoomOthearSeatCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass(YOUPAILZChatRoomOthearSeatCell.class) forIndexPath:indexPath]; YOUPAILZChatRoomSeatModel *model = self.youpaipnormalSeats[indexPath.item]; model.youpaipseat_selected = @""; [cell youpaifreloadWithModel:model]; return cell; } #pragma mark - UICollectionViewDelegate - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ YOUPAILZChatRoomSeatModel *seatModel = self.youpaipnormalSeats[indexPath.item]; if (seatModel.youpaipseatState == LZChatRoomSeatStateWithFree) { self.youpaipselectedSeatModel.youpaipisSelected = NO; seatModel.youpaipisSelected = YES; self.youpaipselectedSeatModel = seatModel; } [self.youpaipcollectonView reloadData]; [self youpaifreloadConfirmBtnStyle]; } @end