//
|
// RegistPage.m
|
// GoldRich
|
//
|
// Created by WindShan on 2017/2/9.
|
// Copyright © 2017年 WindShan. All rights reserved.
|
//
|
|
#import "RegistPage.h"
|
#import "GloriaLabel.h"
|
#import "CommonReqModel.h"
|
#import "NetworkSingleton.h"
|
|
@interface RegistPage ()<UITextFieldDelegate>
|
{
|
UITextField * userPhoneTextField;
|
UITextField * checkCodeTextField;
|
UITextField * userNewPwdTextField;
|
|
GloriaLabel * getCheckCodeLabel;
|
UIButton * resetUserPwdBtn;
|
UIButton *sendBtn;
|
dispatch_source_t _timer;
|
}
|
|
@end
|
|
@implementation RegistPage
|
|
-(void)viewWillAppear:(BOOL)animated
|
{
|
[super viewWillAppear:YES];
|
|
self.navigationController.navigationBarHidden = YES;
|
|
}
|
-(void)viewWillDisappear:(BOOL)animated
|
{
|
[super viewWillDisappear:YES];
|
|
if (_timer) {
|
dispatch_source_cancel(_timer);
|
}
|
|
sendBtn.userInteractionEnabled = YES;
|
sendBtn.alpha = 1;
|
getCheckCodeLabel.text = @"获取验证码";
|
}
|
|
|
- (void)viewDidLoad {
|
[super viewDidLoad];
|
// Do any additional setup after loading the view.
|
|
//self.title = @"用户注册";
|
//[self setNavigationLeft:@"返回" sel:@selector(backAction)];
|
|
|
UIImageView * loginBk = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
|
loginBk.image = [UIImage imageNamed:@"login_bk"];
|
[self.view addSubview:loginBk];
|
|
// 初始化 pagecontrol
|
CGFloat logoHeight = 75;
|
CGFloat logoWidth = 105;
|
CGFloat tipsLabelHeight = NavBarHeight7+75+30;
|
CGFloat textFieldW = 292;
|
CGFloat textFieldH = 41;
|
|
if( IsiPhone4 || IsiPhone5)
|
{
|
logoWidth = 100;
|
logoHeight = 70;
|
tipsLabelHeight = NavBarHeight7+70+10;
|
textFieldH = 40;
|
}
|
|
|
UIImageView * logoPic = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-105)/2, NavBarHeight7, logoWidth, logoHeight)];
|
logoPic.image = [UIImage imageNamed:@"login_logo"];
|
[self.view addSubview:logoPic];
|
|
|
UIImageView * edit_bkimg = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-textFieldW)/2, SCREEN_HEIGHT/2-60, textFieldW, textFieldH)];
|
edit_bkimg.image = [UIImage imageNamed:@"edit_bk"];
|
[self.view addSubview:edit_bkimg];
|
|
UIImageView * edit_name_tagimg = [[UIImageView alloc] initWithFrame:CGRectMake(15, 10, 20, 20)];
|
edit_name_tagimg.image = [UIImage imageNamed:@"edit_tel_no_tag"];
|
[edit_bkimg addSubview:edit_name_tagimg];
|
|
userPhoneTextField = [[UITextField alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-textFieldW)/2+40, SCREEN_HEIGHT/2-60, textFieldW-40-100, textFieldH)];
|
userPhoneTextField.secureTextEntry = NO;
|
userPhoneTextField.placeholder = @"请输入手机号";
|
userPhoneTextField.font = [UIFont fontWithName:@"Arial" size:16];
|
userPhoneTextField.delegate = self;
|
[userPhoneTextField setValue:RgbColor(149, 149, 150) forKeyPath:@"_placeholderLabel.textColor"];
|
//userPhoneTextField.layer.borderColor = [RgbColor(213, 213, 213) CGColor];
|
userPhoneTextField.textColor = RgbColor(149, 149, 150);
|
|
userPhoneTextField.keyboardType = UIKeyboardTypeNumberPad;
|
userPhoneTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
|
// 设置一个空白blankView,15.0就是这块View的宽度width,也是光标的位置,根据你自己的需要设定大小
|
userPhoneTextField.leftView = [[UIView alloc] initWithFrame:CGRectMake(userPhoneTextField.frame.origin.x,userPhoneTextField.frame.origin.y,10.0, userPhoneTextField.frame.size.height)];
|
userPhoneTextField.leftViewMode =UITextFieldViewModeAlways;
|
[self.view addSubview:userPhoneTextField];
|
|
UIImageView * edit_bkimg2 = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-textFieldW)/2, SCREEN_HEIGHT/2, textFieldW, textFieldH)];
|
edit_bkimg2.image = [UIImage imageNamed:@"edit_bk"];
|
[self.view addSubview:edit_bkimg2];
|
|
UIImageView * edit_name_tagimg2 = [[UIImageView alloc] initWithFrame:CGRectMake(15, 11, 18, 18)];
|
edit_name_tagimg2.image = [UIImage imageNamed:@"edit_code_tag"];
|
[edit_bkimg2 addSubview:edit_name_tagimg2];
|
|
|
checkCodeTextField = [[UITextField alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-textFieldW)/2+40, SCREEN_HEIGHT/2, textFieldW-40, textFieldH)];
|
checkCodeTextField.secureTextEntry = NO;
|
checkCodeTextField.placeholder = @"请输入验证码";
|
checkCodeTextField.font = [UIFont fontWithName:@"Arial" size:16];
|
checkCodeTextField.delegate = self;
|
[checkCodeTextField setValue:RgbColor(149, 149, 150) forKeyPath:@"_placeholderLabel.textColor"];
|
//userPhoneTextField.layer.borderColor = [RgbColor(213, 213, 213) CGColor];
|
checkCodeTextField.textColor = RgbColor(149, 149, 150);
|
checkCodeTextField.keyboardType = UIKeyboardTypeNumberPad;
|
checkCodeTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
|
// 设置一个空白blankView,15.0就是这块View的宽度width,也是光标的位置,根据你自己的需要设定大小
|
checkCodeTextField.leftView = [[UIView alloc] initWithFrame:CGRectMake(checkCodeTextField.frame.origin.x,checkCodeTextField.frame.origin.y,10.0, checkCodeTextField.frame.size.height)];
|
checkCodeTextField.leftViewMode =UITextFieldViewModeAlways;
|
[self.view addSubview:checkCodeTextField];
|
|
UIImageView * edit_bkimg3 = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-textFieldW)/2, SCREEN_HEIGHT/2+60, textFieldW, textFieldH)];
|
edit_bkimg3.image = [UIImage imageNamed:@"edit_bk"];
|
[self.view addSubview:edit_bkimg3];
|
|
UIImageView * edit_name_tagimg3 = [[UIImageView alloc] initWithFrame:CGRectMake(15, 11, 18, 18)];
|
edit_name_tagimg3.image = [UIImage imageNamed:@"edit_pwd_tag"];
|
[edit_bkimg3 addSubview:edit_name_tagimg3];
|
|
|
userNewPwdTextField = [[UITextField alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-textFieldW)/2+40, SCREEN_HEIGHT/2+60, textFieldW, textFieldH)];
|
userNewPwdTextField.secureTextEntry = YES;
|
userNewPwdTextField.placeholder = @"请输入密码";
|
userNewPwdTextField.font = [UIFont fontWithName:@"Arial" size:16];
|
userNewPwdTextField.delegate = self;
|
[userNewPwdTextField setValue:RgbColor(149, 149, 150) forKeyPath:@"_placeholderLabel.textColor"];
|
//userPhoneTextField.layer.borderColor = [RgbColor(213, 213, 213) CGColor];
|
userNewPwdTextField.textColor = RgbColor(149, 149, 150);
|
userNewPwdTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
|
// 设置一个空白blankView,15.0就是这块View的宽度width,也是光标的位置,根据你自己的需要设定大小
|
userNewPwdTextField.leftView = [[UIView alloc] initWithFrame:CGRectMake(userNewPwdTextField.frame.origin.x,userNewPwdTextField.frame.origin.y,10.0, userNewPwdTextField.frame.size.height)];
|
userNewPwdTextField.leftViewMode =UITextFieldViewModeAlways;
|
[self.view addSubview:userNewPwdTextField];
|
|
sendBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
|
sendBtn.frame = CGRectMake((SCREEN_WIDTH-textFieldW)/2+40+textFieldW-40-100+2,SCREEN_HEIGHT/2-50,80, textFieldH/2);
|
[sendBtn setTitleColor:BLACKTEXTCOLOR_SUB forState:UIControlStateNormal];
|
sendBtn.userInteractionEnabled = NO;
|
sendBtn.layer.masksToBounds = YES;
|
sendBtn.layer.cornerRadius = 4.0f;
|
sendBtn.layer.borderWidth= 1.0f;
|
sendBtn.backgroundColor = RgbColor(251, 50, 81);
|
[sendBtn addTarget:self action:@selector(getCheckCodeAction) forControlEvents:UIControlEventTouchUpInside];
|
[self.view addSubview:sendBtn];
|
|
getCheckCodeLabel = [[GloriaLabel alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-textFieldW)/2+40+textFieldW-40-100+2, SCREEN_HEIGHT/2-50, 80, textFieldH/2)];
|
getCheckCodeLabel.font = FONT12;
|
getCheckCodeLabel.backgroundColor = kUIColorFromRGB(0x00a2ff);
|
getCheckCodeLabel.textColor = [UIColor whiteColor];
|
getCheckCodeLabel.textAlignment = NSTextAlignmentCenter;
|
getCheckCodeLabel.layer.borderColor = [RgbColor(251, 50, 81) CGColor];
|
getCheckCodeLabel.layer.masksToBounds=YES;
|
getCheckCodeLabel.layer.cornerRadius=4.0f;
|
getCheckCodeLabel.text = @"获取验证码";
|
[self.view addSubview:getCheckCodeLabel];
|
|
resetUserPwdBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
resetUserPwdBtn.frame = CGRectMake((SCREEN_WIDTH-textFieldW)/2, SCREEN_HEIGHT/2+120, textFieldW, textFieldH);
|
[resetUserPwdBtn setTitle:@"注 册" forState:UIControlStateNormal];
|
[resetUserPwdBtn setBackgroundImage:[UIImage imageNamed:@"login_btn_bk" ] forState:UIControlStateNormal];
|
//esetUserPwdBtn.backgroundColor = RgbColor(85, 81, 168);
|
resetUserPwdBtn.titleLabel.font = [UIFont systemFontOfSize: 18.0];
|
[resetUserPwdBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
resetUserPwdBtn.layer.masksToBounds = YES;
|
resetUserPwdBtn.layer.cornerRadius = 5.0f;
|
//resetUserPwdBtn.userInteractionEnabled = NO;
|
[resetUserPwdBtn addTarget:self action:@selector(registAction) forControlEvents:UIControlEventTouchUpInside];
|
[self.view addSubview:resetUserPwdBtn];
|
|
UIButton * backLoginBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
|
backLoginBtn.frame = CGRectMake((SCREEN_WIDTH-200)/2, SCREEN_HEIGHT/2+225, 200, 40);
|
[backLoginBtn setTitle:@"已有账号,返回登录" forState:UIControlStateNormal];
|
backLoginBtn.titleLabel.font = [UIFont systemFontOfSize: 16.0];
|
[backLoginBtn setTitleColor:kUIColorFromRGB(0x00a2ff) forState:UIControlStateNormal];
|
[backLoginBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
|
[self.view addSubview:backLoginBtn];
|
|
}
|
|
// 85 81 168
|
|
#pragma mark custom function begin
|
////倒计时提醒
|
-(void)startCountDown
|
{
|
__block int timeout = 59; //倒计时时间
|
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
|
// dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
|
_timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
|
dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
|
dispatch_source_set_event_handler(_timer, ^{
|
if(timeout<=0){ //倒计时结束,关闭
|
dispatch_source_cancel(_timer);
|
dispatch_async(dispatch_get_main_queue(), ^{
|
//设置界面的按钮显示 根据自己需求设置
|
sendBtn.userInteractionEnabled=YES;
|
sendBtn.alpha=1;
|
|
//[sendBtn setTitle:@"重新获取验证码" forState:UIControlStateNormal];
|
getCheckCodeLabel.text = @"重新获取";
|
|
});
|
}
|
else
|
{
|
// int minutes = timeout / 60;
|
int seconds = timeout % 60;
|
NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
//设置界面的按钮显示 根据自己需求设置
|
LOG_INFO(@"____%@",strTime);
|
sendBtn.userInteractionEnabled=NO;
|
sendBtn.alpha=0.4;
|
//[sendBtn setTitle:[NSString stringWithFormat:@"%@s",strTime] forState:UIControlStateNormal];
|
getCheckCodeLabel.text = [NSString stringWithFormat:@"%@秒",strTime];
|
});
|
|
timeout--;
|
|
}
|
});
|
dispatch_resume(_timer);
|
|
}
|
|
|
-(void)backAction
|
{
|
[self.navigationController popViewControllerAnimated:YES];
|
}
|
|
-(void)registAction
|
{
|
// 重置密码操作
|
if(userPhoneTextField.text.length == 0)
|
{
|
[Global alertMessageEx:@"请输入手机号." title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self];
|
}
|
else if(checkCodeTextField.text.length == 0)
|
{
|
[Global alertMessageEx:@"请输入验证码." title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self];
|
}
|
else if(userNewPwdTextField.text.length == 0)
|
{
|
[Global alertMessageEx:@"请输入新密码." title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self];
|
}
|
else
|
{
|
|
NSString *path = [[NSString alloc] initWithFormat:USER_REGISTER];
|
|
CommonReqModel * model = [[CommonReqModel alloc] init];
|
|
model.phone = userPhoneTextField.text;
|
model.password = userNewPwdTextField.text;
|
model.code = checkCodeTextField.text;
|
|
MPWeakSelf(self);
|
[NetworkSingleton networkingGetMethod:model.toDic urlName:path success:^(id responseBody)
|
{
|
MPStrongSelf(self);
|
BaseResModel * resModel = [Global toBaseModel:responseBody];
|
if(resModel.code == 0)
|
{
|
[Global alertMessageEx:@"恭喜你,账号注册成功!" title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self];
|
[weakself.navigationController popViewControllerAnimated:YES];
|
}
|
else
|
{
|
[Global alertMessageEx:resModel.desc title:@"注册失败" okTtitle:nil cancelTitle:@"OK" delegate:self];
|
}
|
}
|
failure:^(NSString *error)
|
{
|
[Global alertMessageEx:error title:@"注册失败" okTtitle:nil cancelTitle:@"OK" delegate:self];
|
}];
|
}
|
}
|
|
//获取验证码
|
-(void)getCheckCodeAction
|
{
|
NSString *path = [[NSString alloc] initWithFormat:SEND_REGISTER_SMS];
|
|
CommonReqModel * model = [[CommonReqModel alloc] init];
|
model.phone = userPhoneTextField.text;
|
model.type = @"register";
|
|
//NSMutableDictionary *param = [[NSMutableDictionary alloc] init];
|
//[param setObject:userPhoneTextField.text forKey:@"phone"];
|
|
MPWeakSelf(self);
|
[NetworkSingleton networkingGetMethod:model.toDic urlName:path success:^(id responseBody)
|
{
|
BaseResModel * resModel = [Global toBaseModel:responseBody];
|
|
if(resModel.code == 0)
|
{
|
//发送成功提示
|
[Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self];
|
MPStrongSelf(self);
|
[self startCountDown];
|
}
|
else
|
{
|
[Global alertMessageEx:resModel.desc title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self];
|
}
|
}
|
failure:^(NSString *error)
|
{
|
LOG_INFO(@"获取验证码失败:%@",error);
|
[Global alertMessageEx:error title:@"验证码获取失败" okTtitle:nil cancelTitle:@"OK" delegate:self];
|
}];
|
|
}
|
|
# pragma mark custom function end
|
|
|
#pragma mark disappear keyboard begin
|
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
|
{
|
int textLength = 0;
|
|
if ([string isEqualToString:@""]) {
|
textLength = textField.text.length-1;
|
}else
|
{
|
textLength = textField.text.length+1;
|
}
|
|
BOOL flag = NO;
|
if( textField == userPhoneTextField )
|
{
|
// 大于11位数不让输入
|
if( textLength > 11 )
|
return NO;
|
|
// 检测手机号是否合法
|
if( textLength == 11 && [StringUtil isMobile:[userPhoneTextField.text stringByAppendingString:string]] == NO)
|
{
|
[Global alertMessage:@"手机号码不合法,请重新输入!"];
|
}
|
else if( textLength == 11 && [StringUtil isMobile:[userPhoneTextField.text stringByAppendingString:string]] == YES)
|
{
|
getCheckCodeLabel.textColor = [UIColor whiteColor];
|
getCheckCodeLabel.backgroundColor = RgbColor(251, 50, 81);
|
sendBtn.userInteractionEnabled = YES;
|
}
|
else
|
{
|
getCheckCodeLabel.backgroundColor = kUIColorFromRGB(0x00a2ff);
|
getCheckCodeLabel.textColor = [UIColor whiteColor];
|
sendBtn.userInteractionEnabled = NO;
|
}
|
}
|
|
flag = YES;
|
|
return true;
|
}
|
|
- (void)didReceiveMemoryWarning {
|
[super didReceiveMemoryWarning];
|
// Dispose of any resources that can be recreated.
|
}
|
|
-(void)textFieldDidEndEditing:(UITextField *)textField
|
{
|
// if (verifyTextField.text.length > 0 && phoneTextField.text.length == 11 ) {
|
// //高亮登录
|
// quickBtn.backgroundColor = NAVIGATIONTINTCOLOR;
|
// quickBtn.userInteractionEnabled = YES;
|
// }else
|
// {
|
// quickBtn.backgroundColor = BLACKTEXTCOLOR_SUB;
|
// [quickBtn setBackgroundImage:nil forState:UIControlStateNormal];
|
// quickBtn.userInteractionEnabled = NO;
|
// }
|
}
|
|
-(BOOL)textFieldShouldReturn:(UITextField *)textField
|
{
|
if ([textField isFirstResponder]) {
|
[textField resignFirstResponder];
|
}
|
return true;
|
}
|
|
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
|
{
|
[self textFieldShouldReturn:checkCodeTextField];
|
[self textFieldShouldReturn:userPhoneTextField];
|
[self textFieldShouldReturn:userNewPwdTextField];
|
}
|
/*
|
#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.
|
}
|
*/
|
|
@end
|