RQSimulateExamBeginCell.m 12 KB

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