您的位置:首页 > 移动开发 > IOS开发

IOS - 会员中心页面和逻辑

2015-07-09 16:34 417 查看
会员中心界面:

根据VIP状态的不同, 显示不同内容, 并设置按钮跳转支付页面.

代码

//
//  MemberCenterViewController.h
//  SymptomChecker
//
//  Created by C.L.Wang on 15/7/9.
//
//

/**
* 会员中心页面, 根据VIP状态显示不同.
* @{link AutoLoginManager#queryUsableService}设置VIP状态
*/

#import "CYModelViewController.h"

@interface MATMemberCenterViewController : CYModelViewController

@end


//
//  MemberCenterViewController.m
//  SymptomChecker
//
//  Created by C.L.Wang on 15/7/9.
//
//

#import "MATMemberCenterViewController.h"

#import "VIPAlipayViewController.h" // 支付页面

#import "UserLoginViewController.h" // 登录页面

#define kViewRatio viewWidth()/320 // 宽度单位

@interface MATMemberCenterViewController ()

@end

@implementation MATMemberCenterViewController {
UIImageView *_memberStateIcon; // 会员状态图片
UILabel *_memberStateText; // 会员状态文字

UILabel *_serviceOfOwnership; // 拥有服务
UILabel *_noserviceOfOwnership; // 未拥有服务

UIView *_infiniteTimesItem; // 健康数据
UIView *_selfExaminationItem; // 自我检查
UIView *_healthDataItem; // 无线次数

FilledColorButton *_processButton; // 处理按钮

BOOL _needRefresh; // 是否刷新
}

// 初始化类
- (id) initWithNavigatorURL:(NSURL *)URL query:(NSDictionary *)query {
self = [super initWithNavigatorURL:URL query:query];
if (self) {
[self resetData];
}
return self;
}

// 重置数据
- (void) resetData {
_needRefresh = YES;
}

// 页面初始化
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"会员中心";
}

// 页面显示
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear: animated];

if (_needRefresh && [User hasLoggedIn]) {
_needRefresh = NO;

NSMutableDictionary* access = [[NSMutableDictionary alloc] init];
if ([[User currentUser] matIsVip] == 1) { // VIP
[access setObject:@"icon_mat_isvip" forKey:@"memberStateIcon"];
[access setObject:@"已开通会员包月服务" forKey:@"memberStateText"];
[access setObject:@1 forKey:@"noserviceOfOwnership"];
[access setObject:@"icon_mat_checked" forKey:@"infiniteTimesItem"];
[access setObject:@"立即续费" forKey:@"processButton"];
} else { // 非VIP
[access setObject:@"icon_mat_notvip" forKey:@"memberStateIcon"];
[access setObject:@"暂未开通会员优惠" forKey:@"memberStateText"];
[access setObject:@0 forKey:@"noserviceOfOwnership"];
[access setObject:@"icon_mat_notcheck" forKey:@"infiniteTimesItem"];
[access setObject:@"立即开通" forKey:@"processButton"];
}

[self createModelWithDict:access];
}
}

/**
*  创建界面, VIP不同页面不同
*
*  @param access 是否VIP
*/
- (void) createModelWithDict:(NSMutableDictionary*)access {

[self.view setBackgroundColor:[UIColor whiteColor]];

// 会员状态图标
_memberStateIcon = [CYResource loadImageView:access[@"memberStateIcon"]
andFrame:CGRectMake(viewWidth()/2-36*kViewRatio, 36*kViewRatio, 72*kViewRatio, 72*kViewRatio)];
[self.view addSubview:_memberStateIcon];

// 会员状态文字
_memberStateText = [UILabel labelWithFrame:CGRectMake(0, _memberStateIcon.bottom+8*kViewRatio, viewWidth(), 36*kViewRatio)
fontSize:20*kViewRatio
fontColor:[UIColor blackColor]
text:access[@"memberStateText"]];
[_memberStateText setAdjustsFontSizeToFitWidth:YES];
[_memberStateText setTextAlignment:NSTextAlignmentCenter];
[self.view addSubview:_memberStateText];

// 服务标题
_serviceOfOwnership = [UILabel labelWithFrame:CGRectMake(12*kViewRatio, _memberStateText.bottom, viewWidth(), 48*kViewRatio)
fontSize:18*kViewRatio
fontColor:[UIColor blackColor]
text:@"已享有服务"];
[_serviceOfOwnership setAdjustsFontSizeToFitWidth:YES];
[_serviceOfOwnership setTextAlignment:NSTextAlignmentLeft];
[self.view addSubview:_serviceOfOwnership];

// 健康工具项
_healthDataItem = [[UIView alloc] initWithFrame:CGRectMake(12*kViewRatio, _serviceOfOwnership.bottom, viewWidth(), 32*kViewRatio)];
[self.view addSubview:[self viewOfCombinationWithView:_healthDataItem image:@"icon_mat_checked" text:@"健康数据跟踪记录"]];

// 自我检查项
_selfExaminationItem = [[UIView alloc] initWithFrame:CGRectMake(12*kViewRatio, _healthDataItem.bottom, viewWidth(), 32*kViewRatio)];
[self.view addSubview:[self viewOfCombinationWithView:_selfExaminationItem image:@"icon_mat_checked" text:@"自我检查全面分析"]];

// 未服务标题
CGRect cr = CGRectMake(12*kViewRatio, _selfExaminationItem.bottom, viewWidth(), ([access[@"noserviceOfOwnership"] intValue]==0)?48*kViewRatio:0);
_noserviceOfOwnership = [UILabel labelWithFrame:cr
fontSize:18*kViewRatio
fontColor:[UIColor blackColor]
text:([access[@"noserviceOfOwnership"] intValue]==0)?@"开通可享有服务":@""];
[_noserviceOfOwnership setAdjustsFontSizeToFitWidth:YES];
[_noserviceOfOwnership setTextAlignment:NSTextAlignmentLeft];
[self.view addSubview:_noserviceOfOwnership];

// 无线次数项
_infiniteTimesItem = [[UIView alloc] initWithFrame:CGRectMake(12*kViewRatio, _noserviceOfOwnership.bottom, viewWidth(), 32*kViewRatio)];
[self.view addSubview:[self viewOfCombinationWithView:_infiniteTimesItem image:access[@"infiniteTimesItem"] text:@"在线问诊不限次数"]];

// 处理按钮
_processButton = [[FilledColorButton alloc] initWithFrame:CGRectMake(12*kViewRatio, _infiniteTimesItem.bottom, viewWidth()-24*kViewRatio, 40*kViewRatio)
type:kFilledBtnGreen
title:access[@"processButton"]];
[_processButton addTarget: self
action: @selector(onSubmitBtnPressedAfterLogin:)
forControlEvents: UIControlEventTouchUpInside];

[self.view addSubview:_processButton];
}

/**
*  左图片和右文字组合控件
*
*  @param view      父控件
*  @param imageName 图片本地路径
*  @param text      文字
*
*  @return 组合控件
*/
- (UIView*) viewOfCombinationWithView:(UIView*)view image:(NSString*)imageName text:(NSString*)text {

// 图片视图
UIImageView* iv = [CYResource loadImageView:imageName
andFrame:CGRectMake(0, 0, 16*kViewRatio, 16*kViewRatio)];
[iv setContentMode:UIViewContentModeScaleToFill];

// 文字视图
[view addSubview:iv];
UILabel* tv = [UILabel labelWithFrame:CGRectMake(32*kViewRatio, 0, viewWidth(), 16*kViewRatio)
fontSize:16*kViewRatio
fontColor:[UIColor grayColor]
text:text];
[view addSubview:tv];
return view;
}

// 按钮点击事件
- (void) onSubmitBtnPressedAfterLogin:(UIButton*) sender {
NIDPRINTMETHODNAME();
if (![User hasLoggedIn]) {
_needRefresh = YES;
UserLoginViewController *controller = [UserLoginViewController new];
[self cyPresentModalViewController:controller animated:YES];
} else {
NSDictionary *fakeData = @{@"source": @"vip",
@"problem_id": ENSURE_NOT_NULL(@"1234"),
@"ignore_tel": @(YES)};
VIPAlipayViewController* controller =
[[VIPAlipayViewController alloc]initWithNavigatorURL:nil
query:fakeData];
[self.navigationController pushViewController:controller animated:YES];
}
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end


会员中心页面



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息