// // YOUPAILZCommonGiftVC.m // VQU // // Created by 肖浩然的mac on 2021/8/20. // Copyright © 2021 leo. All rights reserved. // #import "YOUPAILZCommonGiftVC.h" #import "YOUPAIWZHorizontalPageFlowlayout.h" #import "YOUPAIWZHorizontalPageCell.h" #import "YOUPAILZLiveBtn.h" #import "YBPopupMenu.h" static NSString * const identifier = @"HorizontalPageCell"; @interface YOUPAILZCommonGiftVC () @property (nonatomic,strong)UIView *youpaipmenuView; @property (nonatomic,strong)UICollectionView *youpaipcollectionView; @property (nonatomic,strong)NSMutableArray *youpaipgiftArray; @property (nonatomic,strong)UIPageControl *youpaippageView; @property (nonatomic,assign)NSInteger youpaipcoinsTotal;//总虾币 @property (nonatomic,strong)NSIndexPath *youpaipselectIndex; @property (nonatomic,strong)NSMutableArray* youpaipcellArray; @property (nonatomic,strong)NSTimer *youpaiptimer; @property (nonatomic,assign)NSInteger youpaipcountDownTime; @property (nonatomic,strong)UILabel *youpaipcountL; /* youpaipisSendGift */ @property (assign, nonatomic) BOOL youpaipisSendGift; /* sendgiftL */ @property (strong, nonatomic) UILabel *youpaipsendgiftL; /* sendGiftBtn */ @property (strong, nonatomic) UIButton *youpaipsendGiftBtn; /* youpaipcoinL */ @property (strong, nonatomic) UILabel *youpaipcoinL; @property (nonatomic, strong) YBPopupMenu *youpaippopupMenu; @property(nonatomic,strong)NSArray *youpaipgiftCountArr; @property(nonatomic,strong)UIButton *youpaipaddCountBtn; @end @implementation YOUPAILZCommonGiftVC -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [UMengRecordTool umengEnterViewWithName:NSStringFromClass(self.class)]; } - (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; [UMengRecordTool umengOutViewWithName:NSStringFromClass(self.class)]; } - (void)viewDidLoad { [super viewDidLoad]; self.youpaipgiftArray = [NSMutableArray array]; [self youpaifsetupUI]; [self youpaifinitData]; self.youpaipcountDown = 0; self.youpaipisSendGift = NO; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifliveQuietlySendGift:) name:@"LZLiveQuietlySendGift" object:nil]; } - (void)youpaifliveQuietlySendGift:(NSNotification *)notification{ self.youpaipsendGiftBtn.selected = [notification.object boolValue]; } - (void)youpaifinitData{ @weakify(self); [LCHttpHelper requestWithURLString:LivegetGiftDet parameters:@{@"gift_type":self.ID} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 self.youpaipcoinsTotal = [[[dict objectForKey:@"data"]objectForKey:@"coin"]integerValue]; self.youpaipgiftArray = [YOUPAILCGiftModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"]objectForKey:@"gift_list"]]; self.youpaipcoinL.text = [NSString stringWithFormat:@"%zd",self.youpaipcoinsTotal]; NSInteger sendtype = [[[dict objectForKey:@"data"]objectForKey:@"send_gift_hide"] intValue]; if (sendtype == 1){ self.youpaipsendGiftBtn.hidden = NO; self.youpaipsendgiftL.hidden = NO; self.youpaipsendGiftBtn.selected = YES; }else if (sendtype == 2){ self.youpaipsendGiftBtn.hidden = NO; self.youpaipsendgiftL.hidden = NO; self.youpaipsendGiftBtn.selected = NO; } if (self.youpaipisAnchor == NO) { self.youpaipsendGiftBtn.hidden = YES; self.youpaipsendgiftL.hidden = YES; } [self.youpaipcollectionView reloadData]; if (self.youpaipgiftArray.count != 0) { [self.youpaipcollectionView lz_hideEmptyView]; }else{ [self.youpaipcollectionView lz_showEmptyViewWithImageSizeWUWU:[UIImage imageNamed:@"vqu_images_IM_sendgift_NoData"] content:@"分类下暂无礼物哦~"]; } NSInteger totalRecord = self.youpaipgiftArray.count; NSInteger maxResult = 8; NSInteger youpaiptotalPage = totalRecord % maxResult == 0 ? totalRecord / maxResult : totalRecord / maxResult + 1 ; self.youpaippageView.numberOfPages = youpaiptotalPage; NSLog(@"GiftConfig == %@",dict); NSMutableArray *youpaipgiftArray = [NSMutableArray array]; youpaipgiftArray = [YOUPAILCGiftModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"]objectForKey:@"gift_list"]]; for (int i = 0; i< youpaipgiftArray.count; i++) { YOUPAILCGiftModel *model = youpaipgiftArray[i]; if (model.youpaipsvga.length> 0 ) { [LCTools giftSVGAWithSvgaUrlStr:model.youpaipsvga]; } } } } failure:^(NSError *error) { }]; } -(void)youpaifsetupUI{ self.youpaipcellArray = [NSMutableArray array]; UIView* youpaipmenuView = [[UIView alloc]initWithFrame:self.view.bounds]; youpaipmenuView.backgroundColor = [UIColor whiteColor]; self.youpaipmenuView = youpaipmenuView; [self.view addSubview:youpaipmenuView]; YOUPAIWZHorizontalPageFlowlayout *layout = [[YOUPAIWZHorizontalPageFlowlayout alloc] initWithRowCount:2 itemCountPerRow:4]; // layout.columnSpacing = 25.0f; layout.youpaiprowSpacing = 12.0f; layout.itemSize = CGSizeMake((KScreenWidth - 30.0f - 3*25.0f)/ 4.0f, (192+15-12.0f) / 2.0f); // layout.edgeInsets = UIEdgeInsetsMake(10.0f, 15.0f, 0.0f, 15.0f); // [layout setColumnSpacing:20 rowSpacing:10 edgeInsets:UIEdgeInsetsMake(10, 105, 0, 0)]; /** 注意,此处设置的item的尺寸是理论值,实际是由行列间距、collectionView的内边距和宽高决定 */ // layout.itemSize = CGSizeMake((KScreenWidth - 30.0f-30.0f) / 4.0f, (192 - 10.0f-10.0f) / 2.0f); // layout.minimumInteritemSpacing = 20; // layout.minimumLineSpacing = 10; layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; _youpaipcollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(15.0f, 0, KScreenWidth-30 , 192+15) collectionViewLayout:layout]; _youpaipcollectionView.backgroundColor = [UIColor clearColor]; _youpaipcollectionView.bounces = YES; _youpaipcollectionView.pagingEnabled = YES; _youpaipcollectionView.dataSource = self; _youpaipcollectionView.delegate = self; _youpaipcollectionView.showsHorizontalScrollIndicator=NO; _youpaipcollectionView.showsVerticalScrollIndicator=NO; [_youpaipcollectionView registerClass:[YOUPAIWZHorizontalPageCell class] forCellWithReuseIdentifier:identifier]; [youpaipmenuView addSubview:self.youpaipcollectionView]; NSInteger totalRecord = self.youpaipgiftArray.count; NSInteger maxResult = 8; NSInteger youpaiptotalPage = totalRecord % maxResult == 0 ? totalRecord / maxResult : totalRecord / maxResult + 1 ; UIPageControl *youpaippageView = [[UIPageControl alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(_youpaipcollectionView.frame), KScreenWidth, 20)]; youpaippageView.numberOfPages = youpaiptotalPage; youpaippageView.currentPage = 1; youpaippageView.pageIndicatorTintColor = [LZA3AABEColor colorWithAlphaComponent:0.4f]; youpaippageView.currentPageIndicatorTintColor = [LZA3AABEColor colorWithAlphaComponent:0.6f]; youpaippageView.userInteractionEnabled = NO; youpaippageView.hidesForSinglePage = YES; self.youpaippageView = youpaippageView; [youpaipmenuView addSubview:youpaippageView]; UIView* bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(youpaippageView.frame), KScreenWidth, 47.0f)]; [youpaipmenuView addSubview:bottomView]; UIImageView *zuanshiImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vqu_images_ic_user_show_zuanshi"]]; [bottomView addSubview:zuanshiImgV]; [zuanshiImgV mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(bottomView); make.left.offset(10.0f); make.size.mas_offset(CGSizeMake(14.0f, 12.0f)); }]; UILabel *youpaipcoinL = [[UILabel alloc] init]; self.youpaipcoinL = youpaipcoinL; youpaipcoinL.font = LCFont14; youpaipcoinL.textColor = UIColor.blackColor; [bottomView addSubview:youpaipcoinL]; [youpaipcoinL mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(bottomView); make.left.equalTo(zuanshiImgV.mas_right).offset(5.0f); }]; UIView *line = [[UIView alloc] init]; line.backgroundColor = [LZA3AABEColor colorWithAlphaComponent:0.29f]; [bottomView addSubview:line]; [line mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(youpaipcoinL.mas_right).offset(10.0f); make.centerY.equalTo(youpaipcoinL); make.size.mas_offset(CGSizeMake(1, 14.0f)); }]; UIButton *rechargeBtn = [UIButton buttonWithType:UIButtonTypeCustom]; rechargeBtn.titleLabel.font = LCFont14; [rechargeBtn setTitle:@"充值" forState:UIControlStateNormal]; [rechargeBtn setTitleColor:HexColorFromRGB(0xA049FC) forState:UIControlStateNormal]; [rechargeBtn addTarget:self action:@selector(youpaifrechargeClick) forControlEvents:(UIControlEventTouchUpInside)]; [bottomView addSubview:rechargeBtn]; [rechargeBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(bottomView); make.left.equalTo(line.mas_right).offset(10.0f); }]; UIView *sendBgView = [UIView new]; [bottomView addSubview:sendBgView]; [sendBgView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.offset(-14.0f); make.top.offset(5.0f); make.size.mas_offset(CGSizeMake(124.0f, 33.0f)); }]; UIImageView *sendGiftBgV = [[UIImageView alloc] init]; sendGiftBgV.userInteractionEnabled = YES; sendGiftBgV.layer.cornerRadius = 16.5f; sendGiftBgV.clipsToBounds = YES; sendGiftBgV.image = [LCTools ColorImage:CGSizeMake(124.0f, 33.0f) FromColors:kMainGradColors ByGradientType:GradientLeftToRight]; [sendBgView addSubview:sendGiftBgV]; [sendGiftBgV mas_makeConstraints:^(MASConstraintMaker *make) { make.right.offset(0.0f); make.top.offset(5.0f); make.size.mas_offset(CGSizeMake(124.0f, 33.0f)); }]; UIButton *sendBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [sendBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(62, 33) FromColors:kMainGradColors ByGradientType:GradientLeftToRight] forState:(UIControlStateNormal)]; [sendBtn setTitle:@"赠送" forState:(UIControlStateNormal)]; [sendBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)]; sendBtn.titleLabel.font = [UIFont systemFontOfSize:12]; [sendBtn addTarget:self action:@selector(youpaifsendClick) forControlEvents:(UIControlEventTouchUpInside)]; [sendGiftBgV addSubview:sendBtn]; [sendBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.top.bottom.offset(0.0f); make.width.offset(62.0f); }]; UIView *countBgV = [[UIView alloc] initWithFrame:CGRectMake(0.5f, 0.5f, 62.0f, 32.0f)]; countBgV.backgroundColor = [UIColor whiteColor]; [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerBottomLeft View:countBgV size:CGSizeMake(17.0f, 17.0f)]; [sendGiftBgV addSubview:countBgV]; //选择更多 UIImageView *addCountImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vqu_images_gift_more"]]; [countBgV addSubview:addCountImgV]; [addCountImgV mas_makeConstraints:^(MASConstraintMaker *make) { make.right.offset(-4.0f); make.centerY.equalTo(countBgV); make.size.mas_offset(CGSizeMake(12.0f, 12.0f)); }]; UILabel *youpaipcountL = [[UILabel alloc] init]; youpaipcountL.font = LCFont14; youpaipcountL.textColor = LZ273145Color; youpaipcountL.text = @"1"; youpaipcountL.textAlignment = NSTextAlignmentCenter; [countBgV addSubview:youpaipcountL]; self.youpaipcountL = youpaipcountL; [youpaipcountL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.bottom.offset(0.0f); make.left.equalTo(4); make.right.equalTo(addCountImgV.mas_left).offset(0.0f); }]; UIButton *youpaipaddCountBtn = [UIButton buttonWithType:UIButtonTypeCustom]; self.youpaipaddCountBtn = youpaipaddCountBtn; [youpaipaddCountBtn addTarget:self action:@selector(youpaifaddCountBtnClick:) forControlEvents:UIControlEventTouchUpInside]; [countBgV addSubview:youpaipaddCountBtn]; [youpaipaddCountBtn mas_makeConstraints:^(MASConstraintMaker *make) { make.right.top.bottom.left.offset(0.0f); }]; //悄悄送礼 UIButton *sendGiftBtn = [UIButton new]; self.youpaipsendGiftBtn = sendGiftBtn; [bottomView addSubview:sendGiftBtn]; [sendGiftBtn makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(countBgV.mas_left).offset(-10); make.top.mas_equalTo(sendBtn); make.size.mas_equalTo(CGSizeMake(27, 16)); }]; [sendGiftBtn setImage:[UIImage imageNamed:@"vqu_images_D_mine_set_Notic_Open"] forState:UIControlStateSelected]; [sendGiftBtn setImage:[UIImage imageNamed:@"vqu_images_D_mine_set_Notic_Close"] forState:UIControlStateNormal]; [sendGiftBtn addTarget:self action:@selector(youpaifsendGiftBtnClick:) forControlEvents:UIControlEventTouchUpInside]; // UILabel *sendgiftL = [[UILabel alloc] init]; [bottomView addSubview:sendgiftL]; self.youpaipsendgiftL = sendgiftL; [sendgiftL mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(sendGiftBtn.mas_bottom).offset(5); make.centerX.mas_equalTo(sendGiftBtn); make.width.mas_equalTo(52); }]; sendgiftL.font = LCFont12; sendgiftL.textColor = [UIColor whiteColor]; sendgiftL.text = @"悄悄送礼"; // 是否悄悄送礼 0不显示 1是 2否 if (self.send_gift_hide == 1){ sendGiftBtn.hidden = NO; sendgiftL.hidden = NO; sendGiftBtn.selected = YES; }else if (self.send_gift_hide == 2){ sendGiftBtn.hidden = NO; sendgiftL.hidden = NO; sendGiftBtn.selected = NO; }else{ sendGiftBtn.hidden = YES; sendgiftL.hidden = YES; } if (self.youpaipisAnchor == NO) { sendGiftBtn.hidden = YES; sendgiftL.hidden = YES; } } - (void)youpaifaddCountBtnClick:(UIButton*)sender{ // NSInteger count = [self.youpaipcountL.text integerValue] + 1; // self.youpaipcountL.text = [NSString stringWithFormat:@"%@",@(count >= 99 ? 99 : count)]; self.youpaipgiftCountArr = @[@"520",@"99",@"66",@"10",@"1"]; @weakify(self); self.youpaippopupMenu = [YBPopupMenu showRelyOnView:self.youpaipaddCountBtn titles:self.youpaipgiftCountArr icons:@[@"",@""] menuWidth:96 otherSettings:^(YBPopupMenu *youpaippopupMenu) { @strongify(self) youpaippopupMenu.delegate = self; youpaippopupMenu.itemHeight = 32; youpaippopupMenu.selectTextColor = NO; youpaippopupMenu.isCenter = YES; youpaippopupMenu.borderWidth = 0.5f; youpaippopupMenu.borderColor = [UIColor whiteColor]; youpaippopupMenu.backColor = [UIColor whiteColor]; youpaippopupMenu.textColor = UIColor.blackColor; youpaippopupMenu.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; }]; } #pragma mark - YBPopupMenuDelegate - (void)ybPopupMenu:(YBPopupMenu *)ybPopupMenu didSelectedAtIndex:(NSInteger)index{ self.youpaipcountL.text = self.youpaipgiftCountArr[index]; } #pragma mark-悄悄送礼按钮 -(void)youpaifsendGiftBtnClick:(UIButton*)sender{ sender.selected = !sender.selected; NSString *switchType = sender.selected ? @"1" : @"2"; [[NSNotificationCenter defaultCenter] postNotificationName:@"LZLiveQuietlySendGift" object:@(sender.selected) userInfo:nil]; [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)youpaifsubtractCountBtnClick{ NSInteger count = [self.youpaipcountL.text integerValue] - 1; self.youpaipcountL.text = [NSString stringWithFormat:@"%@",@(count <= 1 ? 1 : count)]; } - (void)youpaifaddCountBtnClick{ NSInteger count = [self.youpaipcountL.text integerValue] + 1; self.youpaipcountL.text = [NSString stringWithFormat:@"%@",@(count >= 99 ? 99 : count)]; } - (void)youpaifrechargeClick{ [UMengRecordTool umengEventCountWithId:RechargeClickMessage]; if (!self.youpaipisAnchor) { [self dismissViewControllerAnimated:NO completion:^{ if (self.youpaipjumToWalletBlock) { self.youpaipjumToWalletBlock(); } }]; }else{ [ZCHUDHelper showTitle:@"你在直播中,不可以离开哦"]; } } - (void)youpaifsendClick{ [self youpaifstopTimer]; if (self.youpaipselectIndex && self.youpaipisSendGift == NO) { self.youpaipisSendGift = YES; YOUPAIWZHorizontalPageCell * cell = (YOUPAIWZHorizontalPageCell *)[self.youpaipcollectionView cellForItemAtIndexPath:self.youpaipselectIndex]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ if (self.delegate &&[self.delegate respondsToSelector:@selector(youpaifDidSenderGiftWith:Count:CategoryID:)]) { self.youpaipisSendGift = NO; self.youpaipcountDownTime = self.youpaipcountDown; [self youpaifstartTimer]; [self dismissViewControllerAnimated:NO completion:^{ }]; [self.delegate youpaifDidSenderGiftWith:cell.youpaipmodel Count:self.youpaipcountL.text.integerValue CategoryID:self.ID]; // [self.collectionView reloadData]; } }); } } #pragma mark - UICollectionViewDataSource - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.youpaipgiftArray.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { YOUPAIWZHorizontalPageCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; YOUPAILCGiftModel *model = self.youpaipgiftArray[indexPath.row]; cell.youpaipmodel = model; // cell.backgroundColor = [UIColor yellowColor]; return cell; } -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ if (self.youpaipselectIndex) { // YOUPAIWZHorizontalPageCell * oldCell = (YOUPAIWZHorizontalPageCell *)[collectionView cellForItemAtIndexPath:self.selectIndex]; YOUPAILCGiftModel *model = self.youpaipgiftArray[self.youpaipselectIndex.row]; model.youpaipselected = NO; // oldCell.layer.borderColor = [UIColor clearColor].CGColor; // oldCell.layer.borderWidth = 0; // oldCell.layer.cornerRadius = 0; } // YOUPAIWZHorizontalPageCell * cell = (YOUPAIWZHorizontalPageCell *)[collectionView cellForItemAtIndexPath:indexPath]; YOUPAILCGiftModel *model = self.youpaipgiftArray[indexPath.row]; model.youpaipselected = YES; // cell.layer.borderColor = LCOrangeColor.CGColor; // cell.layer.borderWidth = 1.0; // cell.layer.cornerRadius = 10; self.youpaipselectIndex = indexPath; self.youpaipcountL.text = @"1"; [collectionView reloadData]; } -(void)scrollViewDidScroll:(UIScrollView *)scrollView{ // 当前的索引 NSInteger index = scrollView.contentOffset.x / _youpaipcollectionView.mj_w; self.youpaippageView.currentPage = index; } - (void)youpaifstartTimer{ if (self.youpaiptimer == nil) { self.youpaiptimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(youpaifcountDownTimer) userInfo:nil repeats:YES]; [[NSRunLoop currentRunLoop] addTimer:self.youpaiptimer forMode:NSRunLoopCommonModes]; } } - (void)youpaifcountDownTimer{ self.youpaipcountDownTime --; if (self.youpaipcountDownTime <= 0) { [self dismissViewControllerAnimated:YES completion:^{ }]; } } - (void)youpaifstopTimer{ [self.youpaiptimer invalidate]; self.youpaiptimer = nil; } - (void)dealloc{ [self youpaifstopTimer]; [[NSNotificationCenter defaultCenter]removeObserver:self];; } #pragma mark - JXCategoryListContainerView - (UIView *)listView{ return self.view; } @end