// // YOUPAILZCommonGiftView.m // VQU // // Created by 肖浩然的mac on 2021/8/20. // Copyright © 2021 leo. All rights reserved. // #import "YOUPAIHRChatRoomGiftView.h" #import "JXCategoryView.h" #import "JXPagerView.h" #import "YOUPAILZCommonGiftVC.h" #import "YOUPAILZCommonGiftListModel.h" #import "UIViewController+TFPresent.h" #import "YOUPAIHRChatRoomSubGiftVC.h" #import "YOUPAIHRChatRoomHeaderView.h" #import "YOUPAIHRChatRoomGiftModel.h" #import "YOUPAILZChatRoomSeatModel.h" #define LZCategoryViewHeight 54.0f #define LZCategoryViewItemWidth 65.0f @interface YOUPAIHRChatRoomGiftView () @property (nonatomic, weak) JXCategoryListContainerView *youpaippagerView; @property (nonatomic, strong) JXCategoryTitleView *youpaipcategoryView; /* titlearr */ @property (strong, nonatomic) NSArray *youpaiptitlesArr; /* youpaipfirstBtn */ @property (strong, nonatomic) UIButton *youpaipfirstBtn; @property (strong, nonatomic) YOUPAILCFirstRechargeModel *youpaipfirstRechargeModel; @property (nonatomic, strong) NSMutableArray *youpaipseats; @property (nonatomic, strong)YOUPAIHRChatRoomHeaderView *youpaipheadView; @end @implementation YOUPAIHRChatRoomGiftView - (void)dealloc{ [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)viewDidLoad { [super viewDidLoad]; self.baseView.hidden = YES; // self.youpaiptitlesArr = @[@"1",@"2",@"3"]; dispatch_group_t group = dispatch_group_create(); dispatch_group_enter(group); dispatch_group_async(group, dispatch_get_main_queue(), ^{ NSLog(@"%@---获取 余额",[NSThread currentThread]); // 获取余额 [self youpaifrequestBannerData:^{ dispatch_group_leave(group); }]; }); dispatch_group_notify(group, dispatch_get_main_queue(), ^{ NSLog(@"%@---全部结束。。。",[NSThread currentThread]); [self youpaifrequestCategoryListData]; }); [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(youpaifupdateSeat:) name:@"UpdateChatRoomAllSeat" object:nil]; } -(void)youpaifupdateSeat:(NSNotification *)notify{ self.youpaipnormalSeatJsons = notify.userInfo[@"seats"]; [self youpaifhandleSeatInfo]; } -(void)youpaifsetupUI{ UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 333.0f+SafeHeight+50)]; bgV.backgroundColor = LCBkgColor; [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:bgV size:CGSizeMake(20.0f, 20.0f)]; [self.view addSubview:bgV]; [bgV mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.offset(0.0f); make.height.offset(333.0f+SafeHeight+50); }]; NSMutableArray *titles = [NSMutableArray array]; for (YOUPAILZCommonGiftListModel *model in self.youpaiptitlesArr) { [titles addObject:model.youpaipname]; } JXCategoryTitleView *youpaipcategoryView = [[JXCategoryTitleView alloc] init]; youpaipcategoryView.backgroundColor = LCBkgColor; youpaipcategoryView.titles = titles; youpaipcategoryView.delegate = self; youpaipcategoryView.titleSelectedColor = HexColorFromRGB(0xffffff); youpaipcategoryView.titleColor = HexColorFromRGB(0x9F9DA5); youpaipcategoryView.titleColorGradientEnabled = YES; youpaipcategoryView.titleFont = LCFont(18.0f); youpaipcategoryView.titleSelectedFont = LCBoldFont(18.0f); youpaipcategoryView.cellWidth = LZCategoryViewItemWidth; youpaipcategoryView.cellSpacing = 0.0f; youpaipcategoryView.averageCellSpacingEnabled = NO; youpaipcategoryView.defaultSelectedIndex =1; [bgV addSubview:youpaipcategoryView]; self.youpaipcategoryView = youpaipcategoryView; [youpaipcategoryView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.right.offset(0.0f); make.height.offset(49.0f); }]; YOUPAILZCommonGiftListModel *model = self.youpaiptitlesArr[0]; //头部View YOUPAIHRChatRoomHeaderView *youpaipheadView = [[YOUPAIHRChatRoomHeaderView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(youpaipcategoryView.frame), KScreenWidth, 50) send_gift_hide:model.youpaipsend_gift_hide]; [bgV addSubview:youpaipheadView]; self.youpaipheadView = youpaipheadView; // youpaipheadView.youpaipisAnchor = self.youpaipisAnchor; // youpaipheadView.dataArr = arr; [youpaipheadView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.top.mas_equalTo(youpaipcategoryView.mas_bottom); make.height.mas_equalTo(50); }]; JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init]; lineView.verticalMargin = 4.0f; lineView.indicatorHeight = 2.5f; lineView.indicatorWidth = 8; lineView.layer.cornerRadius = 1.25; lineView.layer.masksToBounds = YES; [lineView.layer addSublayer:[LCTools getGradientLayerWithSize:CGSizeMake(lineView.indicatorWidth, lineView.indicatorHeight) twoColors:@[HexColorFromRGB(0xFF0084),HexColorFromRGB(0xFF3A00)] gradientType:GradientLeftToRight]]; // youpaipcategoryView.indicators = @[lineView]; JXCategoryListContainerView *pagerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_CollectionView delegate:self]; [pagerView setDefaultSelectedIndex:1]; pagerView.listCellBackgroundColor = LCSubBkgColor; // pagerView.frame = CGRectMake(0.0f,CGRectGetMaxY(categoryBgV.frame), KScreenWidth, KScreenHeight - CGRectGetMaxY(categoryBgV.frame) - SafeHeight); [bgV addSubview:pagerView]; self.youpaippagerView = pagerView; [pagerView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.offset(0.0f); make.top.equalTo(youpaipheadView.mas_bottom).offset(10); make.bottom.offset(0.0f); }]; self.youpaipcategoryView.listContainer = self.youpaippagerView; } - (void)youpaifhandleSeatInfo{ NSMutableArray *youpaipseats = [YOUPAILZChatRoomSeatModel mj_objectArrayWithKeyValuesArray:self.youpaipnormalSeatJsons]; if (youpaipseats.count != 0) { youpaipseats.lastObject.youpaipisSelected = NO; } // BOOL youpaipisFirst = YES; NSMutableArray *nseats = [NSMutableArray array]; for (NSInteger i = 0; i < youpaipseats.count; i ++) { YOUPAILZChatRoomSeatModel *iseatModel = youpaipseats[i]; iseatModel.youpaipisTalking = NO; if (iseatModel.youpaipseatState == LZChatRoomSeatStateWithBusy) { for (YOUPAILZChatRoomSeatModel *seatModel in self.youpaipseats) { if ([iseatModel.youpaipuserInfo.youpaipid isEqual:seatModel.youpaipuserInfo.youpaipid]) { iseatModel.youpaipisSelected = seatModel.youpaipisSelected; break; } } if (self.youpaipseats == nil/* && youpaipisFirst*/) { // youpaipisFirst = NO; iseatModel.youpaipisSelected = YES; } [nseats addObject:iseatModel]; } } self.youpaipseats = nseats; self.youpaipheadView.youpaipseats = self.youpaipseats; } - (void)youpaifrequestBannerData:(void(^)(void))complete{ [LCHttpHelper requestWithURLString:GetAdvert parameters:@{@"position":@"5"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 self.youpaipfirstRechargeModel = [YOUPAILCFirstRechargeModel mj_objectWithKeyValues:dict[@"data"]]; if (complete) { complete(); } } } failure:^(NSError *error) {}]; } // 返回列表的数量 - (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView { return self.youpaiptitlesArr.count; } // 根据下标 index 返回对应遵守并实现 `JXCategoryListContentViewDelegate` 协议的列表实例 - (id)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index { YOUPAILZCommonGiftListModel *model = self.youpaiptitlesArr[index]; YOUPAIHRChatRoomSubGiftVC *vc = [YOUPAIHRChatRoomSubGiftVC new]; vc.Giftdelegate = self; vc.youpaipisAnchor = self.youpaipisAnchor; vc.youpaipsend_gift_hide = model.youpaipsend_gift_hide; vc.youpaipID = [NSString stringWithFormat:@"%ld",model.youpaipid]; vc.youpaipjumToWalletBlock = self.youpaipjumToWalletBlock1; return vc; } //- (void)youpaipcategoryView:(JXCategoryBaseView *)youpaipcategoryView didSelectedItemAtIndex:(NSInteger)index{ // // [self.youpaipcategoryView.listContainer reloadData]; // // //} -(void)youpaifDidSenderGiftWith:(YOUPAILCGiftModel *)model Count:(NSInteger)count CategoryID:(NSString *)categoryid{ if (self.youpaiplzgiftblock != nil && model != nil) { NSMutableString *userIds = [NSMutableString string]; for (YOUPAILZChatRoomSeatModel *seatModel in self.youpaipseats) { if (seatModel.youpaipisSelected) { [userIds appendFormat:@"%@,",seatModel.youpaipuserInfo.youpaipid]; } } if (userIds.length == 0) { [ZCHUDHelper showTitle:@"请选择赠送的嘉宾"]; return; }else{ [userIds deleteCharactersInRange:NSMakeRange(userIds.length - 1, 1)]; } // [self dismissViewControllerAnimated:NO completion:^{ // // }]; self.youpaiplzgiftblock(model, userIds, count, categoryid); } } - (void)youpaifrequestCategoryListData{ @weakify(self); [LCHttpHelper requestWithURLString:LiveGiftList parameters:@{} needToken:YES type:HttpRequestTypePost success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { self.youpaiptitlesArr = [YOUPAILZCommonGiftListModel mj_objectArrayWithKeyValuesArray:[dict objectForKey:@"data"]]; [self youpaifsetupUI]; [self youpaifhandleSeatInfo]; }else{ [ZCHUDHelper showTitle:[dict objectForKey:@"message"]]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } - (void)youpaifreloadBalance{ [[NSNotificationCenter defaultCenter] postNotificationName:@"VQUChatRoomRefreshBalance" object:nil userInfo:nil]; } @end