123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- //
- // FKVipBuyController.m
- // FirstLink
- //
- // Created by ascii on 2017/5/17.
- // Copyright © 2017年 FirstLink. All rights reserved.
- //
- #import "FKVipBuyController.h"
- #import "FKVipBuyRequest.h"
- #import "FKVipBuyReform.h"
- #import "FKVipBuyViewModel.h"
- #import "FKVipBuyPriceCell.h"
- #import "FKVipPrivilegeDetailCell.h"
- #import "FKVipPayController.h"
- @interface FKVipBuyController ()
- <FLNetworkDelegate, UITableViewDelegate, UITableViewDataSource, FKVipPayDelegate, FKCardSegmentViewDelegate>
- @property (nonatomic, strong) FKCardSegmentView *cardSegmentView;
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, strong) FKVipBuyViewModel *viewModel;
- @end
- @implementation FKVipBuyController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- self.view.backgroundColor = UIColorFromRGB(0xf4f4f4);
- self.navigationItem.title = @"我的会员";
-
- [self setupViews];
- [self requestBuyRule];
-
- [self.cardSegmentView setCardSegmentIndex:self.segmentType];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
-
- [self.navigationController setNavigationBarHidden:NO animated:YES];
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- #pragma mark - Request
- - (void)requestBuyRule {
- [FKVipBuyRequest requestVipBuyRulesWithDelegate:self];
- }
- #pragma mark - Response
- - (void)networkDidReceiveError:(NSError*)error identify:(int)identify header:(MSGHeader*)header{
- [self.hudView hide:NO];
- [FLProgressHUDHelper showText:header.msg inView:self.view];
- }
- - (void)networkDidSuccessResponse:(NSDictionary*)response identify:(int)identify header:(MSGHeader*)header{
- [self.hudView hide:NO];
-
- if (header.code.intValue == RESPONSE_MSG_NORMAL) {
- if (identify == VIP_BUY_RULES_REQ) {
- self.viewModel.ruleItemArray = [FKVipBuyReform parserVIPPrice:response];
- [self.viewModel groupedRuleItem];
- [self.tableView reloadData];
- } else if (identify == VIP_BUY_ORDER) {
- FKVipPayController *controller = [[FKVipPayController alloc] init];
- controller.payItem = [FKVipBuyReform parserForPaymentItem:response];
- controller.delegate = self;
- [self.navigationController pushViewController:controller animated:YES];
- }
- } else {
- [FLProgressHUDHelper showText:header.msg inView:self.view];
- }
- }
- #pragma mark - UITableViewDelegate, UITableViewDataSource
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 2;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- if (section == 0) {
- if (self.segmentType == kCardSegmentIndexLeft) {
- return self.viewModel.vipRuleItemArray.count;
- } else {
- return self.viewModel.superVipRuleItemArray.count;
- }
- }
- return 1;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- if (section == 0) {
- return 48;
- }
- return 10;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- if (section == 0) {
- return self.cardSegmentView;
- }
- return nil;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.section == 0) {
- return 75;
- }
- return 350;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.section == 0) {
- FKVipBuyPriceCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKVipBuyPriceCell class])];
- [cell.actionBtn addTarget:self action:@selector(clickVipBuyActionBtn:) forControlEvents:UIControlEventTouchUpInside];
- cell.actionBtn.tag = indexPath.row;
- cell.horizonLine.hidden = (indexPath.row == 0);
-
- FKVipBuyRuleItem *item = nil;
- if (self.segmentType == kCardSegmentIndexLeft) {
- item = self.viewModel.vipRuleItemArray[indexPath.row];
- } else {
- item = self.viewModel.superVipRuleItemArray[indexPath.row];
- }
-
- if (item) {
- NSString *priceTip = item.title;
- NSString *price = item.price;
- if (priceTip.length > 0 && price.floatValue > 0) {
- NSString *string = [NSString stringWithFormat:@"%@: ¥%.2f", priceTip, price.floatValue/100.0];
- cell.priceLabel.text = string;
- }
- }
-
- return cell;
- } else {
- FKVipPrivilegeDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKVipPrivilegeDetailCell class])];
- if (self.segmentType == kCardSegmentIndexLeft) {
- [cell reloadData:self.viewModel.vipRuleItemArray];
- } else {
- [cell reloadData:self.viewModel.superVipRuleItemArray];
- }
- return cell;
- }
- }
- #pragma mark - FKCardSegmentViewDelegate
- - (void)cardSegmentView:(FKCardSegmentView *)view didSelectWithVipIndex:(kCardSegmentIndex)vip {
- self.segmentType = vip;
- [self.tableView reloadData];
- }
- #pragma mark - vipPayDelegate
- - (void)vipPaySuccess {
- [self.navigationController popToViewController:self animated:YES];
- }
- - (void)vipPayFail {
- [self.navigationController popToViewController:self animated:YES];
-
- [FLProgressHUDHelper showTipAlert:@"VIP购买失败"];
- }
- #pragma mark - Action
- - (IBAction)clickVipBuyActionBtn:(UIButton *)sender {
- FKVipBuyRuleItem *item = nil;
- if (self.segmentType == kCardSegmentIndexLeft) {
- item = self.viewModel.vipRuleItemArray[sender.tag];
- } else {
- item = self.viewModel.superVipRuleItemArray[sender.tag];
- }
- if (item) {
- [FKVipBuyRequest requestOrderWithBuyId:item.itemID.integerValue delegate:self];
- }
- }
- #pragma mark - Method
- - (void)setupViews {
- [self.view addSubview:self.tableView];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.top.right.bottom.equalTo(self.view);
- }];
- }
- #pragma mark - Property
- - (FKCardSegmentView *)cardSegmentView {
- if (!_cardSegmentView) {
- _cardSegmentView = [[FKCardSegmentView alloc] initWithFrame:CGRectMake(0, 0, UISCREENWIDTH, 48)];
- _cardSegmentView.delegate = self;
- }
- return _cardSegmentView;
- }
- - (UITableView *)tableView{
- if (_tableView == nil) {
- _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
- _tableView.dataSource = self;
- _tableView.delegate = self;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.sectionFooterHeight = 0;
- _tableView.contentInset = UIEdgeInsetsMake(6, 0, 0, 0);
- [_tableView registerClass:[FKVipBuyPriceCell class] forCellReuseIdentifier:NSStringFromClass([FKVipBuyPriceCell class])];
- [_tableView registerClass:[FKVipPrivilegeDetailCell class] forCellReuseIdentifier:NSStringFromClass([FKVipPrivilegeDetailCell class])];
-
- if (@available(iOS 11.0, *)) {
- _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- }
- }
- return _tableView;
- }
- - (FKVipBuyViewModel *)viewModel {
- if (!_viewModel) {
- _viewModel = [FKVipBuyViewModel new];
- }
- return _viewModel;
- }
- @end
|