Açıklama Yok

FKVipBuyController.m 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. //
  2. // FKVipBuyController.m
  3. // FirstLink
  4. //
  5. // Created by ascii on 2017/5/17.
  6. // Copyright © 2017年 FirstLink. All rights reserved.
  7. //
  8. #import "FKVipBuyController.h"
  9. #import "FKVipBuyRequest.h"
  10. #import "FKVipBuyReform.h"
  11. #import "FKVipBuyViewModel.h"
  12. #import "FKVipBuyPriceCell.h"
  13. #import "FKVipPrivilegeDetailCell.h"
  14. #import "FKVipPayController.h"
  15. @interface FKVipBuyController ()
  16. <FLNetworkDelegate, UITableViewDelegate, UITableViewDataSource, FKVipPayDelegate, FKCardSegmentViewDelegate>
  17. @property (nonatomic, strong) FKCardSegmentView *cardSegmentView;
  18. @property (nonatomic, strong) UITableView *tableView;
  19. @property (nonatomic, strong) FKVipBuyViewModel *viewModel;
  20. @end
  21. @implementation FKVipBuyController
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. // Do any additional setup after loading the view.
  25. self.view.backgroundColor = UIColorFromRGB(0xf4f4f4);
  26. self.navigationItem.title = @"我的会员";
  27. [self setupViews];
  28. [self requestBuyRule];
  29. [self.cardSegmentView setCardSegmentIndex:self.segmentType];
  30. }
  31. - (void)didReceiveMemoryWarning {
  32. [super didReceiveMemoryWarning];
  33. // Dispose of any resources that can be recreated.
  34. }
  35. - (void)viewWillAppear:(BOOL)animated {
  36. [super viewWillAppear:animated];
  37. [self.navigationController setNavigationBarHidden:NO animated:YES];
  38. }
  39. /*
  40. #pragma mark - Navigation
  41. // In a storyboard-based application, you will often want to do a little preparation before navigation
  42. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  43. // Get the new view controller using [segue destinationViewController].
  44. // Pass the selected object to the new view controller.
  45. }
  46. */
  47. #pragma mark - Request
  48. - (void)requestBuyRule {
  49. [FKVipBuyRequest requestVipBuyRulesWithDelegate:self];
  50. }
  51. #pragma mark - Response
  52. - (void)networkDidReceiveError:(NSError*)error identify:(int)identify header:(MSGHeader*)header{
  53. [self.hudView hide:NO];
  54. [FLProgressHUDHelper showText:header.msg inView:self.view];
  55. }
  56. - (void)networkDidSuccessResponse:(NSDictionary*)response identify:(int)identify header:(MSGHeader*)header{
  57. [self.hudView hide:NO];
  58. if (header.code.intValue == RESPONSE_MSG_NORMAL) {
  59. if (identify == VIP_BUY_RULES_REQ) {
  60. self.viewModel.ruleItemArray = [FKVipBuyReform parserVIPPrice:response];
  61. [self.viewModel groupedRuleItem];
  62. [self.tableView reloadData];
  63. } else if (identify == VIP_BUY_ORDER) {
  64. FKVipPayController *controller = [[FKVipPayController alloc] init];
  65. controller.payItem = [FKVipBuyReform parserForPaymentItem:response];
  66. controller.delegate = self;
  67. [self.navigationController pushViewController:controller animated:YES];
  68. }
  69. } else {
  70. [FLProgressHUDHelper showText:header.msg inView:self.view];
  71. }
  72. }
  73. #pragma mark - UITableViewDelegate, UITableViewDataSource
  74. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  75. return 2;
  76. }
  77. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  78. if (section == 0) {
  79. if (self.segmentType == kCardSegmentIndexLeft) {
  80. return self.viewModel.vipRuleItemArray.count;
  81. } else {
  82. return self.viewModel.superVipRuleItemArray.count;
  83. }
  84. }
  85. return 1;
  86. }
  87. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  88. if (section == 0) {
  89. return 48;
  90. }
  91. return 10;
  92. }
  93. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  94. if (section == 0) {
  95. return self.cardSegmentView;
  96. }
  97. return nil;
  98. }
  99. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  100. if (indexPath.section == 0) {
  101. return 75;
  102. }
  103. return 350;
  104. }
  105. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  106. if (indexPath.section == 0) {
  107. FKVipBuyPriceCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKVipBuyPriceCell class])];
  108. [cell.actionBtn addTarget:self action:@selector(clickVipBuyActionBtn:) forControlEvents:UIControlEventTouchUpInside];
  109. cell.actionBtn.tag = indexPath.row;
  110. cell.horizonLine.hidden = (indexPath.row == 0);
  111. FKVipBuyRuleItem *item = nil;
  112. if (self.segmentType == kCardSegmentIndexLeft) {
  113. item = self.viewModel.vipRuleItemArray[indexPath.row];
  114. } else {
  115. item = self.viewModel.superVipRuleItemArray[indexPath.row];
  116. }
  117. if (item) {
  118. NSString *priceTip = item.title;
  119. NSString *price = item.price;
  120. if (priceTip.length > 0 && price.floatValue > 0) {
  121. NSString *string = [NSString stringWithFormat:@"%@: ¥%.2f", priceTip, price.floatValue/100.0];
  122. cell.priceLabel.text = string;
  123. }
  124. }
  125. return cell;
  126. } else {
  127. FKVipPrivilegeDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKVipPrivilegeDetailCell class])];
  128. if (self.segmentType == kCardSegmentIndexLeft) {
  129. [cell reloadData:self.viewModel.vipRuleItemArray];
  130. } else {
  131. [cell reloadData:self.viewModel.superVipRuleItemArray];
  132. }
  133. return cell;
  134. }
  135. }
  136. #pragma mark - FKCardSegmentViewDelegate
  137. - (void)cardSegmentView:(FKCardSegmentView *)view didSelectWithVipIndex:(kCardSegmentIndex)vip {
  138. self.segmentType = vip;
  139. [self.tableView reloadData];
  140. }
  141. #pragma mark - vipPayDelegate
  142. - (void)vipPaySuccess {
  143. [self.navigationController popToViewController:self animated:YES];
  144. }
  145. - (void)vipPayFail {
  146. [self.navigationController popToViewController:self animated:YES];
  147. [FLProgressHUDHelper showTipAlert:@"VIP购买失败"];
  148. }
  149. #pragma mark - Action
  150. - (IBAction)clickVipBuyActionBtn:(UIButton *)sender {
  151. FKVipBuyRuleItem *item = nil;
  152. if (self.segmentType == kCardSegmentIndexLeft) {
  153. item = self.viewModel.vipRuleItemArray[sender.tag];
  154. } else {
  155. item = self.viewModel.superVipRuleItemArray[sender.tag];
  156. }
  157. if (item) {
  158. [FKVipBuyRequest requestOrderWithBuyId:item.itemID.integerValue delegate:self];
  159. }
  160. }
  161. #pragma mark - Method
  162. - (void)setupViews {
  163. [self.view addSubview:self.tableView];
  164. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  165. make.left.top.right.bottom.equalTo(self.view);
  166. }];
  167. }
  168. #pragma mark - Property
  169. - (FKCardSegmentView *)cardSegmentView {
  170. if (!_cardSegmentView) {
  171. _cardSegmentView = [[FKCardSegmentView alloc] initWithFrame:CGRectMake(0, 0, UISCREENWIDTH, 48)];
  172. _cardSegmentView.delegate = self;
  173. }
  174. return _cardSegmentView;
  175. }
  176. - (UITableView *)tableView{
  177. if (_tableView == nil) {
  178. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  179. _tableView.dataSource = self;
  180. _tableView.delegate = self;
  181. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  182. _tableView.sectionFooterHeight = 0;
  183. _tableView.contentInset = UIEdgeInsetsMake(6, 0, 0, 0);
  184. [_tableView registerClass:[FKVipBuyPriceCell class] forCellReuseIdentifier:NSStringFromClass([FKVipBuyPriceCell class])];
  185. [_tableView registerClass:[FKVipPrivilegeDetailCell class] forCellReuseIdentifier:NSStringFromClass([FKVipPrivilegeDetailCell class])];
  186. if (@available(iOS 11.0, *)) {
  187. _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  188. }
  189. }
  190. return _tableView;
  191. }
  192. - (FKVipBuyViewModel *)viewModel {
  193. if (!_viewModel) {
  194. _viewModel = [FKVipBuyViewModel new];
  195. }
  196. return _viewModel;
  197. }
  198. @end