// // YMFeesSettingViewModel.m // MSYOUPAI // // Created by YoMi on 2024/2/23. // Copyright © 2024 MS. All rights reserved. // #import "YMFeesSettingViewModel.h" #import "YMFeesSettingInfoModel.h" #import "YMFeesSettingPriceModel.h" @interface YMFeesSettingViewModel () /// 列表数据 @property (nonatomic, strong, readwrite) NSArray *listDataArray; /// 说明提示 @property (nonatomic, strong, readwrite) NSAttributedString *notesTipsAttributed; /// 收费设置功能操作 @property (nonatomic, strong, readwrite) RACSubject *feesSettingFunctionsOperationSubject; /// 消息价格数组 @property (nonatomic, strong) NSArray *messagePriceArr; /// 语音价格数组 @property (nonatomic, strong) NSArray *voicePriceArr; /// 视频价格数组 @property (nonatomic, strong) NSArray *videoPriceArr; /// 选中价格 @property (nonatomic, strong) YMFeesPriceModel *feesPriceModel; @end @implementation YMFeesSettingViewModel - (void)ym_initialize{ [super ym_initialize]; self.customNavTitle = @"收费设置"; @weakify(self) [[self.feesSettingFunctionsOperationSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id _Nullable value) { @strongify(self) switch ([value intValue]) { case YMFeesSettingFunctionsTypeMessagePrice: { [self openMessagePricePickerPopupView]; } break; case YMFeesSettingFunctionsTypeVoicePrice: { [self openVoicePricePickerPopupView]; } break; case YMFeesSettingFunctionsTypeVideoPrice: { [self openVideoPricePickerPopupView]; } break; default: break; } }]; } - (void)getFeesSettingBaseInfoData{ @weakify(self) [ZCHUDHelper showWithStatus:@"加载中..."]; [LCHttpHelper requestWithURLString:AnchorGetPrice parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { @strongify(self) NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { [ZCHUDHelper dismiss]; YMFeesSettingInfoModel *mdoel = [YMFeesSettingInfoModel yy_modelWithJSON:[dict dictionaryValueForKey:@"data" defaultValue:@{}]]; self.listDataArray = [@[ // @{ // @"title":@"消息价格", // @"content":mdoel.msg_price, // ParamsCategoryType:@(YMFeesSettingFunctionsTypeMessagePrice), // }, @{ @"title":@"视频价格设置", @"content":mdoel.video_price, ParamsCategoryType:@(YMFeesSettingFunctionsTypeVideoPrice), }, ].rac_sequence map:^(NSDictionary * _Nullable dic) { YMFeesSettingCellViewModel *viewModel = [[YMFeesSettingCellViewModel alloc]initWithParams:@{ ParamsModel:dic }]; return viewModel; }].array; NSString *notesTipsStr = @"收费设置说明:1、对方主动给你发文字消息或与你进行视频/语音通话,你的收费依据本页设置。2、互相关注后,双方发文字消息免费。3、星级越高,可设置的价格越高,查看如何提高星级"; NSMutableAttributedString *notesTipsAttributed = [[NSMutableAttributedString alloc]initWithString:notesTipsStr]; notesTipsAttributed.yy_font = LCFont(11); notesTipsAttributed.yy_color = HexColorFromRGB(0x9c9c9c); notesTipsAttributed.yy_lineSpacing = 3; notesTipsAttributed.yy_alignment = NSTextAlignmentLeft; //设置高亮色和点击事件 [notesTipsAttributed yy_setTextHighlightRange:[notesTipsStr rangeOfString:@"如何提高星级"] color:HexColorFromRGB(0xB26AFD) backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) { YMWebArticleViewModel *webArticleVM = [[YMWebArticleViewModel alloc]initWithParams:@{ ParamsUrl:[YMGlobalUtils shared].increaseStarRatingUrl }]; [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_WEB_ARTICLE) withUserInfo:@{ RouterViewModel:webArticleVM } completion:nil]; }]; self.notesTipsAttributed = notesTipsAttributed; [self.refreshUISubject sendNext:@(YMRefreshUI)]; }else{ [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } - (void)getFeesSettingPriceInfoData{ [LCHttpHelper requestWithURLString:GetAnchorSetting parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { YMFeesSettingPriceModel *model = [YMFeesSettingPriceModel yy_modelWithJSON:[dict dictionaryValueForKey:@"data" defaultValue:@{}]]; self.messagePriceArr = model.chat; self.voicePriceArr = model.voice; self.videoPriceArr = model.video; }else{ [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } - (void)settingFeesPriceDataWithPriceId:(NSInteger)priceId ofType:(NSInteger)type{ ///1语音 2视频 5文字 [LCHttpHelper requestWithURLString:SetSkillPrice parameters:@{ @"price_id":@(priceId), @"type":@(type) } needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { [ZCHUDHelper showTitle:@"价格设置成功"]; self.listDataArray = [self.listDataArray.rac_sequence map:^(YMFeesSettingCellViewModel * _Nullable viewModel) { if (type == 5 && viewModel.feesSettingFunctionsType == YMFeesSettingFunctionsTypeMessagePrice) { viewModel.feesSettingContent = stringFormat(@"%ld%@/条",self.feesPriceModel.coins,self.feesPriceModel.content); } else if (type == 1 && viewModel.feesSettingFunctionsType == YMFeesSettingFunctionsTypeVoicePrice) { viewModel.feesSettingContent = stringFormat(@"%ld%@/分钟",self.feesPriceModel.coins,self.feesPriceModel.content); }else if (type == 2 && viewModel.feesSettingFunctionsType == YMFeesSettingFunctionsTypeVideoPrice) { viewModel.feesSettingContent = stringFormat(@"%ld%@/分钟",self.feesPriceModel.coins,self.feesPriceModel.content); } return viewModel; }].array; [self.refreshUISubject sendNext:@(YMRefreshUI)]; }else{ [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } - (void)openMessagePricePickerPopupView{ NSArray *tempMassagePriceArr = [self.messagePriceArr.rac_sequence map:^(YMFeesPriceModel * _Nullable value) { return @{ @"rowId":@(value.price_id), @"rowName":stringFormat(@"%ld%@",value.coins,value.content) }; }].array; YMPickerViewModel *messagePricePickerVM = [[YMPickerViewModel alloc]initWithParams:@{ @"componentDataSource":@[ @{ @"componentName":@"消息价格", @"rowDataSource":tempMassagePriceArr } ] }]; YMPickerPopupView *customView = [[YMPickerPopupView alloc]init]; [customView ym_bindViewModel:messagePricePickerVM]; customView.titleText = @"请选择消息价格"; YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleSmoothFromBottom dismissStyle:YMDismissStyleSmoothToBottom]; popupView.priority = 999; popupView.cornerRadius = adapt(10); popupView.rectCorners = UIRectCornerTopLeft|UIRectCornerTopRight; popupView.positionStyle = YMPositionStyleBottom; popupView.isClickBgDismiss = YES; popupView.isHideBg = NO; popupView.bgAlpha = 0.5; @weakify(popupView) customView.buttonBlock = ^(BOOL isConfirm, NSArray * _Nonnull currentSelectedDataArray) { @strongify(popupView) if (isConfirm) { NSLog(@"选中消息价格值:%@",currentSelectedDataArray); NSInteger currentSelectedRowIndex = [currentSelectedDataArray[0] integerValueForKey:@"currentSelectedRowIndex" defaultValue:0]; self.feesPriceModel = self.messagePriceArr[currentSelectedRowIndex]; [self settingFeesPriceDataWithPriceId:self.feesPriceModel.price_id ofType:5]; } [popupView dismissWithStyle:YMDismissStyleSmoothToBottom duration:2.0]; }; [popupView pop]; } - (void)openVoicePricePickerPopupView{ NSArray *tempVoicePriceArr = [self.voicePriceArr.rac_sequence map:^(YMFeesPriceModel * _Nullable value) { return @{ @"rowId":@(value.price_id), @"rowName":stringFormat(@"%ld%@",value.coins,value.content) }; }].array; YMPickerViewModel *voicePricePickerVM = [[YMPickerViewModel alloc]initWithParams:@{ @"componentDataSource":@[ @{ @"componentName":@"语音价格", @"rowDataSource":tempVoicePriceArr } ] }]; YMPickerPopupView *customView = [[YMPickerPopupView alloc]init]; [customView ym_bindViewModel:voicePricePickerVM]; customView.titleText = @"请选择语音价格"; YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleSmoothFromBottom dismissStyle:YMDismissStyleSmoothToBottom]; popupView.priority = 999; popupView.cornerRadius = adapt(10); popupView.rectCorners = UIRectCornerTopLeft|UIRectCornerTopRight; popupView.positionStyle = YMPositionStyleBottom; popupView.isClickBgDismiss = YES; popupView.isHideBg = NO; popupView.bgAlpha = 0.5; @weakify(popupView) customView.buttonBlock = ^(BOOL isConfirm, NSArray * _Nonnull currentSelectedDataArray) { @strongify(popupView) if (isConfirm) { NSLog(@"选中语音价格值:%@",currentSelectedDataArray); NSInteger currentSelectedRowIndex = [currentSelectedDataArray[0] integerValueForKey:@"currentSelectedRowIndex" defaultValue:0]; self.feesPriceModel = self.voicePriceArr[currentSelectedRowIndex]; [self settingFeesPriceDataWithPriceId:self.feesPriceModel.price_id ofType:1]; } [popupView dismissWithStyle:YMDismissStyleSmoothToBottom duration:2.0]; }; [popupView pop]; } - (void)openVideoPricePickerPopupView{ NSArray *tempVideoPriceArr = [self.videoPriceArr.rac_sequence map:^(YMFeesPriceModel * _Nullable value) { return @{ @"rowId":@(value.price_id), @"rowName":stringFormat(@"%ld%@",value.coins,value.content) }; }].array; YMPickerViewModel *videoPricePickerVM = [[YMPickerViewModel alloc]initWithParams:@{ @"componentDataSource":@[ @{ @"componentName":@"视频价格", @"rowDataSource":tempVideoPriceArr } ] }]; YMPickerPopupView *customView = [[YMPickerPopupView alloc]init]; [customView ym_bindViewModel:videoPricePickerVM]; customView.titleText = @"请选择视频价格"; YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleSmoothFromBottom dismissStyle:YMDismissStyleSmoothToBottom]; popupView.priority = 999; popupView.cornerRadius = adapt(10); popupView.rectCorners = UIRectCornerTopLeft|UIRectCornerTopRight; popupView.positionStyle = YMPositionStyleBottom; popupView.isClickBgDismiss = YES; popupView.isHideBg = NO; popupView.bgAlpha = 0.5; @weakify(popupView) customView.buttonBlock = ^(BOOL isConfirm, NSArray * _Nonnull currentSelectedDataArray) { @strongify(popupView) if (isConfirm) { NSLog(@"选中视频价格值:%@",currentSelectedDataArray); NSInteger currentSelectedRowIndex = [currentSelectedDataArray[0] integerValueForKey:@"currentSelectedRowIndex" defaultValue:0]; self.feesPriceModel = self.videoPriceArr[currentSelectedRowIndex]; [self settingFeesPriceDataWithPriceId:self.feesPriceModel.price_id ofType:2]; } [popupView dismissWithStyle:YMDismissStyleSmoothToBottom duration:2.0]; }; [popupView pop]; } - (RACSubject *)feesSettingFunctionsOperationSubject{ if (!_feesSettingFunctionsOperationSubject) { _feesSettingFunctionsOperationSubject = [RACSubject subject]; } return _feesSettingFunctionsOperationSubject; } @end