// // YMGuildManagementViewModel.m // MSYOUPAI // // Created by YoMi on 2024/3/26. // Copyright © 2024 MS. All rights reserved. // #import "YMGuildManagementViewModel.h" #import @interface YMGuildManagementViewModel () @end @implementation YMGuildManagementViewModel - (void)ym_initialize{ [super ym_initialize]; self.customNavTitle = @"公会管理"; self.startTime = [self getDefaultStartTime]; self.endTime = [self getDefaultEndTime]; self.kindStr = @"contribution"; self.peopleStr = @""; } /// 获取公会信息 - (void)getGongHuiData { BOOL isCan = [self compareTime]; if (isCan) { @weakify(self) [ZCHUDHelper showWithStatus:@"加载中..."]; [LCHttpHelper requestWithURLString:GuildManagementMyConnectionsList parameters:@{ @"after_key": @"0", @"begin_time": self.startTime, @"end_time": self.endTime, @"sort" : self.kindStr } 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:@[]]; NSArray *modelArray = [NSArray yy_modelArrayWithClass:[GHManageModel class] json:result]; GHManageModel *mangeModel = [GHManageModel yy_modelWithDictionary:data]; self.mangeModel = mangeModel; self.myEarnStr = mangeModel.total_income; self.peopleStr = mangeModel.total_people; NSLog(@"这个组数数量是%ld",mangeModel.list.count); NSLog(@"这个收益是%@",mangeModel.total_income); NSLog(@"这个组数数量222是%ld",modelArray.count); [self.refreshUISubject sendNext:@(YMRefreshUI)]; }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) { [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)]; }); }]; } } - (NSString*)getDefaultEndTime{ NSDate *currentDate = [NSDate date]; NSCalendar *calder = [NSCalendar currentCalendar]; NSDateComponents *compts = [calder components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:currentDate]; NSInteger year = [compts year]; NSInteger month = [compts month]; NSInteger day = [compts day]; NSString *dayStr = [NSString stringWithFormat:@"%ld",day]; NSString *monthStr = [NSString stringWithFormat:@"%ld",month]; if(day< 10){ dayStr = [NSString stringWithFormat:@"0%ld",day]; } if(month < 10){ monthStr = [NSString stringWithFormat:@"0%ld",month]; } return [NSString stringWithFormat:@"%ld-%@-%@",year,monthStr,dayStr]; } - (NSString*)getDefaultStartTime{ NSDate *currentDate = [NSDate date]; NSCalendar *calder = [NSCalendar currentCalendar]; NSDateComponents *compts = [calder components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:currentDate]; NSInteger year = [compts year]; NSInteger month = [compts month]; NSString *monthStr = [NSString stringWithFormat:@"%ld",month]; if(month < 10){ monthStr = [NSString stringWithFormat:@"0%ld",month]; } return [NSString stringWithFormat:@"%ld-%@-01",year,monthStr]; } - (void)showBottomSort{ UIView *customView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, Is_iPhoneX ? adapt(150) : adapt(180))]; customView.backgroundColor = UIColor.whiteColor; UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom]; [btn1 setTitle:@"按贡献值排序" forState:UIControlStateNormal]; [btn1 setTitleColor:UIColor.blackColor forState:UIControlStateNormal]; btn1.titleLabel.font = LCFont(16); [customView addSubview:btn1]; [btn1 mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(customView); make.left.right.equalTo(customView); make.height.mas_equalTo(adapt(50)); }]; UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom]; [btn2 setTitle:@"按注册时间排序" forState:UIControlStateNormal]; [btn2 setTitleColor:UIColor.blackColor forState:UIControlStateNormal]; btn2.titleLabel.font = LCFont(16); [customView addSubview:btn2]; [btn2 mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(btn1.mas_bottom); make.left.right.equalTo(customView); make.height.mas_equalTo(adapt(50)); }]; UIButton *btn3 = [UIButton buttonWithType:UIButtonTypeCustom]; [btn3 setTitle:@"取消" forState:UIControlStateNormal]; [btn3 setTitleColor:UIColor.secondaryLabelColor forState:UIControlStateNormal]; btn3.titleLabel.font = LCFont(16); [customView addSubview:btn3]; [btn3 mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(btn2.mas_bottom); make.left.right.equalTo(customView); make.height.mas_equalTo(adapt(50)); }]; YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade]; popupView.priority = 999; popupView.backgroundColor = UIColor.clearColor; popupView.positionStyle = YMPositionStyleBottom; popupView.isHideBg = NO; popupView.bgAlpha = 0.3; @weakify(popupView) popupView.bgClickBlock = ^{ @strongify(popupView) [popupView dismissWithStyle:YMDismissStyleFade duration:1.0]; }; @weakify(self) [[[btn1 rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) { @strongify(self) self.kindStr = @"contribution"; [self getGongHuiData]; [popupView dismissWithStyle:YMDismissStyleFade duration:1.0]; }]; [[[btn2 rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) { @strongify(self) self.kindStr = @"user_id"; [self getGongHuiData]; [popupView dismissWithStyle:YMDismissStyleFade duration:1.0]; }]; [[[btn3 rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) { [popupView dismissWithStyle:YMDismissStyleFade duration:1.0]; }]; [popupView pop]; } - (BOOL)compareTime{ NSString *start = [self.startTime stringByReplacingOccurrencesOfString:@"-" withString:@""]; NSString *end = [self.endTime stringByReplacingOccurrencesOfString:@"-" withString:@""]; NSInteger start1 = [start integerValue]; NSInteger end1 = [end integerValue]; if(start1 > end1){ [ZCHUDHelper showTitle:@"开始时间不能大于结束时间"]; return NO; }else{ return YES; } } - (void)gotoMember{ YMGuildManagementMyConnectionsViewModel *memberVM = [[YMGuildManagementMyConnectionsViewModel alloc]initWithParams:@{}]; [YMRouter openURL:stringFormat(@"%@%@",YM_ROUTER_URL_PREFIX,YM_ROUTER_URL_MANAGER_MEMBER) withUserInfo:@{ RouterViewModel:memberVM } completion:nil]; } @end