LoginViewController.m 11.6 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1 2 3 4 5 6 7 8 9 10 11
//
//  LoginViewController.m
//  Lighting
//
//  Created by 曹云霄 on 16/4/27.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "LoginViewController.h"
#import "CustomTabbarController.h"
#import "AppDelegate.h"
曹云霄's avatar
曹云霄 committed
12
#import "authenticateView.h"
zhu's avatar
zhu committed
13
#import "FollowHeartViewController.h"
14 15

@interface LoginViewController ()<RightVCselectedDelegate>
曹云霄's avatar
曹云霄 committed
16 17

@property (nonatomic,strong) MMDrawerController *drawerController;
18
@property (nonatomic,strong) CustomTabbarController *customtabbar;
zhu's avatar
zhu committed
19
@property (nonatomic,strong) FollowHeartViewController *followHeartView;
20

曹云霄's avatar
曹云霄 committed
21 22 23 24 25 26 27 28 29
/**
 *  验证身份View
 */
@property (nonatomic,strong) authenticateView *identityView;

/**
 *  重置密码View
 */
@property (nonatomic,strong) authenticateView *resetPasswordView;
30

曹云霄's avatar
曹云霄 committed
31 32 33 34 35
/**
 *  定时器
 */
@property (nonatomic,strong) NSTimer *sendTimer;

曹云霄's avatar
曹云霄 committed
36 37 38 39
@end

@implementation LoginViewController

40 41 42 43 44 45 46 47 48 49

- (CustomTabbarController *)customtabbar
{
    if (_customtabbar == nil) {
        
        _customtabbar = [[CustomTabbarController alloc]init];
    }
    return _customtabbar;
}

曹云霄's avatar
曹云霄 committed
50 51 52
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
53 54 55

    
    [self uiConfigAction];
曹云霄's avatar
曹云霄 committed
56 57 58 59
    
}


60 61 62 63 64 65 66 67 68 69 70 71
#pragma mark - 布局
- (void)uiConfigAction
{
    self.loginButton.layer.masksToBounds = YES;
    self.loginButton.layer.cornerRadius = kCornerRadius;
    self.userNameBackview.layer.masksToBounds = YES;
    self.userNameBackview.layer.cornerRadius = kCornerRadius;
    self.passWordBackview.layer.masksToBounds = YES;
    self.passWordBackview.layer.cornerRadius = kCornerRadius;
    self.userNameLoginView.layer.masksToBounds = YES;
    self.userNameLoginView.layer.cornerRadius = 10;
    self.forgotPasswordButton.titleLabel.font = [UIFont boldSystemFontOfSize:16];
zhu's avatar
zhu committed
72
    self.followHeartView=[[FollowHeartViewController alloc]init];
勾芒's avatar
勾芒 committed
73 74
    self.userName.text = @"demo1";
    self.passWord.text = @"123456";
曹云霄's avatar
曹云霄 committed
75
    
76 77 78 79 80
}


#pragma mark -登陆
- (IBAction)LoginButtonClick:(UIButton *)sender {
曹云霄's avatar
曹云霄 committed
81

勾芒's avatar
勾芒 committed
82

83
//    [self SetTheRootViewController];
曹云霄's avatar
曹云霄 committed
84
    
85 86 87 88 89 90 91 92 93 94
    if (self.userName.text.length == 0) {

        [self ErrorMBProgressView:@"用户名不能为空"];
        return;
        
    }else if (self.passWord.text.length == 0)
    {
        [self ErrorMBProgressView:@"密码不能为空"];
        return;
    }
曹云霄's avatar
曹云霄 committed
95
    
96
    [self judgeUserNameAndPassword];
曹云霄's avatar
曹云霄 committed
97 98
}

99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
#pragma mark -设置根视图控制器
- (void)SetTheRootViewController
{
        RightViewController *rightVC = [[RightViewController alloc]init];
        rightVC.delegate = self;
        self.drawerController = [[MMDrawerController alloc]initWithCenterViewController:self.customtabbar rightDrawerViewController:rightVC];
        [self.drawerController setMaximumRightDrawerWidth:RightWidth];
        [self.drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
        [self.drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
        SHARED_APPDELEGATE.mmdrawer = self.drawerController;
        SHARED_APPDELEGATE.window.rootViewController = self.drawerController;
}


#pragma mark -判断用户名密码是否正确
- (void)judgeUserNameAndPassword
{
    [self CreateMBProgressHUDLoding];
    NSString *URL = [NSString stringWithFormat:@"%@%@",ServerAddress,@"/employee/login"];
    LoginInfo *login = [[LoginInfo alloc]init];
    login.username = self.userName.text;
    login.password = self.passWord.text;
    
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:URL WithRequestType:0 WithParameter:login WithReturnValueBlock:^(id returnValue) {
        
        [self RemoveMBProgressHUDLoding];
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
曹云霄's avatar
曹云霄 committed
127 128 129 130 131
            //保持导购信息
            LoginResult *result = [[LoginResult alloc]initWithDictionary:returnValue[@"data"] error:nil];
            [Shoppersmanager manager].Shoppers = result;
            [Shoppersmanager manager].userNameString = self.userName.text;
            [Shoppersmanager manager].passWordString = self.passWord.text;
132 133
            
            [self SetTheRootViewController];
曹云霄's avatar
曹云霄 committed
134
            
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
            NSLog(@"成功");
        }else
        {
            [self ErrorMBProgressView:returnValue[@"message"]];
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
        NSLog(@"%@",errorCodeValue);
        
    } WithFailureBlock:^(id error) {
        
        [self RemoveMBProgressHUDLoding];
        
    }];
}



154
#pragma mark -RightVCselectedDelegate 方法
曹云霄's avatar
曹云霄 committed
155
- (void)SelectedControllerWithIndex:(NSString *)Name
156
{
zhu's avatar
zhu committed
157

158
    NSInteger selectedIndex;
曹云霄's avatar
曹云霄 committed
159
    if ([Name isEqualToString:@"体验中心"]) {
zhu's avatar
zhu committed
160 161
    [SHARED_APPDELEGATE.window.rootViewController.view addSubview:self.followHeartView.view];
//        selectedIndex = 6;
曹云霄's avatar
曹云霄 committed
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
        
    }else if ([Name isEqualToString:@"场景库"])
    {
       selectedIndex = 5;
    }else if ([Name isEqualToString:@"产品库"])
    {
        selectedIndex = 4;
    }else if ([Name isEqualToString:@"客户管理"])
    {
       selectedIndex = 3;
    }else if ([Name isEqualToString:@"所有客户"])
    {
        selectedIndex = 2;
    }else if ([Name isEqualToString:@"客户订单"])
    {
        selectedIndex = 1;
    }else if ([Name isEqualToString:@"关于"])
    {
        selectedIndex = 0;
181
    }
zhu's avatar
zhu committed
182 183

   self.customtabbar.selectedIndex = selectedIndex;
184 185 186 187
}



曹云霄's avatar
曹云霄 committed
188 189 190 191 192
#pragma mark -忘记密码
- (IBAction)ForgotpasswordButtonClick:(UIButton *)sender {
    
    
    self.identityView = [[[NSBundle mainBundle] loadNibNamed:@"authenticateView" owner:self options:nil]firstObject];
193 194 195 196 197 198 199 200 201 202
    
    //判断登陆界面是否已经输入了用户名
    if (self.userName.text.length != 0) {
        
        self.identityView.userName.text = self.userName.text;
    }
    
    
    self.identityView.layer.masksToBounds = YES;
    self.identityView.layer.cornerRadius = 10;
曹云霄's avatar
曹云霄 committed
203 204
    [self.identityView.backLoginButton addTarget:self action:@selector(BackloginButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [self.identityView.nextButton addTarget:self action:@selector(NextButtonClick) forControlEvents:UIControlEventTouchUpInside];
曹云霄's avatar
曹云霄 committed
205
    [self.identityView.SendButton addTarget:self action:@selector(SendButtonClick) forControlEvents:UIControlEventTouchUpInside];
曹云霄's avatar
曹云霄 committed
206 207 208 209 210 211 212 213 214 215
    self.identityView.alpha = 0;
    self.identityView.frame = self.userNameLoginView.frame;
    [self.view addSubview:self.identityView];
    [UIView animateWithDuration:0.2 animations:^{
        
        self.identityView.alpha = 1;
        
    }];
}

曹云霄's avatar
曹云霄 committed
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
#pragma mark -发送验证码
- (void)SendButtonClick
{
    NSString *inputPhoneNumber = self.identityView.bindingPhoneNumber.text;
    if (inputPhoneNumber.length == 0) {
        
        [self ErrorMBProgressView:@"手机号不能为空"];
        return;
    }
    if (![HENLENSONG isValidateMobile:inputPhoneNumber]) {
        
        [self ErrorMBProgressView:@"手机号码格式不正确"];
        return;
    }
    
    [self RemoveMBProgressHUDLoding];
    //发送验证码
    [[NetworkRequestClassManager Manager] NetworkWithDictionaryRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/system/sendSms"] WithRequestType:0 WithParameter:[NSDictionary dictionaryWithObjectsAndKeys:inputPhoneNumber,@"mobilephone", nil] WithReturnValueBlock:^(id returnValue) {
        
//        NSLog(@"%@",returnValue);
        [self RemoveMBProgressHUDLoding];
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
        
    } WithFailureBlock:^(id error) {
        
//        NSLog(@"%@",error);
        [self RemoveMBProgressHUDLoding];
        
    }];
    
    [self.identityView.SendButton setTitle:@"60" forState:UIControlStateNormal];
    self.identityView.SendButton.enabled = NO;
    self.sendTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(SendbuttonChangetitle) userInfo:nil repeats:YES];
}
曹云霄's avatar
曹云霄 committed
252

曹云霄's avatar
曹云霄 committed
253 254 255 256 257 258 259 260 261 262 263 264 265
#pragma mark -倒计时
- (void)SendbuttonChangetitle
{
    
    NSInteger number = [self.identityView.SendButton.currentTitle integerValue];
    if (number <= 0) {
        
        [self.identityView.SendButton setTitle:@"发送" forState:UIControlStateNormal];
        self.identityView.SendButton.enabled = YES;
        [self.sendTimer invalidate];
        return;
    }
    number --;
曹云霄's avatar
曹云霄 committed
266
    [self.identityView.SendButton setTitle:[NSString stringWithFormat:@"%ld",number] forState:UIControlStateNormal];
曹云霄's avatar
曹云霄 committed
267 268
    
}
曹云霄's avatar
曹云霄 committed
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290


#pragma mark -返回登陆界面
- (void)BackloginButtonClick
{
    
    [UIView animateWithDuration:0.2 animations:^{
        
        self.identityView.alpha = 0;
        
    }completion:^(BOOL finished) {
        
        [self.identityView removeFromSuperview];
        
    }];
}



#pragma mark -下一步(重置密码界面)
- (void)NextButtonClick
{
曹云霄's avatar
曹云霄 committed
291
    [self.sendTimer invalidate];
曹云霄's avatar
曹云霄 committed
292
    self.resetPasswordView = [[[NSBundle mainBundle] loadNibNamed:@"authenticateView" owner:self options:nil]lastObject];
293 294
    self.resetPasswordView.layer.masksToBounds = YES;
    self.resetPasswordView.layer.cornerRadius = 10;
曹云霄's avatar
曹云霄 committed
295 296
    self.resetPasswordView.frame = self.userNameLoginView.frame;
    [self.resetPasswordView.backValidationView addTarget:self action:@selector(backButonClick) forControlEvents:UIControlEventTouchUpInside];
297
    [self.resetPasswordView.resetPasswordNextButton addTarget:self action:@selector(ChangPassWordRequest) forControlEvents:UIControlEventTouchUpInside];
曹云霄's avatar
曹云霄 committed
298 299 300 301 302 303
    [self.view addSubview:self.resetPasswordView];
    self.resetPasswordView.alpha = 0;
    
    [UIView animateWithDuration:0.2 animations:^{
        
        self.resetPasswordView.alpha = 1;
304 305 306 307 308 309 310 311 312
    }];
}


#pragma mark -修改密码
- (void)ChangPassWordRequest
{
    
    if (self.resetPasswordView.newpass.text.length == 0) {
曹云霄's avatar
曹云霄 committed
313
        
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
        [self ErrorMBProgressView:@"新密码为空"];
        return;
        
    }else if (self.resetPasswordView.confirmNewpass.text.length == 0)
    {
        [self ErrorMBProgressView:@"确认密码为空"];
        return;
    }
    
    if (![self.resetPasswordView.newpass.text isEqualToString:self.resetPasswordView.confirmNewpass.text]) {
        
        [self ErrorMBProgressView:@"两次密码不相同"];
        return;
    }

曹云霄's avatar
曹云霄 committed
329
    [self CreateMBProgressHUDLoding];
330 331
    //重置密码接口
    ResetPasswordRequest *passwrod = [[ResetPasswordRequest alloc]init];
曹云霄's avatar
曹云霄 committed
332
    passwrod.fnewPassword = @"123456";
曹云霄's avatar
曹云霄 committed
333 334
    passwrod.username = @"sh1";
    passwrod.smsCode = @"1234";//验证码
335 336 337
    
    [[NetworkRequestClassManager Manager] NetworkRequestWithURL:[NSString stringWithFormat:@"%@%@",ServerAddress,@"/employee/resetPassword"] WithRequestType:0 WithParameter:passwrod WithReturnValueBlock:^(id returnValue) {
        
曹云霄's avatar
曹云霄 committed
338
        [self RemoveMBProgressHUDLoding];
339 340 341 342 343 344 345 346 347 348 349 350 351
        if ([returnValue[@"code"] isEqualToNumber:@0]) {
            
            [self ErrorMBProgressView:returnValue[@"message"]];
            
        }else
        {
           [self ErrorMBProgressView:returnValue[@"message"]];
        }
        
    } WithErrorCodeBlock:^(id errorCodeValue) {
        
    } WithFailureBlock:^(id error) {
        
曹云霄's avatar
曹云霄 committed
352 353
        [self RemoveMBProgressHUDLoding];
        
354 355
    }];
    
曹云霄's avatar
曹云霄 committed
356 357 358
}


359

曹云霄's avatar
曹云霄 committed
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
#pragma mark -返回验证信息界面
- (void)backButonClick
{
    [UIView animateWithDuration:0.2 animations:^{
        
        self.resetPasswordView.alpha = 0;
        
    } completion:^(BOOL finished) {
        
        [self.resetPasswordView removeFromSuperview];
    }];
}







曹云霄's avatar
曹云霄 committed
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#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