// // QXSelectAuctionInfoView.m // QXLive // // Created by 启星 on 2025/6/27. // #import "QXSelectAuctionInfoView.h" #import "QXGiftCell.h" #import "QXMineNetwork.h" @interface QXSelectAuctionInfoView() @property (nonatomic,strong)UIView *bgView; @property (nonatomic,strong)UIImageView *bgImageView; @property (nonatomic,strong)UILabel *titleLabel; //@property (nonatomic,strong)UILabel *contenLabel; @property (nonatomic,strong)UICollectionView *collectionView; @property (nonatomic,strong)UIButton *commitBtn; @property (nonatomic,strong)NSMutableArray *relationshipArray; @property (nonatomic,strong)NSMutableArray *timeArray; @property (nonatomic,strong)NSMutableArray *giftArray; @property (nonatomic,strong)QXRoomRelationModel *relationModel; @property (nonatomic,strong)QXRoomRelationModel *timeModel; @property (nonatomic,assign)QXGiftModel *giftModel; @property (nonatomic,assign)NSInteger giftSelctedIndex; @end @implementation QXSelectAuctionInfoView - (instancetype)init { self = [super init]; if (self) { self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); [self initSubviews]; } return self; } -(void)initSubviews{ // UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)]; // tap.delegate = self; // [self addGestureRecognizer:tap]; self.bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, ScaleWidth(429)+kSafeAreaBottom)]; [self addSubview:self.bgView]; self.bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.bgView.width, self.bgView.height)]; self.bgImageView.image = [UIImage imageNamed:@"room_sound_bg"]; [self.bgView addSubview:self.bgImageView]; self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, 16, self.bgView.width-32, 24)]; self.titleLabel.font = [UIFont systemFontOfSize:16]; self.titleLabel.textColor = UIColor.whiteColor; self.titleLabel.textAlignment = NSTextAlignmentCenter; self.titleLabel.text = @"选择内容"; [self.bgView addSubview:self.titleLabel]; // self.contenLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, self.titleLabel.bottom, self.bgView.width-32, 24)]; // self.contenLabel.font = [UIFont systemFontOfSize:14]; // self.contenLabel.textColor = UIColor.whiteColor; // [self.bgView addSubview:self.contenLabel]; self.commitBtn = [[UIButton alloc] initWithFrame:CGRectMake(38, self.bgView.height-kSafeAreaBottom-12-42, self.bgView.width-76, 42)]; [self.commitBtn setTitle:@"确定" forState:(UIControlStateNormal)]; self.commitBtn.titleLabel.font = [UIFont systemFontOfSize:14]; [self.commitBtn setTitleColor:QXConfig.btnTextColor forState:(UIControlStateNormal)]; self.commitBtn.backgroundColor = QXConfig.themeColor; [self.commitBtn addRoundedCornersWithRadius:21]; [self.commitBtn addTarget:self action:@selector(commitAction) forControlEvents:(UIControlEventTouchUpInside)]; [self.bgView addSubview:self.commitBtn]; UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.minimumLineSpacing = 12; layout.minimumInteritemSpacing = 12; layout.sectionInset = UIEdgeInsetsMake(0, 16, 0, 16); layout.scrollDirection = UICollectionViewScrollDirectionVertical; self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, self.titleLabel.bottom, self.bgView.width, self.commitBtn.top-self.titleLabel.bottom-10) collectionViewLayout:layout]; [self.collectionView registerNib:[UINib nibWithNibName:@"QXGiftCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"QXGiftCell"]; [self.collectionView registerClass:[QXSelectAuctionInfoCell class] forCellWithReuseIdentifier:@"QXSelectAuctionInfoCell"]; [self.collectionView registerClass:[QXSelectAuctionInfoHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"QXSelectAuctionInfoHeaderView"]; self.collectionView.delegate = self; self.collectionView.dataSource = self; self.collectionView.showsHorizontalScrollIndicator = NO; self.collectionView.showsVerticalScrollIndicator = NO; self.collectionView.bounces = NO; self.collectionView.backgroundColor = [UIColor clearColor]; [self.bgView addSubview:self.collectionView]; } -(void)commitAction{ if (self.relationModel == nil) { showToast(@"请选择关系"); return; } if (!self.isRealLove) { if (self.timeModel == nil) { showToast(@"请选择时间"); return; } } if (self.giftModel == nil) { showToast(@"请选择礼物"); return; } MJWeakSelf [QXMineNetwork roomAuctionStartWithRoomId:self.roomId user_id:self.userId gift_id:self.giftModel.gift_id relation_id:self.relationModel.relation_id auction_type:self.isRealLove?@"1":@"2" time_day:self.timeModel.relation_id successBlock:^(NSDictionary * _Nonnull dict) { [weakSelf hide]; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { showToast(msg); }]; } -(void)getRelationShipList{ MJWeakSelf [QXMineNetwork roomRelationListWithType:self.isRealLove?@"1":@"2" successBlock:^(NSArray * _Nonnull list) { [weakSelf.relationshipArray removeAllObjects]; [weakSelf.relationshipArray addObjectsFromArray:list]; [weakSelf.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]]; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { }]; } -(void)getGiftList{ MJWeakSelf [QXMineNetwork giftListWithLabel:@"99" roomId:self.roomId successBlock:^(NSArray * _Nonnull list) { [weakSelf.giftArray removeAllObjects]; [weakSelf.giftArray addObjectsFromArray:list]; [weakSelf.collectionView reloadData]; } failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) { }]; } //-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{ // return touch.view == self; //} -(void)setIsRealLove:(BOOL)isRealLove{ self.giftModel = nil; self.relationModel = nil; self.timeModel = nil; _timeArray = nil; self.giftSelctedIndex = -1; _isRealLove = isRealLove; [self getRelationShipList]; [self getGiftList]; [self.collectionView reloadData]; } -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ if (self.isRealLove) { return 2; }else{ return 3; } } -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ if (section == 0) { return self.relationshipArray.count; }else if(section == 1){ if (self.isRealLove) { return self.giftArray.count; }else{ return self.timeArray.count; } }else{ return self.giftArray.count; } } -(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.section == 0) { QXSelectAuctionInfoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXSelectAuctionInfoCell" forIndexPath:indexPath]; cell.model = self.relationshipArray[indexPath.row]; return cell; }else if(indexPath.section == 1){ if (self.isRealLove) { QXGiftCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXGiftCell" forIndexPath:indexPath]; cell.cellType = QXGiftCellTypeLive; cell.roomGiftModel = self.giftArray[indexPath.row]; if (self.giftSelctedIndex == indexPath.row) { cell.selecteBtn.selected = YES; }else{ cell.selecteBtn.selected = NO; } return cell; }else{ QXSelectAuctionInfoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXSelectAuctionInfoCell" forIndexPath:indexPath]; cell.model = self.timeArray[indexPath.row]; return cell; } }else{ QXGiftCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXGiftCell" forIndexPath:indexPath]; cell.cellType = QXGiftCellTypeLive; cell.roomGiftModel = self.giftArray[indexPath.row]; if (self.giftSelctedIndex == indexPath.row) { cell.selecteBtn.selected = YES; }else{ cell.selecteBtn.selected = NO; } return cell; } } -(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{ if ([kind isEqualToString:UICollectionElementKindSectionHeader]) { QXSelectAuctionInfoHeaderView *header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"QXSelectAuctionInfoHeaderView" forIndexPath:indexPath]; if (indexPath.section == 0) { header.titleLabel.text = @"关系"; }else if(indexPath.section == 1){ if (self.isRealLove) { header.titleLabel.text = @"礼物"; }else{ header.titleLabel.text = @"时间"; } }else{ header.titleLabel.text = @"礼物"; } return header; } return nil; } -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{ return CGSizeMake(SCREEN_WIDTH, 30); } -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.section == 0) { CGFloat width = (SCREEN_WIDTH-16*2-12*3)/4; return CGSizeMake(width, 44); }else if(indexPath.section == 1){ if (self.isRealLove) { CGFloat width = (SCREEN_WIDTH-16*2-12*3)/4; return CGSizeMake(width, ScaleWidth(119)); }else{ CGFloat width = (SCREEN_WIDTH-16*2-12*3)/4; return CGSizeMake(width, 44); } }else{ CGFloat width = (SCREEN_WIDTH-16*2-12*3)/4; return CGSizeMake(width, ScaleWidth(119)); } } -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.section == 0) { QXRoomRelationModel *model = self.relationshipArray[indexPath.row]; if (model.isSelected) { return; } self.relationModel.isSelected = NO; model.isSelected = YES; self.relationModel = model; [collectionView reloadData]; }else if(indexPath.section == 1){ if (self.isRealLove) { QXGiftModel *model = self.giftArray[indexPath.row]; self.giftSelctedIndex = indexPath.row; self.giftModel = model; [collectionView reloadData]; }else{ QXRoomRelationModel *model = self.timeArray[indexPath.row]; if (model.isSelected) { return; } self.timeModel.isSelected = NO; model.isSelected = YES; self.timeModel = model; [collectionView reloadData]; } }else{ QXGiftModel *model = self.giftArray[indexPath.row]; self.giftSelctedIndex = indexPath.row; self.giftModel = model; [collectionView reloadData]; } } -(void)showInView:(UIView *)view{ self.bgView.y = SCREEN_HEIGHT; [view addSubview:self]; [UIView animateWithDuration:0.3 animations:^{ self.bgView.y = SCREEN_HEIGHT-ScaleWidth(429)-kSafeAreaBottom; }]; } -(void)hide{ [UIView animateWithDuration:0.3 animations:^{ self.bgView.y = SCREEN_HEIGHT; } completion:^(BOOL finished) { [self removeFromSuperview]; }]; } -(NSMutableArray *)relationshipArray{ if (!_relationshipArray) { _relationshipArray = [NSMutableArray array]; } return _relationshipArray; } -(NSMutableArray *)timeArray{ if (!_timeArray) { QXRoomRelationModel *md = [[QXRoomRelationModel alloc] init]; md.name = @"1天"; md.relation_id = @"24"; QXRoomRelationModel *md1 = [[QXRoomRelationModel alloc] init]; md1.name = @"3天"; md1.relation_id = @"72"; QXRoomRelationModel *md2 = [[QXRoomRelationModel alloc] init]; md2.name = @"5天"; md2.relation_id = @"120"; QXRoomRelationModel *md3 = [[QXRoomRelationModel alloc] init]; md3.name = @"10天"; md3.relation_id = @"240"; QXRoomRelationModel *md4 = [[QXRoomRelationModel alloc] init]; md4.name = @"15天"; md4.relation_id = @"360"; QXRoomRelationModel *md5 = [[QXRoomRelationModel alloc] init]; md5.name = @"20天"; md5.relation_id = @"480"; QXRoomRelationModel *md6 = [[QXRoomRelationModel alloc] init]; md6.name = @"25天"; md6.relation_id = @"600"; QXRoomRelationModel *md7 = [[QXRoomRelationModel alloc] init]; md7.name = @"30天"; md7.relation_id = @"720"; _timeArray = [NSMutableArray arrayWithArray:@[ md,md1,md2,md3,md4,md5,md6,md7 ]]; } return _timeArray; } -(NSMutableArray *)giftArray{ if (!_giftArray) { _giftArray = [NSMutableArray array]; } return _giftArray; } @end @implementation QXSelectAuctionInfoHeaderView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubviews]; } return self; } -(void)initSubviews{ UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, 0, SCREEN_WIDTH-32, 30)]; titleLabel.textColor = UIColor.whiteColor; titleLabel.font = [UIFont systemFontOfSize:13]; // if (indexPath.section == 0) { // titleLabel.text = @"关系"; // }else if(indexPath.section == 1){ // if (self.isRealLove) { // titleLabel.text = @"礼物"; // }else{ // titleLabel.text = @"时间"; // } // }else{ // titleLabel.text = @"礼物"; // } [self addSubview:titleLabel]; self.titleLabel = titleLabel; } @end @implementation QXSelectAuctionInfoCell - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self initSubviews]; } return self; } -(void)setModel:(QXRoomRelationModel *)model{ _model = model; [self.selectedBtn setTitle:model.name forState:(UIControlStateNormal)]; self.selectedBtn.selected = model.isSelected; } -(void)setTimeModel:(QXRoomRelationModel *)timeModel{ _timeModel = timeModel; [self.selectedBtn setTitleColor:QXConfig.themeColor forState:(UIControlStateSelected)]; [self.selectedBtn setTitleColor:RGB16(0x333333) forState:(UIControlStateNormal)]; [self.selectedBtn setTitle:timeModel.name forState:(UIControlStateNormal)]; self.selectedBtn.layer.borderColor = RGB16(0xF1F2F3).CGColor; self.selectedBtn.layer.borderWidth = 1; self.selectedBtn.selected = timeModel.isSelected; } -(void)initSubviews{ self.selectedBtn = [[UIButton alloc] init]; [self.selectedBtn setBackgroundImage:[UIImage imageNamed:@"room_sound_sel"] forState:(UIControlStateSelected)]; [self.selectedBtn setBackgroundImage:[UIImage imageWithColor:RGB16A(0xE9E9E9, 0.2)] forState:(UIControlStateNormal)]; [self.selectedBtn setTitleColor:UIColor.whiteColor forState:(UIControlStateNormal)]; [self.selectedBtn setTitleColor:RGB16(0x333333) forState:(UIControlStateSelected)]; self.selectedBtn.titleLabel.font = [UIFont systemFontOfSize:14]; [self.selectedBtn addRoundedCornersWithRadius:12]; self.selectedBtn.userInteractionEnabled = NO; [self.contentView addSubview:self.selectedBtn]; [self.selectedBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.top.bottom.right.left.equalTo(self.contentView); }]; // self.titleLabel = [[UILabel alloc] init]; // self.titleLabel } @end