单军华
2018-07-12 3e8437ae559487362fae3525beb79c534c213a51
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
//
//  LoginViewController.m
//  screendisplay
//
//  Created by 单军华 on 2018/7/3.
//  Copyright © 2018年 单军华. All rights reserved.
//
 
#import "LoginViewController.h"
#import "LoginSevice.h"
#import "CommonReqModel.h"
#import "LMJTabBarController.h"
#import "MonitoringMapViewController.h"
 
@interface LoginViewController ()
{
    UIButton * nomalLoginBtn;
    
    UITextField * userPhoneTextField;
    UITextField * userPwdTextFeild;
    
    //UIButton * forgetBtn;
}
 
/** digest */
@property (nonatomic, strong) LoginSevice *loginSevice;
 
 
@end
 
@implementation LoginViewController
 
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setUIView];
}
 
-(void)setUIView
{
    UIImageView * loginBk = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    loginBk.image = [UIImage imageNamed:@"login_background"];
    [self.view addSubview:loginBk];
    
    
    UIImageView * logoPic = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-AdaptedWidth(335))/2, NavBar_Height+AdaptedHeight(27), AdaptedWidth(335), AdaptedHeight(149))];
    logoPic.image = [UIImage imageNamed:@"login_app_logo"];
    [self.view addSubview:logoPic];
    
    UIImageView * edit_bkimg = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-AdaptedWidth(304))/2, NavBar_Height+AdaptedHeight(27+149+33), AdaptedWidth(304), AdaptedHeight(50))];
    edit_bkimg.image = [UIImage imageNamed:@"login_account_pwd_bk"];
    [self.view addSubview:edit_bkimg];
    
    userPhoneTextField = [[UITextField alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-AdaptedWidth(304))/2+AdaptedWidth(40), NavBar_Height+AdaptedHeight(27+149+33), AdaptedWidth(304-40), AdaptedHeight(50))];
    userPhoneTextField.font = [UIFont fontWithName:@"Arial" size:16];
    userPhoneTextField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入用户名"attributes:@{ NSForegroundColorAttributeName:kUIColorFromRGB(0x00b744)}];
    userPhoneTextField.delegate = self;
    [userPhoneTextField setValue:RgbColor(255, 255, 255) forKeyPath:@"_placeholderLabel.textColor"];
    //userPhoneTextField.layer.borderColor = [RgbColor(213, 213, 213) CGColor];
    userPhoneTextField.textColor = RgbColor(255, 255, 255);
    userPhoneTextField.keyboardType = UIKeyboardTypeDefault;
    userPhoneTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    // 设置一个空白blankView,15.0就是这块View的宽度width,也是光标的位置,根据你自己的需要设定大小
    UIView *blankView = [[UIView alloc] initWithFrame:CGRectMake(userPhoneTextField.frame.origin.x,userPhoneTextField.frame.origin.y,10.0, userPhoneTextField.frame.size.height)];
    
    userPhoneTextField.leftView = blankView;
    userPhoneTextField.leftViewMode =UITextFieldViewModeAlways;
    [self.view addSubview:userPhoneTextField];
    
    UIImageView * edit_bkimg2 = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-AdaptedWidth(304))/2, NavBar_Height+AdaptedHeight(27+149+33+50+33), AdaptedWidth(304), AdaptedHeight(50))];
    edit_bkimg2.image = [UIImage imageNamed:@"login_account_pwd_bk"];
    [self.view addSubview:edit_bkimg2];
    
    
    userPwdTextFeild = [[UITextField alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-AdaptedWidth(304))/2+AdaptedWidth(40), NavBar_Height+AdaptedHeight(27+149+33+50+33), AdaptedWidth(304-40), AdaptedHeight(50))];
    userPwdTextFeild.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入密码"attributes:@{ NSForegroundColorAttributeName:kUIColorFromRGB(0x00b744)}];
    userPwdTextFeild.secureTextEntry = YES;
    userPwdTextFeild.font = [UIFont fontWithName:@"Arial" size:16];
    userPwdTextFeild.delegate = self;
    [userPwdTextFeild setValue:RgbColor(255, 255, 255) forKeyPath:@"_placeholderLabel.textColor"];
    //userPhoneTextField.layer.borderColor = [RgbColor(213, 213, 213) CGColor];
    userPwdTextFeild.textColor = RgbColor(255, 255, 255);
    userPwdTextFeild.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    // 设置一个空白blankView,15.0就是这块View的宽度width,也是光标的位置,根据你自己的需要设定大小
    UIView *blankView2 = [[UIView alloc] initWithFrame:CGRectMake(userPwdTextFeild.frame.origin.x,userPwdTextFeild.frame.origin.y,10.0, userPwdTextFeild.frame.size.height)];
    userPwdTextFeild.leftView = blankView2;
    userPwdTextFeild.leftViewMode =UITextFieldViewModeAlways;
    [self.view addSubview:userPwdTextFeild];
    
    nomalLoginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    nomalLoginBtn.frame = CGRectMake((SCREEN_WIDTH-AdaptedWidth(304))/2, NavBar_Height+AdaptedHeight(27+149+33+50+33+50+33), AdaptedWidth(304), AdaptedHeight(50));
    [nomalLoginBtn setBackgroundImage:[UIImage imageNamed:@"login_user_login_btnbk" ] forState:UIControlStateNormal];
    [nomalLoginBtn setTitle:@"登 录" forState:UIControlStateNormal];
    nomalLoginBtn.titleLabel.font = [UIFont systemFontOfSize: 18.0];
    [nomalLoginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    nomalLoginBtn.layer.masksToBounds=YES;
    nomalLoginBtn.layer.cornerRadius=8.0f;
    [nomalLoginBtn addTarget:self action:@selector(userLogin) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:nomalLoginBtn];
    
//    forgetBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
//    forgetBtn.frame = CGRectMake((SCREEN_WIDTH-120)/2, SCREEN_HEIGHT/2+225, 120, 40);
//    [forgetBtn setTitle:@"忘记密码" forState:UIControlStateNormal];
//    forgetBtn.titleLabel.font = [UIFont systemFontOfSize: 16.0];
//    [forgetBtn setTitleColor:kUIColorFromRGB(0x009dff)  forState:UIControlStateNormal];
//    [forgetBtn addTarget:self action:@selector(registAction) forControlEvents:UIControlEventTouchUpInside];
//    [self.view addSubview:forgetBtn];
}
 
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    
    self.navigationController.navigationBarHidden = YES;
    
    if([UserDefault stringForKey:@"isLogin"] != nil && [[UserDefault stringForKey:@"isLogin"] intValue] == 1 )
    {
        // 跳转主界面
        [self getUserInfo];
    }
    
}
-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:YES];
    //self.navigationController.navigationBarHidden = NO;
}
 
 
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
 
- (LoginSevice *)loginSevice
{
    if(_loginSevice == nil) {
        _loginSevice = [LoginSevice new];
    }
    return _loginSevice;
}
 
-(void)registAction
{
    
}
 
-(void) userLogin
{
    // 重置密码操作
    if(userPhoneTextField.text.length == 0)
    {
        [Global alertMessageEx:@"请输入账号." title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self];
    }
    else if(userPwdTextFeild.text.length == 0)
    {
        [Global alertMessageEx:@"请输入登录密码." title:@"提示信息" okTtitle:nil cancelTitle:@"OK" delegate:self];
    }
    else
    {
        // 执行登录操作
        MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        HUD.labelText = @"登录中...";
        // 隐藏时候从父控件中移除
        HUD.removeFromSuperViewOnHide = YES;
        // YES代表需要蒙版效果
        HUD.dimBackground = YES;
        
        CommonReqModel * model = [[CommonReqModel alloc] init];
        [model setAccount:userPhoneTextField.text];
        [model setPassword:userPwdTextFeild.text];
        
        TWWeak(self);
        [self.loginSevice getLoginWithParameters:model.toDic completion:^(NSString *desc, int code) {
            HUD.hidden = YES;
            if(code == 1)
            {
                MonitoringMapViewController * page = [[MonitoringMapViewController alloc] init];
                [weakself.navigationController pushViewController:page animated:YES];
            }
            else
            {
                [Global alertMessageEx:desc title:@"登录失败" okTtitle:nil cancelTitle:@"OK" delegate:self];
            }
        }];
    }
    
}
 
-(void)getUserInfo
{    
    CommonReqModel * model = [[CommonReqModel alloc] init];
    [model setAccount:[UserDefault stringForKey:@"accountName"]];
    [model setPassword:[UserDefault stringForKey:@"password"]];
    
    TWWeak(self);
    [self.loginSevice getLoginWithParameters:model.toDic completion:^(NSString *desc, int code) {
        if(code == 1)
        {
            // 跳转主界面
            MonitoringMapViewController * page = [[MonitoringMapViewController alloc] init];
            [weakself.navigationController pushViewController:page animated:YES];
        }
        else
        {
            [Global alertMessageEx:desc title:@"登录失败" okTtitle:nil cancelTitle:@"OK" delegate:self];
        }
    }];
}
/*
#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 - LMJNavUIBaseViewControllerDataSource
 
- (UIStatusBarStyle)navUIBaseViewControllerPreferStatusBarStyle:(LMJNavUIBaseViewController *)navUIBaseViewController
{
    return UIStatusBarStyleDefault;
}
 
/**头部标题*/
- (NSMutableAttributedString*)lmjNavigationBarTitle:(LMJNavigationBar *)navigationBar
{
    return nil;
}
 
 
/** 背景色 */
- (UIColor *)lmjNavigationBackgroundColor:(LMJNavigationBar *)navigationBar
{
    return [UIColor clearColor];
}
 
/** 是否隐藏底部黑线 */
- (BOOL)lmjNavigationIsHideBottomLine:(LMJNavigationBar *)navigationBar
{
    return YES;
}
 
/** 导航条左边的按钮 */
- (UIImage *)lmjNavigationBarLeftButtonImage:(UIButton *)leftButton navigationBar:(LMJNavigationBar *)navigationBar
{
    
    return [UIImage imageNamed:@"login_close_icon"];
}
/** 导航条右边的按钮 */
- (UIImage *)lmjNavigationBarRightButtonImage:(UIButton *)rightButton navigationBar:(LMJNavigationBar *)navigationBar
{
    
    [rightButton setEnabled:NO];
//    [rightButton setTitle:@"立即注册" forState: UIControlStateNormal];
//    [rightButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    [rightButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
//    rightButton.titleLabel.font = [UIFont systemFontOfSize:15];
//
//    rightButton.lmj_width = 80;
    
    return nil;
}
 
 
 
#pragma mark - LMJNavUIBaseViewControllerDelegate
/** 左边的按钮的点击 */
-(void)leftButtonEvent:(UIButton *)sender navigationBar:(LMJNavigationBar *)navigationBar
{
    [self dismissViewControllerAnimated:YES completion:nil];
}
 
 
/** 右边的按钮的点击 */
-(void)rightButtonEvent:(UIButton *)sender navigationBar:(LMJNavigationBar *)navigationBar
{
    
}
 
@end