| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- //
- // HJSalaryViewController.m
- // HappyJob
- //
- // Created by Bob on 2019/5/29.
- // Copyright © 2019 Bob. All rights reserved.
- //
- #import "HJSalaryCodeViewController.h"
- #import "HJSalaryAgreementViewController.h"
- #import "HJSalaryDataBox.h"
- #import "HJSalaryDetailViewController.h"
- #import "HJSalaryAuthAPIManager.h"
- #import "HJUserInfoModel.h"
- #import "HJSalaryCodeView.h"
- #import "HJSalaryListViewController.h"//薪资查询列表
- #import "HJSMSValidationWebView.h"//短信验证
- @interface HJSalaryCodeViewController ()
- <
- FBAPIManagerInterceptor,
- FBAPIManagerDelegate
- >
- @property (nonatomic, strong) HJSalaryCodeView *codeView;
- @property (nonatomic, strong) HJSalaryDataBox *dataBox;
- @property (nonatomic, assign) NSInteger second;//倒计时时间
- @property (nonatomic, strong) NSTimer *timer;//定时器
- @property (nonatomic, strong) HJSMSValidationWebView *validationWebView;
- @property (nonatomic, strong) HJSalaryAuthAPIManager *salaryAuthAPIManager;//校验验证码
- @end
- @implementation HJSalaryCodeViewController
- #pragma mark - life cycle
- - (void)viewWillAppear:(BOOL)animated {
-
- [super viewWillAppear:animated];
- [self hj_setupNavBar];
- }
- - (void)viewDidDisappear:(BOOL)animated {
-
- [super viewDidDisappear:animated];
- [self.timer invalidate];
- [self.validationWebView removeFromSuperview];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.title = @"薪资查询";
- [self setUpSubViews];
- }
- #pragma mark - init
- - (void)setUpSubViews {
-
- self.view.backgroundColor = [UIColor whiteColor];
- //导航栏右侧按钮
- self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"rule_white"] style:UIBarButtonItemStylePlain target:self action:@selector(ruleClick)];
- [self.view addSubview:self.codeView];
-
- [self.codeView mas_makeConstraints:^(MASConstraintMaker *make) {
-
- make.left.top.right.offset(0);
- }];
-
- //验证-验证码
- __weak typeof(self) weakSelf = self;
- self.codeView.codeBlock = ^(NSString * _Nonnull code) {
-
- [weakSelf startVerificationCode:code];
-
- };
- }
- #pragma mark - event response
- /* 规则 */
- - (void)ruleClick {
-
- HJSalaryAgreementViewController *vc = [[HJSalaryAgreementViewController alloc] init];
- vc.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:vc animated:YES];
- }
- /* 获取验证码 */
- - (void)codeButtonClick:(UIButton *)btn {
- __weak typeof(self) weakSelf = self;
- [self.validationWebView removeFromSuperview];
- self.validationWebView = [[HJSMSValidationWebView alloc] init];
- [self.validationWebView createWebViewPhone:[HJMemberInfoModel memberInfo].phone];
- self.validationWebView.successfulBlock = ^{
-
- weakSelf.codeView.codeBtn.userInteractionEnabled = NO;
- [weakSelf.codeView.codeView.textView becomeFirstResponder];
- weakSelf.codeView.phonelabel.text = [NSString stringWithFormat:@"验证码已发送至%@",[HJMemberInfoModel memberInfo].phone];
- weakSelf.second = 60;
- weakSelf.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:weakSelf selector:@selector(runTimer) userInfo:weakSelf repeats:YES];
- };
-
- }
- - (void)runTimer {
-
- self.second -- ;
- [self.codeView.codeBtn setTitleColor:COLOR_000000 forState:UIControlStateNormal];
- [self.codeView.codeBtn setTitle:[NSString stringWithFormat:@"%lds 后重新获取验证码",(long)_second] forState:UIControlStateNormal];
- if (self.second <= 0)
- {
- self.codeView.codeBtn.userInteractionEnabled = YES;
- [self.codeView.codeBtn setTitle:@"重新发送" forState:UIControlStateNormal];
- [self.codeView.codeBtn setTitleColor:COLOR_0177FF forState:UIControlStateNormal];
- [self.timer invalidate];
- self.timer = nil;
- }
- }
- #pragma mark - FBAPIManagerInterceptor
- - (BOOL)manager:(FBBaseAPIManager *)manager shouldStartCallAPIWithParams:(NSDictionary *)params {
-
- [self.view fb_showLoading];
- return YES;
- }
- - (void)managerShouldFinishCallAPI:(FBBaseAPIManager *)manager {
-
- [self.view fb_dismiss];
- }
- #pragma mark - FBAPIManagerDelegate
- - (void)managerCallAPIDidSuccess:(FBBaseAPIManager *)manager {
-
- if (manager == self.salaryAuthAPIManager)
- {
- [manager fetchDataWithBox:self.dataBox];
- HJSalaryListViewController *list = [[HJSalaryListViewController alloc]init];
- list.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:list animated:YES];
- }
- }
- - (void)managerCallAPIDidFailed:(FBBaseAPIManager *)manager {
-
- id fetchData = [manager fetchDataWithBox:self.dataBox];
- if ([fetchData isKindOfClass:[NSString class]])
- {
- [self.view fb_showFailureWithStatus:fetchData];
- }
- }
- #pragma mark - private metnod
- /* 开始校验验证码*/
- - (void)startVerificationCode:(NSString *)code {
-
- self.salaryAuthAPIManager.phone = [HJMemberInfoModel memberInfo].phone;
- self.salaryAuthAPIManager.authCode = code;
- [self.salaryAuthAPIManager start];
- }
- #pragma mark - getters and setters
- - (HJSalaryCodeView *)codeView {
-
- if (_codeView == nil)
- {
- _codeView = [[HJSalaryCodeView alloc] init];
- [_codeView.codeBtn addTarget:self action:@selector(codeButtonClick:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _codeView;
- }
- - (HJSalaryDataBox *)dataBox {
-
- if (_dataBox == nil)
- {
- _dataBox = [[HJSalaryDataBox alloc] init];
- }
- return _dataBox;
- }
- - (HJSalaryAuthAPIManager *)salaryAuthAPIManager {
-
- if (_salaryAuthAPIManager == nil)
- {
- _salaryAuthAPIManager = [[HJSalaryAuthAPIManager alloc] init];
- _salaryAuthAPIManager.APIManagerDelegate = self;
- }
- return _salaryAuthAPIManager;
- }
- @end
|