// // YMGroupGreetingViewModel.m // MSYOUPAI // // Created by macmini on 2025/5/25. // Copyright © 2025 MS. All rights reserved. // #import "YMGroupGreetingViewModel.h" @implementation YMGroupGreetingViewModel - (void)ym_initialize{ [super ym_initialize]; self.customNavTitle = @"打招呼设置"; self.currentPage = 0; self.currentSize = 6; } - (void)getGroupGreetingDataIsNew:(BOOL)isNew completion:(void(^)(BOOL isSuccess))completion { if (isNew) { self.currentPage = 0; } // 每次请求翻一页 self.currentPage += 1; @weakify(self) [ZCHUDHelper showWithStatus:@"加载中..."]; [LCHttpHelper requestWithURLString:HomeRecommend parameters:@{ @"page":@(self.currentPage), @"limit":@(self.currentSize) } 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:@{}]; NSDictionary *result = [data dictionaryValueForKey:@"list" defaultValue:@{}]; NSArray *userListData = [result arrayValueForKey:@"list" defaultValue:@[]]; if (userListData.count == 0) { [ZCHUDHelper showWithStatus:@"没有更多数据~"]; self.currentPage --; return; } if (userListData.count < self.currentSize) { [ZCHUDHelper showWithStatus:@"没有更多数据~"]; self.currentPage --; } NSMutableArray *userList = [NSMutableArray array]; // 解析用户数据 for (NSDictionary *userDict in userListData) { YMGroupGreetingUserModel *user = [YMGroupGreetingUserModel mj_objectWithKeyValues:userDict]; [userList addObject:user]; } // 每次清空,再放进去 [self.listDataArray removeAllObjects]; // NSArray *viewModelArr = [[NSArray yy_modelArrayWithClass:[YMGroupGreetingUserModel class] json:result].rac_sequence map:^(YMGroupGreetingUserModel * _Nullable model) { // YMGroupGreetingUserModel *viewModel = [[YMGroupGreetingUserModel alloc] initWithParams:@{ // ParamsModel:model // }]; // // return viewModel; // }].array; // // [self.listDataArray addObjectsFromArray:viewModelArr]; [self.listDataArray addObjectsFromArray:userList]; // if(self.currentPage > 0 && self.currentPage % 6 == 0){ // [[SDImageCache sharedImageCache] clearMemory]; // } [self.refreshUISubject sendNext:@(result.count < self.currentSize ? YMFooterRefresh_HasNoMoreData : YMFooterRefresh_HasMoreData)]; if (completion) { completion(YES); } }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)]; }); if (completion) { completion(NO); } } } 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)]; }); if (completion) { completion(NO); } }]; } - (NSMutableArray *)listDataArray{ if (!_listDataArray) { _listDataArray = [NSMutableArray array]; } return _listDataArray; } @end