YOUPAILZChatRoomSelectedSeatWindow.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. //
  2. // YOUPAILZChatRoomSelectedSeatWindow.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/11/6.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZChatRoomSelectedSeatWindow.h"
  9. #import "YOUPAILZChatRoomSeatModel.h"
  10. #import "YOUPAILZChatRoomOthearSeatCell.h"
  11. @interface YOUPAILZChatRoomSelectedSeatWindow ()<UICollectionViewDelegate,UICollectionViewDataSource>
  12. @property (nonatomic, strong) NSMutableArray <YOUPAILZChatRoomSeatModel *>* youpaipnormalSeats;
  13. @property (nonatomic, strong) YOUPAILZChatRoomSeatModel *youpaipselectedSeatModel;
  14. @property (nonatomic,weak)UICollectionView *youpaipcollectonView;
  15. @property (nonatomic,weak)UIButton *youpaipconfirmBtn;
  16. @end
  17. @implementation YOUPAILZChatRoomSelectedSeatWindow
  18. - (void)dealloc{
  19. [[NSNotificationCenter defaultCenter] removeObserver:self];
  20. }
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. self.baseView.hidden = YES;
  24. [self youpaifinitUI];
  25. [self youpaifhandleSeatInfo];
  26. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(youpaifupdateSeat:) name:@"UpdateChatRoomSeat" object:nil];
  27. }
  28. -(void)youpaifupdateSeat:(NSNotification *)notify{
  29. self.youpaipnormalSeatJsons = notify.userInfo[@"seats"];
  30. [self youpaifhandleSeatInfo];
  31. }
  32. - (void)youpaifinitUI{
  33. UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 415.0f + SafeHeight)];
  34. bgV.backgroundColor = HexColorFromRGB(0x2A2935);
  35. [self.view addSubview:bgV];
  36. [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.left.right.bottom.offset(0.0f);
  38. make.height.offset(415.0f + SafeHeight);
  39. }];
  40. [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:bgV size:CGSizeMake(20.0f, 20.0f)];
  41. UIView *navV = [[UIView alloc] init];
  42. [bgV addSubview:navV];
  43. [navV mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.left.right.top.offset(0.0f);
  45. make.height.offset(49.0f);
  46. }];
  47. UIButton *youpaipcloseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  48. [youpaipcloseBtn setImage:[UIImage imageNamed:@"vqu_images_nav_return_white"] forState:UIControlStateNormal];
  49. [youpaipcloseBtn setImage:[UIImage imageNamed:@"vqu_images_nav_return_white"] forState:UIControlStateHighlighted];
  50. [youpaipcloseBtn addTarget:self action:@selector(youpaifcloseBtnClick) forControlEvents:UIControlEventTouchUpInside];
  51. [navV addSubview:youpaipcloseBtn];
  52. [youpaipcloseBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  53. make.left.offset(4.0f);
  54. make.centerY.equalTo(navV);
  55. make.size.mas_offset(CGSizeMake(44.0f, 44.0f));
  56. }];
  57. UILabel *titleL = [[UILabel alloc] init];
  58. titleL.text = @"上麦";
  59. titleL.textColor = [UIColor whiteColor];
  60. titleL.font = LCBoldFont(17.0f);
  61. [navV addSubview:titleL];
  62. [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.center.equalTo(navV);
  64. }];
  65. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  66. flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
  67. flowLayout.minimumLineSpacing = 0.0f;
  68. flowLayout.minimumInteritemSpacing = 0.0f;
  69. flowLayout.sectionInset = UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f);
  70. flowLayout.itemSize = CGSizeMake(KScreenWidth / 4.0f, 114.0f);
  71. UICollectionView *youpaipotherSeatCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
  72. youpaipotherSeatCollectionView.delegate = self;
  73. youpaipotherSeatCollectionView.dataSource = self;
  74. youpaipotherSeatCollectionView.showsVerticalScrollIndicator = NO;
  75. youpaipotherSeatCollectionView.showsHorizontalScrollIndicator = NO;
  76. youpaipotherSeatCollectionView.backgroundColor = [UIColor clearColor];
  77. youpaipotherSeatCollectionView.clipsToBounds = NO;
  78. [youpaipotherSeatCollectionView registerClass:YOUPAILZChatRoomOthearSeatCell.class forCellWithReuseIdentifier:NSStringFromClass(YOUPAILZChatRoomOthearSeatCell.class)];
  79. [bgV addSubview:youpaipotherSeatCollectionView];
  80. self.youpaipcollectonView = youpaipotherSeatCollectionView;
  81. [youpaipotherSeatCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  82. make.top.equalTo(navV.mas_bottom).offset(35.0f);
  83. make.left.right.offset(0.0f);
  84. make.height.offset(228.0f);
  85. }];
  86. UIButton *youpaipconfirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  87. [youpaipconfirmBtn addTarget:self action:@selector(youpaifconfirmBtnClick) forControlEvents:UIControlEventTouchUpInside];
  88. [youpaipconfirmBtn setTitle:@"确定麦位" forState:0];
  89. [youpaipconfirmBtn setTitleColor:HexColorFromRGB(0x9F9DA5) forState:0];
  90. youpaipconfirmBtn.titleLabel.font = LCFont(16);
  91. if (self.youpaipplayType == 2) {
  92. [youpaipconfirmBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 80.0f, 48.0f) FromColors:@[HexColorFromRGB(0xFF7FDA),HexColorFromRGB(0xFF48B3)] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal];
  93. }else{
  94. [youpaipconfirmBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 80.0f, 48.0f) FromColors:@[HexColorFromRGB(0x4F4B5B),HexColorFromRGB(0x4F4B5B)] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal];
  95. }
  96. youpaipconfirmBtn.layer.cornerRadius = 24.0f;
  97. youpaipconfirmBtn.clipsToBounds = YES;
  98. youpaipconfirmBtn.userInteractionEnabled = NO;
  99. [bgV addSubview:youpaipconfirmBtn];
  100. self.youpaipconfirmBtn = youpaipconfirmBtn;
  101. [youpaipconfirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  102. make.left.offset(40.0f);
  103. make.right.offset(-40.0f);
  104. make.bottom.offset(-SafeHeight-32.0f);
  105. make.height.offset(48.0f);
  106. }];
  107. }
  108. - (void)youpaifcloseBtnClick{
  109. [self dismissViewControllerAnimated:YES completion:^{}];
  110. }
  111. - (void)youpaifconfirmBtnClick{
  112. NSInteger index = [self.youpaipnormalSeats indexOfObject:self.youpaipselectedSeatModel];
  113. if (self.youpaipisInviation) {
  114. [LCHttpHelper requestWithURLString:InviteUpperSeat parameters:@{@"room_id":self.youpaiproomId,@"seat":@(index),@"op_uid":self.youpaipoperationUserId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  115. NSDictionary* dict = (NSDictionary*)responseObject;
  116. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  117. if (code==0) {//成功
  118. [ZCHUDHelper showTitle:@"邀请成功"];
  119. }
  120. } failure:^(NSError *error) {
  121. }];
  122. }else{
  123. [LCHttpHelper requestWithURLString:HoldSeat parameters:@{@"room_id":self.youpaiproomId,@"op_uid":self.youpaipoperationUserId,@"seat":@(index)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  124. [[NSNotificationCenter defaultCenter]postNotificationName:@"ChatRoomConfirmSuccess" object:nil userInfo:@{@"userId":self.youpaipoperationUserId}];
  125. } failure:^(NSError *error) {
  126. }];
  127. }
  128. }
  129. - (void)youpaifhandleSeatInfo{
  130. self.youpaipnormalSeats = [YOUPAILZChatRoomSeatModel mj_objectArrayWithKeyValuesArray:self.youpaipnormalSeatJsons];
  131. if (self.youpaipnormalSeats.count != 0) {
  132. self.youpaipnormalSeats.lastObject.youpaipisSelected = NO;
  133. }
  134. for (YOUPAILZChatRoomSeatModel *seatModel in self.youpaipnormalSeats) {
  135. seatModel.youpaipisTalking = NO;
  136. if ([self.youpaipselectedSeatModel.youpaipseatName isEqual:seatModel.youpaipseatName]) {
  137. if (seatModel.youpaipseatState == LZChatRoomSeatStateWithFree) {
  138. seatModel.youpaipisSelected = YES;
  139. self.youpaipselectedSeatModel = seatModel;
  140. }else{
  141. self.youpaipselectedSeatModel = nil;
  142. }
  143. }
  144. }
  145. [self.youpaipcollectonView reloadData];
  146. [self youpaifreloadConfirmBtnStyle];
  147. }
  148. - (void)youpaifreloadConfirmBtnStyle{
  149. if (self.youpaipselectedSeatModel != nil) {
  150. [self.youpaipconfirmBtn setTitleColor:[UIColor whiteColor] forState:0];
  151. if (self.youpaipplayType == 2) {
  152. [self.youpaipconfirmBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 80.0f, 48.0f) FromColors:@[HexColorFromRGB(0xFF7FDA),HexColorFromRGB(0xFF48B3)] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal];
  153. }else{
  154. [self.youpaipconfirmBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 80.0f, 48.0f) FromColors:@[HexColorFromRGB(0xFF0084),HexColorFromRGB(0xFF3A00)] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal];
  155. }
  156. self.youpaipconfirmBtn.userInteractionEnabled = YES;
  157. }else{
  158. [self.youpaipconfirmBtn setTitleColor:HexColorFromRGB(0x9F9DA5) forState:0];
  159. [self.youpaipconfirmBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 80.0f, 48.0f) FromColors:@[HexColorFromRGB(0x4F4B5B),HexColorFromRGB(0x4F4B5B)] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal];
  160. self.youpaipconfirmBtn.userInteractionEnabled = NO;
  161. }
  162. }
  163. #pragma mark - UICollectionViewDataSource
  164. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  165. return self.youpaipnormalSeats.count;
  166. }
  167. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  168. YOUPAILZChatRoomOthearSeatCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass(YOUPAILZChatRoomOthearSeatCell.class) forIndexPath:indexPath];
  169. YOUPAILZChatRoomSeatModel *model = self.youpaipnormalSeats[indexPath.item];
  170. model.youpaipseat_selected = @"";
  171. [cell youpaifreloadWithModel:model];
  172. return cell;
  173. }
  174. #pragma mark - UICollectionViewDelegate
  175. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  176. YOUPAILZChatRoomSeatModel *seatModel = self.youpaipnormalSeats[indexPath.item];
  177. if (seatModel.youpaipseatState == LZChatRoomSeatStateWithFree) {
  178. self.youpaipselectedSeatModel.youpaipisSelected = NO;
  179. seatModel.youpaipisSelected = YES;
  180. self.youpaipselectedSeatModel = seatModel;
  181. }
  182. [self.youpaipcollectonView reloadData];
  183. [self youpaifreloadConfirmBtnStyle];
  184. }
  185. @end