YOUPAIHRChatRoomGiftView.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. //
  2. // YOUPAILZCommonGiftView.m
  3. // VQU
  4. //
  5. // Created by 肖浩然的mac on 2021/8/20.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "YOUPAIHRChatRoomGiftView.h"
  9. #import "JXCategoryView.h"
  10. #import "JXPagerView.h"
  11. #import "YOUPAILZCommonGiftVC.h"
  12. #import "YOUPAILZCommonGiftListModel.h"
  13. #import "UIViewController+TFPresent.h"
  14. #import "YOUPAIHRChatRoomSubGiftVC.h"
  15. #import "YOUPAIHRChatRoomHeaderView.h"
  16. #import "YOUPAIHRChatRoomGiftModel.h"
  17. #import "YOUPAILZChatRoomSeatModel.h"
  18. #define LZCategoryViewHeight 54.0f
  19. #define LZCategoryViewItemWidth 65.0f
  20. @interface YOUPAIHRChatRoomGiftView ()<JXCategoryViewDelegate,JXPagerViewDelegate,JXCategoryListContainerViewDelegate,GiftSenderDelegate>
  21. @property (nonatomic, weak) JXCategoryListContainerView *youpaippagerView;
  22. @property (nonatomic, strong) JXCategoryTitleView *youpaipcategoryView;
  23. /* titlearr */
  24. @property (strong, nonatomic) NSArray *youpaiptitlesArr;
  25. /* youpaipfirstBtn */
  26. @property (strong, nonatomic) UIButton *youpaipfirstBtn;
  27. @property (strong, nonatomic) YOUPAILCFirstRechargeModel *youpaipfirstRechargeModel;
  28. @property (nonatomic, strong) NSMutableArray <YOUPAILZChatRoomSeatModel *>*youpaipseats;
  29. @property (nonatomic, strong)YOUPAIHRChatRoomHeaderView *youpaipheadView;
  30. @end
  31. @implementation YOUPAIHRChatRoomGiftView
  32. - (void)dealloc{
  33. [[NSNotificationCenter defaultCenter] removeObserver:self];
  34. }
  35. - (void)viewDidLoad {
  36. [super viewDidLoad];
  37. self.baseView.hidden = YES;
  38. // self.youpaiptitlesArr = @[@"1",@"2",@"3"];
  39. dispatch_group_t group = dispatch_group_create();
  40. dispatch_group_enter(group);
  41. dispatch_group_async(group, dispatch_get_main_queue(), ^{
  42. NSLog(@"%@---获取 余额",[NSThread currentThread]);
  43. // 获取余额
  44. [self youpaifrequestBannerData:^{
  45. dispatch_group_leave(group);
  46. }];
  47. });
  48. dispatch_group_notify(group, dispatch_get_main_queue(), ^{
  49. NSLog(@"%@---全部结束。。。",[NSThread currentThread]);
  50. [self youpaifrequestCategoryListData];
  51. });
  52. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(youpaifupdateSeat:) name:@"UpdateChatRoomAllSeat" object:nil];
  53. }
  54. -(void)youpaifupdateSeat:(NSNotification *)notify{
  55. self.youpaipnormalSeatJsons = notify.userInfo[@"seats"];
  56. [self youpaifhandleSeatInfo];
  57. }
  58. -(void)youpaifsetupUI{
  59. UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 333.0f+SafeHeight+50)];
  60. bgV.backgroundColor = LCBkgColor;
  61. [LCTools clipCorner:UIRectCornerTopLeft|UIRectCornerTopRight View:bgV size:CGSizeMake(20.0f, 20.0f)];
  62. [self.view addSubview:bgV];
  63. [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.left.right.bottom.offset(0.0f);
  65. make.height.offset(333.0f+SafeHeight+50);
  66. }];
  67. NSMutableArray <NSString *>*titles = [NSMutableArray array];
  68. for (YOUPAILZCommonGiftListModel *model in self.youpaiptitlesArr) {
  69. [titles addObject:model.youpaipname];
  70. }
  71. JXCategoryTitleView *youpaipcategoryView = [[JXCategoryTitleView alloc] init];
  72. youpaipcategoryView.backgroundColor = LCBkgColor;
  73. youpaipcategoryView.titles = titles;
  74. youpaipcategoryView.delegate = self;
  75. youpaipcategoryView.titleSelectedColor = HexColorFromRGB(0xffffff);
  76. youpaipcategoryView.titleColor = HexColorFromRGB(0x9F9DA5);
  77. youpaipcategoryView.titleColorGradientEnabled = YES;
  78. youpaipcategoryView.titleFont = LCFont(18.0f);
  79. youpaipcategoryView.titleSelectedFont = LCBoldFont(18.0f);
  80. youpaipcategoryView.cellWidth = LZCategoryViewItemWidth;
  81. youpaipcategoryView.cellSpacing = 0.0f;
  82. youpaipcategoryView.averageCellSpacingEnabled = NO;
  83. youpaipcategoryView.defaultSelectedIndex =1;
  84. [bgV addSubview:youpaipcategoryView];
  85. self.youpaipcategoryView = youpaipcategoryView;
  86. [youpaipcategoryView mas_makeConstraints:^(MASConstraintMaker *make) {
  87. make.left.top.right.offset(0.0f);
  88. make.height.offset(49.0f);
  89. }];
  90. YOUPAILZCommonGiftListModel *model = self.youpaiptitlesArr[0];
  91. //头部View
  92. YOUPAIHRChatRoomHeaderView *youpaipheadView = [[YOUPAIHRChatRoomHeaderView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(youpaipcategoryView.frame), KScreenWidth, 50) send_gift_hide:model.youpaipsend_gift_hide];
  93. [bgV addSubview:youpaipheadView];
  94. self.youpaipheadView = youpaipheadView;
  95. // youpaipheadView.youpaipisAnchor = self.youpaipisAnchor;
  96. // youpaipheadView.dataArr = arr;
  97. [youpaipheadView mas_makeConstraints:^(MASConstraintMaker *make) {
  98. make.left.mas_equalTo(0);
  99. make.right.mas_equalTo(0);
  100. make.top.mas_equalTo(youpaipcategoryView.mas_bottom);
  101. make.height.mas_equalTo(50);
  102. }];
  103. JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
  104. lineView.verticalMargin = 4.0f;
  105. lineView.indicatorHeight = 2.5f;
  106. lineView.indicatorWidth = 8;
  107. lineView.layer.cornerRadius = 1.25;
  108. lineView.layer.masksToBounds = YES;
  109. [lineView.layer addSublayer:[LCTools getGradientLayerWithSize:CGSizeMake(lineView.indicatorWidth, lineView.indicatorHeight) twoColors:@[HexColorFromRGB(0xFF0084),HexColorFromRGB(0xFF3A00)] gradientType:GradientLeftToRight]];
  110. // youpaipcategoryView.indicators = @[lineView];
  111. JXCategoryListContainerView *pagerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_CollectionView delegate:self];
  112. [pagerView setDefaultSelectedIndex:1];
  113. pagerView.listCellBackgroundColor = LCSubBkgColor;
  114. // pagerView.frame = CGRectMake(0.0f,CGRectGetMaxY(categoryBgV.frame), KScreenWidth, KScreenHeight - CGRectGetMaxY(categoryBgV.frame) - SafeHeight);
  115. [bgV addSubview:pagerView];
  116. self.youpaippagerView = pagerView;
  117. [pagerView mas_makeConstraints:^(MASConstraintMaker *make) {
  118. make.left.right.offset(0.0f);
  119. make.top.equalTo(youpaipheadView.mas_bottom).offset(10);
  120. make.bottom.offset(0.0f);
  121. }];
  122. self.youpaipcategoryView.listContainer = self.youpaippagerView;
  123. }
  124. - (void)youpaifhandleSeatInfo{
  125. NSMutableArray <YOUPAILZChatRoomSeatModel *> *youpaipseats = [YOUPAILZChatRoomSeatModel mj_objectArrayWithKeyValuesArray:self.youpaipnormalSeatJsons];
  126. if (youpaipseats.count != 0) {
  127. youpaipseats.lastObject.youpaipisSelected = NO;
  128. }
  129. // BOOL youpaipisFirst = YES;
  130. NSMutableArray <YOUPAILZChatRoomSeatModel *> *nseats = [NSMutableArray array];
  131. for (NSInteger i = 0; i < youpaipseats.count; i ++) {
  132. YOUPAILZChatRoomSeatModel *iseatModel = youpaipseats[i];
  133. iseatModel.youpaipisTalking = NO;
  134. if (iseatModel.youpaipseatState == LZChatRoomSeatStateWithBusy) {
  135. for (YOUPAILZChatRoomSeatModel *seatModel in self.youpaipseats) {
  136. if ([iseatModel.youpaipuserInfo.youpaipid isEqual:seatModel.youpaipuserInfo.youpaipid]) {
  137. iseatModel.youpaipisSelected = seatModel.youpaipisSelected;
  138. break;
  139. }
  140. }
  141. if (self.youpaipseats == nil/* && youpaipisFirst*/) {
  142. // youpaipisFirst = NO;
  143. iseatModel.youpaipisSelected = YES;
  144. }
  145. [nseats addObject:iseatModel];
  146. }
  147. }
  148. self.youpaipseats = nseats;
  149. self.youpaipheadView.youpaipseats = self.youpaipseats;
  150. }
  151. - (void)youpaifrequestBannerData:(void(^)(void))complete{
  152. [LCHttpHelper requestWithURLString:GetAdvert parameters:@{@"position":@"5"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  153. NSDictionary* dict = (NSDictionary*)responseObject;
  154. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  155. if (code==0) {//成功
  156. self.youpaipfirstRechargeModel = [YOUPAILCFirstRechargeModel mj_objectWithKeyValues:dict[@"data"]];
  157. if (complete) {
  158. complete();
  159. }
  160. }
  161. } failure:^(NSError *error) {}];
  162. }
  163. // 返回列表的数量
  164. - (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
  165. return self.youpaiptitlesArr.count;
  166. }
  167. // 根据下标 index 返回对应遵守并实现 `JXCategoryListContentViewDelegate` 协议的列表实例
  168. - (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
  169. YOUPAILZCommonGiftListModel *model = self.youpaiptitlesArr[index];
  170. YOUPAIHRChatRoomSubGiftVC *vc = [YOUPAIHRChatRoomSubGiftVC new];
  171. vc.Giftdelegate = self;
  172. vc.youpaipisAnchor = self.youpaipisAnchor;
  173. vc.youpaipsend_gift_hide = model.youpaipsend_gift_hide;
  174. vc.youpaipID = [NSString stringWithFormat:@"%ld",model.youpaipid];
  175. vc.youpaipjumToWalletBlock = self.youpaipjumToWalletBlock1;
  176. return vc;
  177. }
  178. //- (void)youpaipcategoryView:(JXCategoryBaseView *)youpaipcategoryView didSelectedItemAtIndex:(NSInteger)index{
  179. //
  180. // [self.youpaipcategoryView.listContainer reloadData];
  181. //
  182. //
  183. //}
  184. -(void)youpaifDidSenderGiftWith:(YOUPAILCGiftModel *)model Count:(NSInteger)count CategoryID:(NSString *)categoryid{
  185. if (self.youpaiplzgiftblock != nil && model != nil) {
  186. NSMutableString *userIds = [NSMutableString string];
  187. for (YOUPAILZChatRoomSeatModel *seatModel in self.youpaipseats) {
  188. if (seatModel.youpaipisSelected) {
  189. [userIds appendFormat:@"%@,",seatModel.youpaipuserInfo.youpaipid];
  190. }
  191. }
  192. if (userIds.length == 0) {
  193. [ZCHUDHelper showTitle:@"请选择赠送的嘉宾"];
  194. return;
  195. }else{
  196. [userIds deleteCharactersInRange:NSMakeRange(userIds.length - 1, 1)];
  197. }
  198. // [self dismissViewControllerAnimated:NO completion:^{
  199. //
  200. // }];
  201. self.youpaiplzgiftblock(model, userIds, count, categoryid);
  202. }
  203. }
  204. - (void)youpaifrequestCategoryListData{
  205. @weakify(self);
  206. [LCHttpHelper requestWithURLString:LiveGiftList parameters:@{} needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  207. @strongify(self);
  208. NSDictionary* dict = (NSDictionary*)responseObject;
  209. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  210. if (code == 0) {
  211. self.youpaiptitlesArr = [YOUPAILZCommonGiftListModel mj_objectArrayWithKeyValuesArray:[dict objectForKey:@"data"]];
  212. [self youpaifsetupUI];
  213. [self youpaifhandleSeatInfo];
  214. }else{
  215. [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  216. }
  217. } failure:^(NSError *error) {
  218. [ZCHUDHelper showTitle:error.localizedDescription];
  219. }];
  220. }
  221. - (void)youpaifreloadBalance{
  222. [[NSNotificationCenter defaultCenter] postNotificationName:@"VQUChatRoomRefreshBalance" object:nil userInfo:nil];
  223. }
  224. @end