YBVipVC.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. //
  2. // YBVipVC.m
  3. // YBVideo
  4. //
  5. // Created by YB007 on 2019/11/20.
  6. // Copyright © 2019 cat. All rights reserved.
  7. //
  8. #import "YBVipVC.h"
  9. #import "YBVipCell.h"
  10. #import "YBVipHeader.h"
  11. #import "vipBuyView.h"
  12. #import "YBRechargeType.h"
  13. @interface YBVipVC ()<UITableViewDelegate,UITableViewDataSource>
  14. {
  15. NSDictionary *_infoDic;
  16. NSArray *_vipLimiteArray;
  17. vipBuyView *buyView;
  18. }
  19. @property(nonatomic,strong)YBVipHeader *headerView;
  20. @property(nonatomic,strong)UITableView *tableView;
  21. @end
  22. @implementation YBVipVC
  23. -(void)viewWillAppear:(BOOL)animated {
  24. [super viewWillAppear:animated];
  25. [self pullData];
  26. }
  27. - (void)clickNaviLeftBtn {
  28. [super clickNaviLeftBtn];
  29. [[YBRechargeType chargeManeger]removePayNotice];
  30. }
  31. -(void)dealloc {
  32. [[YBRechargeType chargeManeger]removePayNotice];
  33. }
  34. - (void)viewDidLoad {
  35. [super viewDidLoad];
  36. //支付监听
  37. [[YBRechargeType chargeManeger]addPayNotice];
  38. self.titleL.text = YZMsg(@"会员中心");
  39. self.subNavi.backgroundColor = [UIColor clearColor];
  40. self.view.backgroundColor = [UIColor whiteColor];
  41. _infoDic = [NSDictionary dictionary];
  42. _vipLimiteArray = [NSArray array];
  43. [self.view addSubview:self.tableView];
  44. self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  45. [self.view bringSubviewToFront:self.naviView];
  46. [self.tableView reloadData];
  47. }
  48. -(void)pullData {
  49. [YBNetworking postWithUrl:@"User.getVip" Dic:@{@"type":@"1",@"version_ios":[PublicObj getAppBuild]} Suc:^(int code, id info, NSString *msg) {
  50. if (code == 0) {
  51. _infoDic = [info firstObject];
  52. NSDictionary *userInfo = [_infoDic valueForKey:@"userinfo"];
  53. NSDictionary *vipInfo = [userInfo valueForKey:@"vipinfo"];
  54. NSString *isVip = minstr([vipInfo valueForKey:@"isvip"]);
  55. NSString *vipEndTime = [NSString stringWithFormat:@"%@%@",[vipInfo valueForKey:@"vip_endtime"],YZMsg(@"到期")];
  56. if ([isVip isEqual:@"1"]) {
  57. [YBPower saveCanTakeLongVideo:@"1"];
  58. _headerView.timeL.text = vipEndTime;
  59. [_headerView.buyVipBtn setTitle:YZMsg(@"续费VIP") forState:0];
  60. }else {
  61. _headerView.timeL.text = YZMsg(@"暂未开通会员");
  62. [_headerView.buyVipBtn setTitle:YZMsg(@"立即开通") forState:0];
  63. }
  64. _vipLimiteArray = [NSArray arrayWithArray:[_infoDic valueForKey:@"equity_lists"]];
  65. [_tableView reloadData];
  66. }else {
  67. [MBProgressHUD showPop:msg];
  68. }
  69. } Fail:^(id fail) {
  70. }];
  71. }
  72. #pragma mark - UITableViewDelegate、UITableViewDataSource
  73. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  74. return (_window_width*280/375 + 110);
  75. }
  76. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  77. return self.headerView;
  78. }
  79. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  80. return 0;
  81. }
  82. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  83. return nil;
  84. }
  85. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  86. if (![lagType isEqual:ZH_CN]) {
  87. return 70;
  88. }
  89. return 60;
  90. }
  91. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  92. return _vipLimiteArray.count;
  93. }
  94. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  95. YBVipCell *cell = [YBVipCell cellWithTab:tableView index:indexPath];
  96. NSDictionary *subDic = _vipLimiteArray[indexPath.row];
  97. [cell.flagIV sd_setImageWithURL:[NSURL URLWithString:minstr([subDic valueForKey:@"thumb"])]];
  98. cell.nameL.text = minstr([subDic valueForKey:@"title"]);
  99. cell.infoL.text = minstr([subDic valueForKey:@"des"]);
  100. return cell;
  101. }
  102. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  103. [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
  104. }
  105. #pragma mark - set/get
  106. -(UITableView *)tableView {
  107. if (!_tableView) {
  108. _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,0, _window_width, _window_height)style:UITableViewStyleGrouped];
  109. _tableView.delegate = self;
  110. _tableView.dataSource = self;
  111. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  112. _tableView.backgroundColor = [UIColor whiteColor];
  113. _tableView.bounces = NO;
  114. _tableView.contentInset = UIEdgeInsetsMake(0, 0, ShowDiff, 0);
  115. }
  116. return _tableView;
  117. }
  118. - (YBVipHeader *)headerView {
  119. if (!_headerView) {
  120. _headerView = [[[NSBundle mainBundle]loadNibNamed:@"YBVipHeader" owner:nil options:nil]objectAtIndex:0];
  121. _headerView.frame = CGRectMake(0, 0, _window_width, (_window_width*280/375 + 110));
  122. [_headerView setSubView];
  123. YBWeakSelf;
  124. _headerView.vipEvent = ^(NSString *eventStr) {
  125. //开通
  126. [weakSelf buyVipPop];
  127. };
  128. YBButton *youngBtn = [PublicObj youngAlertBtn];
  129. [_headerView addSubview:youngBtn];
  130. [youngBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  131. make.width.lessThanOrEqualTo(_headerView);
  132. make.centerX.equalTo(_headerView);
  133. make.top.equalTo(_headerView.buyVipBtn.mas_bottom).offset(8);
  134. }];
  135. }
  136. return _headerView;
  137. }
  138. #pragma mark - 购买
  139. -(void)buyVipPop {
  140. if (!buyView) {
  141. buyView = [[vipBuyView alloc]initWithMsg:_infoDic];
  142. [self.view addSubview:buyView];
  143. }
  144. YBWeakSelf;
  145. buyView.block = ^{
  146. [weakSelf pullData];
  147. };
  148. [buyView show];
  149. [self.view bringSubviewToFront:buyView];
  150. }
  151. @end