省钱达人

DRGetMoneyNextViewController.m 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. //
  2. // DRGetMoneyNextViewController.m
  3. // YouHuiProject
  4. //
  5. // Created by jcymac on 2018/6/11.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "DRGetMoneyNextViewController.h"
  9. @interface DRGetMoneyNextViewController ()<UITextFieldDelegate>
  10. @property (nonatomic,strong) UIView *codeView;
  11. @property (nonatomic,strong) UIButton *nextBtn;
  12. @end
  13. @implementation DRGetMoneyNextViewController
  14. - (void)viewDidLoad {
  15. [super viewDidLoad];
  16. [self addUI];
  17. [self adjustUI];
  18. [self timeAction:[self.view viewWithTag:10003]];
  19. }
  20. -(void)viewWillAppear:(BOOL)animated{
  21. [super viewWillAppear:animated];
  22. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  23. }
  24. - (void)configNavigationBar {
  25. [self.navigationBar setNavTitle:@"验证手机号"];
  26. self.navigationBar.backgroundColor = [UIColor changeColor];
  27. self.navigationBar.navTitleLabel.textColor = [UIColor whiteColor];
  28. UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  29. [leftBtn setImage:[UIImage imageNamed:@"back_white"] forState:UIControlStateNormal];
  30. [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
  31. [self.navigationBar setCustomLeftButtons:@[leftBtn]];
  32. }
  33. -(void)addUI{
  34. [self.view addSubview:self.codeView];
  35. [self.view addSubview:self.nextBtn];
  36. [self configNavigationBar];
  37. }
  38. -(void)adjustUI{
  39. [self.codeView mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.left.mas_equalTo(FITSIZE(35));
  41. make.right.mas_equalTo(FITSIZE(-35));
  42. make.top.mas_equalTo(154);
  43. make.height.mas_equalTo(144);
  44. }];
  45. [self.nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.top.equalTo(self.codeView.mas_bottom).offset(25);
  47. make.centerX.equalTo(self.view.mas_centerX);
  48. make.height.mas_equalTo(42);
  49. make.width.mas_equalTo(FITSIZE(250));
  50. }];
  51. UIView *imgView=[self.codeView viewWithTag:10001];
  52. UIView *textFieldView=[self.codeView viewWithTag:10002];
  53. UIView *timeView=[self.codeView viewWithTag:10003];
  54. UIView *lineView=[self.codeView viewWithTag:10004];
  55. [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.left.mas_equalTo(0);
  57. make.bottom.mas_equalTo((-41-10));
  58. make.width.height.mas_equalTo(18);
  59. }];
  60. [timeView mas_makeConstraints:^(MASConstraintMaker *make) {
  61. make.right.mas_equalTo(0);
  62. make.centerY.equalTo(imgView.mas_centerY);
  63. make.width.mas_equalTo(76);
  64. make.height.mas_equalTo(22);
  65. }];
  66. [textFieldView mas_makeConstraints:^(MASConstraintMaker *make) {
  67. make.left.equalTo(imgView.mas_right).offset(FITSIZE(10));
  68. make.centerY.equalTo(imgView.mas_centerY);
  69. make.right.equalTo(timeView.mas_left);
  70. }];
  71. [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
  72. make.left.equalTo(imgView.mas_left);
  73. make.right.equalTo(timeView.mas_right);
  74. make.top.equalTo(imgView.mas_bottom).offset(10);
  75. make.height.mas_equalTo(1);
  76. }];
  77. }
  78. #pragma mark -事件
  79. -(void)timeAction:(UIButton *)sender{
  80. [self requestCode];
  81. [sender startWithTime:60 title:@"重新发送" countDownTitle:@"s" mainColor:[UIColor clearColor] countColor:[UIColor clearColor]];
  82. }
  83. #pragma mark -网络请求
  84. -(void)requestCode{
  85. //获取验证码
  86. NSString *url=[NSString stringWithFormat:@"%@/api/v2/users/sendCode",BaseURL];
  87. [DRHttp post:url params:nil success:^(id json) {
  88. } failure:^(NSError *error) {
  89. if (error) {
  90. [MBProgressHUD showMessage:@"获取失败"];
  91. }
  92. }];
  93. }
  94. -(void)requestGetMoney{
  95. UITextField *textField=[self.codeView viewWithTag:10002];
  96. if(textField.text &&![@"" isEqualToString:textField.text]) {
  97. NSString *url=[NSString stringWithFormat:@"%@/api/v2/adzoneCreate/embodyApplication",BaseURL];
  98. NSDictionary *dic=@{
  99. @"money":self.moneyStr,
  100. @"code":textField.text
  101. };
  102. [DRHttp post:url params:dic success:^(id json) {
  103. [MBProgressHUD showMessage:@"提现成功"];
  104. [SVProgressHUD dismissWithDelay:1.0f];
  105. [self.navigationController popToRootViewControllerAnimated:YES];
  106. } failure:^(NSError *error) {
  107. if (error) {
  108. [MBProgressHUD showMessage:@"服务器开小差了,请稍后再试"];
  109. }
  110. }];
  111. }else{
  112. [MBProgressHUD showMessage:@"您的输入有误,请重新输入"];
  113. }
  114. }
  115. #pragma mark -代理
  116. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
  117. if ([@"" isEqualToString:string]) {
  118. return YES;
  119. }
  120. if ([@"0123456789" rangeOfString:string].location!= NSNotFound) {
  121. return YES;
  122. }
  123. return NO;
  124. }
  125. #pragma mark -事件响应
  126. - (void)backAction {
  127. [self.navigationController popViewControllerAnimated:YES];
  128. }
  129. #pragma mark -懒加载
  130. -(UIView *)codeView{
  131. if (!_codeView) {
  132. _codeView=[[UIView alloc]init];
  133. UIImageView *imgView=[[UIImageView alloc]init];
  134. UITextField *textField=[[UITextField alloc]init];
  135. UIButton *timeBtn=[UIButton buttonWithType:UIButtonTypeCustom];
  136. UIView *lineView=[[UIView alloc]init];
  137. imgView.tag=10001;
  138. textField.tag=10002;
  139. timeBtn.tag=10003;
  140. lineView.tag=10004;
  141. [_codeView addSubview:imgView];
  142. [_codeView addSubview:textField];
  143. [_codeView addSubview:timeBtn];
  144. [_codeView addSubview:lineView];
  145. imgView.image = [UIImage imageNamed:@"code_left"];
  146. textField.placeholder=@"输入验证码";
  147. textField.textColor=[UIColor blackColor];
  148. textField.font=[UIFont systemFontOfSize:14];
  149. textField.delegate=self;
  150. textField.keyboardType=UIKeyboardTypeNumberPad;
  151. [timeBtn setTitleColor:[UIColor YHColorWithHex:0xFF6D33] forState:UIControlStateNormal];
  152. timeBtn.layer.borderColor=[UIColor YHColorWithHex:0xFF6D33].CGColor;
  153. [timeBtn addTarget:self action:@selector(timeAction:) forControlEvents:UIControlEventTouchUpInside];
  154. [timeBtn setTitle:@"重新获取" forState:UIControlStateNormal];
  155. timeBtn.titleLabel.font=[UIFont systemFontOfSize:12];
  156. [timeBtn setTitleColor:[UIColor YHColorWithHex:0xFF6D33] forState:UIControlStateNormal];
  157. timeBtn.layer.borderWidth=1;
  158. timeBtn.layer.cornerRadius=11;
  159. timeBtn.layer.masksToBounds=YES;
  160. lineView.backgroundColor=[UIColor YHColorWithHex:0xD8D8D8];
  161. }
  162. return _codeView;
  163. }
  164. -(UIButton *)nextBtn{
  165. if (!_nextBtn) {
  166. _nextBtn=[UIButton buttonWithType:UIButtonTypeCustom];
  167. _nextBtn.layer.cornerRadius=21;
  168. [_nextBtn setTitle:@"完成" forState:UIControlStateNormal];
  169. _nextBtn.backgroundColor=[UIColor gradientWidthFromColor:[UIColor YHColorWithHex:0xFF9000] toColor:[UIColor YHColorWithHex:0xFF5000] withWidth:FITSIZE(250)];
  170. [[_nextBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
  171. [self requestGetMoney];
  172. }];
  173. }
  174. return _nextBtn;
  175. }
  176. @end