123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- //
- // FKMyVipController.m
- // FirstLink
- //
- // Created by jack on 15/9/11.
- // Copyright (c) 2015年 FirstLink. All rights reserved.
- //
- #import "FKMyVipController.h"
- #import "FKVipStatusCell.h"
- #import "FKVipFeatureCell.h"
- #import "FKMyVipRequest.h"
- #import "FKVipBuyRequest.h"
- #import "FKVipBuyReform.h"
- #import "FKMyVipViewModel.h"
- #import "FKMyVipReform.h"
- #import "PindanDetailController.h"
- #import "WebViewController.h"
- #import "FKVipBuyController.h"
- @interface FKMyVipController () <UITableViewDataSource, UITableViewDelegate, FLNetworkDelegate>
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, strong) FKMyVipViewModel *viewModel;
- @end
- @implementation FKMyVipController
- - (void)viewDidLoad{
- [super viewDidLoad];
- [self configerTableView];
- [self configRightNaviItem];
- [self addAllSubViews];
-
- [self requestInitalData];
-
- self.navigationItem.title = @"我的会员";
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [self.navigationController setNavigationBarHidden:NO animated:YES];
- }
- - (void)viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
- }
- - (void)requestInitalData {
- [self.hudView show:YES];
- [FKMyVipRequest requestVipInfoWithDelegate:self];
- }
- - (void)addAllSubViews{
- [self.view addSubview:self.tableView];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.insets(UIEdgeInsetsZero);
- }];
- }
- - (void)configRightNaviItem {
- self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"开通攻略"
- style:UIBarButtonItemStylePlain
- target:self
- action:@selector(clickVIPStrageAction:)];
- }
- - (void)configerTableView{
- [self.tableView registerClass:[FKVipStatusCell class] forCellReuseIdentifier:NSStringFromClass([FKVipStatusCell class])];
- [self.tableView registerClass:[FKVipFeatureCell class] forCellReuseIdentifier:NSStringFromClass([FKVipFeatureCell class])];
- }
- #pragma mark - tableView dataSource
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- if (!self.viewModel.infoItem) return 0;
- return 2;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- if (section == 0) {
- return (1 + [self.viewModel.ruleItemArray count]);
- }
- return 1;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
- if (section == 0) {
- return CGFLOAT_MIN;
- }
- return 10.0f;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- if (indexPath.section == 0) {
- if (indexPath.row == 0) {
- return [FKVipStatusCell height];
- }
- }
- if (indexPath.section == 1) return 362;
- return 0;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- if (indexPath.section == 0) {
- FKVipStatusCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKVipStatusCell class])];
- [cell config:[self.viewModel.infoItem currentVipState] remainDays:[self.viewModel.infoItem getVipDays]];
- return cell;
- } else if (indexPath.section == 1){
- FKVipFeatureCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([FKVipFeatureCell class])];
- cell.viewModel = self.viewModel;
- [cell.buyButton addTarget:self action:@selector(clickBuyButton:) forControlEvents:UIControlEventTouchUpInside];
- return cell;
- }
- return nil;
- }
- #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_INFO_REQ) {
- self.viewModel.infoItem = [FKMyVipReform parserForInfoItem:response];
- [self.tableView reloadData];
- }
- } else {
- [FLProgressHUDHelper showText:header.msg inView:self.view];
- }
- }
- #pragma mark - Action
- - (IBAction)clickBuyButton:(UIButton*)sender {
- FKVipBuyController *controller = [[FKVipBuyController alloc] init];
- controller.hidesBottomBarWhenPushed = YES;
- if (sender.tag == 0) {
- controller.segmentType = kCardSegmentTypeVip;
- } else if (sender.tag == 1) {
- controller.segmentType = kCardSegmentTypeSuperVip;
- }
- [self.navigationController pushViewController:controller animated:YES];
- }
- - (IBAction)clickVIPStrageAction:(id)sender {
- NSString *urlString = [NSString stringWithFormat:@"%@/vip-guide/index.html?uploaded=true", [[FKServerUtil sharedInstance] webServer]];
-
- WebViewController *newViewController = [[WebViewController alloc] init];
- newViewController.url = urlString;
- newViewController.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:newViewController animated:YES];
- }
- #pragma mark - property
- - (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.backgroundColor = UIColorFromRGB(0xf4f4f4);
-
- if (@available(iOS 11.0, *)) {
- _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- }
- }
- return _tableView;
- }
- - (FKMyVipViewModel *)viewModel{
- if (_viewModel == nil) {
- _viewModel = [[FKMyVipViewModel alloc]init];
- }
- return _viewModel;
- }
- @end
|