AccountDeleteViewController.m 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. //
  2. // AccountDeleteViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by 王智 on 2022/7/12.
  6. //
  7. #import "AccountDeleteViewController.h"
  8. #import "DeleteAccountBodyView.h"
  9. #import "VeriCheckView.h"
  10. #import "LoginViewController.h"
  11. #import "AppDelegate.h"
  12. #import "CustomNavViewController.h"
  13. #import "JPUSHService.h"
  14. #import "UserInfoManager.h"
  15. #import "GroupQuitAlert.h"
  16. #import "KSDeleteFailedAlertView.h"
  17. @interface AccountDeleteViewController ()
  18. {
  19. NSTimer *_time;
  20. int _count;
  21. }
  22. @property (nonatomic, strong) DeleteAccountBodyView *bodyView;
  23. @property (nonatomic, strong) GroupQuitAlert *alertView;
  24. @property (nonatomic, strong) KSDeleteFailedAlertView *failAlert;
  25. @end
  26. @implementation AccountDeleteViewController
  27. - (void)viewDidLoad {
  28. [super viewDidLoad];
  29. // Do any additional setup after loading the view.
  30. [self allocTitle:@"注销账号"];
  31. [self configUI];
  32. }
  33. - (void)configUI {
  34. self.bodyView = [DeleteAccountBodyView shareInstance];
  35. [self.scrollView addSubview:_bodyView];
  36. [_bodyView mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.left.right.mas_equalTo(self.view);
  38. make.top.mas_equalTo(self.scrollView.mas_top);
  39. make.bottom.mas_equalTo(self.scrollView.mas_bottom);
  40. make.height.mas_equalTo(KPortraitHeight - kNaviBarHeight);
  41. }];
  42. MJWeakSelf;
  43. [_bodyView deleteAccountCallback:^(DELETEACCOUNT action, NSDictionary * _Nonnull parm) {
  44. [weakSelf operationWithAction:action parm:parm];
  45. }];
  46. self.bodyView.lineView.backgroundColor = CLIENT_THEMECOLOR;
  47. [self.bodyView.codeButton setTitleColor:CLIENT_THEMECOLOR forState:UIControlStateNormal];
  48. if ([UserDefault(TENANT_ID) integerValue] > 0) {
  49. CAGradientLayer *colorLayer = [UIView createGradientLayerFromColor:HexRGB(0xFF204B) startPoint:CGPointMake(1, 0.5) endColor:HexRGB(0xFE5B71) endPoint:CGPointMake(0, 0.5) bounds:CGRectMake(0, 0, KPortraitWidth - 25 *2, 44)];
  50. [self.bodyView.sureButton.layer addSublayer:colorLayer];
  51. }
  52. }
  53. - (void)operationWithAction:(DELETEACCOUNT)action parm:(NSDictionary *)parm {
  54. if (action == DELETEACCOUNT_CODE) {
  55. // 图形化验证
  56. [self veriCheckWithParm:parm];
  57. }
  58. else if (action == DELETEACCOUNT_SURE) {
  59. MJWeakSelf;
  60. self.alertView = [GroupQuitAlert shareInstance];
  61. [self.alertView configTitle:@"提示" desc:@"注销账号后您所有的留存信息将被清空且无法恢复,请谨慎操作" callback:^(BOOL isSure) {
  62. if (isSure) {
  63. [weakSelf deleteAccount:[parm ks_stringValueForKey:@"code"]];
  64. }
  65. }];
  66. [self.alertView showAlert];
  67. }
  68. }
  69. #pragma mark ----- 删除账号
  70. - (void)deleteAccount:(NSString *)code {
  71. [LOADING_MANAGER showHUD];
  72. [KSNetworkingManager logoffRequest:KS_GET smsCode:code success:^(NSDictionary * _Nonnull dic) {
  73. [LOADING_MANAGER removeHUD];
  74. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  75. [LOADING_MANAGER KSShowMsg:@"注销成功,感谢您的使用" promptCompletion:^{
  76. [self successDeleteBack];
  77. }];
  78. }
  79. else if ([dic ks_integerValueForKey:@"code"] == 5201) {
  80. [self showFailAlert:@[]];
  81. }
  82. else {
  83. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  84. }
  85. } faliure:^(NSError * _Nonnull error) {
  86. [LOADING_MANAGER removeHUD];
  87. }];
  88. }
  89. - (void)showFailAlert:(NSArray *)messageList {
  90. self.failAlert = [KSDeleteFailedAlertView shareIntance];
  91. [self.failAlert configWithSource:messageList];
  92. [self.failAlert showAlert];
  93. }
  94. - (void)successDeleteBack {
  95. [APPLOGIN_MANAGER logoutActionWithMsg:@""];
  96. }
  97. #pragma mark --- 验证码
  98. - (void)veriCheckWithParm:(NSDictionary *)parm {
  99. NSString *phoneNo = [parm ks_stringValueForKey:@"phone"];
  100. // 图形化验证
  101. VeriCheckView *view = [VeriCheckView shareInstanceShowInView:self.scrollView];
  102. __weak typeof(view) weakView = view;
  103. [view showViewCallback:^(NSDictionary * _Nonnull parm) {
  104. [self veriImageCodeWithParm:parm checkView:weakView];
  105. }];
  106. [view disPlayImageWithPhone:phoneNo];
  107. }
  108. // 发送短信 校验图形验证码
  109. - (void)veriImageCodeWithParm:(NSDictionary *)parm checkView:(VeriCheckView *)checkView {
  110. [LOADING_MANAGER showHUD];
  111. [KSNetworkingManager sendSmsRequest:KS_POST mobile:[parm ks_stringValueForKey:@"phone"] type:@"LOGOFF" code:[parm ks_stringValueForKey:@"code"] success:^(NSDictionary * _Nonnull dic) {
  112. [LOADING_MANAGER removeHUD];
  113. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  114. [checkView hiddView];
  115. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"验证码已发送"];
  116. [self codeButtonCountDown];
  117. }
  118. else {
  119. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  120. }
  121. } faliure:^(NSError * _Nonnull error) {
  122. [LOADING_MANAGER removeHUD];
  123. }];
  124. }
  125. - (void)codeButtonCountDown {
  126. _bodyView.codeButton.userInteractionEnabled = NO;
  127. [_bodyView.codeButton setTitleColor:HexRGB(0xe5e5e5) forState:UIControlStateNormal];
  128. __weak typeof(self) weakSelf = self;
  129. _time = [NSTimer scheduledTimerWithTimeInterval:1 target:weakSelf selector:@selector(buttonChangeAction) userInfo:nil repeats:YES];
  130. [[NSRunLoop mainRunLoop] addTimer:_time forMode:NSRunLoopCommonModes];
  131. _count = 59;
  132. }
  133. - (void)clearButtonState {
  134. [_time invalidate];
  135. _time = nil;
  136. _count = 0;
  137. [_bodyView.codeButton setTitle:@"获取验证码" forState:UIControlStateNormal];
  138. [_bodyView.codeButton setTitleColor:CLIENT_THEMECOLOR forState:UIControlStateNormal];
  139. _bodyView.codeButton.userInteractionEnabled = YES;
  140. }
  141. #pragma mark ---- 验证码按钮状态
  142. - (void)buttonChangeAction {
  143. _bodyView.codeButton.userInteractionEnabled = NO;
  144. NSString *title = [NSString stringWithFormat:@"%ds",_count];
  145. [_bodyView.codeButton setTitle:title forState:UIControlStateNormal];
  146. _count--;
  147. if(_count == -1){
  148. [_time invalidate];
  149. _time = nil;
  150. [_bodyView.codeButton setTitle:@"获取验证码" forState:UIControlStateNormal];
  151. [_bodyView.codeButton setTitleColor:CLIENT_THEMECOLOR forState:UIControlStateNormal];
  152. _bodyView.codeButton.userInteractionEnabled = YES;
  153. }
  154. }
  155. - (void)dealloc {
  156. [_time invalidate];
  157. _time = nil;
  158. }
  159. /*
  160. #pragma mark - Navigation
  161. // In a storyboard-based application, you will often want to do a little preparation before navigation
  162. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  163. // Get the new view controller using [segue destinationViewController].
  164. // Pass the selected object to the new view controller.
  165. }
  166. */
  167. @end