UpHotView.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. //
  2. // UpHotView.m
  3. // YBVideo
  4. //
  5. // Created by ybRRR on 2023/7/10.
  6. // Copyright © 2023 cat. All rights reserved.
  7. //
  8. #import "UpHotView.h"
  9. #import "UphotCoinCell.h"
  10. #import "EditPayView.h"
  11. @interface UpHotView ()<UICollectionViewDelegate,UICollectionViewDataSource,UIGestureRecognizerDelegate>
  12. {
  13. UILabel *exposureLb;
  14. UILabel *payLb;
  15. UILabel *userNumLb;
  16. UICollectionView *_collectionView;
  17. UIView *backView;
  18. }
  19. @property (nonatomic, strong)NSMutableArray *dataArr;
  20. @property (nonatomic, strong)EditPayView *editPayView;
  21. @end
  22. @implementation UpHotView
  23. -(instancetype)initWithFrame:(CGRect)frame
  24. {
  25. self = [super initWithFrame:frame];
  26. if(self){
  27. _dataArr = [NSMutableArray array];
  28. self.backgroundColor = RGBA(1, 1, 1, 0.4);
  29. UITapGestureRecognizer *closeTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(closeTapClick)];
  30. closeTap.delegate = self;
  31. [self addGestureRecognizer:closeTap];
  32. [self createUI];
  33. [self getHotLiveRules];
  34. }
  35. return self;
  36. }
  37. -(void)getHotLiveRules{
  38. [ YBNetworking postWithUrl:@"Popular.getHotLiveRules" Dic:@{@"uid":[Config getOwnID],@"token":[Config getOwnToken]} Suc:^(int code, id info, NSString *msg) {
  39. if(code == 0){
  40. [_dataArr removeAllObjects];
  41. NSDictionary *infoDic = [info firstObject];
  42. NSArray *rulesArr = [infoDic valueForKey:@"rules"];
  43. [_dataArr addObjectsFromArray:rulesArr];
  44. [_dataArr addObject:@{@"coin":YZMsg(@"自定义")}];
  45. [_collectionView reloadData];
  46. exposureLb.text = minstr([infoDic valueForKey:@"exposure"]);
  47. userNumLb.text = [NSString stringWithFormat:@"%@-%@人",minstr([infoDic valueForKey:@"user_min_num"]),minstr([infoDic valueForKey:@"user_max_num"])];
  48. if(rulesArr.count > 0){
  49. payLb.text =minstr([[rulesArr firstObject] valueForKey:@"coin"]);
  50. }
  51. }
  52. } Fail:^(id fail) {
  53. }] ;
  54. }
  55. -(void)closeTapClick{
  56. if(self.closeEvent){
  57. self.closeEvent(@"关闭",@"");
  58. }
  59. }
  60. -(void)createUI{
  61. backView = [[UIView alloc]init];
  62. backView.backgroundColor = Normal_Color;
  63. backView.frame = CGRectMake(0, _window_height-_window_height *0.5, _window_width, _window_height *0.5);
  64. [self addSubview:backView];
  65. UILabel *titleLb = [[UILabel alloc]init];
  66. titleLb.frame = CGRectMake(0, 10, backView.width, 20);
  67. titleLb.textColor = UIColor.whiteColor;
  68. titleLb.font = [UIFont systemFontOfSize:16];
  69. titleLb.text = YZMsg(@"直播上热门");
  70. titleLb.textAlignment = NSTextAlignmentCenter;
  71. [backView addSubview:titleLb];
  72. UIButton *upinfoBtn = [UIButton buttonWithType:0];
  73. upinfoBtn.frame = CGRectMake(backView.width-30, 10, 20, 20);
  74. [upinfoBtn setImage:[UIImage imageNamed:@"uphotInfo"] forState:0];
  75. [upinfoBtn addTarget:self action:@selector(uphotInfoClick) forControlEvents:UIControlEventTouchUpInside];
  76. [backView addSubview:upinfoBtn];
  77. UILabel *subTitleLb = [[UILabel alloc]init];
  78. subTitleLb.frame = CGRectMake(0, titleLb.bottom+5, backView.width, 20);
  79. subTitleLb.textColor = UIColor.grayColor;
  80. subTitleLb.font = [UIFont systemFontOfSize:12];
  81. subTitleLb.text = YZMsg(@"预计曝光量");
  82. subTitleLb.textAlignment = NSTextAlignmentCenter;
  83. [backView addSubview:subTitleLb];
  84. exposureLb = [[UILabel alloc]init];
  85. exposureLb.frame = CGRectMake(backView.width/2-40, subTitleLb.bottom+5, 80, 20);
  86. exposureLb.textColor = UIColor.grayColor;
  87. exposureLb.font = [UIFont systemFontOfSize:12];
  88. exposureLb.text = YZMsg(@"1000+");
  89. exposureLb.textAlignment = NSTextAlignmentCenter;
  90. [exposureLb setBackgroundColor:Normal_SubColor];
  91. [backView addSubview:exposureLb];
  92. [PublicObj lineViewWithFrame:CGRectMake(10, exposureLb.bottom+10, _window_width-20, 1) andColor:Normal_SubColor andView:backView];
  93. CGFloat pwidth = [PublicObj widthOfString:YZMsg(@"预估带来的观众数:") andFont:[UIFont systemFontOfSize:14] andHeight:20];
  94. UILabel *peopleLb = [[UILabel alloc]init];
  95. peopleLb.frame = CGRectMake(20, exposureLb.bottom+15, pwidth, 20);
  96. peopleLb.text =YZMsg(@"预估带来的观众数:");
  97. peopleLb.textColor = UIColor.grayColor;
  98. peopleLb.font = [UIFont systemFontOfSize:14];
  99. [backView addSubview:peopleLb];
  100. userNumLb= [[UILabel alloc]init];
  101. userNumLb.frame = CGRectMake(peopleLb.right+5, exposureLb.bottom+15, 160, 20);
  102. userNumLb.text =@"0";
  103. userNumLb.textColor = Pink_Cor;
  104. userNumLb.font = [UIFont systemFontOfSize:14];
  105. [backView addSubview:userNumLb];
  106. UILabel *peopleTipLb = [[UILabel alloc]init];
  107. peopleTipLb.frame = CGRectMake(20, peopleLb.bottom+5, backView.width-20, 20);
  108. peopleTipLb.text =YZMsg(@"实际效果与直播效果有关");
  109. peopleTipLb.textColor = UIColor.grayColor;
  110. peopleTipLb.font = [UIFont systemFontOfSize:12];
  111. [backView addSubview:peopleTipLb];
  112. [PublicObj lineViewWithFrame:CGRectMake(10, peopleTipLb.bottom+10, _window_width-20, 1) andColor:Normal_SubColor andView:backView];
  113. UILabel *subCoinLb = [[UILabel alloc]init];
  114. subCoinLb.frame = CGRectMake(20, peopleTipLb.bottom+20, pwidth, 20);
  115. subCoinLb.text =YZMsg(@"投放金额");
  116. subCoinLb.textColor = UIColor.grayColor;
  117. subCoinLb.font = [UIFont systemFontOfSize:14];
  118. [backView addSubview:subCoinLb];
  119. UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc]init];
  120. flow.scrollDirection = UICollectionViewScrollDirectionVertical;
  121. flow.itemSize = CGSizeMake((_window_width-90)/3, 30);
  122. flow.minimumLineSpacing = 10;
  123. flow.minimumInteritemSpacing = 10;
  124. _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(20, subCoinLb.bottom+10, backView.width-40, 120) collectionViewLayout:flow];
  125. _collectionView.delegate = self;
  126. _collectionView.dataSource = self;
  127. [_collectionView registerNib:[UINib nibWithNibName:@"UphotCoinCell" bundle:nil] forCellWithReuseIdentifier:@"UphotCoinCell"];
  128. _collectionView.backgroundColor = UIColor.clearColor;
  129. [backView addSubview:_collectionView];
  130. UIView *bottomView = [[UIView alloc]init];
  131. bottomView.frame = CGRectMake(0, backView.height-50-ShowDiff, backView.width, 50+ShowDiff);
  132. bottomView.backgroundColor = RGB_COLOR(@"#272048", 1);
  133. [backView addSubview:bottomView];
  134. UILabel *paytitleLb = [[UILabel alloc]init];
  135. paytitleLb.frame = CGRectMake(12, 20, 70, 20);
  136. paytitleLb.font = [UIFont systemFontOfSize:16];
  137. paytitleLb.text = YZMsg(@"待支付:");
  138. paytitleLb.textColor = UIColor.whiteColor;
  139. paytitleLb.adjustsFontSizeToFitWidth = YES;
  140. [bottomView addSubview:paytitleLb];
  141. payLb = [[UILabel alloc]init];
  142. payLb.frame = CGRectMake(paytitleLb.right+5, 20, 80, 20);
  143. payLb.font = [UIFont systemFontOfSize:16];
  144. payLb.text = YZMsg(@"100");
  145. payLb.textColor = UIColor.whiteColor;
  146. [bottomView addSubview:payLb];
  147. UIButton *payBtn = [UIButton buttonWithType:0];
  148. payBtn.frame = CGRectMake(backView.width-110, 0, 110, 50);
  149. [payBtn setBackgroundColor:RGB_COLOR(@"#EA377F", 1)];
  150. [payBtn setTitle:YZMsg(@"确定支付") forState:0];
  151. payBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
  152. [payBtn setTitleColor: UIColor.whiteColor forState:0];
  153. payBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  154. [payBtn addTarget:self action:@selector(payBtnClick) forControlEvents:UIControlEventTouchUpInside];
  155. [bottomView addSubview:payBtn];
  156. }
  157. -(void)payBtnClick{
  158. NSString *titleStr = [NSString stringWithFormat:@"您将支付%@%@,进行直播上热门投放,是否继续",payLb.text,[common name_coin]];
  159. UIAlertController *alertcontrol = [UIAlertController alertControllerWithTitle:nil message:titleStr preferredStyle:UIAlertControllerStyleAlert];
  160. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:YZMsg(@"取消") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  161. }];
  162. [cancelAction setValue:UIColor.grayColor forKey:@"_titleTextColor"];
  163. UIAlertAction *sureAction = [UIAlertAction actionWithTitle:YZMsg(@"确定支付") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  164. [ YBNetworking postWithUrl:@"Popular.createHotLiveOrder" Dic:@{@"uid":[Config getOwnID],@"token":[Config getOwnToken],@"nums": payLb.text} Suc:^(int code, id info, NSString *msg) {
  165. if(code == 0){
  166. NSDictionary *infos = [info firstObject];
  167. NSString *orderid = [infos valueForKey:@"orderid"];
  168. if(self.closeEvent){
  169. self.closeEvent(@"确定",orderid);
  170. }
  171. }else{
  172. [MBProgressHUD showError:msg];
  173. }
  174. } Fail:^(id fail) {
  175. }] ;
  176. }];
  177. [cancelAction setValue:UIColor.grayColor forKey:@"_titleTextColor"];
  178. [sureAction setValue:Pink_Cor forKey:@"_titleTextColor"];
  179. [alertcontrol addAction:cancelAction];
  180. [alertcontrol addAction:sureAction];
  181. [[[YBBaseAppDelegate sharedAppDelegate] topViewController]presentViewController:alertcontrol animated:YES completion:nil];
  182. }
  183. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  184. return _dataArr.count;
  185. }
  186. -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  187. {
  188. return UIEdgeInsetsMake(5, 5, 5, 5);
  189. }
  190. -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  191. return 1;
  192. }
  193. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  194. UphotCoinCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"UphotCoinCell" forIndexPath:indexPath];
  195. cell.backgroundColor = RGB_COLOR(@"#272048", 1);
  196. cell.layer.cornerRadius = 5;
  197. cell.layer.masksToBounds = YES;
  198. cell.dataDic = _dataArr[indexPath.item];
  199. return cell;
  200. }
  201. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  202. {
  203. if(indexPath.item == _dataArr.count-1){
  204. [self showEditPayView];
  205. }else{
  206. NSDictionary *itemData = _dataArr[indexPath.item];
  207. payLb.text =[itemData valueForKey:@"coin"];
  208. [self getExposureByCoin:minstr([itemData valueForKey:@"coin"])];
  209. }
  210. }
  211. -(void)getExposureByCoin:(NSString *)coinStr{
  212. [YBNetworking postWithUrl:@"Popular.getExposureByCoin" Dic:@{@"nums":coinStr} Suc:^(int code, id info, NSString *msg) {
  213. if(code == 0){
  214. NSDictionary *infoDic = [info firstObject];
  215. exposureLb.text =[NSString stringWithFormat:@"%@+",minstr([infoDic valueForKey:@"exposure"])];
  216. userNumLb.text = [NSString stringWithFormat:@"%@-%@人",minstr([infoDic valueForKey:@"user_min_num"]),minstr([infoDic valueForKey:@"user_max_num"])];
  217. }
  218. } Fail:^(id fail) {
  219. }];
  220. }
  221. -(void)uphotInfoClick{
  222. NSString *url =[NSString stringWithFormat:@"%@/appapi/page/news?id=163",h5url];
  223. PubH5 *h5VC = [[PubH5 alloc]init];
  224. h5VC.url =url;
  225. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:h5VC animated:YES];
  226. }
  227. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
  228. NSLog(@"s0000000000:%@",NSStringFromClass([touch.view class]));
  229. if ([touch.view isDescendantOfView:backView] ||[touch.view isDescendantOfView:_editPayView] ) {
  230. return NO;
  231. }
  232. return YES;
  233. }
  234. -(void)showEditPayView{
  235. YBWeakSelf;
  236. _editPayView = [[EditPayView alloc]initWithFrame:CGRectMake(0, 0, _window_width, _window_height)];
  237. _editPayView.closeEvent = ^(NSString *type, NSString *coinStr) {
  238. if([type isEqual:@"确定"]){
  239. [weakSelf.dataArr removeLastObject];
  240. [weakSelf.dataArr addObject:@{@"coin":coinStr}];
  241. payLb.text =coinStr;
  242. [self getExposureByCoin:coinStr];
  243. NSIndexPath *lastIndex = [NSIndexPath indexPathForItem:weakSelf.dataArr.count-1 inSection:0];
  244. UphotCoinCell *cell = [_collectionView cellForItemAtIndexPath:lastIndex];
  245. cell.coinLb.text =coinStr;
  246. // [_collectionView reloadData];
  247. }
  248. [weakSelf.editPayView removeFromSuperview];
  249. weakSelf.editPayView = nil;
  250. };
  251. [self addSubview:_editPayView];
  252. }
  253. @end