YMWithdrawalAccountListViewModel.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // YMWithdrawalAccountListViewModel.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/3/6.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMWithdrawalAccountListViewModel.h"
  9. #import "YMWithdrawalAccountModel.h"
  10. @interface YMWithdrawalAccountListViewModel ()
  11. /// 当前数据数量
  12. @property (nonatomic, assign) NSInteger currentSize;
  13. /// 列表数据
  14. @property (nonatomic, strong, readwrite) NSMutableArray <YMWithdrawalAccountListCellViewModel*>*listDataArray;
  15. @end
  16. @implementation YMWithdrawalAccountListViewModel
  17. - (void)ym_initialize{
  18. [super ym_initialize];
  19. self.customNavTitle = @"提现账号";
  20. self.currentPage = 1;
  21. self.currentSize = 10;
  22. }
  23. - (void)getWithdrawalAccountListData{
  24. @weakify(self)
  25. [ZCHUDHelper showWithStatus:@"加载中..."];
  26. [LCHttpHelper requestWithURLString:WithdrawalAccountList parameters:@{
  27. @"page":@(self.currentPage),
  28. @"limit":@(self.currentSize)
  29. } needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  30. @strongify(self)
  31. NSDictionary* dict = (NSDictionary*)responseObject;
  32. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  33. if (code == 0) {
  34. [ZCHUDHelper dismiss];
  35. NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}];
  36. NSArray *result = [data arrayValueForKey:@"list" defaultValue:@[]];
  37. if (self.currentPage == 1) {
  38. [self.listDataArray removeAllObjects];
  39. }
  40. NSArray *viewModelArr = [[NSArray yy_modelArrayWithClass:[YMWithdrawalAccountModel class] json:result].rac_sequence map:^(YMWithdrawalAccountModel * _Nullable model) {
  41. YMWithdrawalAccountListCellViewModel *viewModel = [[YMWithdrawalAccountListCellViewModel alloc]initWithParams:@{
  42. ParamsModel:model
  43. }];
  44. return viewModel;
  45. }].array;
  46. [self.listDataArray addObjectsFromArray:viewModelArr];
  47. if(self.currentPage > 0 && self.currentPage % 5 == 0){
  48. [[SDImageCache sharedImageCache] clearMemory];
  49. }
  50. [self.refreshUISubject sendNext:@(result.count < self.currentSize ? YMFooterRefresh_HasNoMoreData : YMFooterRefresh_HasMoreData)];
  51. }else{
  52. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  53. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  54. [self.refreshUISubject sendNext:@(YMRefreshError)];
  55. });
  56. }
  57. } failure:^(NSError *error) {
  58. if(self.currentPage != 1){
  59. self.currentPage--;
  60. }
  61. [ZCHUDHelper showTitle:error.localizedDescription];
  62. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  63. [self.refreshUISubject sendNext:@(YMRefreshError)];
  64. });
  65. }];
  66. }
  67. - (void)defaultWithdrawalAccountData:(NSInteger)withdrawalAccountId{
  68. @weakify(self)
  69. [ZCHUDHelper showWithStatus:@"设置中..."];
  70. [LCHttpHelper requestWithURLString:DefaultWithdrawalAccount parameters:@{
  71. @"id":@(withdrawalAccountId)
  72. } needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  73. @strongify(self)
  74. NSDictionary* dict = (NSDictionary*)responseObject;
  75. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  76. if (code == 0) {
  77. [ZCHUDHelper dismiss];
  78. [[YMGlobalUtils getCurrentVC].navigationController popViewControllerAnimated:YES];
  79. }else{
  80. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  81. }
  82. } failure:^(NSError *error) {
  83. [ZCHUDHelper showTitle:error.localizedDescription];
  84. }];
  85. }
  86. - (NSMutableArray<YMWithdrawalAccountListCellViewModel *> *)listDataArray{
  87. if (!_listDataArray) {
  88. _listDataArray = [NSMutableArray array];
  89. }
  90. return _listDataArray;
  91. }
  92. @end