YBYoungSetVC.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. //
  2. // YBYoungSetVC.m
  3. // YBVideo
  4. //
  5. // Created by YB007 on 2022/6/2.
  6. // Copyright © 2022 cat. All rights reserved.
  7. //
  8. #import "YBYoungSetVC.h"
  9. #import "RKCodeInputView.h"
  10. @interface YBYoungSetVC ()
  11. @property(nonatomic,strong)RKCodeInputView *codeInputView; /// 输入框
  12. @end
  13. @implementation YBYoungSetVC
  14. - (UIStatusBarStyle)preferredStatusBarStyle {
  15. if (@available(iOS 13.0,*)) {
  16. return UIStatusBarStyleDarkContent;
  17. }
  18. return UIStatusBarStyleDefault;
  19. }
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. self.titleL.textColor = RGB_COLOR(@"#323232", 1);
  23. [self.leftBtn setImage:[UIImage imageNamed:@"pubBlack_back"] forState:0];
  24. self.subNavi.backgroundColor = UIColor.whiteColor;
  25. self.view.backgroundColor = UIColor.whiteColor;
  26. UILabel *topTitleL = [[UILabel alloc]init];
  27. topTitleL.font = [UIFont boldSystemFontOfSize:18];
  28. topTitleL.textColor = RGB_COLOR(@"#323232", 1);
  29. topTitleL.textAlignment = NSTextAlignmentCenter;
  30. [self.view addSubview:topTitleL];
  31. [topTitleL mas_makeConstraints:^(MASConstraintMaker *make) {
  32. make.width.centerX.equalTo(self.view);
  33. make.height.mas_equalTo(30);
  34. make.top.equalTo(self.naviView.mas_bottom).offset(20);
  35. }];
  36. _codeInputView = [[RKCodeInputView alloc]init];
  37. _codeInputView.contentView.backgroundColor = UIColor.whiteColor;
  38. _codeInputView.secureTextEntry = YES;
  39. _codeInputView.becomeFirstRes = YES;
  40. [self.view addSubview:_codeInputView];
  41. [_codeInputView mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.width.equalTo(self.view.mas_width).multipliedBy(0.6);
  43. make.centerX.equalTo(self.view);
  44. make.height.mas_equalTo(40);
  45. make.top.equalTo(topTitleL.mas_bottom).offset(15);
  46. }];
  47. YBWeakSelf;
  48. _codeInputView.finishEvent = ^{
  49. //NSLog(@"input:%@",weakSelf.codeInputView.codeText);
  50. [weakSelf inputFinish];
  51. };
  52. // 更新布局
  53. [self.view layoutIfNeeded];
  54. [_codeInputView updateSubViews];
  55. if (_youngMode == YoungMode_First) {
  56. // 第一次
  57. self.titleL.text = YZMsg(@"设置密码");
  58. topTitleL.text = YZMsg(@"请设置新密码");
  59. }else{
  60. // 开启-关闭
  61. self.titleL.text = YZMsg(@"输入密码");
  62. topTitleL.text = YZMsg(@"请输入密码");
  63. }
  64. }
  65. -(void)inputFinish {
  66. int type = 0;
  67. int youngSwitch = 0;
  68. if (_youngMode == YoungMode_First) {
  69. // 第一次
  70. type = 1;
  71. youngSwitch = 1;
  72. }else if (_youngMode == YoungMode_FirstReset){
  73. // 首次设置后的重设
  74. type = 5;
  75. youngSwitch = 1;
  76. }else if (_youngMode == YoungMode_Open){
  77. // 开启
  78. type = 2;
  79. youngSwitch = 1;
  80. }else{
  81. // 关闭
  82. type = 3;
  83. youngSwitch = 0;
  84. }
  85. /**
  86. * type(1设置密码并开启 2开启青少年模式 3关闭青少年模式 4修改密码 5重新设置密码)
  87. * pwd当前密码 newpwd 修改新密码 newspwd 确认新密码
  88. */
  89. NSDictionary *postDic = @{
  90. @"type":@(type),
  91. @"pwd":_codeInputView.codeText,
  92. };
  93. YBWeakSelf;
  94. [YBNetworking postWithUrl:@"User.setTeenagers" Dic:postDic Suc:^(int code, id info, NSString *msg) {
  95. if (code == 0) {
  96. /// isfirst isuser msg
  97. NSDictionary *infoDic = [info firstObject];
  98. int isfirst = [minstr([infoDic valueForKey:@"isfirst"]) intValue];
  99. /// 是首次,提示是否要重设
  100. if (isfirst == 1) {
  101. [weakSelf showFirstAlertMsg:msg andUseinfo:infoDic];
  102. }else{
  103. [MBProgressHUD showError:msg];
  104. [weakSelf goRootVCYoungSwitch:youngSwitch useInfo:infoDic];
  105. }
  106. }else{
  107. [MBProgressHUD showError:msg];
  108. [_codeInputView clearText];
  109. }
  110. } Fail:^(id fail) {
  111. }];
  112. }
  113. -(void)showFirstAlertMsg:(NSString *)alertStr andUseinfo:(NSDictionary *)useInfo {
  114. NSDictionary *contentDic = @{
  115. @"title":YZMsg(@"提示"),
  116. @"msg":alertStr,
  117. @"left":YZMsg(@"重新设置"),
  118. @"right":YZMsg(@"确定"),
  119. };
  120. YBWeakSelf;
  121. [YBAlertView showAlertView:contentDic complete:^(int eventType) {
  122. dispatch_async(dispatch_get_main_queue(), ^{
  123. if (eventType == 0) {
  124. // 重新设置
  125. _youngMode = YoungMode_FirstReset;
  126. [_codeInputView clearText];
  127. }else{
  128. // 确定
  129. [weakSelf goRootVCYoungSwitch:1 useInfo:useInfo];
  130. }
  131. });
  132. }];
  133. }
  134. -(void)goRootVCYoungSwitch:(int)youngSwitch useInfo:(NSDictionary *)useInfo {
  135. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  136. [[YBYoungManager shareInstance] changeYoungSwitch:youngSwitch youngInfo:useInfo];
  137. [self.navigationController popToRootViewControllerAnimated:YES];
  138. YBTabBarController *tabbar = [PublicObj currentTabbar];
  139. [tabbar selectController:0];
  140. [tabbar goForYouViewRefresh:YES];
  141. });
  142. }
  143. @end