Няма описание

FKMyVipController.m 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. //
  2. // FKMyVipController.m
  3. // FirstLink
  4. //
  5. // Created by jack on 15/9/11.
  6. // Copyright (c) 2015年 FirstLink. All rights reserved.
  7. //
  8. #import "FKMyVipController.h"
  9. #import "FKVipStatusCell.h"
  10. #import "FKVipFeatureCell.h"
  11. #import "FKMyVipRequest.h"
  12. #import "FKVipBuyRequest.h"
  13. #import "FKVipBuyReform.h"
  14. #import "FKMyVipViewModel.h"
  15. #import "FKMyVipReform.h"
  16. #import "PindanDetailController.h"
  17. #import "WebViewController.h"
  18. #import "FKVipBuyController.h"
  19. @interface FKMyVipController () <UITableViewDataSource, UITableViewDelegate, FLNetworkDelegate>
  20. @property (nonatomic, strong) UITableView *tableView;
  21. @property (nonatomic, strong) FKMyVipViewModel *viewModel;
  22. @end
  23. @implementation FKMyVipController
  24. - (void)viewDidLoad{
  25. [super viewDidLoad];
  26. [self configerTableView];
  27. [self configRightNaviItem];
  28. [self addAllSubViews];
  29. [self requestInitalData];
  30. self.navigationItem.title = @"我的会员";
  31. }
  32. - (void)viewWillAppear:(BOOL)animated {
  33. [super viewWillAppear:animated];
  34. [self.navigationController setNavigationBarHidden:NO animated:YES];
  35. }
  36. - (void)viewDidAppear:(BOOL)animated {
  37. [super viewDidAppear:animated];
  38. }
  39. - (void)requestInitalData {
  40. [self.hudView show:YES];
  41. [FKMyVipRequest requestVipInfoWithDelegate:self];
  42. }
  43. - (void)addAllSubViews{
  44. [self.view addSubview:self.tableView];
  45. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.edges.insets(UIEdgeInsetsZero);
  47. }];
  48. }
  49. - (void)configRightNaviItem {
  50. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"开通攻略"
  51. style:UIBarButtonItemStylePlain
  52. target:self
  53. action:@selector(clickVIPStrageAction:)];
  54. }
  55. - (void)configerTableView{
  56. [self.tableView registerClass:[FKVipStatusCell class] forCellReuseIdentifier:NSStringFromClass([FKVipStatusCell class])];
  57. [self.tableView registerClass:[FKVipFeatureCell class] forCellReuseIdentifier:NSStringFromClass([FKVipFeatureCell class])];
  58. }
  59. #pragma mark - tableView dataSource
  60. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  61. if (!self.viewModel.infoItem) return 0;
  62. return 2;
  63. }
  64. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  65. if (section == 0) {
  66. return (1 + [self.viewModel.ruleItemArray count]);
  67. }
  68. return 1;
  69. }
  70. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  71. if (section == 0) {
  72. return CGFLOAT_MIN;
  73. }
  74. return 10.0f;
  75. }
  76. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  77. if (indexPath.section == 0) {
  78. if (indexPath.row == 0) {
  79. return [FKVipStatusCell height];
  80. }
  81. }
  82. if (indexPath.section == 1) return 362;
  83. return 0;
  84. }
  85. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  86. if (indexPath.section == 0) {
  87. FKVipStatusCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKVipStatusCell class])];
  88. [cell config:[self.viewModel.infoItem currentVipState] remainDays:[self.viewModel.infoItem getVipDays]];
  89. return cell;
  90. } else if (indexPath.section == 1){
  91. FKVipFeatureCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKVipFeatureCell class])];
  92. cell.viewModel = self.viewModel;
  93. [cell.buyButton addTarget:self action:@selector(clickBuyButton:) forControlEvents:UIControlEventTouchUpInside];
  94. return cell;
  95. }
  96. return nil;
  97. }
  98. #pragma mark - response
  99. - (void)networkDidReceiveError:(NSError*)error identify:(int)identify header:(MSGHeader*)header{
  100. [self.hudView hide:NO];
  101. [FLProgressHUDHelper showText:header.msg inView:self.view];
  102. }
  103. - (void)networkDidSuccessResponse:(NSDictionary*)response identify:(int)identify header:(MSGHeader*)header{
  104. [self.hudView hide:NO];
  105. if (header.code.intValue == RESPONSE_MSG_NORMAL) {
  106. if (identify == VIP_INFO_REQ) {
  107. self.viewModel.infoItem = [FKMyVipReform parserForInfoItem:response];
  108. [self.tableView reloadData];
  109. }
  110. } else {
  111. [FLProgressHUDHelper showText:header.msg inView:self.view];
  112. }
  113. }
  114. #pragma mark - Action
  115. - (IBAction)clickBuyButton:(UIButton*)sender {
  116. FKVipBuyController *controller = [[FKVipBuyController alloc] init];
  117. controller.hidesBottomBarWhenPushed = YES;
  118. if (sender.tag == 0) {
  119. controller.segmentType = kCardSegmentTypeVip;
  120. } else if (sender.tag == 1) {
  121. controller.segmentType = kCardSegmentTypeSuperVip;
  122. }
  123. [self.navigationController pushViewController:controller animated:YES];
  124. }
  125. - (IBAction)clickVIPStrageAction:(id)sender {
  126. NSString *urlString = [NSString stringWithFormat:@"%@/vip-guide/index.html?uploaded=true", [[FKServerUtil sharedInstance] webServer]];
  127. WebViewController *newViewController = [[WebViewController alloc] init];
  128. newViewController.url = urlString;
  129. newViewController.hidesBottomBarWhenPushed = YES;
  130. [self.navigationController pushViewController:newViewController animated:YES];
  131. }
  132. #pragma mark - property
  133. - (UITableView *)tableView{
  134. if (_tableView == nil) {
  135. _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  136. _tableView.dataSource = self;
  137. _tableView.delegate = self;
  138. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  139. _tableView.sectionFooterHeight = 0;
  140. _tableView.backgroundColor = UIColorFromRGB(0xf4f4f4);
  141. if (@available(iOS 11.0, *)) {
  142. _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  143. }
  144. }
  145. return _tableView;
  146. }
  147. - (FKMyVipViewModel *)viewModel{
  148. if (_viewModel == nil) {
  149. _viewModel = [[FKMyVipViewModel alloc]init];
  150. }
  151. return _viewModel;
  152. }
  153. @end