// // RQSimulateExamBeginCell.m // jiaPei // // Created by 张嵘 on 2022/8/2. // Copyright © 2022 JCZ. All rights reserved. // #import "RQSimulateExamBeginCell.h" @interface RQSimulateExamBeginCell () @property (nonatomic, readwrite, strong) RQSimulateExamBeginItemViewModel *viewModel; @property (weak, nonatomic) IBOutlet UIView *myContentView; @property (weak, nonatomic) IBOutlet QMUIButton *tiShengTongGuoLvBtn; @property (weak, nonatomic) IBOutlet QMUIButton *beginExamBtn; @property (weak, nonatomic) IBOutlet QMUIButton *miJuanBtn; @property (weak, nonatomic) IBOutlet UIView *realExamView; @property (weak, nonatomic) IBOutlet QMUIButton *tuiJianBtn; @property (weak, nonatomic) IBOutlet UIImageView *myHeadImageView; @property (weak, nonatomic) IBOutlet UILabel *nameLabel; @property (nonatomic, readwrite, copy) NSArray *questionArr; @property (weak, nonatomic) IBOutlet UILabel *passRateLabel; @property (weak, nonatomic) IBOutlet UILabel *passRateDscLabel; @property (weak, nonatomic) IBOutlet UILabel *scoreLabel; @property (weak, nonatomic) IBOutlet UILabel *countLabel; @property (weak, nonatomic) IBOutlet UILabel *examCountLabel; @property (weak, nonatomic) IBOutlet UILabel *passCountLabel; @end @implementation RQSimulateExamBeginCell #pragma mark - PublicMethods + (instancetype)cellWithTableView:(UITableView *)tableView { static NSString *ID = @"RQSimulateExamBeginCell"; RQSimulateExamBeginCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; if (!cell) { cell = [self rq_viewFromXib]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } return cell; } - (void)bindViewModel:(RQSimulateExamBeginItemViewModel *)viewModel { _viewModel = viewModel; @weakify(self) [RACObserve(RQ_USER_MANAGER, currentUser) subscribeNext:^(RQUserModel *userModel) { @strongify(self); self.nameLabel.text = RQ_USER_MANAGER.currentUser.userName; [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) { @strongify(self); if(image) { image = [image qmui_imageResizedInLimitedSize:CGSizeMake(RQ_FIT_HORIZONTAL(54.f), RQ_FIT_HORIZONTAL(54.f)) resizingMode:QMUIImageResizingModeScaleAspectFill]; image = [image qmui_imageWithBorderColor:UIColor.whiteColor borderWidth:1 cornerRadius:RQ_FIT_HORIZONTAL(54.f) / 2.f]; self.myHeadImageView.image = image; } }]; }]; } - (void)awakeFromNib { [super awakeFromNib]; @weakify(self) _myHeadImageView.layer.cornerRadius = RQ_FIT_HORIZONTAL(54.f) / 2.f; _myContentView.layer.shadowColor = RGBA_COLOR(124, 129, 136, 0.2).CGColor; [_tiShengTongGuoLvBtn setBackgroundImage:[UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) { graColor.fromColor = [UIColor qmui_colorWithHexString:@"#FF4C52"]; graColor.toColor = [UIColor qmui_colorWithHexString:@"#FC8269"]; graColor.type = QQGradualChangeTypeLeftToRight; } size:CGSizeMake(RQ_FIT_HORIZONTAL(104.f), RQ_FIT_HORIZONTAL(34.f)) cornerRadius:QQRadiusMakeSame(RQ_FIT_HORIZONTAL(34.f) / 2.f)] forState:UIControlStateNormal]; _beginExamBtn.layer.cornerRadius = RQ_FIT_HORIZONTAL(50.f) / 2.f; _miJuanBtn.layer.cornerRadius = RQ_FIT_HORIZONTAL(50.f) / 2.f; _miJuanBtn.layer.borderColor = RQ_MAIN_TEXT_COLOR_1.CGColor; _realExamView.layer.cornerRadius = RQ_FIT_HORIZONTAL(71.f) / 2.f; _realExamView.layer.borderColor = RQ_MAIN_TEXT_COLOR_1.CGColor; [_tuiJianBtn setBackgroundImage:[UIImage imageWithGradualChangingColor:^(QQGradualChangingColor *graColor) { graColor.fromColor = [UIColor qmui_colorWithHexString:@"#FF4C52"]; graColor.toColor = [UIColor qmui_colorWithHexString:@"#FC8269"]; graColor.type = QQGradualChangeTypeLeftToRight; } 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]; [_realExamView setTapActionWithBlock:^(UITapGestureRecognizer *tap) { [RQ_VIP_Module isVipWithSubject:RQ_YDTQuestion_Module.subject + 1 complete:^(BOOL isVip) { if (isVip) { 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]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:urlStr]]; RQWebViewModel *webViewModel = [[RQWebViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{RQViewModelRequestKey:request, RQViewModelWebViewTypeKey:@(RQWebViewType_Exam)}]; webViewModel.prefersNavigationBarHidden = YES; [RQ_APPDELEGATE.services pushViewModel:webViewModel animated:YES]; } else { if (RQ_VIP_Module.freeLookSimExamNum == 1) { 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]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:urlStr]]; RQWebViewModel *webViewModel = [[RQWebViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{RQViewModelRequestKey:request, RQViewModelWebViewTypeKey:@(RQWebViewType_Exam)}]; webViewModel.prefersNavigationBarHidden = YES; [RQ_APPDELEGATE.services pushViewModel:webViewModel animated:YES]; RQ_VIP_Module.freeLookSimExamNum = 0; } else { [RQ_ALERTVIEW_MANAGER showAlertWithAlertType:RQAlertType_AD title:@"" message:@"" confirmTitle:@"充值会员无限使用" cancelTitle:@"看广告解锁使用" confirmAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) { [RQ_VIP_Module gotoBuyVipWithVipPageType:RQVIPPageType_Full]; } cancelAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) { [RQ_AD_Module loadRewardvodAd]; }]; } } }]; }]; NSArray *arr = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Exam]; __block NSInteger num = 0; arr = [arr.rac_sequence.signal map:^id _Nullable(RQYDTQuestionModel *ydtQuestionModel) { ydtQuestionModel.num = num; num ++; return [RQExerciseModel exerciseModelWithRQYDTQuestionModel:ydtQuestionModel]; }].toArray; self.questionArr = arr; [[RQ_HTTP_Service getPassRate] subscribeNext:^(NSString *str) { @strongify(self) if (RQStringIsNotEmpty(str)) { self.passRateLabel.text = str; NSInteger c = str.integerValue; if (c >= 0 && c <= 10) { self.passRateDscLabel.text = @"极低"; } else if (c > 10 && c <= 20) { self.passRateDscLabel.text = @"很低"; } else if (c > 20 && c <= 30) { self.passRateDscLabel.text = @"较低"; } else if (c > 30 && c <= 40) { self.passRateDscLabel.text = @"稍低"; } else if (c > 40 && c <= 50) { self.passRateDscLabel.text = @"低"; } else if (c > 50 && c <= 60) { self.passRateDscLabel.text = @"不高"; } else if (c > 60 && c <= 70) { self.passRateDscLabel.text = @"稍高"; } else if (c > 70 && c <= 80) { self.passRateDscLabel.text = @"较高"; } else if (c > 80 && c <= 90) { self.passRateDscLabel.text = @"很高"; } else if (c > 90 && c <= 100) { self.passRateDscLabel.text = @"极高"; } } }]; RAC(self.scoreLabel, text) = [[RACSignal combineLatest:@[RACObserve(RQ_COMMON_MANAGER, examResultOneListArr), RACObserve(RQ_COMMON_MANAGER, examResultFourListArr)] reduce:^id (NSArray *examResultOneListArr, NSArray *examResultFourListArr) { BOOL isSubjectOne = RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectOne; NSArray *arr; if (isSubjectOne) { arr = examResultOneListArr; } else { arr = examResultFourListArr; } float avg = [[[arr.rac_sequence.signal map:^id _Nullable(RQExamResultModel *examResultModel) { return examResultModel.score; }].toArray valueForKeyPath:@"@avg.floatValue"] floatValue]; NSArray *passArr = [arr.rac_sequence.signal filter:^BOOL(RQExamResultModel *examResultModel) { return [examResultModel.score integerValue] >= 90; }].toArray; self.passCountLabel.text = [NSString qmui_stringWithNSInteger:passArr.count]; NSString *score = [NSString qmui_stringWithCGFloat:avg decimal:0]; return score; }] takeUntil:self.rac_willDeallocSignal]; RAC(self.countLabel, text) = [[RACSignal combineLatest:@[RACObserve(RQ_COMMON_MANAGER, examResultOneListArr), RACObserve(RQ_COMMON_MANAGER, examResultFourListArr)] reduce:^id (NSArray *examResultOneListArr, NSArray *examResultFourListArr) { @strongify(self) BOOL isSubjectOne = RQ_YDTQuestion_Module.subject == RQHomePageSubjectType_SubjectOne; NSArray *arr; if (isSubjectOne) { arr = examResultOneListArr; } else { arr = examResultFourListArr; } NSString *count = [NSString qmui_stringWithNSInteger:arr.count]; self.examCountLabel.text = count; return [NSString stringWithFormat:@"近%@次平均分",count]; }] takeUntil:self.rac_willDeallocSignal]; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } - (IBAction)beginExamBtnAction:(id)sender { NSArray *arr = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Exam]; __block NSInteger num = 0; arr = [arr.rac_sequence.signal map:^id _Nullable(RQYDTQuestionModel *ydtQuestionModel) { ydtQuestionModel.num = num; num ++; return [RQExerciseModel exerciseModelWithRQYDTQuestionModel:ydtQuestionModel]; }].toArray; [[RACScheduler mainThreadScheduler] schedule:^{ // RQ_Exercise_Module.currentExerciseType = RQExerciseType_Exam; RQExerciseViewModel *exerciseViewModel = [[RQExerciseViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:@{ RQHomePageCarTypeKey : @(RQ_YDTQuestion_Module.carType), RQHomePageSubjectTypeKey : @(RQ_YDTQuestion_Module.subject), RQHomeSubPageTypeKey : @(RQHomeSubPageType_MockExamination), RQViewModelIDKey : @"模拟考试", RQExerciseTypeKey : @(RQExerciseType_Exam), RQViewModelUtilKey : arr, }]; [RQ_APPDELEGATE.services pushViewModel:exerciseViewModel animated:YES]; }]; } - (IBAction)miJuanBtnAction:(id)sender { RQHoursBeforeExamHomeViewModel *hoursBeforeExamHomeViewModel = [[RQHoursBeforeExamHomeViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:nil]; [RQ_APPDELEGATE.services pushViewModel:hoursBeforeExamHomeViewModel animated:YES]; } - (IBAction)tiShengTongGuoLvBtnAction:(id)sender { [RQ_VIP_Module isVipWithSubject:0 complete:^(BOOL isVip) { if (RQ_VIP_Module.isVip) { [RQ_VIP_Module gotoVipCenter]; } else { [RQ_VIP_Module gotoBuyVipWithVipPageType:RQVIPPageType_Full]; } }]; } - (IBAction)simulateExamShouldKonwBtnAction:(id)sender { NSDictionary *dic = @{ @"questionArr" : self.questionArr, }; [RQ_Exercise_Module showAlertWithRQExerciseAlertType:RQExerciseAlertType_Exam_Konw valueDic:dic confirmAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) { } cancelAction:^(__kindof QMUIDialogViewController * _Nonnull dialogViewController) { }]; } @end