YOUPAILZBlindDateSelectWindow.m 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. //
  2. // YOUPAILZBlindDateSelectWindow.m
  3. // YOUQU
  4. //
  5. // Created by CY on 2021/12/15.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZBlindDateSelectWindow.h"
  9. #import "YOUPAILZChatRoomSeatModel.h"
  10. #import "YOUPAILZBlindDateSelectCell.h"
  11. @interface YOUPAILZBlindDateSelectWindow () <UICollectionViewDelegate,UICollectionViewDataSource>
  12. @property (nonatomic, weak) UICollectionView *youpaipcollectionView;
  13. @property (nonatomic, weak) UIButton *youpaipconfirmBtn;
  14. @property (nonatomic, strong) NSMutableArray <YOUPAILZChatRoomSeatModel *>* youpaipnormalSeats;
  15. @end
  16. @implementation YOUPAILZBlindDateSelectWindow
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. self.baseView.hidden = YES;
  20. [self youpaifinitUI];
  21. [self youpaifhandleSeatInfo];
  22. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(youpaifupdateSeat:) name:@"UpdateChatRoomSeat" object:nil];
  23. }
  24. -(void)youpaifupdateSeat:(NSNotification *)notify{
  25. self.youpaipnormalSeatJsons = notify.userInfo[@"seats"];
  26. [self youpaifhandleSeatInfo];
  27. }
  28. - (void)youpaifinitUI{
  29. UIView *bgV = [[UIView alloc] init];
  30. bgV.backgroundColor = HexColorFromRGB(0x2A2935);
  31. bgV.layer.cornerRadius = 10.0f;
  32. bgV.clipsToBounds = YES;
  33. bgV.layer.borderColor = HexColorFromRGB(0x4F4B5B).CGColor;
  34. bgV.layer.borderWidth = 0.5f;
  35. [self.view addSubview:bgV];
  36. [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.size.mas_offset(CGSizeMake(313.0f, 229.0f));
  38. make.center.equalTo(self.view);
  39. }];
  40. UILabel *titleL = [[UILabel alloc] init];
  41. titleL.text = @"请选择让你心动的嘉宾吧~";
  42. titleL.textColor = [UIColor whiteColor];
  43. titleL.font = LCBoldFont(19.0f);
  44. [bgV addSubview:titleL];
  45. [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.top.offset(20.0f);
  47. make.centerX.equalTo(bgV);
  48. }];
  49. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
  50. flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
  51. flowLayout.minimumLineSpacing = 0.0f;
  52. flowLayout.minimumInteritemSpacing = 0.0f;
  53. flowLayout.sectionInset = UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f);
  54. flowLayout.itemSize = CGSizeMake(313.0f / 4.0f, 80.0f);
  55. UICollectionView *youpaipseatCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
  56. youpaipseatCollectionView.delegate = self;
  57. youpaipseatCollectionView.dataSource = self;
  58. youpaipseatCollectionView.showsVerticalScrollIndicator = NO;
  59. youpaipseatCollectionView.showsHorizontalScrollIndicator = NO;
  60. youpaipseatCollectionView.backgroundColor = [UIColor clearColor];
  61. youpaipseatCollectionView.clipsToBounds = NO;
  62. [youpaipseatCollectionView registerClass:YOUPAILZBlindDateSelectCell.class forCellWithReuseIdentifier:NSStringFromClass(YOUPAILZBlindDateSelectCell.class)];
  63. [bgV addSubview:youpaipseatCollectionView];
  64. self.youpaipcollectionView = youpaipseatCollectionView;
  65. [youpaipseatCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  66. make.top.equalTo(titleL.mas_bottom).offset(20.0f);
  67. make.left.right.offset(0.0f);
  68. make.height.offset(80.0f);
  69. }];
  70. UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  71. [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
  72. [cancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  73. cancelBtn.layer.cornerRadius = 24.0f;
  74. cancelBtn.clipsToBounds = YES;
  75. [cancelBtn setBackgroundColor:HexColorFromRGB(0x4F4B5B)];
  76. cancelBtn.titleLabel.font = LCFont(17.0f);
  77. [cancelBtn addTarget:self action:@selector(youpaifcancelBtnClick) forControlEvents:UIControlEventTouchUpInside];
  78. [bgV addSubview:cancelBtn];
  79. [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.left.offset(14.0f);
  81. make.bottom.offset(-20.0f);
  82. make.size.mas_offset(CGSizeMake(135.0f, 48.0f));
  83. }];
  84. UIButton *youpaipconfirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  85. [youpaipconfirmBtn setTitle:@"确定" forState:UIControlStateNormal];
  86. [youpaipconfirmBtn setTitleColor:HexColorFromRGB(0x9F9DA5) forState:UIControlStateNormal];
  87. [youpaipconfirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
  88. [youpaipconfirmBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(135.0f, 48.0f) FromColors:@[HexColorFromRGB(0x4F4B5B),HexColorFromRGB(0x4F4B5B)] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal];
  89. [youpaipconfirmBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(135.0f, 48.0f) FromColors:@[HexColorFromRGB(0xFF7FDA),HexColorFromRGB(0xFF48B3)] ByGradientType:GradientLeftToRight] forState:UIControlStateSelected];
  90. youpaipconfirmBtn.selected = NO;
  91. youpaipconfirmBtn.userInteractionEnabled = NO;
  92. youpaipconfirmBtn.layer.cornerRadius = 24.0f;
  93. youpaipconfirmBtn.clipsToBounds = YES;
  94. youpaipconfirmBtn.titleLabel.font = LCFont(17.0f);
  95. [youpaipconfirmBtn addTarget:self action:@selector(youpaifconfirmBtnClick) forControlEvents:UIControlEventTouchUpInside];
  96. [bgV addSubview:youpaipconfirmBtn];
  97. self.youpaipconfirmBtn = youpaipconfirmBtn;
  98. [youpaipconfirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  99. make.right.offset(-14.0f);
  100. make.bottom.offset(-20.0f);
  101. make.size.mas_offset(CGSizeMake(135.0f, 48.0f));
  102. }];
  103. }
  104. - (void)youpaifhandleSeatInfo{
  105. NSMutableArray <YOUPAILZChatRoomSeatModel *>*normalAllSeats = [YOUPAILZChatRoomSeatModel mj_objectArrayWithKeyValuesArray:self.youpaipnormalSeatJsons];
  106. YOUPAILZChatRoomSeatModel *localSeat = nil;
  107. for (YOUPAILZChatRoomSeatModel *f_seatModel in normalAllSeats) {
  108. if ([self.youpaipchatroomModel.youpaipuserInfo.youpaipid isEqual:f_seatModel.youpaipuserInfo.youpaipid]) {
  109. localSeat = f_seatModel;
  110. break;
  111. }
  112. }
  113. if (localSeat != nil) {
  114. NSMutableArray <YOUPAILZChatRoomSeatModel *>*youpaipnormalSeats = nil;
  115. if (localSeat.youpaipseatIndex <= 4) {
  116. youpaipnormalSeats = [normalAllSeats subarrayWithRange:NSMakeRange(4, 4)].mutableCopy;
  117. }else{
  118. youpaipnormalSeats = [normalAllSeats subarrayWithRange:NSMakeRange(0, 4)].mutableCopy;
  119. }
  120. YOUPAILZChatRoomSeatModel *selectedSeatModel = nil;
  121. for (YOUPAILZChatRoomSeatModel *f_seatModel in self.youpaipnormalSeats) {
  122. if (f_seatModel.youpaipisSelected) {
  123. selectedSeatModel = f_seatModel;
  124. break;
  125. }
  126. }
  127. if (selectedSeatModel != nil) {
  128. for (YOUPAILZChatRoomSeatModel *f_seatModel in youpaipnormalSeats) {
  129. if ([f_seatModel.youpaipuserInfo.youpaipid isEqual:selectedSeatModel.youpaipuserInfo.youpaipid]) {
  130. f_seatModel.youpaipisSelected = YES;
  131. break;
  132. }
  133. }
  134. }
  135. self.youpaipnormalSeats = youpaipnormalSeats;
  136. }else{
  137. [ZCHUDHelper showTitle:@"你没有在座位上"];
  138. [self youpaifcancelBtnClick];
  139. }
  140. [self.youpaipcollectionView reloadData];
  141. [self youpaifreloadConfirmBtnStyle];
  142. }
  143. - (void)youpaifreloadConfirmBtnStyle{
  144. YOUPAILZChatRoomSeatModel *seatModel = nil;
  145. for (YOUPAILZChatRoomSeatModel *f_seatModel in self.youpaipnormalSeats) {
  146. if (f_seatModel.youpaipisSelected) {
  147. seatModel = f_seatModel;
  148. break;
  149. }
  150. }
  151. if (seatModel != nil) {
  152. self.youpaipconfirmBtn.selected = YES;
  153. self.youpaipconfirmBtn.userInteractionEnabled = YES;
  154. }else{
  155. self.youpaipconfirmBtn.selected = NO;
  156. self.youpaipconfirmBtn.userInteractionEnabled = NO;
  157. }
  158. }
  159. - (void)youpaifcancelBtnClick{
  160. [self dismissViewControllerAnimated:YES completion:^{}];
  161. }
  162. - (void)youpaifconfirmBtnClick{
  163. YOUPAILZChatRoomSeatModel *seatModel = nil;
  164. for (YOUPAILZChatRoomSeatModel *f_seatModel in self.youpaipnormalSeats) {
  165. if (f_seatModel.youpaipisSelected) {
  166. seatModel = f_seatModel;
  167. break;
  168. }
  169. }
  170. if (seatModel != nil) {
  171. NSInteger seatIndex = seatModel.youpaipseatIndex - 1;
  172. @weakify(self);
  173. [LCHttpHelper requestWithURLString:ChatRoomBlindDateSelect parameters:@{@"room_id":self.youpaipchatroomModel.youpaiproom_id,@"seat":@(seatIndex)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  174. @strongify(self);
  175. NSDictionary* dict = (NSDictionary*)responseObject;
  176. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  177. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  178. if (code==0) {//成功
  179. [self dismissViewControllerAnimated:YES completion:^{}];
  180. }
  181. } failure:^(NSError *error) {
  182. }];
  183. }
  184. }
  185. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  186. return self.youpaipnormalSeats.count;
  187. }
  188. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  189. YOUPAILZBlindDateSelectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass(YOUPAILZBlindDateSelectCell.class) forIndexPath:indexPath];
  190. [cell youpaifreloadWithModel:self.youpaipnormalSeats[indexPath.item]];
  191. return cell;
  192. }
  193. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  194. YOUPAILZChatRoomSeatModel *seatModel = self.youpaipnormalSeats[indexPath.item];
  195. if (seatModel.youpaipseatState == LZChatRoomSeatStateWithBusy) {
  196. for (YOUPAILZChatRoomSeatModel *f_seatModel in self.youpaipnormalSeats) {
  197. f_seatModel.youpaipisSelected = NO;
  198. }
  199. seatModel.youpaipisSelected = YES;
  200. }
  201. [self.youpaipcollectionView reloadData];
  202. [self youpaifreloadConfirmBtnStyle];
  203. }
  204. @end