RQSimulateExamBeginCell.m 13 KB

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