// // RQHomePageOneOrFourBigItemViewModel.m // jiaPei // // Created by 张嵘 on 2022/6/10. // Copyright © 2022 JCZ. All rights reserved. // #import "RQHomePageOneOrFourBigItemViewModel.h" @interface RQHomePageOneOrFourBigItemViewModel () @property (nonatomic, readwrite, assign) RQHomePageCarType homePageCarType; @property (nonatomic, readwrite, assign) RQHomePageSubjectType homePageSubjectType; @property (nonatomic, readwrite, copy) NSAttributedString *leftStr; @property (nonatomic, readwrite, copy) NSAttributedString *rightStr; @end @implementation RQHomePageOneOrFourBigItemViewModel /// init - (instancetype)initWithRQHomePageCarType:(RQHomePageCarType)homePageCarType homePageSubjectType:(RQHomePageSubjectType)homePageSubjectType homePageOneOrFourItemModel:(RQHomePageOneOrFourItemModel *)homePageOneOrFourItemModel { if (self = [super init]) { @weakify(self) self.homePageCarType = homePageCarType; self.homePageSubjectType = homePageSubjectType; CGFloat width = (RQ_SCREEN_WIDTH - (16 * 2) - 11) / 2.f; CGFloat height = width * (68.f / 167.f); self.itemSize = CGSizeMake(width, height); self.title = homePageOneOrFourItemModel.titleStr; self.icon = homePageOneOrFourItemModel.iconImgStr; if ([self.title isEqualToString:@"顺序练习"]) { RAC(self, rightStr) = [[RACSignal combineLatest:@[RACObserve(RQ_YDTQuestion_Module, subjectOneArr), RACObserve(RQ_YDTQuestion_Module, subjectFourArr)] reduce:^id (NSArray *subjectOneArr, NSArray *subjectFourArr) { @strongify(self) NSInteger allCount = [RQ_YDTQuestion_Module getQuestionNumWithWithSubject:self.homePageSubjectType exerciseType:RQExerciseType_Sequential]; return [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"/%ld",allCount]]; }] takeUntil:self.rac_willDeallocSignal]; RAC(self, leftStr) = [[RACSignal combineLatest:@[RACObserve(RQ_YDTQuestion_Module, carType), [RACObserve(RQ_YDTQuestion_Module, subject) filter:^BOOL(id _Nullable value) { return (RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectFour || RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectOne); }], RACObserve(RQ_YDT_USER_Question_Module, doNum)] reduce:^id (NSNumber *carType, NSNumber *subject, NSNumber *doNum) { return [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%ld",[RQ_YDT_USER_Question_Module getDoQuestionNum]]]; }] takeUntil:self.rac_willDeallocSignal]; self.operation = ^{ @strongify(self) // NSMutableArray *oneArr = [[NSMutableArray alloc] init]; // NSMutableArray *fourArr = [NSMutableArray array]; // [oneArr addObjectsFromArray:RQ_YDTQuestion_Module.subjectOneArr]; // [fourArr addObjectsFromArray:RQ_YDTQuestion_Module.subjectFourArr]; NSArray *arr = [[RQ_YDTQuestion_Module getQuestionWithSubject:RQ_YDTQuestion_Module.subject exerciseType:RQExerciseType_Sequential ].rac_sequence.signal map:^id _Nullable(RQYDTQuestionModel *ydtQuestionModel) { return [RQExerciseModel exerciseModelWithRQYDTQuestionModel:ydtQuestionModel]; }].toArray; // NSArray *arr = (self.homePageSubjectType == RQHomePageSubjectType_SubjectFour)? fourArr.copy : oneArr.copy; // arr = [arr.rac_sequence.signal map:^id _Nullable(RQYDTQuestionModel *ydtQuestionModel) { // return [RQExerciseModel exerciseModelWithRQYDTQuestionModel:ydtQuestionModel]; // }].toArray; RQExerciseViewModel *exerciseViewModel = [[RQExerciseViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{ RQHomePageCarTypeKey : @(self.homePageCarType), RQHomePageSubjectTypeKey : @(self.homePageSubjectType), RQHomeSubPageTypeKey : @(RQHomeSubPageType_SequentialPractice), RQViewModelIDKey : self.title, RQExerciseTypeKey : @(RQExerciseType_Sequential), RQViewModelUtilKey : arr, }]; [RQ_APPDELEGATE.services pushViewModel:exerciseViewModel animated:YES]; }; } else if (([self.title isEqualToString:@"模拟考试"])) { NSString *score = [NSString stringWithFormat:@"%@",@"0"]; NSString *fen = [NSString stringWithFormat:@"分"]; NSString *myScore = [NSString stringWithFormat:@"%@%@",score,fen]; NSMutableAttributedString *myScoreAttrStr = [[NSMutableAttributedString alloc] initWithString:myScore]; [myScoreAttrStr addAttribute:NSFontAttributeName value:RQSemiboldFont(34) range:[myScore rangeOfString:score]]; [myScoreAttrStr addAttribute:NSFontAttributeName value:RQRegularFont_15 range:[myScore rangeOfString:fen]]; self.leftStr = myScoreAttrStr; self.rightStr = [[NSMutableAttributedString alloc] initWithString:[self.leftStr.string isEqualToString:@"0分"]? @"最高分" : @"最高分"]; RAC(self, leftStr) = [[RACSignal combineLatest:@[RACObserve(RQ_COMMON_MANAGER, examResultOneListArr), RACObserve(RQ_COMMON_MANAGER, examResultFourListArr)] reduce:^id (NSArray *examResultOneListArr, NSArray *examResultFourListArr) { @strongify(self) NSArray *arr; if (self.homePageSubjectType == RQHomePageSubjectType_SubjectOne) { arr = examResultOneListArr; } if (self.homePageSubjectType == RQHomePageSubjectType_SubjectFour) { arr = examResultFourListArr; } float max = [[[arr.rac_sequence.signal map:^id _Nullable(RQExamResultModel *examResultModel) { return examResultModel.score; }].toArray valueForKeyPath:@"@max.floatValue"] floatValue]; NSString *score = [NSString qmui_stringWithCGFloat:max decimal:0]; NSString *fen = [NSString stringWithFormat:@"分"]; NSString *myScore = [NSString stringWithFormat:@"%@%@",score,fen]; NSMutableAttributedString *myScoreAttrStr = [[NSMutableAttributedString alloc] initWithString:myScore]; [myScoreAttrStr addAttribute:NSFontAttributeName value:RQSemiboldFont(34) range:[myScore rangeOfString:score]]; [myScoreAttrStr addAttribute:NSFontAttributeName value:RQRegularFont_15 range:[myScore rangeOfString:fen]]; self.rightStr = [[NSMutableAttributedString alloc] initWithString:[myScoreAttrStr.string isEqualToString:@"0分"]? @"最高分" : @"最高分"]; return myScoreAttrStr; }] takeUntil:self.rac_willDeallocSignal]; self.operation = ^{ if (RQ_USER_MANAGER.isShouldLogin) { RQSimulateExamViewModel *viewModel = [[RQSimulateExamViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{}]; [RQ_APPDELEGATE.services pushViewModel:viewModel animated:YES]; } }; } } return self; } @end