// // RQExamResultViewModel.m // jiaPei // // Created by 张嵘 on 2022/7/26. // Copyright © 2022 JCZ. All rights reserved. // #import "RQExamResultViewModel.h" @interface RQExamResultViewModel () @property (nonatomic, readwrite, strong) RQCommonGroupViewModel *group0; @property (nonatomic, readwrite, strong) RQCommonGroupViewModel *group1; @property (nonatomic, readwrite, copy) NSArray *questionArr; @property (nonatomic, readwrite, copy) NSArray *errorArr; @property (nonatomic, readwrite, copy) NSArray *correctArr; @end @implementation RQExamResultViewModel #pragma mark - Public Method - (instancetype)initWithServices:(id)services params:(NSDictionary *)params { if (self = [super initWithServices:services params:params]) { self.questionArr = params[RQViewModelUtilKey]; self.errorArr = params[RQViewCommonValueKey]; self.correctArr = params[RQViewModelIDKey]; } return self; } - (void)initialize { [super initialize]; @weakify(self) self.title = @"本次考试成绩"; self.prefersNavigationBarBottomLineHidden = YES; self.interactivePopDisabled = YES; NSInteger totalNum = self.questionArr.count; NSInteger rightNum = self.correctArr.count; NSInteger perScore = 100 / totalNum; NSInteger score = rightNum * perScore; NSUInteger sec = RQ_Exercise_Module.count%60; NSUInteger min = RQ_Exercise_Module.count/60; if (score > 100) { [Bugly reportException:[NSException exceptionWithName:@"saveFavQuestion" reason:[@{ @"score" : @(score), @"totalNum" : @(totalNum) , @"rightNum" : @(rightNum), @"perScore" : @(perScore)} jsonStringEncoded] userInfo:nil]]; score = 100; } ///配置数据 [self rq_configureData]; NSInteger allTimeCount = (RQ_YDTQuestion_Module.carType == RQHomePageCarType_Motorcycle)? 30 * 60 : 45 * 60; NSInteger useCount = allTimeCount - min * 60 - sec; NSString *beginDateStr = [[NSDateFormatter rq_defaultDateFormatter] stringFromDate:RQ_Exercise_Module.beginDate]; NSDate *endDte = [NSDate dateWithTimeInterval:useCount sinceDate:RQ_Exercise_Module.beginDate]; NSString *endDateStr = [[NSDateFormatter rq_defaultDateFormatter] stringFromDate:endDte]; [[[RQ_HTTP_Service saveFavQuestionWithScore:score startDate:beginDateStr endDate:endDateStr] deliverOnMainThread] subscribeNext:^(id _Nullable x) { [[RQ_HTTP_Service getMyScore] subscribeNext:^(NSArray *examResultModelArr) { @strongify(self) if (RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectOne) { RQ_COMMON_MANAGER.myExamOneCount = examResultModelArr.count; RQ_COMMON_MANAGER.examResultOneListArr = examResultModelArr; } else if (RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectFour) { RQ_COMMON_MANAGER.myExamFourCount = examResultModelArr.count; RQ_COMMON_MANAGER.examResultFourListArr = examResultModelArr; } RQExamSituationItemViewModel *examSituationItemViewModel = [[RQExamSituationItemViewModel alloc] init]; examSituationItemViewModel.examResultArr = RQObjectIsNil(examResultModelArr)? @[] : examResultModelArr; self.group1.itemViewModels = @[examSituationItemViewModel]; self.dataSource = @[self.group0, self.group1]; }]; } error:^(NSError * _Nullable error) { @strongify(self) self.dataSource = @[self.group0]; }]; } #pragma mark - PrivateMethod - (void)rq_configureData { self.dataSource = @[self.group0, self.group1]; } - (RQCommonGroupViewModel *)group0 { if (!_group0) { _group0 = [RQCommonGroupViewModel groupViewModel]; [_group0 setCustomStyleWithRQCommonGroupModel:^(RQCommonGroupModel *groupModel) { groupModel.footerHeight = 10.f; groupModel.footerBgColor = RQ_LIST_BACKGROUNDCOLOR; }]; RQHomePageSimulationExamItemViewModel *homePageSimulationExamItemViewModel = [[RQHomePageSimulationExamItemViewModel alloc] initWithRQHomePageCarType:RQ_YDTQuestion_Module.carType homePageSubjectType:RQ_YDTQuestion_Module.subject]; _group0.itemViewModels = @[homePageSimulationExamItemViewModel]; } return _group0; } - (RQCommonGroupViewModel *)group1 { if (!_group1) { _group1 = [RQCommonGroupViewModel groupViewModel]; [_group1 setCustomStyleWithRQCommonGroupModel:^(RQCommonGroupModel *groupModel) { groupModel.footerHeight = 10.f; groupModel.footerBgColor = RQ_LIST_BACKGROUNDCOLOR; }]; RQExamSituationItemViewModel *examSituationItemViewModel = [[RQExamSituationItemViewModel alloc] init]; _group1.itemViewModels = @[examSituationItemViewModel]; } return _group1; } @end