YMAdolescentModelViewModel.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // YMAdolescentModelViewModel.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/22.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMAdolescentModelViewModel.h"
  9. @interface YMAdolescentModelViewModel ()
  10. /// 青少年模式类型
  11. @property (nonatomic, assign, readwrite) YMAdolescentModelType adolescentModelType;
  12. /// 青少年模式操作文本
  13. @property (nonatomic, strong, readwrite) NSString *adolescentModelOperationText;
  14. /// 青少年模式密码操作文本
  15. @property (nonatomic, strong, readwrite) NSString *adolescentModelPasswordOperationText;
  16. @end
  17. @implementation YMAdolescentModelViewModel
  18. - (void)ym_initialize{
  19. [super ym_initialize];
  20. self.customNavTitle = @"青少年模式";
  21. self.adolescentModelType = [self.params integerValueForKey:ParamsCategoryType defaultValue:YMAdolescentModelTypeTips];
  22. self.adolescentModelSettingPassword = [self.params stringValueForKey:@"settingPassword" defaultValue:@""];
  23. switch (self.adolescentModelType) {
  24. case YMAdolescentModelTypeTips:
  25. {
  26. self.adolescentModelOperationText = @"开启青少年模式";
  27. }
  28. break;
  29. case YMAdolescentModelTypeSettingPassword:
  30. {
  31. self.adolescentModelOperationText = @"开启青少年模式";
  32. self.adolescentModelPasswordOperationText = @"设置密码";
  33. }
  34. break;
  35. case YMAdolescentModelTypeConfirmPassword:
  36. {
  37. self.adolescentModelOperationText = @"开启青少年模式";
  38. self.adolescentModelPasswordOperationText = @"确认密码";
  39. }
  40. break;
  41. case YMAdolescentModelTypeClosePassword:
  42. {
  43. self.adolescentModelOperationText = @"关闭青少年模式";
  44. self.adolescentModelPasswordOperationText = @"输入密码";
  45. }
  46. break;
  47. default:
  48. break;
  49. }
  50. }
  51. - (void)openAdolescentModel{
  52. @weakify(self)
  53. [ZCHUDHelper showWithStatus:@"正在开启中..."];
  54. [LCHttpHelper requestWithURLString:SetAdolescent parameters:@{
  55. @"password":self.adolescentModelConfirmPassword
  56. } needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  57. @strongify(self)
  58. NSDictionary* dict = (NSDictionary*)responseObject;
  59. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  60. if (code == 0) {
  61. [ZCHUDHelper dismiss];
  62. [LCSaveData saveYoungMode:YES];
  63. kAppDelegate.kadolescentStatus = 1;
  64. [[YMGlobalUtils getCurrentVC].navigationController popToRootViewControllerAnimated:YES];
  65. }else{
  66. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  67. }
  68. } failure:^(NSError *error) {
  69. [ZCHUDHelper showTitle:error.localizedDescription];
  70. }];
  71. }
  72. - (void)closeAdolescentModel{
  73. @weakify(self)
  74. [ZCHUDHelper showWithStatus:@"正在关闭中..."];
  75. [LCHttpHelper requestWithURLString:SwitchAdolescent parameters:@{
  76. @"is_open":@(0),
  77. @"password":self.adolescentModelConfirmPassword
  78. } needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  79. @strongify(self)
  80. NSDictionary* dict = (NSDictionary*)responseObject;
  81. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  82. if (code == 0) {
  83. [ZCHUDHelper dismiss];
  84. [LCSaveData saveYoungMode:NO];
  85. kAppDelegate.kadolescentStatus = 0;
  86. [[YMGlobalUtils getCurrentVC].navigationController popToRootViewControllerAnimated:YES];
  87. }else{
  88. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  89. }
  90. } failure:^(NSError *error) {
  91. [ZCHUDHelper dismiss];
  92. [ZCHUDHelper showTitle:error.localizedDescription];
  93. }];
  94. }
  95. @end