HJSalaryCodeViewController.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. //
  2. // HJSalaryViewController.m
  3. // HappyJob
  4. //
  5. // Created by Bob on 2019/5/29.
  6. // Copyright © 2019 Bob. All rights reserved.
  7. //
  8. #import "HJSalaryCodeViewController.h"
  9. #import "HJSalaryAgreementViewController.h"
  10. #import "HJSalaryDataBox.h"
  11. #import "HJSalaryDetailViewController.h"
  12. #import "HJSalaryAuthAPIManager.h"
  13. #import "HJUserInfoModel.h"
  14. #import "HJSalaryCodeView.h"
  15. #import "HJSalaryListViewController.h"//薪资查询列表
  16. #import "HJSMSValidationWebView.h"//短信验证
  17. @interface HJSalaryCodeViewController ()
  18. <
  19. FBAPIManagerInterceptor,
  20. FBAPIManagerDelegate
  21. >
  22. @property (nonatomic, strong) HJSalaryCodeView *codeView;
  23. @property (nonatomic, strong) HJSalaryDataBox *dataBox;
  24. @property (nonatomic, assign) NSInteger second;//倒计时时间
  25. @property (nonatomic, strong) NSTimer *timer;//定时器
  26. @property (nonatomic, strong) HJSMSValidationWebView *validationWebView;
  27. @property (nonatomic, strong) HJSalaryAuthAPIManager *salaryAuthAPIManager;//校验验证码
  28. @end
  29. @implementation HJSalaryCodeViewController
  30. #pragma mark - life cycle
  31. - (void)viewWillAppear:(BOOL)animated {
  32. [super viewWillAppear:animated];
  33. [self hj_setupNavBar];
  34. }
  35. - (void)viewDidDisappear:(BOOL)animated {
  36. [super viewDidDisappear:animated];
  37. [self.timer invalidate];
  38. [self.validationWebView removeFromSuperview];
  39. }
  40. - (void)viewDidLoad {
  41. [super viewDidLoad];
  42. self.title = @"薪资查询";
  43. [self setUpSubViews];
  44. }
  45. #pragma mark - init
  46. - (void)setUpSubViews {
  47. self.view.backgroundColor = [UIColor whiteColor];
  48. //导航栏右侧按钮
  49. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"rule_white"] style:UIBarButtonItemStylePlain target:self action:@selector(ruleClick)];
  50. [self.view addSubview:self.codeView];
  51. [self.codeView mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.left.top.right.offset(0);
  53. }];
  54. //验证-验证码
  55. __weak typeof(self) weakSelf = self;
  56. self.codeView.codeBlock = ^(NSString * _Nonnull code) {
  57. [weakSelf startVerificationCode:code];
  58. };
  59. }
  60. #pragma mark - event response
  61. /* 规则 */
  62. - (void)ruleClick {
  63. HJSalaryAgreementViewController *vc = [[HJSalaryAgreementViewController alloc] init];
  64. vc.hidesBottomBarWhenPushed = YES;
  65. [self.navigationController pushViewController:vc animated:YES];
  66. }
  67. /* 获取验证码 */
  68. - (void)codeButtonClick:(UIButton *)btn {
  69. __weak typeof(self) weakSelf = self;
  70. [self.validationWebView removeFromSuperview];
  71. self.validationWebView = [[HJSMSValidationWebView alloc] init];
  72. [self.validationWebView createWebViewPhone:[HJMemberInfoModel memberInfo].phone];
  73. self.validationWebView.successfulBlock = ^{
  74. weakSelf.codeView.codeBtn.userInteractionEnabled = NO;
  75. [weakSelf.codeView.codeView.textView becomeFirstResponder];
  76. weakSelf.codeView.phonelabel.text = [NSString stringWithFormat:@"验证码已发送至%@",[HJMemberInfoModel memberInfo].phone];
  77. weakSelf.second = 60;
  78. weakSelf.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:weakSelf selector:@selector(runTimer) userInfo:weakSelf repeats:YES];
  79. };
  80. }
  81. - (void)runTimer {
  82. self.second -- ;
  83. [self.codeView.codeBtn setTitleColor:COLOR_000000 forState:UIControlStateNormal];
  84. [self.codeView.codeBtn setTitle:[NSString stringWithFormat:@"%lds 后重新获取验证码",(long)_second] forState:UIControlStateNormal];
  85. if (self.second <= 0)
  86. {
  87. self.codeView.codeBtn.userInteractionEnabled = YES;
  88. [self.codeView.codeBtn setTitle:@"重新发送" forState:UIControlStateNormal];
  89. [self.codeView.codeBtn setTitleColor:COLOR_0177FF forState:UIControlStateNormal];
  90. [self.timer invalidate];
  91. self.timer = nil;
  92. }
  93. }
  94. #pragma mark - FBAPIManagerInterceptor
  95. - (BOOL)manager:(FBBaseAPIManager *)manager shouldStartCallAPIWithParams:(NSDictionary *)params {
  96. [self.view fb_showLoading];
  97. return YES;
  98. }
  99. - (void)managerShouldFinishCallAPI:(FBBaseAPIManager *)manager {
  100. [self.view fb_dismiss];
  101. }
  102. #pragma mark - FBAPIManagerDelegate
  103. - (void)managerCallAPIDidSuccess:(FBBaseAPIManager *)manager {
  104. if (manager == self.salaryAuthAPIManager)
  105. {
  106. [manager fetchDataWithBox:self.dataBox];
  107. HJSalaryListViewController *list = [[HJSalaryListViewController alloc]init];
  108. list.hidesBottomBarWhenPushed = YES;
  109. [self.navigationController pushViewController:list animated:YES];
  110. }
  111. }
  112. - (void)managerCallAPIDidFailed:(FBBaseAPIManager *)manager {
  113. id fetchData = [manager fetchDataWithBox:self.dataBox];
  114. if ([fetchData isKindOfClass:[NSString class]])
  115. {
  116. [self.view fb_showFailureWithStatus:fetchData];
  117. }
  118. }
  119. #pragma mark - private metnod
  120. /* 开始校验验证码*/
  121. - (void)startVerificationCode:(NSString *)code {
  122. self.salaryAuthAPIManager.phone = [HJMemberInfoModel memberInfo].phone;
  123. self.salaryAuthAPIManager.authCode = code;
  124. [self.salaryAuthAPIManager start];
  125. }
  126. #pragma mark - getters and setters
  127. - (HJSalaryCodeView *)codeView {
  128. if (_codeView == nil)
  129. {
  130. _codeView = [[HJSalaryCodeView alloc] init];
  131. [_codeView.codeBtn addTarget:self action:@selector(codeButtonClick:) forControlEvents:UIControlEventTouchUpInside];
  132. }
  133. return _codeView;
  134. }
  135. - (HJSalaryDataBox *)dataBox {
  136. if (_dataBox == nil)
  137. {
  138. _dataBox = [[HJSalaryDataBox alloc] init];
  139. }
  140. return _dataBox;
  141. }
  142. - (HJSalaryAuthAPIManager *)salaryAuthAPIManager {
  143. if (_salaryAuthAPIManager == nil)
  144. {
  145. _salaryAuthAPIManager = [[HJSalaryAuthAPIManager alloc] init];
  146. _salaryAuthAPIManager.APIManagerDelegate = self;
  147. }
  148. return _salaryAuthAPIManager;
  149. }
  150. @end