// // YMBindWithdrawalAccountViewModel.m // MSYOUPAI // // Created by YoMi on 2024/3/5. // Copyright © 2024 MS. All rights reserved. // #import "YMBindWithdrawalAccountViewModel.h" @interface YMBindWithdrawalAccountViewModel () /// 绑定提现账号类型 @property (nonatomic, assign, readwrite) YMBindWithdrawalAccountType bindWithdrawalAccountType; /// 保存按钮有效性 @property (nonatomic, strong, readwrite) RACSignal *validSaveSignal; /// 账号类型名称 @property (nonatomic, strong, readwrite) NSString *accountTypeName; /// 账号持有人占位符 @property (nonatomic, strong, readwrite) NSAttributedString *accountHolderPlaceholder; /// 账号占位符 @property (nonatomic, strong, readwrite) NSAttributedString *accountPlaceholder; /// 绑定账号温馨提示 @property (nonatomic, strong, readwrite) NSAttributedString *bindWithdrawalAccountWarmTips; /// 提现账号Id @property (nonatomic, assign) NSInteger withdrawalAccountId; /// 提现账号类型 @property (nonatomic, assign) NSInteger withdrawalAccountType; @end @implementation YMBindWithdrawalAccountViewModel - (void)ym_initialize{ [super ym_initialize]; self.customNavTitle = @"绑定提现账号"; self.bindWithdrawalAccountType = [self.params integerValueForKey:ParamsCategoryType defaultValue:YMBindWithdrawalAccountTypeAdd]; switch (self.bindWithdrawalAccountType) { case YMBindWithdrawalAccountTypeAdd: { [LCHttpHelper requestWithURLString:GetWithdarwStyle parameters:@{@"id":@(0),@"is_master":@(1)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; NSArray*arr = dict[@"data"][@"cardTypes"]; NSMutableArray *titleArr =[NSMutableArray new]; for (NSDictionary*typeDic in arr) { [titleArr addObject:typeDic[@"bank"]]; } NSDictionary*typeDic = arr[0]; [self customPlaceholderWithTitle:typeDic[@"bank"]withType:[typeDic[@"type"]intValue]]; } failure:^(NSError *error) { }]; } break; case YMBindWithdrawalAccountTypeEdit: { self.withdrawalAccountId = [self.params integerValueForKey:@"withdrawalAccountId" defaultValue:0]; self.withdrawalAccountType = [self.params integerValueForKey:@"withdrawalAccountType" defaultValue:0]; switch (self.withdrawalAccountType) { case 1: [self alipayPlaceholder]; break; case 2: [self wechatPlaceholder]; break; case 3: [self bankcardPlaceholder]; break; case 4: [self shandebaoPlaceholder]; break; default: break; } self.withdrawalAccountHolder = [self.params stringValueForKey:@"withdrawalAccountHolder" defaultValue:@""]; self.withdrawalAccount = [self.params stringValueForKey:@"withdrawalAccount" defaultValue:@""]; } break; default: break; } /// 保存按钮有效性 self.validSaveSignal = [[[RACSignal combineLatest:@[ RACObserve(self, withdrawalAccountHolder), RACObserve(self, withdrawalAccount) ] reduce:^(NSString *withdrawalAccountHolder, NSString *withdrawalAccount) { //是否不为空 return @(!OCStringIsEmpty(withdrawalAccountHolder) && !OCStringIsEmpty(withdrawalAccount)); }] distinctUntilChanged] takeUntil:self.rac_willDeallocSignal]; NSString *bindWithdrawalAccountWarmTipsStr = @"为了保证您能快速提现,请认真阅读以下提示哦~\n1、请填写正确【基本信息】及【账号信息】,保证账号的准确性;\n2、请确保【基本信息】及【账号信息】为同一人,否则会影响您的提现进度;\n3、如在提现过程中有任何疑问,请及时联系客服处理。"; NSMutableAttributedString *bindWithdrawalAccountWarmTipsAttributed = [[NSMutableAttributedString alloc]initWithString:bindWithdrawalAccountWarmTipsStr]; bindWithdrawalAccountWarmTipsAttributed.yy_font = LCFont(11); bindWithdrawalAccountWarmTipsAttributed.yy_color = HexColorFromRGB(0x9c9c9c); bindWithdrawalAccountWarmTipsAttributed.yy_alignment = NSTextAlignmentLeft; bindWithdrawalAccountWarmTipsAttributed.yy_lineSpacing = 5; NSString *baseInfoHighlightStr = @"【基本信息】"; NSArray *baseInfoArray = [self rangeOfSubString:baseInfoHighlightStr inString:bindWithdrawalAccountWarmTipsStr]; for (NSInteger i = 0; i < baseInfoArray.count; i++) { NSValue *value = baseInfoArray[i]; [bindWithdrawalAccountWarmTipsAttributed yy_setColor:HexColorFromRGB(0x8b7db8) range:value.rangeValue]; } NSString *accountInfoHighlightStr = @"【账号信息】"; NSArray *accountInfoArray = [self rangeOfSubString:accountInfoHighlightStr inString:bindWithdrawalAccountWarmTipsStr]; for (NSInteger i = 0; i < accountInfoArray.count; i++) { NSValue *value = accountInfoArray[i]; [bindWithdrawalAccountWarmTipsAttributed yy_setColor:HexColorFromRGB(0x8b7db8) range:value.rangeValue]; } self.bindWithdrawalAccountWarmTips = bindWithdrawalAccountWarmTipsAttributed; } - (void)openAccountTypeAlert{ [LCHttpHelper requestWithURLString:GetWithdarwStyle parameters:@{@"id":@(0),@"is_master":@(1)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; NSArray*arr = dict[@"data"][@"cardTypes"]; NSMutableArray *titleArr =[NSMutableArray new]; for (NSDictionary*typeDic in arr) { [titleArr addObject:typeDic[@"bank"]]; } YMSheetPopupView *customView = [[YMSheetPopupView alloc]init]; [customView configutationWithItemList:titleArr]; 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.selectIndexBlock = ^(NSInteger index) { @strongify(popupView) [popupView dismissWithStyle:YMDismissStyleSmoothToBottom duration:2.0]; NSDictionary*typeDic = arr[index]; [self customPlaceholderWithTitle:typeDic[@"bank"]withType:[typeDic[@"type"]intValue]]; }; customView.closeBlock = ^{ @strongify(popupView) [popupView dismissWithStyle:YMDismissStyleSmoothToBottom duration:2.0]; }; [popupView pop]; } failure:^(NSError *error) { }]; } - (void)customPlaceholderWithTitle:(NSString*)title withType:(NSInteger)type{ self.accountTypeName = title; NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init]; style.minimumLineHeight = 0; NSMutableAttributedString *accountHolderPlaceholderAttributed = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"请输入您的%@姓名",title]]; accountHolderPlaceholderAttributed.yy_paragraphStyle = style; accountHolderPlaceholderAttributed.yy_font = LCFont(12); accountHolderPlaceholderAttributed.yy_color = HexColorFromRGB(0xADB0BC); self.accountHolderPlaceholder = accountHolderPlaceholderAttributed; NSMutableAttributedString *accountPlaceholderAttributed = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"请输入您的%@账号",title]]; accountPlaceholderAttributed.yy_paragraphStyle = style; accountPlaceholderAttributed.yy_font = LCFont(12); accountPlaceholderAttributed.yy_color = HexColorFromRGB(0xADB0BC); self.accountPlaceholder = accountPlaceholderAttributed; self.withdrawalAccountType = type; } - (void)alipayPlaceholder{ self.accountTypeName = @"支付宝"; NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init]; style.minimumLineHeight = 0; NSMutableAttributedString *accountHolderPlaceholderAttributed = [[NSMutableAttributedString alloc]initWithString:@"请输入您的支付宝姓名"]; accountHolderPlaceholderAttributed.yy_paragraphStyle = style; accountHolderPlaceholderAttributed.yy_font = LCFont(12); accountHolderPlaceholderAttributed.yy_color = HexColorFromRGB(0xADB0BC); self.accountHolderPlaceholder = accountHolderPlaceholderAttributed; NSMutableAttributedString *accountPlaceholderAttributed = [[NSMutableAttributedString alloc]initWithString:@"请输入您的支付宝账号"]; accountPlaceholderAttributed.yy_paragraphStyle = style; accountPlaceholderAttributed.yy_font = LCFont(12); accountPlaceholderAttributed.yy_color = HexColorFromRGB(0xADB0BC); self.accountPlaceholder = accountPlaceholderAttributed; self.withdrawalAccountType = 1; } - (void)wechatPlaceholder{ self.accountTypeName = @"微信"; NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init]; style.minimumLineHeight = 0; NSMutableAttributedString *accountHolderPlaceholderAttributed = [[NSMutableAttributedString alloc]initWithString:@"请输入您的微信姓名"]; accountHolderPlaceholderAttributed.yy_paragraphStyle = style; accountHolderPlaceholderAttributed.yy_font = LCFont(12); accountHolderPlaceholderAttributed.yy_color = HexColorFromRGB(0xADB0BC); self.accountHolderPlaceholder = accountHolderPlaceholderAttributed; NSMutableAttributedString *accountPlaceholderAttributed = [[NSMutableAttributedString alloc]initWithString:@"请输入您的微信账号"]; accountPlaceholderAttributed.yy_paragraphStyle = style; accountPlaceholderAttributed.yy_font = LCFont(12); accountPlaceholderAttributed.yy_color = HexColorFromRGB(0xADB0BC); self.accountPlaceholder = accountPlaceholderAttributed; self.withdrawalAccountType = 2; } - (void)bankcardPlaceholder{ self.accountTypeName = @"银行卡"; NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init]; style.minimumLineHeight = 0; NSMutableAttributedString *accountHolderPlaceholderAttributed = [[NSMutableAttributedString alloc]initWithString:@"请输入您的银行卡姓名"]; accountHolderPlaceholderAttributed.yy_paragraphStyle = style; accountHolderPlaceholderAttributed.yy_font = LCFont(12); accountHolderPlaceholderAttributed.yy_color = HexColorFromRGB(0xADB0BC); self.accountHolderPlaceholder = accountHolderPlaceholderAttributed; NSMutableAttributedString *accountPlaceholderAttributed = [[NSMutableAttributedString alloc]initWithString:@"请输入您的银行卡账号"]; accountPlaceholderAttributed.yy_paragraphStyle = style; accountPlaceholderAttributed.yy_font = LCFont(12); accountPlaceholderAttributed.yy_color = HexColorFromRGB(0xADB0BC); self.accountPlaceholder = accountPlaceholderAttributed; self.withdrawalAccountType = 3; } - (void)shandebaoPlaceholder{ self.accountTypeName = @"杉德宝"; NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init]; style.minimumLineHeight = 0; NSMutableAttributedString *accountHolderPlaceholderAttributed = [[NSMutableAttributedString alloc]initWithString:@"请输入您的杉德宝姓名"]; accountHolderPlaceholderAttributed.yy_paragraphStyle = style; accountHolderPlaceholderAttributed.yy_font = LCFont(12); accountHolderPlaceholderAttributed.yy_color = HexColorFromRGB(0xADB0BC); self.accountHolderPlaceholder = accountHolderPlaceholderAttributed; NSMutableAttributedString *accountPlaceholderAttributed = [[NSMutableAttributedString alloc]initWithString:@"请输入您的杉德宝账号"]; accountPlaceholderAttributed.yy_paragraphStyle = style; accountPlaceholderAttributed.yy_font = LCFont(12); accountPlaceholderAttributed.yy_color = HexColorFromRGB(0xADB0BC); self.accountPlaceholder = accountPlaceholderAttributed; self.withdrawalAccountType = 4; } #pragma mark - 获取字符串的所在位置 //获取一个字符在字符串中出现的所有位置 返回一个被NSValue包装的NSRange数组 - (NSArray *)rangeOfSubString:(NSString *)subStr inString:(NSString *)string { if (subStr == nil && [subStr isEqualToString:@""]) { return nil; } NSMutableArray *rangeArray = [NSMutableArray array]; NSString *string1 = [string stringByAppendingString:subStr]; NSString *temp; for (int i = 0; i < string.length; i ++) { temp = [string1 substringWithRange:NSMakeRange(i, subStr.length)]; if ([temp isEqualToString:subStr]) { NSRange range = {i,subStr.length}; [rangeArray addObject:[NSValue valueWithRange:range]]; } } return rangeArray; } - (void)submitBindWithdrawalAccount{ @weakify(self) [ZCHUDHelper showWithStatus:@"提交中..."]; NSMutableDictionary *params = [NSMutableDictionary dictionary]; if (self.bindWithdrawalAccountType == YMBindWithdrawalAccountTypeEdit) { [params setObject:@(self.withdrawalAccountId) forKey:@"id"]; } [params setObject:@(self.withdrawalAccountType) forKey:@"card_type"]; [params setObject:self.withdrawalAccount forKey:@"card_account"]; [params setObject:self.withdrawalAccountHolder forKey:@"card_name"]; [params setObject:@(1) forKey:@"is_master"]; [LCHttpHelper requestWithURLString:BindWithdrawalAccount parameters:params 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.bindWithdrawalAccountBlock) { self.bindWithdrawalAccountBlock(); } dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [[YMGlobalUtils getCurrentVC].navigationController popViewControllerAnimated:YES]; }); }else{ [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } @end