RQSimulateExamBeginCell.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. if(RQ_COMMON_MANAGER.APP_SWITCH){//审核状态走web 页
  78. 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];
  79. NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:urlStr]];
  80. RQWebViewModel *webViewModel = [[RQWebViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{RQViewModelRequestKey:request, RQViewModelWebViewTypeKey:@(RQWebViewType_Exam)}];
  81. webViewModel.prefersNavigationBarHidden = YES;
  82. [RQ_APPDELEGATE.services pushViewModel:webViewModel animated:YES];
  83. }else{
  84. //显示真实考场
  85. NYExaminationViewModel *examinationViewModel = [[NYExaminationViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{}];
  86. examinationViewModel.km = RQ_YDTQuestion_Module.subjectStr.intValue;
  87. [RQ_APPDELEGATE.services pushViewModel:examinationViewModel animated:YES];
  88. }
  89. } else {
  90. if (RQ_VIP_Module.freeLookSimExamNum == 1||
  91. RQ_COMMON_MANAGER.APP_SWITCH) {//审核状态不用看广告
  92. if(RQ_COMMON_MANAGER.APP_SWITCH){//审核状态走web 页
  93. 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];
  94. NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:urlStr]];
  95. RQWebViewModel *webViewModel = [[RQWebViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{RQViewModelRequestKey:request, RQViewModelWebViewTypeKey:@(RQWebViewType_Exam)}];
  96. webViewModel.prefersNavigationBarHidden = YES;
  97. [RQ_APPDELEGATE.services pushViewModel:webViewModel animated:YES];
  98. }else{
  99. //显示真实考场
  100. NYExaminationViewModel *examinationViewModel = [[NYExaminationViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{}];
  101. examinationViewModel.km = RQ_YDTQuestion_Module.subjectStr.intValue;
  102. [RQ_APPDELEGATE.services pushViewModel:examinationViewModel animated:YES];
  103. }
  104. RQ_VIP_Module.freeLookSimExamNum = 0;
  105. } else {
  106. if(!RQ_COMMON_MANAGER.APP_SWITCH){
  107. [RQ_ALERTVIEW_MANAGER showAlertWithAlertType:RQAlertType_AD title:@"" message:@"" confirmTitle:@"充值会员无限使用" cancelTitle:@"看广告解锁使用" confirmAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
  108. [RQ_VIP_Module gotoBuyVipWithVipPageType:RQVIPPageType_Full];
  109. } cancelAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
  110. [RQ_AD_Module loadRewardvodAd];
  111. }];
  112. }
  113. }
  114. }
  115. }];
  116. }];
  117. NSArray *arr = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Exam];
  118. __block NSInteger num = 0;
  119. arr = [arr.rac_sequence.signal map:^id _Nullable(RQYDTQuestionModel *ydtQuestionModel) {
  120. ydtQuestionModel.num = num;
  121. num ++;
  122. return [RQExerciseModel exerciseModelWithRQYDTQuestionModel:ydtQuestionModel];
  123. }].toArray;
  124. self.questionArr = arr;
  125. [[RQ_HTTP_Service getPassRate] subscribeNext:^(NSString *str) {
  126. @strongify(self)
  127. if (RQStringIsNotEmpty(str)) {
  128. self.passRateLabel.text = str;
  129. NSInteger c = str.integerValue;
  130. if (c >= 0 && c <= 10) {
  131. self.passRateDscLabel.text = @"极低";
  132. } else if (c > 10 && c <= 20) {
  133. self.passRateDscLabel.text = @"很低";
  134. } else if (c > 20 && c <= 30) {
  135. self.passRateDscLabel.text = @"较低";
  136. } else if (c > 30 && c <= 40) {
  137. self.passRateDscLabel.text = @"稍低";
  138. } else if (c > 40 && c <= 50) {
  139. self.passRateDscLabel.text = @"低";
  140. } else if (c > 50 && c <= 60) {
  141. self.passRateDscLabel.text = @"不高";
  142. } else if (c > 60 && c <= 70) {
  143. self.passRateDscLabel.text = @"稍高";
  144. } else if (c > 70 && c <= 80) {
  145. self.passRateDscLabel.text = @"较高";
  146. } else if (c > 80 && c <= 90) {
  147. self.passRateDscLabel.text = @"很高";
  148. } else if (c > 90 && c <= 100) {
  149. self.passRateDscLabel.text = @"极高";
  150. }
  151. }
  152. }];
  153. RAC(self.scoreLabel, text) = [[RACSignal combineLatest:@[RACObserve(RQ_COMMON_MANAGER, examResultOneListArr), RACObserve(RQ_COMMON_MANAGER, examResultFourListArr)] reduce:^id (NSArray *examResultOneListArr, NSArray *examResultFourListArr) {
  154. BOOL isSubjectOne = RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectOne;
  155. NSArray *arr;
  156. if (isSubjectOne) {
  157. arr = examResultOneListArr;
  158. } else {
  159. arr = examResultFourListArr;
  160. }
  161. float avg = [[[arr.rac_sequence.signal map:^id _Nullable(RQExamResultModel *examResultModel) {
  162. return examResultModel.score;
  163. }].toArray valueForKeyPath:@"@avg.floatValue"] floatValue];
  164. NSArray *passArr = [arr.rac_sequence.signal filter:^BOOL(RQExamResultModel *examResultModel) {
  165. return [examResultModel.score integerValue] >= 90;
  166. }].toArray;
  167. self.passCountLabel.text = [NSString qmui_stringWithNSInteger:passArr.count];
  168. NSString *score = [NSString qmui_stringWithCGFloat:avg decimal:0];
  169. return score;
  170. }] takeUntil:self.rac_willDeallocSignal];
  171. RAC(self.countLabel, text) = [[RACSignal combineLatest:@[RACObserve(RQ_COMMON_MANAGER, examResultOneListArr), RACObserve(RQ_COMMON_MANAGER, examResultFourListArr)] reduce:^id (NSArray *examResultOneListArr, NSArray *examResultFourListArr) {
  172. @strongify(self)
  173. BOOL isSubjectOne = RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectOne;
  174. NSArray *arr;
  175. if (isSubjectOne) {
  176. arr = examResultOneListArr;
  177. } else {
  178. arr = examResultFourListArr;
  179. }
  180. NSString *count = [NSString qmui_stringWithNSInteger:arr.count];
  181. self.examCountLabel.text = count;
  182. return [NSString stringWithFormat:@"近%@次平均分",count];
  183. }] takeUntil:self.rac_willDeallocSignal];
  184. }
  185. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  186. [super setSelected:selected animated:animated];
  187. // Configure the view for the selected state
  188. }
  189. - (IBAction)beginExamBtnAction:(id)sender {
  190. NSArray *arr = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Exam];
  191. __block NSInteger num = 0;
  192. arr = [arr.rac_sequence.signal map:^id _Nullable(RQYDTQuestionModel *ydtQuestionModel) {
  193. ydtQuestionModel.num = num;
  194. num ++;
  195. return [RQExerciseModel exerciseModelWithRQYDTQuestionModel:ydtQuestionModel];
  196. }].toArray;
  197. [[RACScheduler mainThreadScheduler] schedule:^{
  198. // RQ_Exercise_Module.currentExerciseType = RQExerciseType_Exam;
  199. RQExerciseViewModel *exerciseViewModel = [[RQExerciseViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{
  200. RQHomePageCarTypeKey : @(RQ_YDTQuestion_Module.carType),
  201. RQHomePageSubjectTypeKey : @(RQ_YDTQuestion_Module.subject),
  202. RQHomeSubPageTypeKey : @(RQHomeSubPageType_MockExamination),
  203. RQViewModelIDKey : @"模拟考试",
  204. RQExerciseTypeKey : @(RQExerciseType_Exam),
  205. RQViewModelUtilKey : arr,
  206. }];
  207. [RQ_APPDELEGATE.services pushViewModel:exerciseViewModel animated:YES];
  208. }];
  209. }
  210. - (IBAction)miJuanBtnAction:(id)sender {
  211. RQHoursBeforeExamHomeViewModel *hoursBeforeExamHomeViewModel = [[RQHoursBeforeExamHomeViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:nil];
  212. [RQ_APPDELEGATE.services pushViewModel:hoursBeforeExamHomeViewModel animated:YES];
  213. }
  214. - (IBAction)tiShengTongGuoLvBtnAction:(id)sender {
  215. [RQ_VIP_Module isVipWithSubject:0 complete:^(BOOL isVip) {
  216. if (RQ_VIP_Module.isVip) {
  217. [RQ_VIP_Module gotoVipCenter];
  218. } else {
  219. [RQ_VIP_Module gotoBuyVipWithVipPageType:RQVIPPageType_Full];
  220. }
  221. }];
  222. }
  223. - (IBAction)simulateExamShouldKonwBtnAction:(id)sender {
  224. NSDictionary *dic = @{
  225. @"questionArr" : self.questionArr,
  226. };
  227. [RQ_Exercise_Module showAlertWithRQExerciseAlertType:RQExerciseAlertType_Exam_Konw valueDic:dic confirmAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
  228. } cancelAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) {
  229. }];
  230. }
  231. @end