123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- //
- // YOUPAILZBlindDateSelectWindow.m
- // YOUQU
- //
- // Created by CY on 2021/12/15.
- // Copyright © 2021 MS. All rights reserved.
- //
- #import "YOUPAILZBlindDateSelectWindow.h"
- #import "YOUPAILZChatRoomSeatModel.h"
- #import "YOUPAILZBlindDateSelectCell.h"
- @interface YOUPAILZBlindDateSelectWindow () <UICollectionViewDelegate,UICollectionViewDataSource>
- @property (nonatomic, weak) UICollectionView *youpaipcollectionView;
- @property (nonatomic, weak) UIButton *youpaipconfirmBtn;
- @property (nonatomic, strong) NSMutableArray <YOUPAILZChatRoomSeatModel *>* youpaipnormalSeats;
- @end
- @implementation YOUPAILZBlindDateSelectWindow
- - (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] init];
- bgV.backgroundColor = HexColorFromRGB(0x2A2935);
- bgV.layer.cornerRadius = 10.0f;
- bgV.clipsToBounds = YES;
- bgV.layer.borderColor = HexColorFromRGB(0x4F4B5B).CGColor;
- bgV.layer.borderWidth = 0.5f;
- [self.view addSubview:bgV];
- [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_offset(CGSizeMake(313.0f, 229.0f));
- make.center.equalTo(self.view);
- }];
-
- UILabel *titleL = [[UILabel alloc] init];
- titleL.text = @"请选择让你心动的嘉宾吧~";
- titleL.textColor = [UIColor whiteColor];
- titleL.font = LCBoldFont(19.0f);
- [bgV addSubview:titleL];
- [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.offset(20.0f);
- make.centerX.equalTo(bgV);
- }];
-
- 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(313.0f / 4.0f, 80.0f);
- UICollectionView *youpaipseatCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
- youpaipseatCollectionView.delegate = self;
- youpaipseatCollectionView.dataSource = self;
- youpaipseatCollectionView.showsVerticalScrollIndicator = NO;
- youpaipseatCollectionView.showsHorizontalScrollIndicator = NO;
- youpaipseatCollectionView.backgroundColor = [UIColor clearColor];
- youpaipseatCollectionView.clipsToBounds = NO;
- [youpaipseatCollectionView registerClass:YOUPAILZBlindDateSelectCell.class forCellWithReuseIdentifier:NSStringFromClass(YOUPAILZBlindDateSelectCell.class)];
- [bgV addSubview:youpaipseatCollectionView];
- self.youpaipcollectionView = youpaipseatCollectionView;
- [youpaipseatCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(titleL.mas_bottom).offset(20.0f);
- make.left.right.offset(0.0f);
- make.height.offset(80.0f);
- }];
-
- UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
- [cancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- cancelBtn.layer.cornerRadius = 24.0f;
- cancelBtn.clipsToBounds = YES;
- [cancelBtn setBackgroundColor:HexColorFromRGB(0x4F4B5B)];
- cancelBtn.titleLabel.font = LCFont(17.0f);
- [cancelBtn addTarget:self action:@selector(youpaifcancelBtnClick) forControlEvents:UIControlEventTouchUpInside];
- [bgV addSubview:cancelBtn];
- [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(14.0f);
- make.bottom.offset(-20.0f);
- make.size.mas_offset(CGSizeMake(135.0f, 48.0f));
- }];
-
- UIButton *youpaipconfirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [youpaipconfirmBtn setTitle:@"确定" forState:UIControlStateNormal];
- [youpaipconfirmBtn setTitleColor:HexColorFromRGB(0x9F9DA5) forState:UIControlStateNormal];
- [youpaipconfirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
- [youpaipconfirmBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(135.0f, 48.0f) FromColors:@[HexColorFromRGB(0x4F4B5B),HexColorFromRGB(0x4F4B5B)] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal];
- [youpaipconfirmBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(135.0f, 48.0f) FromColors:@[HexColorFromRGB(0xFF7FDA),HexColorFromRGB(0xFF48B3)] ByGradientType:GradientLeftToRight] forState:UIControlStateSelected];
- youpaipconfirmBtn.selected = NO;
- youpaipconfirmBtn.userInteractionEnabled = NO;
- youpaipconfirmBtn.layer.cornerRadius = 24.0f;
- youpaipconfirmBtn.clipsToBounds = YES;
- youpaipconfirmBtn.titleLabel.font = LCFont(17.0f);
- [youpaipconfirmBtn addTarget:self action:@selector(youpaifconfirmBtnClick) forControlEvents:UIControlEventTouchUpInside];
- [bgV addSubview:youpaipconfirmBtn];
- self.youpaipconfirmBtn = youpaipconfirmBtn;
- [youpaipconfirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.offset(-14.0f);
- make.bottom.offset(-20.0f);
- make.size.mas_offset(CGSizeMake(135.0f, 48.0f));
- }];
-
- }
- - (void)youpaifhandleSeatInfo{
- NSMutableArray <YOUPAILZChatRoomSeatModel *>*normalAllSeats = [YOUPAILZChatRoomSeatModel mj_objectArrayWithKeyValuesArray:self.youpaipnormalSeatJsons];
-
- YOUPAILZChatRoomSeatModel *localSeat = nil;
- for (YOUPAILZChatRoomSeatModel *f_seatModel in normalAllSeats) {
- if ([self.youpaipchatroomModel.youpaipuserInfo.youpaipid isEqual:f_seatModel.youpaipuserInfo.youpaipid]) {
- localSeat = f_seatModel;
- break;
- }
- }
-
- if (localSeat != nil) {
- NSMutableArray <YOUPAILZChatRoomSeatModel *>*youpaipnormalSeats = nil;
- if (localSeat.youpaipseatIndex <= 4) {
- youpaipnormalSeats = [normalAllSeats subarrayWithRange:NSMakeRange(4, 4)].mutableCopy;
- }else{
- youpaipnormalSeats = [normalAllSeats subarrayWithRange:NSMakeRange(0, 4)].mutableCopy;
- }
- YOUPAILZChatRoomSeatModel *selectedSeatModel = nil;
- for (YOUPAILZChatRoomSeatModel *f_seatModel in self.youpaipnormalSeats) {
- if (f_seatModel.youpaipisSelected) {
- selectedSeatModel = f_seatModel;
- break;
- }
- }
- if (selectedSeatModel != nil) {
- for (YOUPAILZChatRoomSeatModel *f_seatModel in youpaipnormalSeats) {
- if ([f_seatModel.youpaipuserInfo.youpaipid isEqual:selectedSeatModel.youpaipuserInfo.youpaipid]) {
- f_seatModel.youpaipisSelected = YES;
- break;
- }
- }
- }
- self.youpaipnormalSeats = youpaipnormalSeats;
- }else{
- [ZCHUDHelper showTitle:@"你没有在座位上"];
- [self youpaifcancelBtnClick];
- }
-
-
- [self.youpaipcollectionView reloadData];
- [self youpaifreloadConfirmBtnStyle];
- }
- - (void)youpaifreloadConfirmBtnStyle{
- YOUPAILZChatRoomSeatModel *seatModel = nil;
- for (YOUPAILZChatRoomSeatModel *f_seatModel in self.youpaipnormalSeats) {
- if (f_seatModel.youpaipisSelected) {
- seatModel = f_seatModel;
- break;
- }
- }
-
-
- if (seatModel != nil) {
- self.youpaipconfirmBtn.selected = YES;
- self.youpaipconfirmBtn.userInteractionEnabled = YES;
- }else{
- self.youpaipconfirmBtn.selected = NO;
- self.youpaipconfirmBtn.userInteractionEnabled = NO;
- }
- }
- - (void)youpaifcancelBtnClick{
- [self dismissViewControllerAnimated:YES completion:^{}];
- }
- - (void)youpaifconfirmBtnClick{
- YOUPAILZChatRoomSeatModel *seatModel = nil;
- for (YOUPAILZChatRoomSeatModel *f_seatModel in self.youpaipnormalSeats) {
- if (f_seatModel.youpaipisSelected) {
- seatModel = f_seatModel;
- break;
- }
- }
- if (seatModel != nil) {
- NSInteger seatIndex = seatModel.youpaipseatIndex - 1;
- @weakify(self);
- [LCHttpHelper requestWithURLString:ChatRoomBlindDateSelect parameters:@{@"room_id":self.youpaipchatroomModel.youpaiproom_id,@"seat":@(seatIndex)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- @strongify(self);
- NSDictionary* dict = (NSDictionary*)responseObject;
- [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code==0) {//成功
- [self dismissViewControllerAnimated:YES completion:^{}];
- }
- } failure:^(NSError *error) {
- }];
-
- }
-
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
- return self.youpaipnormalSeats.count;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
- YOUPAILZBlindDateSelectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass(YOUPAILZBlindDateSelectCell.class) forIndexPath:indexPath];
- [cell youpaifreloadWithModel:self.youpaipnormalSeats[indexPath.item]];
- return cell;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
- YOUPAILZChatRoomSeatModel *seatModel = self.youpaipnormalSeats[indexPath.item];
- if (seatModel.youpaipseatState == LZChatRoomSeatStateWithBusy) {
- for (YOUPAILZChatRoomSeatModel *f_seatModel in self.youpaipnormalSeats) {
- f_seatModel.youpaipisSelected = NO;
- }
- seatModel.youpaipisSelected = YES;
- }
- [self.youpaipcollectionView reloadData];
- [self youpaifreloadConfirmBtnStyle];
- }
- @end
|