// // YMGuildManagementMyConnectionsViewModel.m // MSYOUPAI // // Created by YoMi on 2024/3/26. // Copyright © 2024 MS. All rights reserved. // #import "YMGuildManagementMyConnectionsViewModel.h" @interface YMGuildManagementMyConnectionsViewModel () /// 当前数据数量 @property (nonatomic, assign) NSInteger currentSize; /// 列表数据 @property (nonatomic, strong, readwrite) NSMutableArray *listDataArray; @end @implementation YMGuildManagementMyConnectionsViewModel - (void)ym_initialize{ [super ym_initialize]; self.customNavTitle = @"公会成员"; self.currentPage = 1; self.currentSize = 15; self.memberNumber = @""; } - (void)getMyConnectionsListData { @weakify(self) [ZCHUDHelper showWithStatus:@"加载中..."]; [LCHttpHelper requestWithURLString:ChatRoom_guildCenter parameters:@{ @"page":@(self.currentPage), @"number":@(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 *resultDic = [data dictionaryValueForKey:@"guildMember" defaultValue:@{}]; NSArray *result = [resultDic arrayValueForKey:@"list" defaultValue:@[]]; self.memberNumber = [NSString stringWithFormat:@"%@",data[@"count"][@"memberNumber"]]; if (self.currentPage == 1) { [self.listDataArray removeAllObjects]; } NSArray *modelArray = [NSArray yy_modelArrayWithClass:[GHMemberListModel class] json:result]; [self.listDataArray addObjectsFromArray:modelArray]; 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 *)listDataArray{ if (!_listDataArray) { _listDataArray = [NSMutableArray array]; } return _listDataArray; } @end