RQSimulateExamBeginCell.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. //
  2. // RQSimulateExamBeginCell.m
  3. // jiaPei
  4. //
  5. // Created by 张嵘 on 2022/8/2.
  6. // Copyright © 2022 JCZ. All rights reserved.
  7. //
  8. #import "RQSimulateExamBeginCell.h"
  9. @interface RQSimulateExamBeginCell ()
  10. @property (nonatomic, readwrite, strong) RQSimulateExamBeginItemViewModel *viewModel;
  11. @property (weak, nonatomic) IBOutlet UIView *myContentView;
  12. @property (weak, nonatomic) IBOutlet QMUIButton *tiShengTongGuoLvBtn;
  13. @property (weak, nonatomic) IBOutlet QMUIButton *beginExamBtn;
  14. @property (weak, nonatomic) IBOutlet QMUIButton *miJuanBtn;
  15. @property (weak, nonatomic) IBOutlet UIView *realExamView;
  16. @property (weak, nonatomic) IBOutlet QMUIButton *tuiJianBtn;
  17. @property (weak, nonatomic) IBOutlet UIImageView *myHeadImageView;
  18. @property (weak, nonatomic) IBOutlet UILabel *nameLabel;
  19. @property (nonatomic, readwrite, copy) NSArray *questionArr;
  20. @property (weak, nonatomic) IBOutlet UILabel *passRateLabel;
  21. @property (weak, nonatomic) IBOutlet UILabel *passRateDscLabel;
  22. @property (weak, nonatomic) IBOutlet UILabel *scoreLabel;
  23. @property (weak, nonatomic) IBOutlet UILabel *countLabel;
  24. @property (weak, nonatomic) IBOutlet UILabel *examCountLabel;
  25. @property (weak, nonatomic) IBOutlet UILabel *passCountLabel;
  26. @end
  27. @implementation RQSimulateExamBeginCell
  28. #pragma mark - PublicMethods
  29. + (instancetype)cellWithTableView:(UITableView *)tableView {
  30. static NSString *ID = @"RQSimulateExamBeginCell";
  31. RQSimulateExamBeginCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
  32. if (!cell) {
  33. cell = [self rq_viewFromXib];
  34. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  35. }
  36. return cell;
  37. }
  38. - (void)bindViewModel:(RQSimulateExamBeginItemViewModel *)viewModel {
  39. _viewModel = viewModel;
  40. @weakify(self)
  41. [RACObserve(RQ_USER_MANAGER, currentUser) subscribeNext:^(RQUserModel *userModel) {
  42. @strongify(self);
  43. self.nameLabel.text = RQ_USER_MANAGER.currentUser.userName;
  44. [self.myHeadImageView yy_setImageWithURL:[NSURL URLWithString:RQ_USER_MANAGER.currentUser.photo] placeholder:RQWebAvatarImagePlaceholder() options:RQWebImageOptionAutomatic completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {
  45. @strongify(self);
  46. if(image) {
  47. image = [image qmui_imageResizedInLimitedSize:CGSizeMake(RQ_FIT_HORIZONTAL(54.f), RQ_FIT_HORIZONTAL(54.f)) resizingMode:QMUIImageResizingModeScaleAspectFill];
  48. image = [image qmui_imageWithBorderColor:UIColor.whiteColor borderWidth:1 cornerRadius:RQ_FIT_HORIZONTAL(54.f) / 2.f];
  49. self.myHeadImageView.image = image;
  50. }
  51. }];
  52. }];
  53. }
  54. - (void)awakeFromNib {
  55. [super awakeFromNib];
  56. @weakify(self)
  57. _myHeadImageView.layer.cornerRadius = RQ_FIT_HORIZONTAL(54.f) / 2.f;
  58. _myContentView.layer.shadowColor = RGBA_COLOR(124, 129, 136, 0.2).CGColor;
  59. [_tiShengTongGuoLvBtn setBackgroundImage:[UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) {
  60. graColor.fromColor = [UIColor qmui_colorWithHexString:@"#FF4C52"];
  61. graColor.toColor = [UIColor qmui_colorWithHexString:@"#FC8269"];
  62. graColor.type = QQGradualChangeTypeLeftToRight;
  63. } size:CGSizeMake(RQ_FIT_HORIZONTAL(104.f), RQ_FIT_HORIZONTAL(34.f)) cornerRadius:QQRadiusMakeSame(RQ_FIT_HORIZONTAL(34.f) / 2.f)] forState:UIControlStateNormal];
  64. _beginExamBtn.layer.cornerRadius = RQ_FIT_HORIZONTAL(50.f) / 2.f;
  65. _miJuanBtn.layer.cornerRadius = RQ_FIT_HORIZONTAL(50.f) / 2.f;
  66. _miJuanBtn.layer.borderColor = RQ_MAIN_TEXT_COLOR_1.CGColor;
  67. _realExamView.layer.cornerRadius = RQ_FIT_HORIZONTAL(71.f) / 2.f;
  68. _realExamView.layer.borderColor = RQ_MAIN_TEXT_COLOR_1.CGColor;
  69. [_tuiJianBtn setBackgroundImage:[UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) {
  70. graColor.fromColor = [UIColor qmui_colorWithHexString:@"#FF4C52"];
  71. graColor.toColor = [UIColor qmui_colorWithHexString:@"#FC8269"];
  72. graColor.type = QQGradualChangeTypeLeftToRight;
  73. } size:CGSizeMake(RQ_FIT_HORIZONTAL(32.f), RQ_FIT_HORIZONTAL(16.f)) cornerRadius:QQRadiusMake(0.f, RQ_FIT_HORIZONTAL(16.f) / 2.f, RQ_FIT_HORIZONTAL(16.f) / 2.f, 0.f)] forState:UIControlStateNormal];
  74. [_realExamView setTapActionWithBlock:^(UITapGestureRecognizer *tap) {
  75. [RQ_VIP_Module isVipWithSubject:RQ_YDTQuestion_Module.subject + 1 complete:^(BOOL isVip) {
  76. if (isVip) {
  77. NSString *urlStr = [NSString stringWithFormat:@"https://mn.zzxcx.net/#/exam/begin?username=%@&subject=%@&model=%@&headimg=%@",[RQ_USER_MANAGER.currentUser.userName qmui_stringByEncodingUserInputQuery],RQ_YDTQuestion_Module.subjectStr,RQ_YDTQuestion_Module.carTypeStrNew,RQ_USER_MANAGER.currentUser.photo];
  78. NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:urlStr]];
  79. RQWebViewModel *webViewModel = [[RQWebViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{RQViewModelRequestKey:request, RQViewModelWebViewTypeKey:@(RQWebViewType_Exam)}];
  80. webViewModel.prefersNavigationBarHidden = YES;
  81. [RQ_APPDELEGATE.services pushViewModel:webViewModel animated:YES];
  82. // NYExaminationViewModel *examinationViewModel = [[NYExaminationViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{}];
  83. // examinationViewModel.km = RQ_YDTQuestion_Module.subjectStr.intValue;
  84. // [RQ_APPDELEGATE.services pushViewModel:examinationViewModel animated:YES];
  85. } else {
  86. if (RQ_VIP_Module.freeLookSimExamNum == 1||
  87. RQ_COMMON_MANAGER.APP_SWITCH) {//审核状态不用看广告
  88. NSString *urlStr = [NSString stringWithFormat:@"https://mn.zzxcx.net/#/exam/begin?username=%@&subject=%@&model=%@&headimg=%@",[RQ_USER_MANAGER.currentUser.userName qmui_stringByEncodingUserInputQuery],RQ_YDTQuestion_Module.subjectStr,RQ_YDTQuestion_Module.carTypeStrNew,RQ_USER_MANAGER.currentUser.photo];
  89. NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:urlStr]];
  90. RQWebViewModel *webViewModel = [[RQWebViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{RQViewModelRequestKey:request, RQViewModelWebViewTypeKey:@(RQWebViewType_Exam)}];
  91. webViewModel.prefersNavigationBarHidden = YES;
  92. [RQ_APPDELEGATE.services pushViewModel:webViewModel animated:YES];
  93. // NYExaminationViewModel *examinationViewModel = [[NYExaminationViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{}];
  94. // examinationViewModel.km = RQ_YDTQuestion_Module.subjectStr.intValue;
  95. // [RQ_APPDELEGATE.services pushViewModel:examinationViewModel animated:YES];
  96. RQ_VIP_Module.freeLookSimExamNum = 0;
  97. } else {
  98. if(!RQ_COMMON_MANAGER.APP_SWITCH){
  99. [RQ_ALERTVIEW_MANAGER showAlertWithAlertType:RQAlertType_AD title:@"" message:@"" confirmTitle:@"充值会员无限使用" cancelTitle:@"看广告解锁使用" confirmAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
  100. [RQ_VIP_Module gotoBuyVipWithVipPageType:RQVIPPageType_Full];
  101. } cancelAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
  102. [RQ_AD_Module loadRewardvodAd];
  103. }];
  104. }
  105. }
  106. }
  107. }];
  108. }];
  109. NSArray *arr = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Exam];
  110. __block NSInteger num = 0;
  111. arr = [arr.rac_sequence.signal map:^id _Nullable(RQYDTQuestionModel *ydtQuestionModel) {
  112. ydtQuestionModel.num = num;
  113. num ++;
  114. return [RQExerciseModel exerciseModelWithRQYDTQuestionModel:ydtQuestionModel];
  115. }].toArray;
  116. self.questionArr = arr;
  117. [[RQ_HTTP_Service getPassRate] subscribeNext:^(NSString *str) {
  118. @strongify(self)
  119. if (RQStringIsNotEmpty(str)) {
  120. self.passRateLabel.text = str;
  121. NSInteger c = str.integerValue;
  122. if (c >= 0 && c <= 10) {
  123. self.passRateDscLabel.text = @"极低";
  124. } else if (c > 10 && c <= 20) {
  125. self.passRateDscLabel.text = @"很低";
  126. } else if (c > 20 && c <= 30) {
  127. self.passRateDscLabel.text = @"较低";
  128. } else if (c > 30 && c <= 40) {
  129. self.passRateDscLabel.text = @"稍低";
  130. } else if (c > 40 && c <= 50) {
  131. self.passRateDscLabel.text = @"低";
  132. } else if (c > 50 && c <= 60) {
  133. self.passRateDscLabel.text = @"不高";
  134. } else if (c > 60 && c <= 70) {
  135. self.passRateDscLabel.text = @"稍高";
  136. } else if (c > 70 && c <= 80) {
  137. self.passRateDscLabel.text = @"较高";
  138. } else if (c > 80 && c <= 90) {
  139. self.passRateDscLabel.text = @"很高";
  140. } else if (c > 90 && c <= 100) {
  141. self.passRateDscLabel.text = @"极高";
  142. }
  143. }
  144. }];
  145. RAC(self.scoreLabel, text) = [[RACSignal combineLatest:@[RACObserve(RQ_COMMON_MANAGER, examResultOneListArr), RACObserve(RQ_COMMON_MANAGER, examResultFourListArr)] reduce:^id (NSArray *examResultOneListArr, NSArray *examResultFourListArr) {
  146. BOOL isSubjectOne = RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectOne;
  147. NSArray *arr;
  148. if (isSubjectOne) {
  149. arr = examResultOneListArr;
  150. } else {
  151. arr = examResultFourListArr;
  152. }
  153. float avg = [[[arr.rac_sequence.signal map:^id _Nullable(RQExamResultModel *examResultModel) {
  154. return examResultModel.score;
  155. }].toArray valueForKeyPath:@"@avg.floatValue"] floatValue];
  156. NSArray *passArr = [arr.rac_sequence.signal filter:^BOOL(RQExamResultModel *examResultModel) {
  157. return [examResultModel.score integerValue] >= 90;
  158. }].toArray;
  159. self.passCountLabel.text = [NSString qmui_stringWithNSInteger:passArr.count];
  160. NSString *score = [NSString qmui_stringWithCGFloat:avg decimal:0];
  161. return score;
  162. }] takeUntil:self.rac_willDeallocSignal];
  163. RAC(self.countLabel, text) = [[RACSignal combineLatest:@[RACObserve(RQ_COMMON_MANAGER, examResultOneListArr), RACObserve(RQ_COMMON_MANAGER, examResultFourListArr)] reduce:^id (NSArray *examResultOneListArr, NSArray *examResultFourListArr) {
  164. @strongify(self)
  165. BOOL isSubjectOne = RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectOne;
  166. NSArray *arr;
  167. if (isSubjectOne) {
  168. arr = examResultOneListArr;
  169. } else {
  170. arr = examResultFourListArr;
  171. }
  172. NSString *count = [NSString qmui_stringWithNSInteger:arr.count];
  173. self.examCountLabel.text = count;
  174. return [NSString stringWithFormat:@"近%@次平均分",count];
  175. }] takeUntil:self.rac_willDeallocSignal];
  176. }
  177. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  178. [super setSelected:selected animated:animated];
  179. // Configure the view for the selected state
  180. }
  181. - (IBAction)beginExamBtnAction:(id)sender {
  182. NSArray *arr = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Exam];
  183. __block NSInteger num = 0;
  184. arr = [arr.rac_sequence.signal map:^id _Nullable(RQYDTQuestionModel *ydtQuestionModel) {
  185. ydtQuestionModel.num = num;
  186. num ++;
  187. return [RQExerciseModel exerciseModelWithRQYDTQuestionModel:ydtQuestionModel];
  188. }].toArray;
  189. [[RACScheduler mainThreadScheduler] schedule:^{
  190. // RQ_Exercise_Module.currentExerciseType = RQExerciseType_Exam;
  191. RQExerciseViewModel *exerciseViewModel = [[RQExerciseViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{
  192. RQHomePageCarTypeKey : @(RQ_YDTQuestion_Module.carType),
  193. RQHomePageSubjectTypeKey : @(RQ_YDTQuestion_Module.subject),
  194. RQHomeSubPageTypeKey : @(RQHomeSubPageType_MockExamination),
  195. RQViewModelIDKey : @"模拟考试",
  196. RQExerciseTypeKey : @(RQExerciseType_Exam),
  197. RQViewModelUtilKey : arr,
  198. }];
  199. [RQ_APPDELEGATE.services pushViewModel:exerciseViewModel animated:YES];
  200. }];
  201. }
  202. - (IBAction)miJuanBtnAction:(id)sender {
  203. RQHoursBeforeExamHomeViewModel *hoursBeforeExamHomeViewModel = [[RQHoursBeforeExamHomeViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:nil];
  204. [RQ_APPDELEGATE.services pushViewModel:hoursBeforeExamHomeViewModel animated:YES];
  205. }
  206. - (IBAction)tiShengTongGuoLvBtnAction:(id)sender {
  207. [RQ_VIP_Module isVipWithSubject:0 complete:^(BOOL isVip) {
  208. if (RQ_VIP_Module.isVip) {
  209. [RQ_VIP_Module gotoVipCenter];
  210. } else {
  211. [RQ_VIP_Module gotoBuyVipWithVipPageType:RQVIPPageType_Full];
  212. }
  213. }];
  214. }
  215. - (IBAction)simulateExamShouldKonwBtnAction:(id)sender {
  216. NSDictionary *dic = @{
  217. @"questionArr" : self.questionArr,
  218. };
  219. [RQ_Exercise_Module showAlertWithRQExerciseAlertType:RQExerciseAlertType_Exam_Konw valueDic:dic confirmAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
  220. } cancelAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
  221. }];
  222. }
  223. @end