// // YMGreetingSettingCellViewModel.m // MSYOUPAI // // Created by YoMi on 2024/2/24. // Copyright © 2024 MS. All rights reserved. // #import "YMGreetingSettingCellViewModel.h" #import "YMGreetingSettingModel.h" @interface YMGreetingSettingCellViewModel () /// 是否是审核状态 @property (nonatomic, assign, readwrite) BOOL isReviewStatus; /// 是否是审核失败 @property (nonatomic, assign, readwrite) BOOL isReviewFailure; /// 打招呼模板审核状态图标 @property (nonatomic, strong, readwrite) UIImage *greetingTemplateReviewStatusIcon; /// 是否是默认打招呼模板 @property (nonatomic, assign, readwrite) BOOL isDefaultGreetingTemplate; /// 打招呼模板名称 @property (nonatomic, strong, readwrite) NSString *greetingTemplateName; /// 打招呼模板文本 @property (nonatomic, strong, readwrite) NSString *greetingTemplateText; /// 打招呼模板图片 @property (nonatomic, strong, readwrite) NSString *greetingTemplateImage; /// 打招呼模板语音 @property (nonatomic, strong, readwrite) NSString *greetingTemplateVoice; /// 打招呼模板语音秒数 @property (nonatomic, assign, readwrite) NSInteger greetingTemplateVoiceSeconds; /// 打招呼模板Id @property (nonatomic, assign) NSInteger greetingId; @end @implementation YMGreetingSettingCellViewModel - (void)ym_initialize{ [super ym_initialize]; if ([self.params[ParamsModel] isKindOfClass:[YMGreetingSettingModel class]]) { YMGreetingSettingModel *model = self.params[ParamsModel]; self.greetingId = model.greeting_id; switch (model.status) { case 0: { self.isReviewStatus = YES; self.isReviewFailure = NO; self.greetingTemplateReviewStatusIcon = ImageByName(@"ym_greeting_setting_reviewing_icon"); } break; case 1: { self.isReviewStatus = NO; self.isReviewFailure = NO; } break; case 2: { self.isReviewStatus = YES; self.isReviewFailure = YES; self.greetingTemplateReviewStatusIcon = ImageByName(@"ym_greeting_setting_review_failure_icon"); } break; default: break; } self.isDefaultGreetingTemplate = model.is_default ? YES : NO; self.greetingTemplateName = OCStringIsEmpty(model.name) ? @"我的模板" : model.name; self.greetingTemplateText = model.title; self.greetingTemplateImage = model.file; self.greetingTemplateVoice = model.voice_file; self.greetingTemplateVoiceSeconds = model.len; } } - (void)updateGreetingTemplateName{ YMInputPopupView *customView = [[YMInputPopupView alloc]init]; customView.titleText = @"模板备注"; customView.textAlignment = NSTextAlignmentCenter; [customView configutationWithContentText:self.greetingTemplateText ofInputHeight:adapt(30) IsHideTitle:NO IsHideSingleButton:YES]; YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade]; popupView.priority = 999; popupView.cornerRadius = adapt(10); popupView.rectCorners = UIRectCornerAllCorners; popupView.positionStyle = YMPositionStyleCenter; popupView.isHideBg = NO; popupView.bgAlpha = 0.3; @weakify(popupView) customView.buttonBlock = ^(BOOL isConfirm, NSString * _Nonnull contentText) { @strongify(popupView) if (isConfirm) { @weakify(self) [ZCHUDHelper showWithStatus:@"修改中..."]; [LCHttpHelper requestWithURLString:api_greetset_name parameters:@{ @"id":@(self.greetingId), @"name":contentText } needToken:YES type:HttpRequestTypePost success:^(id responseObject) { @strongify(self) NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { [ZCHUDHelper dismiss]; if (self.refreshGreetingSettingListBlock) { self.refreshGreetingSettingListBlock(); } }else{ [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } [popupView dismissWithStyle:YMDismissStyleFade duration:2.0]; }; [popupView pop]; } - (void)deleteGreetingTemplate{ YMTipsPopupView *customView = [[YMTipsPopupView alloc]init]; [customView configutationWithTips:@"确定删除当前模板?" TipsAlignment:NSTextAlignmentCenter IsHideTitle:YES IsHideSingleButton:YES]; YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade]; popupView.priority = 999; popupView.cornerRadius = adapt(10); popupView.rectCorners = UIRectCornerAllCorners; popupView.positionStyle = YMPositionStyleCenter; popupView.isHideBg = NO; popupView.bgAlpha = 0.3; @weakify(popupView) customView.buttonBlock = ^(BOOL isConfirm) { @strongify(popupView) if (isConfirm) { @weakify(self) [ZCHUDHelper showWithStatus:@"删除中..."]; [LCHttpHelper requestWithURLString:api_greetdelete_new parameters:@{ @"id":@(self.greetingId) } needToken:YES type:HttpRequestTypePost success:^(id responseObject) { @strongify(self) NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { [ZCHUDHelper dismiss]; if (self.refreshGreetingSettingListBlock) { self.refreshGreetingSettingListBlock(); } }else{ [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } [popupView dismissWithStyle:YMDismissStyleFade duration:2.0]; }; [popupView pop]; } - (void)defualGreetingTemplate{ if (!self.isDefaultGreetingTemplate) { @weakify(self) [ZCHUDHelper showWithStatus:@"设置中..."]; [LCHttpHelper requestWithURLString:api_greetset_default parameters:@{ @"id":@(self.greetingId) } needToken:YES type:HttpRequestTypePost success:^(id responseObject) { @strongify(self) NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { [ZCHUDHelper dismiss]; if (self.refreshGreetingSettingListBlock) { self.refreshGreetingSettingListBlock(); } }else{ [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } } @end