YOUPAILPYoungForgetPWD.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. //
  2. // YOUPAILPYoungForgetPWD.m
  3. // livePro
  4. //
  5. // Created by leo on 2019/12/27.
  6. // Copyright © 2019 caiPro. All rights reserved.
  7. //
  8. #import "YOUPAILPYoungForgetPWD.h"
  9. @interface YOUPAILPYoungForgetPWD ()<UIScrollViewDelegate,UITextViewDelegate>
  10. @property(nonatomic,strong)UITextField* youpaipphoneTextField,*youpaippwdTextField;
  11. @property(nonatomic,assign)NSInteger youpaipphoneLength;
  12. @property(nonatomic,strong)UITextField* youpaipcodeTextField;
  13. @property(nonatomic,strong)UIButton* youpaiploginBtn;
  14. @property(nonatomic,strong)UIButton* youpaipverifyBtn;
  15. @property(nonatomic,strong)dispatch_source_t youpaipcodeTimer;
  16. @end
  17. @implementation YOUPAILPYoungForgetPWD
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. self.title = @"关闭未成年模式";
  21. self.youpaipphoneLength = 0;
  22. [self youpaifsetupView];
  23. self.view.backgroundColor = [UIColor whiteColor];
  24. }
  25. - (void)youpaifsetupView{
  26. UIScrollView* scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, NavBarHeight, KScreenWidth, KScreenHeight-NavBarHeight)];
  27. scrollView.contentSize = CGSizeMake(KScreenWidth, KScreenHeight-NavBarHeight+1);
  28. scrollView.bounces = YES;
  29. scrollView.showsHorizontalScrollIndicator = NO;
  30. scrollView.showsVerticalScrollIndicator = NO;
  31. scrollView.delegate = self;
  32. [self.view addSubview:scrollView];
  33. UITextField* phoneTextField = [[UITextField alloc]initWithFrame:CGRectMake(27, 27, KScreenWidth-54, 56)];
  34. self.youpaipphoneTextField = phoneTextField;
  35. phoneTextField.layer.cornerRadius = 28.0f;
  36. phoneTextField.clipsToBounds = YES;
  37. phoneTextField.backgroundColor = LZF7F8FAColor;
  38. phoneTextField.textColor = LZ273145Color;
  39. phoneTextField.tintColor = LZ7C69FEColor;
  40. UIView *phoneTipV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 28+53+12, 56)];
  41. UILabel* phoneTipLabel = [[UILabel alloc]initWithFrame:CGRectMake(28, 0, 53, 56)];
  42. phoneTipLabel.text = @"手机号";
  43. phoneTipLabel.textColor = LZ273145Color;
  44. phoneTipLabel.font = LCFont17;
  45. phoneTipLabel.textAlignment = NSTextAlignmentLeft;
  46. [phoneTipV addSubview:phoneTipLabel];
  47. phoneTextField.leftView = phoneTipV;
  48. phoneTextField.leftViewMode = UITextFieldViewModeAlways;
  49. phoneTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
  50. [[phoneTextField valueForKey:@"_clearButton"] setImage:[UIImage imageNamed:@"vqu_images_D_nick_clean"] forState:UIControlStateNormal];
  51. phoneTextField.keyboardType = UIKeyboardTypeNumberPad;
  52. [phoneTextField addTarget:self action:@selector(textFieldDidEditing:) forControlEvents:UIControlEventEditingChanged];
  53. NSMutableAttributedString* attrStr = [[NSMutableAttributedString alloc]initWithString:@"请输入手机号码"];
  54. [attrStr addAttribute:NSFontAttributeName value:LCFont17 range:NSMakeRange(0, attrStr.length)];
  55. [attrStr addAttribute:NSForegroundColorAttributeName value:LZD3D1D7Color range:NSMakeRange(0, attrStr.length)];
  56. phoneTextField.attributedPlaceholder = attrStr;
  57. phoneTextField.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;
  58. [scrollView addSubview:phoneTextField];
  59. UITextField* codeTextField = [[UITextField alloc]initWithFrame:CGRectMake(27, CGRectGetMaxY(phoneTextField.frame) + 14.0f, KScreenWidth-54, 56)];
  60. self.youpaipcodeTextField = codeTextField;
  61. codeTextField.layer.cornerRadius = 28.0f;
  62. codeTextField.clipsToBounds = YES;
  63. codeTextField.backgroundColor = LZF7F8FAColor;
  64. codeTextField.textColor = LZ273145Color;
  65. codeTextField.tintColor = LZ7C69FEColor;
  66. UIView *codeTipLV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 28+53+12, 56)];
  67. UILabel* codeTipLabel = [[UILabel alloc]initWithFrame:CGRectMake(28, 0, 53, 56)];
  68. codeTipLabel.text = @"验证码";
  69. codeTipLabel.textColor = LZ273145Color;
  70. codeTipLabel.font =LCFont17;
  71. codeTipLabel.textAlignment = NSTextAlignmentLeft;
  72. [codeTipLV addSubview:codeTipLabel];
  73. codeTextField.leftView = codeTipLV;
  74. codeTextField.leftViewMode = UITextFieldViewModeAlways;
  75. UIView* rightview = [[UIView alloc]initWithFrame:CGRectMake(0, 0,107, 56)];
  76. UIButton* verifyBtn = [[UIButton alloc]initWithFrame:CGRectMake(14.0f, 14.0f, 79.0f, 28.0f)];
  77. self.youpaipverifyBtn = verifyBtn;
  78. verifyBtn.layer.cornerRadius = 14.0f;
  79. verifyBtn.layer.masksToBounds = YES;
  80. verifyBtn.backgroundColor = LZD3D1D7Color;
  81. verifyBtn.titleLabel.font = LCFont12;
  82. [verifyBtn setTitleColor:LZ273145Color forState:(UIControlStateNormal)];
  83. [verifyBtn setTitle:@"获取验证码" forState:(UIControlStateNormal)];
  84. verifyBtn.userInteractionEnabled = NO;
  85. [verifyBtn addTarget:self action:@selector(youpaifverifyBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
  86. [rightview addSubview:verifyBtn];
  87. codeTextField.rightView = rightview;
  88. codeTextField.rightViewMode = UITextFieldViewModeAlways;
  89. codeTextField.keyboardType = UIKeyboardTypeNumberPad;
  90. [codeTextField addTarget:self action:@selector(textFieldDidEditing:) forControlEvents:UIControlEventEditingChanged];
  91. NSMutableAttributedString* attrStrCode = [[NSMutableAttributedString alloc]initWithString:@"短信验证码"];
  92. [attrStrCode addAttribute:NSFontAttributeName value:LCFont17 range:NSMakeRange(0, attrStrCode.length)];
  93. [attrStrCode addAttribute:NSForegroundColorAttributeName value:LZD3D1D7Color range:NSMakeRange(0, attrStrCode.length)];
  94. codeTextField.attributedPlaceholder = attrStrCode;
  95. codeTextField.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;
  96. [scrollView addSubview:codeTextField];
  97. UIButton* loginBtn = [[UIButton alloc]init];
  98. self.youpaiploginBtn = loginBtn;
  99. loginBtn.userInteractionEnabled = NO;
  100. loginBtn.backgroundColor = LZD3D1D7Color;
  101. loginBtn.layer.cornerRadius = 28.0;
  102. loginBtn.layer.masksToBounds = YES;
  103. loginBtn.titleLabel.font = LCFont17;
  104. [loginBtn setTitleColor:LZ273145Color forState:(UIControlStateNormal)];
  105. [loginBtn setTitle:@"关闭未成年模式" forState:(UIControlStateNormal)];
  106. [loginBtn addTarget:self action:@selector(youpaifloginBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
  107. [scrollView addSubview:loginBtn];
  108. [loginBtn makeConstraints:^(MASConstraintMaker *make) {
  109. make.top.offset(KScreenHeight-100-SafeHeight-56.0f-NavBarHeight);
  110. make.centerX.equalTo(self.view.mas_centerX);
  111. make.size.mas_equalTo(CGSizeMake(KScreenWidth-54.0f, 56.0f));
  112. }];
  113. }
  114. //监听输入的手机号码自动添加空格
  115. -(void)textFieldDidEditing:(UITextField *)textField{
  116. if ([self.youpaipphoneTextField.text isEqualToString:@""] || [self.youpaipcodeTextField.text isEqualToString:@""]|| [self.youpaippwdTextField.text isEqualToString:@""]){
  117. self.youpaiploginBtn.backgroundColor = LZD3D1D7Color;
  118. [self.youpaiploginBtn setTitleColor:LZ273145Color forState:UIControlStateNormal];
  119. [self.youpaiploginBtn setBackgroundImage:nil forState:(UIControlStateNormal)];
  120. self.youpaiploginBtn.userInteractionEnabled = NO;
  121. }else{
  122. [self.youpaiploginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  123. [self.youpaiploginBtn setBackgroundImage:[LCTools ColorImage:self.youpaiploginBtn.frame.size FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:(GradientLeftToRight)] forState:(UIControlStateNormal)];
  124. self.youpaiploginBtn.userInteractionEnabled = YES;;
  125. }
  126. if (textField == self.youpaipphoneTextField) {
  127. if (textField.text.length > self.youpaipphoneLength) {
  128. if (textField.text.length == 4 || textField.text.length == 9 ) {//输入
  129. NSMutableString * str = [[NSMutableString alloc ] initWithString:textField.text];
  130. [str insertString:@" " atIndex:(textField.text.length-1)];
  131. textField.text = str;
  132. }if (textField.text.length >= 13 ) {//输入完成
  133. textField.text = [textField.text substringToIndex:13];
  134. self.youpaipverifyBtn.userInteractionEnabled = YES;
  135. [self.youpaipverifyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  136. [self.youpaipverifyBtn setBackgroundImage:[LCTools ColorImage:self.youpaipverifyBtn.frame.size FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:(GradientLeftToRight)] forState:(UIControlStateNormal)];
  137. }
  138. self.youpaipphoneLength = textField.text.length;
  139. }else if (textField.text.length < self.youpaipphoneLength){//删除
  140. if (textField.text.length == 4 || textField.text.length == 9) {
  141. textField.text = [NSString stringWithFormat:@"%@",textField.text];
  142. textField.text = [textField.text substringToIndex:(textField.text.length-1)];
  143. }
  144. [self.youpaipverifyBtn setTitleColor:LZ273145Color forState:UIControlStateNormal];
  145. self.youpaipverifyBtn.userInteractionEnabled = NO;
  146. [self.youpaipverifyBtn setBackgroundImage:nil forState:(UIControlStateNormal)];
  147. self.youpaipphoneLength = textField.text.length;
  148. }
  149. }
  150. }
  151. - (void)youpaifverifyBtnClick{
  152. NSString *phoneText = [self.youpaipphoneTextField.text stringByReplacingOccurrencesOfString:@" " withString:@""];
  153. if ([ZCRegularHelper regularPhoneNumber:phoneText]) {//首先手机格式保证正确
  154. [LCHttpHelper requestWithURLString:PhoneCode parameters:@{@"mobile":phoneText,@"type":@"findadpwd"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  155. NSDictionary* dict = (NSDictionary*)responseObject;
  156. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  157. if (code==0) {//成功
  158. [ZCHUDHelper showTitle:@"验证码已发送"];
  159. __block int timeout=120;
  160. dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  161. dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
  162. dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
  163. dispatch_source_set_event_handler(_timer, ^{
  164. if(timeout<=0){
  165. dispatch_source_cancel(_timer);
  166. dispatch_async(dispatch_get_main_queue(), ^{
  167. [self.youpaipverifyBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
  168. self.youpaipverifyBtn.userInteractionEnabled = YES;
  169. });
  170. }else{
  171. NSString *strTime = [NSString stringWithFormat:@"%.2dS",timeout];
  172. dispatch_async(dispatch_get_main_queue(), ^{
  173. //设置界面的按钮显示 根据自己需求设置
  174. [self.youpaipverifyBtn setTitle:strTime forState:UIControlStateNormal];
  175. self.youpaipverifyBtn.userInteractionEnabled = NO;
  176. });
  177. timeout--;
  178. }
  179. });
  180. dispatch_resume(_timer);
  181. }
  182. } failure:^(NSError *error) {
  183. }];
  184. }
  185. }
  186. - (void)youpaifloginBtnClick{
  187. NSString *phoneText = [self.youpaipphoneTextField.text stringByReplacingOccurrencesOfString:@" " withString:@""];
  188. if ([ZCRegularHelper regularPhoneNumber:phoneText]) {
  189. if ([ZCRegularHelper regularVerifyCode4:self.youpaipcodeTextField.text]) {
  190. NSMutableDictionary* params = [NSMutableDictionary dictionary];
  191. [params setObject:phoneText forKey:@"mobile"];
  192. [params setObject:self.youpaipcodeTextField.text forKey:@"phone_code"];
  193. // [params setObject:self.pwdTextField.text forKey:@"password"];
  194. //password
  195. [LCHttpHelper requestWithURLString:VerifyMobileCode parameters:params needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  196. NSDictionary* dict = (NSDictionary*)responseObject;
  197. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  198. if (code==0) {//成功
  199. [_youpaipdelegate youpaifswitchYounModel:0];
  200. [self.navigationController popToRootViewControllerAnimated:YES];
  201. }
  202. } failure:^(NSError *error) {
  203. }];
  204. }
  205. }
  206. }
  207. -(void)youpaifshowBtnClick:(UIButton*)btn{
  208. if (btn.selected) {
  209. btn.selected = NO;
  210. [btn setImage:[UIImage imageNamed:@"vqu_images_sign_input3"] forState:(UIControlStateNormal)];
  211. self.youpaippwdTextField.secureTextEntry = YES;
  212. }else{
  213. btn.selected = YES;
  214. [btn setImage:[UIImage imageNamed:@"vqu_images_sign_input2"] forState:(UIControlStateNormal)];
  215. self.youpaippwdTextField.secureTextEntry = NO;
  216. }
  217. }
  218. - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
  219. [self.view endEditing:YES];
  220. }
  221. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  222. [self.view endEditing:YES];
  223. }
  224. /*
  225. #pragma mark - Navigation
  226. // In a storyboard-based application, you will often want to do a little preparation before navigation
  227. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  228. // Get the new view controller using [segue destinationViewController].
  229. // Pass the selected object to the new view controller.
  230. }
  231. */
  232. @end