YMBindWithdrawalAccountViewModel.m 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. //
  2. // YMBindWithdrawalAccountViewModel.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/3/5.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMBindWithdrawalAccountViewModel.h"
  9. @interface YMBindWithdrawalAccountViewModel ()
  10. /// 绑定提现账号类型
  11. @property (nonatomic, assign, readwrite) YMBindWithdrawalAccountType bindWithdrawalAccountType;
  12. /// 保存按钮有效性
  13. @property (nonatomic, strong, readwrite) RACSignal *validSaveSignal;
  14. /// 账号类型名称
  15. @property (nonatomic, strong, readwrite) NSString *accountTypeName;
  16. /// 账号持有人占位符
  17. @property (nonatomic, strong, readwrite) NSAttributedString *accountHolderPlaceholder;
  18. /// 账号占位符
  19. @property (nonatomic, strong, readwrite) NSAttributedString *accountPlaceholder;
  20. /// 绑定账号温馨提示
  21. @property (nonatomic, strong, readwrite) NSAttributedString *bindWithdrawalAccountWarmTips;
  22. /// 提现账号Id
  23. @property (nonatomic, assign) NSInteger withdrawalAccountId;
  24. /// 提现账号类型
  25. @property (nonatomic, assign) NSInteger withdrawalAccountType;
  26. @end
  27. @implementation YMBindWithdrawalAccountViewModel
  28. - (void)ym_initialize{
  29. [super ym_initialize];
  30. self.customNavTitle = @"绑定提现账号";
  31. self.bindWithdrawalAccountType = [self.params integerValueForKey:ParamsCategoryType defaultValue:YMBindWithdrawalAccountTypeAdd];
  32. switch (self.bindWithdrawalAccountType) {
  33. case YMBindWithdrawalAccountTypeAdd:
  34. {
  35. [LCHttpHelper requestWithURLString:GetWithdarwStyle parameters:@{@"id":@(0),@"is_master":@(1)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  36. NSDictionary* dict = (NSDictionary*)responseObject;
  37. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  38. NSArray*arr = dict[@"data"][@"cardTypes"];
  39. NSMutableArray *titleArr =[NSMutableArray new];
  40. for (NSDictionary*typeDic in arr) {
  41. [titleArr addObject:typeDic[@"bank"]];
  42. }
  43. NSDictionary*typeDic = arr[0];
  44. [self customPlaceholderWithTitle:typeDic[@"bank"]withType:[typeDic[@"type"]intValue]];
  45. } failure:^(NSError *error) {
  46. }];
  47. }
  48. break;
  49. case YMBindWithdrawalAccountTypeEdit:
  50. {
  51. self.withdrawalAccountId = [self.params integerValueForKey:@"withdrawalAccountId" defaultValue:0];
  52. self.withdrawalAccountType = [self.params integerValueForKey:@"withdrawalAccountType" defaultValue:0];
  53. switch (self.withdrawalAccountType) {
  54. case 1:
  55. [self alipayPlaceholder];
  56. break;
  57. case 2:
  58. [self wechatPlaceholder];
  59. break;
  60. case 3:
  61. [self bankcardPlaceholder];
  62. break;
  63. case 4:
  64. [self shandebaoPlaceholder];
  65. break;
  66. default:
  67. break;
  68. }
  69. self.withdrawalAccountHolder = [self.params stringValueForKey:@"withdrawalAccountHolder" defaultValue:@""];
  70. self.withdrawalAccount = [self.params stringValueForKey:@"withdrawalAccount" defaultValue:@""];
  71. }
  72. break;
  73. default:
  74. break;
  75. }
  76. /// 保存按钮有效性
  77. self.validSaveSignal = [[[RACSignal combineLatest:@[
  78. RACObserve(self, withdrawalAccountHolder),
  79. RACObserve(self, withdrawalAccount)
  80. ] reduce:^(NSString *withdrawalAccountHolder, NSString *withdrawalAccount) {
  81. //是否不为空
  82. return @(!OCStringIsEmpty(withdrawalAccountHolder) && !OCStringIsEmpty(withdrawalAccount));
  83. }] distinctUntilChanged] takeUntil:self.rac_willDeallocSignal];
  84. NSString *bindWithdrawalAccountWarmTipsStr = @"为了保证您能快速提现,请认真阅读以下提示哦~\n1、请填写正确【基本信息】及【账号信息】,保证账号的准确性;\n2、请确保【基本信息】及【账号信息】为同一人,否则会影响您的提现进度;\n3、如在提现过程中有任何疑问,请及时联系客服处理。";
  85. NSMutableAttributedString *bindWithdrawalAccountWarmTipsAttributed = [[NSMutableAttributedString alloc]initWithString:bindWithdrawalAccountWarmTipsStr];
  86. bindWithdrawalAccountWarmTipsAttributed.yy_font = LCFont(11);
  87. bindWithdrawalAccountWarmTipsAttributed.yy_color = HexColorFromRGB(0x9c9c9c);
  88. bindWithdrawalAccountWarmTipsAttributed.yy_alignment = NSTextAlignmentLeft;
  89. bindWithdrawalAccountWarmTipsAttributed.yy_lineSpacing = 5;
  90. NSString *baseInfoHighlightStr = @"【基本信息】";
  91. NSArray *baseInfoArray = [self rangeOfSubString:baseInfoHighlightStr inString:bindWithdrawalAccountWarmTipsStr];
  92. for (NSInteger i = 0; i < baseInfoArray.count; i++) {
  93. NSValue *value = baseInfoArray[i];
  94. [bindWithdrawalAccountWarmTipsAttributed yy_setColor:HexColorFromRGB(0x8b7db8) range:value.rangeValue];
  95. }
  96. NSString *accountInfoHighlightStr = @"【账号信息】";
  97. NSArray *accountInfoArray = [self rangeOfSubString:accountInfoHighlightStr inString:bindWithdrawalAccountWarmTipsStr];
  98. for (NSInteger i = 0; i < accountInfoArray.count; i++) {
  99. NSValue *value = accountInfoArray[i];
  100. [bindWithdrawalAccountWarmTipsAttributed yy_setColor:HexColorFromRGB(0x8b7db8) range:value.rangeValue];
  101. }
  102. self.bindWithdrawalAccountWarmTips = bindWithdrawalAccountWarmTipsAttributed;
  103. }
  104. - (void)openAccountTypeAlert{
  105. [LCHttpHelper requestWithURLString:GetWithdarwStyle parameters:@{@"id":@(0),@"is_master":@(1)} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  106. NSDictionary* dict = (NSDictionary*)responseObject;
  107. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  108. NSArray*arr = dict[@"data"][@"cardTypes"];
  109. NSMutableArray *titleArr =[NSMutableArray new];
  110. for (NSDictionary*typeDic in arr) {
  111. [titleArr addObject:typeDic[@"bank"]];
  112. }
  113. YMSheetPopupView *customView = [[YMSheetPopupView alloc]init];
  114. [customView configutationWithItemList:titleArr];
  115. YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleSmoothFromBottom dismissStyle:YMDismissStyleSmoothToBottom];
  116. popupView.priority = 999;
  117. popupView.cornerRadius = adapt(10);
  118. popupView.rectCorners = UIRectCornerTopLeft|UIRectCornerTopRight;
  119. popupView.positionStyle = YMPositionStyleBottom;
  120. popupView.isClickBgDismiss = YES;
  121. popupView.isHideBg = NO;
  122. popupView.bgAlpha = 0.5;
  123. @weakify(popupView)
  124. customView.selectIndexBlock = ^(NSInteger index) {
  125. @strongify(popupView)
  126. [popupView dismissWithStyle:YMDismissStyleSmoothToBottom duration:2.0];
  127. NSDictionary*typeDic = arr[index];
  128. [self customPlaceholderWithTitle:typeDic[@"bank"]withType:[typeDic[@"type"]intValue]];
  129. };
  130. customView.closeBlock = ^{
  131. @strongify(popupView)
  132. [popupView dismissWithStyle:YMDismissStyleSmoothToBottom duration:2.0];
  133. };
  134. [popupView pop];
  135. } failure:^(NSError *error) {
  136. }];
  137. }
  138. - (void)customPlaceholderWithTitle:(NSString*)title withType:(NSInteger)type{
  139. self.accountTypeName = title;
  140. NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];
  141. style.minimumLineHeight = 0;
  142. NSMutableAttributedString *accountHolderPlaceholderAttributed = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"请输入您的%@姓名",title]];
  143. accountHolderPlaceholderAttributed.yy_paragraphStyle = style;
  144. accountHolderPlaceholderAttributed.yy_font = LCFont(12);
  145. accountHolderPlaceholderAttributed.yy_color = HexColorFromRGB(0xADB0BC);
  146. self.accountHolderPlaceholder = accountHolderPlaceholderAttributed;
  147. NSMutableAttributedString *accountPlaceholderAttributed = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"请输入您的%@账号",title]];
  148. accountPlaceholderAttributed.yy_paragraphStyle = style;
  149. accountPlaceholderAttributed.yy_font = LCFont(12);
  150. accountPlaceholderAttributed.yy_color = HexColorFromRGB(0xADB0BC);
  151. self.accountPlaceholder = accountPlaceholderAttributed;
  152. self.withdrawalAccountType = type;
  153. }
  154. - (void)alipayPlaceholder{
  155. self.accountTypeName = @"支付宝";
  156. NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];
  157. style.minimumLineHeight = 0;
  158. NSMutableAttributedString *accountHolderPlaceholderAttributed = [[NSMutableAttributedString alloc]initWithString:@"请输入您的支付宝姓名"];
  159. accountHolderPlaceholderAttributed.yy_paragraphStyle = style;
  160. accountHolderPlaceholderAttributed.yy_font = LCFont(12);
  161. accountHolderPlaceholderAttributed.yy_color = HexColorFromRGB(0xADB0BC);
  162. self.accountHolderPlaceholder = accountHolderPlaceholderAttributed;
  163. NSMutableAttributedString *accountPlaceholderAttributed = [[NSMutableAttributedString alloc]initWithString:@"请输入您的支付宝账号"];
  164. accountPlaceholderAttributed.yy_paragraphStyle = style;
  165. accountPlaceholderAttributed.yy_font = LCFont(12);
  166. accountPlaceholderAttributed.yy_color = HexColorFromRGB(0xADB0BC);
  167. self.accountPlaceholder = accountPlaceholderAttributed;
  168. self.withdrawalAccountType = 1;
  169. }
  170. - (void)wechatPlaceholder{
  171. self.accountTypeName = @"微信";
  172. NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];
  173. style.minimumLineHeight = 0;
  174. NSMutableAttributedString *accountHolderPlaceholderAttributed = [[NSMutableAttributedString alloc]initWithString:@"请输入您的微信姓名"];
  175. accountHolderPlaceholderAttributed.yy_paragraphStyle = style;
  176. accountHolderPlaceholderAttributed.yy_font = LCFont(12);
  177. accountHolderPlaceholderAttributed.yy_color = HexColorFromRGB(0xADB0BC);
  178. self.accountHolderPlaceholder = accountHolderPlaceholderAttributed;
  179. NSMutableAttributedString *accountPlaceholderAttributed = [[NSMutableAttributedString alloc]initWithString:@"请输入您的微信账号"];
  180. accountPlaceholderAttributed.yy_paragraphStyle = style;
  181. accountPlaceholderAttributed.yy_font = LCFont(12);
  182. accountPlaceholderAttributed.yy_color = HexColorFromRGB(0xADB0BC);
  183. self.accountPlaceholder = accountPlaceholderAttributed;
  184. self.withdrawalAccountType = 2;
  185. }
  186. - (void)bankcardPlaceholder{
  187. self.accountTypeName = @"银行卡";
  188. NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];
  189. style.minimumLineHeight = 0;
  190. NSMutableAttributedString *accountHolderPlaceholderAttributed = [[NSMutableAttributedString alloc]initWithString:@"请输入您的银行卡姓名"];
  191. accountHolderPlaceholderAttributed.yy_paragraphStyle = style;
  192. accountHolderPlaceholderAttributed.yy_font = LCFont(12);
  193. accountHolderPlaceholderAttributed.yy_color = HexColorFromRGB(0xADB0BC);
  194. self.accountHolderPlaceholder = accountHolderPlaceholderAttributed;
  195. NSMutableAttributedString *accountPlaceholderAttributed = [[NSMutableAttributedString alloc]initWithString:@"请输入您的银行卡账号"];
  196. accountPlaceholderAttributed.yy_paragraphStyle = style;
  197. accountPlaceholderAttributed.yy_font = LCFont(12);
  198. accountPlaceholderAttributed.yy_color = HexColorFromRGB(0xADB0BC);
  199. self.accountPlaceholder = accountPlaceholderAttributed;
  200. self.withdrawalAccountType = 3;
  201. }
  202. - (void)shandebaoPlaceholder{
  203. self.accountTypeName = @"杉德宝";
  204. NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];
  205. style.minimumLineHeight = 0;
  206. NSMutableAttributedString *accountHolderPlaceholderAttributed = [[NSMutableAttributedString alloc]initWithString:@"请输入您的杉德宝姓名"];
  207. accountHolderPlaceholderAttributed.yy_paragraphStyle = style;
  208. accountHolderPlaceholderAttributed.yy_font = LCFont(12);
  209. accountHolderPlaceholderAttributed.yy_color = HexColorFromRGB(0xADB0BC);
  210. self.accountHolderPlaceholder = accountHolderPlaceholderAttributed;
  211. NSMutableAttributedString *accountPlaceholderAttributed = [[NSMutableAttributedString alloc]initWithString:@"请输入您的杉德宝账号"];
  212. accountPlaceholderAttributed.yy_paragraphStyle = style;
  213. accountPlaceholderAttributed.yy_font = LCFont(12);
  214. accountPlaceholderAttributed.yy_color = HexColorFromRGB(0xADB0BC);
  215. self.accountPlaceholder = accountPlaceholderAttributed;
  216. self.withdrawalAccountType = 4;
  217. }
  218. #pragma mark - 获取字符串的所在位置
  219. //获取一个字符在字符串中出现的所有位置 返回一个被NSValue包装的NSRange数组
  220. - (NSArray *)rangeOfSubString:(NSString *)subStr inString:(NSString *)string {
  221. if (subStr == nil && [subStr isEqualToString:@""]) {
  222. return nil;
  223. }
  224. NSMutableArray *rangeArray = [NSMutableArray array];
  225. NSString *string1 = [string stringByAppendingString:subStr];
  226. NSString *temp;
  227. for (int i = 0; i < string.length; i ++) {
  228. temp = [string1 substringWithRange:NSMakeRange(i, subStr.length)];
  229. if ([temp isEqualToString:subStr]) {
  230. NSRange range = {i,subStr.length};
  231. [rangeArray addObject:[NSValue valueWithRange:range]];
  232. }
  233. }
  234. return rangeArray;
  235. }
  236. - (void)submitBindWithdrawalAccount{
  237. @weakify(self)
  238. [ZCHUDHelper showWithStatus:@"提交中..."];
  239. NSMutableDictionary *params = [NSMutableDictionary dictionary];
  240. if (self.bindWithdrawalAccountType == YMBindWithdrawalAccountTypeEdit) {
  241. [params setObject:@(self.withdrawalAccountId) forKey:@"id"];
  242. }
  243. [params setObject:@(self.withdrawalAccountType) forKey:@"card_type"];
  244. [params setObject:self.withdrawalAccount forKey:@"card_account"];
  245. [params setObject:self.withdrawalAccountHolder forKey:@"card_name"];
  246. [params setObject:@(1) forKey:@"is_master"];
  247. [LCHttpHelper requestWithURLString:BindWithdrawalAccount parameters:params needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  248. @strongify(self)
  249. NSDictionary* dict = (NSDictionary*)responseObject;
  250. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  251. if (code == 0) {
  252. [ZCHUDHelper dismiss];
  253. if (self.bindWithdrawalAccountBlock) {
  254. self.bindWithdrawalAccountBlock();
  255. }
  256. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  257. [[YMGlobalUtils getCurrentVC].navigationController popViewControllerAnimated:YES];
  258. });
  259. }else{
  260. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  261. }
  262. } failure:^(NSError *error) {
  263. [ZCHUDHelper showTitle:error.localizedDescription];
  264. }];
  265. }
  266. @end