BindMobileController.m
8.9 KB
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
//
// BindMobileController.m
// DreamSleep
//
// Created by peter on 2022/9/24.
//
#import "BindMobileController.h"
@interface BindMobileController ()
@property (weak, nonatomic) IBOutlet UILabel *bindMobileLab;
@property (weak, nonatomic) IBOutlet UILabel *mobileLab;
@property (weak, nonatomic) IBOutlet UIImageView *mobileIcon;
@property (weak, nonatomic) IBOutlet UILabel *countryLab;
@property (weak, nonatomic) IBOutlet UIImageView *selectIcon;
@property (weak, nonatomic) IBOutlet UITextField *mobileTF;
@property (weak, nonatomic) IBOutlet UIView *mobileLine;
@property (weak, nonatomic) IBOutlet UILabel *verifyLab;
@property (weak, nonatomic) IBOutlet UITextField *verifyTF;
@property (weak, nonatomic) IBOutlet UIButton *getCodeBtn;
@property (weak, nonatomic) IBOutlet UIView *codeLine;
@property (weak, nonatomic) IBOutlet UIButton *bindBtn;
@property (weak, nonatomic) IBOutlet UILabel *tipsLab;
@property (weak, nonatomic) IBOutlet UILabel *timeLab;
@property (nonatomic, strong) NSTimer *countTimer;
@property (nonatomic, assign) int totalSecond;
@end
@implementation BindMobileController
- (void)viewDidLoad {
[super viewDidLoad];
[self initUI];
}
- (void)initUI {
self.totalSecond = 60;
self.naviBarAlpha = 1.0;
self.naviBgColor = DSClearColor;
self.view.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
[self.backBtn dk_setImage:DKImagePickerWithNames(@"cus_back_icon", @"sys_back_icon", @"sys_back_icon") forState:UIControlStateNormal];
[self.dsNaviBar addSubview:self.backBtn];
self.bindMobileLab.dk_textColorPicker = DKColorPickerWithKey(Dk_TITLE);
self.mobileLab.dk_textColorPicker = DKColorPickerWithKey(Dk_TITLE);
self.countryLab.dk_textColorPicker = DKColorPickerWithKey(Dk_TITLE);
self.mobileTF.dk_textColorPicker = DKColorPickerWithKey(Dk_TITLE);
UIColor *placeholderColor = [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNormal] ? ColorFromHexA(0x333333, .5) : ColorFromHexA(0xE8E9E9, .5);
NSDictionary *attributes = @{NSForegroundColorAttributeName:placeholderColor, NSFontAttributeName:SysFont(15)};
self.mobileTF.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入手机号" attributes:attributes];
self.verifyLab.dk_textColorPicker = DKColorPickerWithKey(Dk_TITLE);
self.verifyLab.dk_textColorPicker = DKColorPickerWithKey(Dk_TITLE);
self.verifyTF.dk_textColorPicker = DKColorPickerWithKey(Dk_TITLE);
self.verifyTF.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入验证码" attributes:attributes];
self.tipsLab.dk_textColorPicker = DKColorPickerWithColors(SmallTextColor, ColorFromHexA(0xFFFFFF, .3), DSWhite);
self.timeLab.dk_textColorPicker = DKColorPickerWithColors(SubTitleColor, ColorFromHexA(0xFFFFFF, .5), DSWhite);
self.mobileLine.dk_backgroundColorPicker = DKColorPickerWithColors(ColorFromHex(0xE6E6E6), AlertDarkColor, DSWhite);
self.codeLine.dk_backgroundColorPicker = DKColorPickerWithColors(ColorFromHex(0xE6E6E6), AlertDarkColor, DSWhite);
self.mobileIcon.dk_imagePicker = DKImagePickerWithNames(@"ic_bangding_shouji", @"dk_ic_bangding_shouji", @"ic_bangding_shouji");
self.selectIcon.dk_imagePicker = DKImagePickerWithNames(@"ic_bangding_xiala", @"dk_ic_bangding_xiala", @"ic_bangding_xiala");
self.bindBtn.dk_backgroundColorPicker = DKColorPickerWithKey(BrandBG);
[self.bindBtn dk_setTitleColorPicker:DKColorPickerWithKey(Sub_Navi_TITLE) forState:UIControlStateNormal];
[self.bindMobileLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.view).offset(30);
make.top.equalTo(self.view).offset(118);
}];
[self.mobileLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.bindMobileLab);
make.top.equalTo(self.bindMobileLab.mas_bottom).offset(40);
}];
[self.mobileIcon mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.mobileLab);
make.top.equalTo(self.mobileLab.mas_bottom).offset(24);
}];
[self.countryLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.mobileIcon.mas_right).offset(8);
make.centerY.equalTo(self.mobileIcon);
}];
[self.selectIcon mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.countryLab.mas_right).offset(4);
make.centerY.equalTo(self.countryLab);
}];
[self.mobileTF mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.selectIcon.mas_right).offset(12);
make.centerY.equalTo(self.selectIcon);
make.right.equalTo(self.view).offset(-60);
}];
[self.mobileLine mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.mobileIcon);
make.right.equalTo(self.view).offset(-30);
make.top.equalTo(self.mobileIcon.mas_bottom).offset(9);
make.height.equalTo(@1);
}];
[self.verifyLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.mobileLine);
make.top.equalTo(self.mobileLine.mas_bottom).offset(24);
}];
[self.verifyTF mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.verifyLab);
make.top.equalTo(self.verifyLab.mas_bottom).offset(24);
}];
[self.getCodeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.view).offset(-30);
make.center.equalTo(self.verifyTF);
}];
[self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.view).offset(-30);
make.center.equalTo(self.verifyTF);
}];
[self.codeLine mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.verifyTF);
make.right.equalTo(self.view).offset(-30);
make.top.equalTo(self.verifyTF.mas_bottom).offset(8);
make.height.equalTo(@1);
}];
[self.bindBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.view);
make.top.equalTo(self.codeLine.mas_bottom).offset(64);
make.size.mas_equalTo(CGSizeMake(206, 50));
}];
[self.tipsLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.view).offset(15);
make.right.equalTo(self.view).offset(-15);
make.top.equalTo(self.bindBtn.mas_bottom).offset(48);
}];
}
- (void)dealloc {
[_countTimer invalidate];
_countTimer = nil;
}
#pragma mark - Action
- (IBAction)getMobileCode:(UIButton *)sender {
if (self.mobileTF.text.length == 0) {
[DSProgressHUD showToast:@"请输入手机号"];
return;
}
[DSProgressHUD showProgressHUDWithInfo:@""];
[UserRequestModel getMobileCode:self.mobileTF.text completion:^(UserRequestModel * _Nonnull requestModel) {
[DSProgressHUD dissmissProgressHUD];
if (requestModel.resCode == DSResCodeSuccess) {
[self.verifyTF becomeFirstResponder];
self.timeLab.hidden = NO;
self.getCodeBtn.hidden = YES;
[self.countTimer setFireDate:[NSDate date]];
[self.getCodeBtn setTitle:@"重新获取" forState:UIControlStateNormal];
} else {
[DSProgressHUD showToast:requestModel.errMessage];
}
}];
}
- (IBAction)bindMobile:(UIButton *)sender {
if (self.mobileTF.text.length == 0) {
[DSProgressHUD showToast:@"请输入手机号"];
return;
}
if (self.verifyTF.text.length == 0) {
[DSProgressHUD showToast:@"请输入验证码"];
return;
}
if (self.mobileTF.text.length && self.verifyTF.text.length) {
[DSProgressHUD showProgressHUDWithInfo:@""];
[UserRequestModel verifyBindMobile:self.mobileTF.text code:self.verifyTF.text completion:^(UserRequestModel * _Nonnull requestModel) {
[DSProgressHUD dissmissProgressHUD];
if (requestModel.resCode == DSResCodeSuccess) {
// 保存绑定手机号码标识
[LoginUtils updateUserInfo:requestModel.mobileDic];
[self.navigationController popViewControllerAnimated:YES];
} else {
[DSProgressHUD showToast:requestModel.errMessage];
}
}];
}
}
#pragma mark - 关闭侧滑
- (BOOL)enableInteractivePopGestureRecognizer {
return NO;
}
#pragma mark - lazy
- (NSTimer *)countTimer {
if (!_countTimer) {
WS(weakSelf);
_countTimer = [NSTimer timerWithTimeInterval:1.0 repeats:YES block:^(NSTimer * _Nonnull timer) {
if (weakSelf.totalSecond == 0) {
weakSelf.getCodeBtn.hidden = NO;
weakSelf.timeLab.hidden = YES;
[weakSelf.countTimer setFireDate:[NSDate distantFuture]];
return;
}
weakSelf.totalSecond--;
weakSelf.timeLab.text = [NSString stringWithFormat:@"%ds后重发", weakSelf.totalSecond];
}];
[[NSRunLoop currentRunLoop] addTimer:_countTimer forMode:NSRunLoopCommonModes];
}
return _countTimer;
}
@end