// // YOUPAIHRChatRoomHeaderView.m // VQU // // Created by xiaohaoran on 2021/10/29. // Copyright © 2021 MS. All rights reserved. // #import "YOUPAIHRChatRoomHeaderView.h" #import "YOUPAIHRChatRoomHeaderCell.h" #import "YOUPAIHRChatRoomGiftModel.h" @interface YOUPAIHRChatRoomHeaderView () @property(nonatomic,strong)UICollectionView *youpaipcollectionView; @property(nonatomic,strong)UIButton *youpaipmicroBtn; /* 是否显示悄悄送礼 */ @property (assign, nonatomic) NSInteger youpaipsend_gift_hide; @end @implementation YOUPAIHRChatRoomHeaderView -(instancetype)initWithFrame:(CGRect)frame send_gift_hide:(NSInteger)send_gift_hide{ if (self = [super initWithFrame:frame]) { self.youpaipsend_gift_hide = send_gift_hide; [self youpaifsetSubView]; } return self; } -(void)youpaifqiaoqiaoBtnClick:(UIButton*)sender{ sender.selected = !sender.selected; NSString *switchType = sender.selected ? @"1" : @"2"; [LCHttpHelper requestWithURLString:NobleSetting parameters:@{@"send_gift_hide":switchType} needToken:YES type:HttpRequestTypePost success:^(id responseObject) { if (responseObject) { if ([responseObject[@"code"] intValue]== 0) { } [ZCHUDHelper showTitle:responseObject[@"message"]]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } -(void)youpaifmicroBtnClick:(UIButton*)sender{ sender.selected = !sender.selected; if (sender.selected) { for (YOUPAILZChatRoomSeatModel *model in self.youpaipseats) { model.youpaipisSelected = YES; } }else{ for (YOUPAILZChatRoomSeatModel *model in self.youpaipseats) { model.youpaipisSelected = NO; } } [self.youpaipcollectionView reloadData]; } - (void)youpaifverityAllSelectState { BOOL youpaipisSelectedAll = YES; if (self.youpaipseats.count == 0) { youpaipisSelectedAll = NO; } for (YOUPAILZChatRoomSeatModel *model in self.youpaipseats) { if (model.youpaipisSelected == NO) { youpaipisSelectedAll = NO; break; } } self.youpaipmicroBtn.selected = youpaipisSelectedAll; } -(void)youpaifsetSubView{ //送给 UILabel *sendLabel = [UILabel new]; [self addSubview:sendLabel]; [sendLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(14); make.centerY.mas_equalTo(0); make.width.mas_equalTo(25); }]; sendLabel.text = @"送给"; sendLabel.textColor = HexColorFromRGB(0x9F9DA5); sendLabel.font = [UIFont systemFontOfSize:10]; //用户头像collectionView UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init]; UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:layout]; self.youpaipcollectionView = collectionView; [self addSubview:collectionView]; [collectionView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.left.mas_offset(39); make.width.mas_offset(KScreenWidth-14-25-ScaleSize(148)); make.bottom.mas_offset(0.f); }]; [layout setScrollDirection:UICollectionViewScrollDirectionHorizontal]; self.youpaipcollectionView.backgroundColor = LCBkgColor; self.youpaipcollectionView.showsHorizontalScrollIndicator = NO; self.youpaipcollectionView.showsVerticalScrollIndicator = NO; self.youpaipcollectionView.scrollEnabled = YES; self.youpaipcollectionView.delegate = self; self.youpaipcollectionView.dataSource = self; //悄悄送礼和全麦按钮 UIView *selectView = [UIView new]; [self addSubview:selectView]; [selectView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(0); make.top.mas_equalTo(0); make.bottom.mas_equalTo(0); make.width.mas_equalTo(ScaleSize(148)); }]; selectView.backgroundColor = LCBkgColor; //全麦按钮 UIButton *youpaipmicroBtn = [UIButton new]; self.youpaipmicroBtn = youpaipmicroBtn; [selectView addSubview:youpaipmicroBtn]; [youpaipmicroBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(0); make.top.mas_equalTo(0); make.bottom.mas_equalTo(0); make.width.mas_equalTo(ScaleSize(59)); }]; [youpaipmicroBtn setTitle:@"全麦 " forState:UIControlStateNormal]; [youpaipmicroBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; youpaipmicroBtn.titleLabel.font = [UIFont systemFontOfSize:12]; [youpaipmicroBtn setImage:[UIImage imageNamed:@"vqu_images_gift_off"] forState:UIControlStateNormal]; [youpaipmicroBtn setImage:[UIImage imageNamed:@"vqu_images_gift_on"] forState:UIControlStateSelected]; youpaipmicroBtn.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft; //悄悄送礼 UIButton *qiaoqiaoBtn = [UIButton new]; [selectView addSubview:qiaoqiaoBtn]; [qiaoqiaoBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(youpaipmicroBtn.mas_left); make.top.mas_equalTo(0); make.bottom.mas_equalTo(0); make.width.mas_equalTo(ScaleSize(89)); }]; [qiaoqiaoBtn setTitle:@"悄悄送礼 " forState:UIControlStateNormal]; [qiaoqiaoBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; qiaoqiaoBtn.titleLabel.font = [UIFont systemFontOfSize:12]; [qiaoqiaoBtn setImage:[UIImage imageNamed:@"vqu_images_gift_off"] forState:UIControlStateNormal]; [qiaoqiaoBtn setImage:[UIImage imageNamed:@"vqu_images_gift_on"] forState:UIControlStateSelected]; qiaoqiaoBtn.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft; [qiaoqiaoBtn addTarget:self action:@selector(youpaifqiaoqiaoBtnClick:) forControlEvents:UIControlEventTouchUpInside]; [youpaipmicroBtn addTarget:self action:@selector(youpaifmicroBtnClick:) forControlEvents:UIControlEventTouchUpInside]; if (self.youpaipsend_gift_hide == 1){ [selectView mas_remakeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(0); make.top.mas_equalTo(0); make.bottom.mas_equalTo(0); make.width.mas_equalTo(ScaleSize(148)); }]; qiaoqiaoBtn.hidden = NO; qiaoqiaoBtn.selected = YES; }else if (self.youpaipsend_gift_hide == 2){ [selectView mas_remakeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(0); make.top.mas_equalTo(0); make.bottom.mas_equalTo(0); make.width.mas_equalTo(ScaleSize(148)); }]; qiaoqiaoBtn.hidden = NO; qiaoqiaoBtn.selected = NO; }else{ [selectView mas_remakeConstraints:^(MASConstraintMaker *make) { make.right.mas_equalTo(0); make.top.mas_equalTo(0); make.bottom.mas_equalTo(0); make.width.mas_equalTo(ScaleSize(59)); }]; qiaoqiaoBtn.hidden = YES; [collectionView mas_remakeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(0); make.left.mas_offset(39); make.width.mas_offset(KScreenWidth-14-25-ScaleSize(59)); make.bottom.mas_offset(0.f); }]; } } #pragma mark /** 返回区数 @param collectionView 集合视图 @return 返回区数 */ - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } /** 返回项目数 @param collectionView 集合视图 @param section 区 @return 项目数 */ - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.youpaipseats.count; } -(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ NSString *ID = [NSString stringWithFormat:@"%ld%ld",indexPath.section,indexPath.item]; [self.youpaipcollectionView registerClass:[YOUPAIHRChatRoomHeaderCell class] forCellWithReuseIdentifier:ID]; YOUPAIHRChatRoomHeaderCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath]; YOUPAILZChatRoomSeatModel *model = self.youpaipseats[indexPath.item]; cell.youpaipmodel = model; return cell; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ YOUPAILZChatRoomSeatModel *model = self.youpaipseats[indexPath.item]; model.youpaipisSelected = !model.youpaipisSelected; [self.youpaipcollectionView reloadItemsAtIndexPaths:@[indexPath]]; [self youpaifverityAllSelectState]; } #pragma mark UICollectionViewDelegateFlowLayout /** 项目大小 @param collectionView 集合视图 @param collectionViewLayout 布局 @param indexPath 布局 @return 大小 */ - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { return CGSizeMake(32, 32); } #pragma mark - X间距 - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section { return 4.0; } //设置段落的内边距 - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { return UIEdgeInsetsMake(0,0,0,0);//UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right) } - (void)setYoupaipseats:(NSMutableArray *)youpaipseats{ _youpaipseats = youpaipseats; [self.youpaipcollectionView reloadData]; [self youpaifverityAllSelectState]; } @end