RQSimulateExamBeginCell.m 15 KB

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