123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- //
- // YMIncomeBreakdownListViewModel.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/3/3.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMIncomeBreakdownListViewModel.h"
- #import "YMPointsAndEarningsListModel.h"
- #import "YMWithdrawalRecordsListModel.h"
- @interface YMIncomeBreakdownListViewModel ()
- /// 当前数据数量
- @property (nonatomic, assign) NSInteger currentSize;
- /// 好友分类类型
- @property (nonatomic, assign, readwrite) YMIncomeBreakdownCategoryType categoryType;
- /// 金币和收益数据
- @property (nonatomic, strong, readwrite) NSMutableArray <YMIncomeBreakdownListPointsAndEarningsSectionViewModel*>*pointsAndEarningsDataArray;
- /// 金币和收益数据
- @property (nonatomic, strong, readwrite) NSMutableArray <YMIncomeBreakdownListWithdrawalRecordsCellModel*>*withdrawalRecordsDataArray;
- /// 更改收支明细日期
- @property (nonatomic, strong, readwrite) RACSubject *changeIncomeBreakdownDateSubject;
- /// 筛选Id 0全部 1充值 2提现 3视频 4礼物 5系统 6兑换 7私信
- @property (nonatomic, assign) NSInteger *screeningId;
- /// 筛选日期
- @property (nonatomic, copy) NSString *screeningDate;
- @end
- @implementation YMIncomeBreakdownListViewModel
- - (void)ym_initialize{
- [super ym_initialize];
-
- self.currentPage = 1;
- self.currentSize = 10;
-
- self.categoryType = [self.params integerValueForKey:ParamsCategoryType defaultValue:YMIncomeBreakdownCategoryTypePoints];
-
-
- @weakify(self)
- [[self.changeIncomeBreakdownDateSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id _Nullable value) {
- @strongify(self)
- self.screeningDate = value;
- self.currentPage = 1;
- [self getIncomeBreakdownListData];
- }];
- }
- - (void)getIncomeBreakdownListData {
- switch (self.categoryType) {
- case YMIncomeBreakdownCategoryTypePoints:
- case YMIncomeBreakdownCategoryTypeEarnings:
- {
- [self getBillListData];
- }
- break;
- case YMIncomeBreakdownCategoryTypeWithdrawalRecords:
- {
- [self getWithdrawalRecordsListData];
- }
- break;
- default:
- break;
- }
-
- }
- - (void)getBillListData{
- @weakify(self)
- [ZCHUDHelper showWithStatus:@"加载中..."];
- [LCHttpHelper requestWithURLString:WalletBill parameters:@{
- @"page":@(self.currentPage),
- @"category":@(self.categoryType),
- @"type":@(0),
- @"new_type":@(self.categoryType),
- @"cate_id":@(0),
- @"date":self.screeningDate
- } needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- @strongify(self)
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- [ZCHUDHelper dismiss];
- NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}];
- NSArray <NSDictionary*>*newlist = [data arrayValueForKey:@"new_list" defaultValue:@[]];
- NSArray *result = [newlist.lastObject arrayValueForKey:@"list" defaultValue:@[]];
- if (self.currentPage == 1) {
- [self.pointsAndEarningsDataArray removeAllObjects];
- }
- NSArray *viewModelArr = [[NSArray yy_modelArrayWithClass:[YMPointsAndEarningsListModel class] json:newlist].rac_sequence map:^(YMPointsAndEarningsListModel * _Nullable model) {
- YMIncomeBreakdownListPointsAndEarningsSectionViewModel *viewModel = [[YMIncomeBreakdownListPointsAndEarningsSectionViewModel alloc]initWithParams:@{
- ParamsModel:model,
- ParamsCategoryType:@(self.categoryType)
- }];
- return viewModel;
- }].array;
- [self.pointsAndEarningsDataArray addObjectsFromArray:viewModelArr];
-
- if(self.currentPage > 0 && self.currentPage % 5 == 0){
- [[SDImageCache sharedImageCache] clearMemory];
- }
-
- [self.refreshUISubject sendNext:@(result.count < self.currentSize ? YMFooterRefresh_HasNoMoreData : YMFooterRefresh_HasMoreData)];
- }else{
- [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self.refreshUISubject sendNext:@(YMRefreshError)];
- });
- }
-
- } failure:^(NSError *error) {
- if(self.currentPage != 1){
- self.currentPage--;
- }
- [ZCHUDHelper showTitle:error.localizedDescription];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self.refreshUISubject sendNext:@(YMRefreshError)];
- });
- }];
- }
- - (void)getWithdrawalRecordsListData{
- @weakify(self)
- [ZCHUDHelper showWithStatus:@"加载中..."];
- [LCHttpHelper requestWithURLString:WithdrawalRecordsInfo parameters:@{
- @"page":@(self.currentPage),
- @"date":self.screeningDate
- } needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- @strongify(self)
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- [ZCHUDHelper dismiss];
- NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}];
- NSArray *result = [data arrayValueForKey:@"list" defaultValue:@[]];
- if (self.currentPage == 1) {
- [self.withdrawalRecordsDataArray removeAllObjects];
- }
-
- NSArray *viewModelArr = [[NSArray yy_modelArrayWithClass:[YMWithdrawalRecordsListModel class] json:result].rac_sequence map:^(YMWithdrawalRecordsListModel * _Nullable model) {
- YMIncomeBreakdownListWithdrawalRecordsCellModel *viewModel = [[YMIncomeBreakdownListWithdrawalRecordsCellModel alloc]initWithParams:@{
- ParamsModel:model,
- ParamsCategoryType:@(self.categoryType)
- }];
- return viewModel;
- }].array;
- [self.withdrawalRecordsDataArray addObjectsFromArray:viewModelArr];
-
- if(self.currentPage > 0 && self.currentPage % 5 == 0){
- [[SDImageCache sharedImageCache] clearMemory];
- }
-
- [self.refreshUISubject sendNext:@(result.count < self.currentSize ? YMFooterRefresh_HasNoMoreData : YMFooterRefresh_HasMoreData)];
- }else{
- [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self.refreshUISubject sendNext:@(YMRefreshError)];
- });
- }
-
- } failure:^(NSError *error) {
- if(self.currentPage != 1){
- self.currentPage--;
- }
- [ZCHUDHelper showTitle:error.localizedDescription];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self.refreshUISubject sendNext:@(YMRefreshError)];
- });
- }];
- }
- - (NSMutableArray<YMIncomeBreakdownListPointsAndEarningsSectionViewModel *> *)pointsAndEarningsDataArray{
- if (!_pointsAndEarningsDataArray) {
- _pointsAndEarningsDataArray = [NSMutableArray array];
- }
- return _pointsAndEarningsDataArray;
- }
- - (NSMutableArray<YMIncomeBreakdownListWithdrawalRecordsCellModel *> *)withdrawalRecordsDataArray{
- if (!_withdrawalRecordsDataArray) {
- _withdrawalRecordsDataArray = [NSMutableArray array];
- }
- return _withdrawalRecordsDataArray;
- }
- - (RACSubject *)changeIncomeBreakdownDateSubject{
- if (!_changeIncomeBreakdownDateSubject) {
- _changeIncomeBreakdownDateSubject = [RACSubject subject];
- }
- return _changeIncomeBreakdownDateSubject;
- }
- @end
|