RQExamResultViewModel.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // RQExamResultViewModel.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2022/7/26.
  6. // Copyright © 2022 JCZ. All rights reserved.
  7. //
  8. #import "RQExamResultViewModel.h"
  9. @interface RQExamResultViewModel ()
  10. @property (nonatomic, readwrite, strong) RQCommonGroupViewModel *group0;
  11. @property (nonatomic, readwrite, strong) RQCommonGroupViewModel *group1;
  12. @property (nonatomic, readwrite, copy) NSArray *questionArr;
  13. @property (nonatomic, readwrite, copy) NSArray *errorArr;
  14. @property (nonatomic, readwrite, copy) NSArray *correctArr;
  15. @end
  16. @implementation RQExamResultViewModel
  17. #pragma mark - Public Method
  18. - (instancetype)initWithServices:(id<RQViewModelServices>)services params:(NSDictionary *)params {
  19. if (self = [super initWithServices:services params:params]) {
  20. self.questionArr = params[RQViewModelUtilKey];
  21. self.errorArr = params[RQViewCommonValueKey];
  22. self.correctArr = params[RQViewModelIDKey];
  23. if(params[RQHomeSubPageTypeKHModeKey]){
  24. self.subPageTypeKHMode = [params[RQHomeSubPageTypeKHModeKey] integerValue];
  25. }
  26. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateScoreView) name:@"updateScoreView" object:nil];
  27. }
  28. return self;
  29. }
  30. - (void)updateViewUI {
  31. @weakify(self)
  32. [[RQ_HTTP_Service getMyScore] subscribeNext:^(NSArray *examResultModelArr) {
  33. @strongify(self)
  34. if (RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectOne) {
  35. RQ_COMMON_MANAGER.myExamOneCount = examResultModelArr.count;
  36. RQ_COMMON_MANAGER.examResultOneListArr = examResultModelArr;
  37. } else if (RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectFour) {
  38. RQ_COMMON_MANAGER.myExamFourCount = examResultModelArr.count;
  39. RQ_COMMON_MANAGER.examResultFourListArr = examResultModelArr;
  40. }
  41. RQExamSituationItemViewModel *examSituationItemViewModel = [[RQExamSituationItemViewModel alloc] init];
  42. examSituationItemViewModel.examResultArr = RQObjectIsNil(examResultModelArr)? @[] : examResultModelArr;
  43. self.group1.itemViewModels = @[examSituationItemViewModel];
  44. self.dataSource = @[self.group0, self.group1];
  45. }];
  46. }
  47. - (void)dealloc{
  48. // [[NSNotificationCenter defaultCenter] removeObserver:self];
  49. }
  50. - (void)initialize {
  51. [super initialize];
  52. self.title = @"本次考试成绩";
  53. self.prefersNavigationBarBottomLineHidden = YES;
  54. self.interactivePopDisabled = YES;
  55. NSInteger totalNum = self.questionArr.count;
  56. NSInteger rightNum = self.correctArr.count;
  57. NSInteger perScore = 100 / totalNum;
  58. NSInteger score = rightNum * perScore;
  59. NSUInteger sec = RQ_Exercise_Module.count%60;
  60. NSUInteger min = RQ_Exercise_Module.count/60;
  61. if (score > 100) {
  62. [Bugly reportException:[NSException exceptionWithName:@"saveFavQuestion" reason:[@{ @"score" : @(score), @"totalNum" : @(totalNum) , @"rightNum" : @(rightNum), @"perScore" : @(perScore)} jsonStringEncoded] userInfo:nil]];
  63. score = 100;
  64. }
  65. ///配置数据
  66. [self rq_configureData];
  67. NSInteger allTimeCount = (RQ_YDTQuestion_Module.carType == RQHomePageCarType_Motorcycle)? 30 * 60 : 45 * 60;
  68. NSInteger useCount = allTimeCount - min * 60 - sec;
  69. NSString *beginDateStr = [[NSDateFormatter rq_defaultDateFormatter] stringFromDate:RQ_Exercise_Module.beginDate];
  70. NSDate *endDte = [NSDate dateWithTimeInterval:useCount sinceDate:RQ_Exercise_Module.beginDate];
  71. NSString *endDateStr = [[NSDateFormatter rq_defaultDateFormatter] stringFromDate:endDte];
  72. @weakify(self)
  73. if(self.subPageTypeKHMode==1){
  74. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  75. @strongify(self)
  76. [self updateViewUI];
  77. });
  78. }else{
  79. [[[RQ_HTTP_Service saveFavQuestionWithScore:score startDate:beginDateStr endDate:endDateStr] deliverOnMainThread] subscribeNext:^(id _Nullable x) {
  80. @strongify(self)
  81. [self updateViewUI];
  82. } error:^(NSError * _Nullable error) {
  83. @strongify(self)
  84. self.dataSource = @[self.group0];
  85. }];
  86. }
  87. }
  88. #pragma mark - PrivateMethod
  89. - (void)rq_configureData {
  90. self.dataSource = @[self.group0, self.group1];
  91. }
  92. - (RQCommonGroupViewModel *)group0 {
  93. if (!_group0) {
  94. _group0 = [RQCommonGroupViewModel groupViewModel];
  95. [_group0 setCustomStyleWithRQCommonGroupModel:^(RQCommonGroupModel *groupModel) {
  96. groupModel.footerHeight = 10.f;
  97. groupModel.footerBgColor = RQ_LIST_BACKGROUNDCOLOR;
  98. }];
  99. RQHomePageSimulationExamItemViewModel *homePageSimulationExamItemViewModel = [[RQHomePageSimulationExamItemViewModel alloc] initWithRQHomePageCarType:RQ_YDTQuestion_Module.carType homePageSubjectType:RQ_YDTQuestion_Module.subject];
  100. _group0.itemViewModels = @[homePageSimulationExamItemViewModel];
  101. }
  102. return _group0;
  103. }
  104. - (RQCommonGroupViewModel *)group1 {
  105. if (!_group1) {
  106. _group1 = [RQCommonGroupViewModel groupViewModel];
  107. [_group1 setCustomStyleWithRQCommonGroupModel:^(RQCommonGroupModel *groupModel) {
  108. groupModel.footerHeight = 10.f;
  109. groupModel.footerBgColor = RQ_LIST_BACKGROUNDCOLOR;
  110. }];
  111. RQExamSituationItemViewModel *examSituationItemViewModel = [[RQExamSituationItemViewModel alloc] init];
  112. _group1.itemViewModels = @[examSituationItemViewModel];
  113. }
  114. return _group1;
  115. }
  116. @end