// // YMAdolescentModelViewModel.m // MSYOUPAI // // Created by YoMi on 2024/2/22. // Copyright © 2024 MS. All rights reserved. // #import "YMAdolescentModelViewModel.h" @interface YMAdolescentModelViewModel () /// 青少年模式类型 @property (nonatomic, assign, readwrite) YMAdolescentModelType adolescentModelType; /// 青少年模式操作文本 @property (nonatomic, strong, readwrite) NSString *adolescentModelOperationText; /// 青少年模式密码操作文本 @property (nonatomic, strong, readwrite) NSString *adolescentModelPasswordOperationText; @end @implementation YMAdolescentModelViewModel - (void)ym_initialize{ [super ym_initialize]; self.customNavTitle = @"青少年模式"; self.adolescentModelType = [self.params integerValueForKey:ParamsCategoryType defaultValue:YMAdolescentModelTypeTips]; self.adolescentModelSettingPassword = [self.params stringValueForKey:@"settingPassword" defaultValue:@""]; switch (self.adolescentModelType) { case YMAdolescentModelTypeTips: { self.adolescentModelOperationText = @"开启青少年模式"; } break; case YMAdolescentModelTypeSettingPassword: { self.adolescentModelOperationText = @"开启青少年模式"; self.adolescentModelPasswordOperationText = @"设置密码"; } break; case YMAdolescentModelTypeConfirmPassword: { self.adolescentModelOperationText = @"开启青少年模式"; self.adolescentModelPasswordOperationText = @"确认密码"; } break; case YMAdolescentModelTypeClosePassword: { self.adolescentModelOperationText = @"关闭青少年模式"; self.adolescentModelPasswordOperationText = @"输入密码"; } break; default: break; } } - (void)openAdolescentModel{ @weakify(self) [ZCHUDHelper showWithStatus:@"正在开启中..."]; [LCHttpHelper requestWithURLString:SetAdolescent parameters:@{ @"password":self.adolescentModelConfirmPassword } needToken:YES type:HttpRequestTypePost success:^(id responseObject) { @strongify(self) NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { [ZCHUDHelper dismiss]; [LCSaveData saveYoungMode:YES]; kAppDelegate.kadolescentStatus = 1; [[YMGlobalUtils getCurrentVC].navigationController popToRootViewControllerAnimated:YES]; }else{ [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } - (void)closeAdolescentModel{ @weakify(self) [ZCHUDHelper showWithStatus:@"正在关闭中..."]; [LCHttpHelper requestWithURLString:SwitchAdolescent parameters:@{ @"is_open":@(0), @"password":self.adolescentModelConfirmPassword } needToken:YES type:HttpRequestTypePost success:^(id responseObject) { @strongify(self) NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { [ZCHUDHelper dismiss]; [LCSaveData saveYoungMode:NO]; kAppDelegate.kadolescentStatus = 0; [[YMGlobalUtils getCurrentVC].navigationController popToRootViewControllerAnimated:YES]; }else{ [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]]; } } failure:^(NSError *error) { [ZCHUDHelper dismiss]; [ZCHUDHelper showTitle:error.localizedDescription]; }]; } @end