123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- //
- // 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<YMGroupGreetingUserModel *> *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<YMGroupGreetingUserModel *> *)listDataArray{
- if (!_listDataArray) {
- _listDataArray = [NSMutableArray array];
- }
- return _listDataArray;
- }
- @end
|