/** 先试一试循环滚动吧。 */ #import "ExerciseVC.h" #import "ExerView.h" #import "ExamResultVC.h" #import "Grade.h" #import "EXButton.h" #import "ExerciseSetting.h" #import "BtnCollectionViewCell.h" #import "ADLinkVC.h" #import "DES3Util.h" #import "ThirdLoginBindYunGuanVC.h" /** AlertTypeSubmit 提交 AlertTypePause 暂停 AlertTypeTimeOut 时间到 */ typedef NS_ENUM(NSInteger, AlertType){ AlertTypeSubmit = 1, AlertTypePause, AlertTypeTimeOut, AlertTypeIsLoad, AlertTypeIsQuit }; @interface ExerciseVC () //@property(nonatomic,strong)UIToolbar* toolBar; { // ExerView* exerV; //我的错题 NSArray* questions; //0 到 (cont-1) NSInteger qIndex; /**就是考试时,用来选择题号的view。在页面底部 */ UIView * contantV; STButton* bbi0,*bbi1,*bbi2,*bbi3,*bbi4; UIScrollView* scroll; /**保存scroll主页面。最后一次滚动的offset */ CGPoint lastOffset; #define answersLen 4000 #define correctLen 100 //#define sub1Minutes 45 //#define sub4Minutes 30 /**最大的错误分数 */ //#define faultCntMaxSub1 11 //#define faultCntMaxSub4 6 // NSInteger faultCntMax; /**用于保存用户的答题情况,默认值是0表示没答题 */ int answers[answersLen]; /**表示这题是否展开解释。0是不展开,1是展开。 */ int showAnsw[answersLen]; /**表示这题是否正确。1未答题,2正确,0错误。 */ int correct[correctLen]; /**保存做错的题目数量 */ int faultCnt,rigCnt; /**保存做错的分数 */ int faultMark; /**保存做对的分数 */ int correctMark; /**保存剩余的秒数。 */ int secCnt; /**考试计时用的. */ // NSTimer *timer; /**保存这次考试的信息。 */ Grade *grade; /**保存各种考试成绩的称号。例如,赛车之神 */ NSArray *honors; /**选择题目序号,view */ UIView *chooseView; UILabel *rigLbl,*errorLbl,*indexLbl,*barRigLbl,*barErrLbl; /**选择题号的按钮 */ NSMutableArray *choBtns; /**是否自动翻页 */ BOOL isSkip; /**是否自动显示答案 */ BOOL isExplain; /**声音模式 */ /// 是否继续考试 BOOL isContinue; UIView *adView; UIButton *adBtn; NSDictionary *adDic; //学时相关 UIView *rightView;//右侧视图 UIView *show_hideView;//左侧详情栏 UILabel *trainStateLabel;//右侧计时状态展示 UILabel *timeLabel1;//右侧按钮上 显示时分 UILabel *timeLabel2;//弹出View上 显示时分秒 UIButton *begin_endBtn;//开始结束按钮 UITextField *searchTf;//搜索题目框 UIButton *sureBtn;//搜索确定按钮 // NSInteger seconds;//时间 NSDateFormatter *formatter; } /**科一45分钟100题。 科四45分钟50题。 */ @property (nonatomic, readwrite, assign) CGFloat adWidth; @property (nonatomic, readwrite, assign) CGFloat adHeight; @property (nonatomic, readwrite, strong) UIView *bannerView; @property (assign, readwrite, nonatomic) NSInteger seconds; @property (strong, readwrite, nonatomic) NSTimer *timer; //@property (strong, readwrite, nonatomic) UIButton *on_offBtn; @property (nonatomic, copy) NSString *secondString; @end @implementation ExerciseVC { NSMutableArray *navBtns; ExerciseSetting *setView; /**用于滚动的练习题的页面,总共3个 */ NSMutableArray *exVs; } #pragma mark - - (void)viewDidLoad { [super viewDidLoad]; RQ_COMMON_MANAGER.bannerOnVC = self; //关于模式选择 [self loadQuestion];//==>设置qIndex 和 questions //通用导航栏 [self configNavBar]; //展示题目 [self configExerV:NO];//==>setQueIndex //默认设置 isSkip = YES; isExplain = YES; isContinue = NO; // //计时 // [[RQ_HTTP_Service getIsUsePhone] subscribeNext:^(NSString *timeStr) { // if ([timeStr containsString:@"-"] || [timeStr containsString:@":"]) { // if ([timeStr componentsSeparatedByString:@"-"].firstObject.integerValue >= 2023) { // [self initTrainView]; // } // } // } error:^(NSError * _Nullable error) { //// NSString *timeStr = @"2022-12-19 16:11:57"; // // }]; for (NSDictionary * dic in defUser.userDict[@"params"]) { if ([dic[@"KEY"] isEqualToString:@"SP_SHOW_YC"]) { BOOL isShow = [dic[@"VALUE"] boolValue]; if (isShow) { // [self initTrainView]; [self.view bringSubviewToFront:RQ_TIMING_VIEW]; } } } } //页面将要进入前台,开启定时器 -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { //开启定时器 [self.timer setFireDate:[NSDate distantPast]]; } else { if ([defUser.car_type isEqualToString:@"2"] && myDelegate.isLogin) { } else { //开启定时器 [self.timer setFireDate:[NSDate distantPast]]; } } if (!adView) { if (QuestionTypeExam != myDelegate.type.intValue) { [self creatADView]; } } for (NSDictionary * dic in defUser.userDict[@"params"]) { if ([dic[@"KEY"] isEqualToString:@"SP_SHOW_YC"]) { BOOL isShow = [dic[@"VALUE"] boolValue]; if (isShow) { RQ_TIMING_VIEW.hidden = NO; } } } } -(void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [self setNavBarNormalColor]; RQ_TIMING_VIEW.hidden = YES; } //页面消失,进入后台不显示该页面,关闭定时器 -(void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; for (ExerView* v in exVs) { [v stopMovie]; } if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { //关闭定时器 [self.timer setFireDate:[NSDate distantFuture]]; } else { if ([defUser.car_type isEqualToString:@"2"] && myDelegate.isLogin) { } else { //关闭定时器 [self.timer setFireDate:[NSDate distantFuture]]; } } if (myDelegate.timer) { [myDelegate.timer invalidate]; myDelegate.timer = nil; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } - (void)dealloc { } #pragma mark - -(void)configButtomBar { if (QuestionTypeExam == myDelegate.type.intValue){ CGFloat h = 40 , w = 60; CGFloat topHeight = RQ_APPLICATION_TOP_BAR_HEIGHT; CGFloat height = RQ_SCREEN_HEIGHT; CGFloat buttomBarY = height - topHeight - h - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT; UIView *buttomBar = [[UIView alloc] initWithFrame:CGRectMake(0, buttomBarY, RQ_SCREEN_WIDTH, h)]; [self.view addSubview:buttomBar]; [buttomBar setBackgroundColor:KlineColor]; UILabel* label; label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, w*2, h)]; [label setTextAlignment:NSTextAlignmentCenter]; [label setTextColor:subTitleColor]; NSInteger examQuestionCount = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Exam].count; if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { if (1 == myDelegate.subject.intValue) { [label setText:examQuestionCount > 0? [NSString stringWithFormat:@"1/%ld",examQuestionCount] : [defUser.car_type isEqualToString:@"D"]? @"1/50" : @"1/100"]; }else{ [label setText:examQuestionCount > 0? [NSString stringWithFormat:@"1/%ld",examQuestionCount] : @"1/50"]; } } else { if ([defUser.car_type isEqualToString:@"2"]) { [label setText:@"1/50"]; } else { if (1 == myDelegate.subject.intValue) { [label setText:examQuestionCount > 0? [NSString stringWithFormat:@"1/%ld",examQuestionCount] : [defUser.car_type isEqualToString:@"D"]? @"1/50" : @"1/100"]; }else{ [label setText:examQuestionCount > 0? [NSString stringWithFormat:@"1/%ld",examQuestionCount] : @"1/50"]; } } } [buttomBar addSubview:label]; indexLbl = label; label = [[UILabel alloc] initWithFrame:CGRectMake(kSize.width - w, 0, w, h)]; [label setFont:[UIFont scaleSize:13]]; [label setTextColor:[UIColor redColor]]; [buttomBar addSubview:label]; barErrLbl = label; label = [[UILabel alloc] initWithFrame:CGRectMake(kSize.width - 2*w, 0, w, h)]; [label setFont:[UIFont scaleSize:13]]; [label setTextColor:defGreen]; [buttomBar addSubview:label]; barRigLbl = label; UIButton* btn = [[UIButton alloc] initWithFrame:buttomBar.bounds]; [btn addTarget:self action:@selector(showChooseView) forControlEvents:UIControlEventTouchUpInside]; [buttomBar addSubview:btn]; [barRigLbl setText:[NSString stringWithFormat:@"对 %d",rigCnt]]; [barErrLbl setText:[NSString stringWithFormat:@"错 %d",faultCnt]]; }else{ // if (myDelegate.type.intValue != QuestionTypeRandom) { CGFloat h = 40; CGFloat topHeight = RQ_APPLICATION_TOP_BAR_HEIGHT; CGFloat height = RQ_SCREEN_HEIGHT; CGFloat buttomBarY = height - topHeight - h - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT; UIView *buttomBar = [[UIView alloc] initWithFrame:CGRectMake(0, buttomBarY, RQ_SCREEN_WIDTH, h + RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT)]; [self.view addSubview:buttomBar]; [buttomBar setBackgroundColor:backGroundColor]; UILabel* label; label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kSize.width/3, h)]; [label setTextAlignment:NSTextAlignmentCenter]; [label setTextColor:subTitleColor]; [label setText:[NSString stringWithFormat:@"1/%d",(int)questions.count]]; [buttomBar addSubview:label]; indexLbl = label; // label = [[UILabel alloc] initWithFrame:CGRectMake(w*2, 0, kSize.width - w*2 - 20, h)]; // [label setTextAlignment:NSTextAlignmentRight]; // [label setTextColor:subTitleColor]; // [label setText:[NSString stringWithFormat:@"点我选择题号哦!"]]; // [buttomBar addSubview:label]; NSArray *arr = @[@"",@"上一题",@"下一题"]; CGFloat wid = kSize.width/4; for (int i=0; i 28) { myDelegate.optionFont = 17; } exVs = [NSMutableArray array]; for (int i =0; i<3; i++) { ExerView* exv = [[ExerView alloc] initWithFrame:CGRectMake(RQ_SCREEN_WIDTH * i, 0, RQ_SCREEN_WIDTH, scrollHeight)];//40 是bottombar 60是顶部隐藏的广告 exv.index = i; exv.questions = questions; [scroll addSubview:exv]; [exVs addObject:exv]; if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { [exv setYdtQuestionModel:questions[0]]; if ( i>1 && questions.count > 1) { [exv setYdtQuestionModel:questions[1]]; } } else { if ([defUser.car_type isEqualToString:@"2"]) { [exv setQuestion:questions[0]]; if ( i>1 && questions.count > 1) { [exv setQuestion:questions[1]]; } } else { [exv setYdtQuestionModel:questions[0]]; if ( i>1 && questions.count > 1) { [exv setYdtQuestionModel:questions[1]]; } } } exv.delegate2 = self; } //夜间模式 [self checkIsNightMode]; int pageCnt = (int)questions.count; if (pageCnt >3) { pageCnt = 3; } [scroll setContentSize:CGSizeMake(RQ_SCREEN_WIDTH*pageCnt, 0)]; [scroll setPagingEnabled:YES]; [self setQueIndex]; if (!isLoad) {//isload:yes改变字体进来的(无须括号内操作),no初始化 [self configButtomBar]; } } - (void)creatADView { @weakify(self) //获取广告总数量 取一个随机数 NSMutableArray *newAD = [NSMutableArray array]; for (NSDictionary *dic in myDelegate.adArray) { if ([dic[@"LOCATION"] isEqualToString:@"3"]) { [newAD addObject:dic]; } } CGFloat topHeight = RQ_APPLICATION_TOP_BAR_HEIGHT; CGFloat height = RQ_SCREEN_HEIGHT; adView = [[UIView alloc] initWithFrame:CGRectMake(0, height - topHeight - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT - 40 - self.adHeight, self.adWidth, self.adHeight)]; [self.view addSubview:adView]; [adView mas_remakeConstraints:^(MASConstraintMaker *make) { @strongify(self) make.left.mas_equalTo(self.view).mas_offset(0); make.bottom.mas_equalTo(self.view).mas_offset(- RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT - 40 - 8); make.size.mas_equalTo(CGSizeMake(self.adWidth, self.adHeight)); }]; UIImageView *adImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.adWidth, self.adHeight)]; adImg.layer.cornerRadius = 0; adImg.contentMode = UIViewContentModeScaleAspectFill; [adImg setClipsToBounds:YES]; [adView addSubview:adImg]; adBtn = [UIButton buttonWithType:UIButtonTypeCustom]; adBtn.frame = CGRectMake(adView.frame.size.width - 40, 5, 30, 30); [adBtn setImage:[[UIImage imageNamed:@"community6"] tint:[UIColor redColor]] forState:UIControlStateNormal]; [adBtn borderColor:[UIColor redColor] width:2 cornorRadios:15]; [adBtn addTarget:self action:@selector(removeRandomAD) forControlEvents:UIControlEventTouchUpInside]; [adView addSubview:adBtn]; if (newAD.count < 1) { [adImg setImage:[UIImage imageNamed:@"subject_main_banner.jpg"]]; }else{ NSInteger rendomIndex = arc4random()%newAD.count; NSDictionary *dic = newAD[rendomIndex]; adDic = [NSDictionary dictionaryWithDictionary:dic]; NSString *path = dic[@"IMG"]; [adImg sd_setImageWithURL:[NSURL URLWithString:path] placeholderImage:[UIImage imageNamed:@"subject_main_banner.jpg"]]; //把手势添加到指定视图上 [adImg setUserInteractionEnabled:YES]; UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(skipToADLink:)]; [adImg addGestureRecognizer:tapGesture]; } // if (scroll.y < 10.0) { // scroll.y = adView.height; // } adView.hidden = NO; BOOL isShow1; BOOL isShow2; NSInteger begin1 = [RQ_COMMON_MANAGER.YYXC_AD_TIME1 componentsSeparatedByString:@"-"].firstObject.integerValue? : 23; NSInteger end1 = [RQ_COMMON_MANAGER.YYXC_AD_TIME1 componentsSeparatedByString:@"-"].lastObject.integerValue? :24; NSInteger begin2 = [RQ_COMMON_MANAGER.YYXC_AD_TIME2 componentsSeparatedByString:@"-"].firstObject.integerValue? : 0; NSInteger end2 = [RQ_COMMON_MANAGER.YYXC_AD_TIME2 componentsSeparatedByString:@"-"].lastObject.integerValue? : 6; isShow1 = [NSDate isBetweenFromHour:begin1 toHour:end1]; isShow2 = [NSDate isBetweenFromHour:begin2 toHour:end2]; if (RQ_COMMON_MANAGER.YYXC_AD_OPEN) { if (RQ_COMMON_MANAGER.YYXC_BANNER_AD_OPEN) { if (isShow1 || isShow2) { [self loadAdAndShow]; } } } } - (void)loadAdAndShow { @weakify(self) [adView addSubview:self.bannerView]; [RQ_AD_MODULE loadAdWithAdType:GromoreAdTypeBanner customView:self.bannerView]; [RQ_AD_MODULE initADStatusChangeBlock:^(GromoreAdType adType, RQADDoType adDoType) { @strongify(self) if (adType == GromoreAdTypeBanner) { if (adDoType == RQADDoType_Close) { [self removeRandomAD]; } else if (adDoType == RQADDoType_Success) { [adView bringSubviewToFront:adBtn]; } } }]; } - (void)removeAd:(id)sender { [RQ_AD_MODULE closeAdWithAdType:GromoreAdTypeBanner]; [self.bannerView removeFromSuperview]; self.bannerView = nil; } -(void)skipToADLink:(UITapGestureRecognizer *)gesture { //1是程序内 2是程序外 NSString *skipType = adDic[@"OPENTYPE"]; if ([skipType isEqualToString:@"1"]) { ADLinkVC *ad = [[ADLinkVC alloc] init]; ad.title = adDic[@"TITLE"]; ad.urlString = adDic[@"URL"]; if (ad.urlString && ad.urlString.length != 0) { [self navPushHideTabbarToVC:ad]; } }else{ [[UIApplication sharedApplication] openURL:[NSURL URLWithString:adDic[@"URL"]]]; } } /**0,16,32,64,128 这里还要告诉是否答题正确,如果正确,自动翻页。否则显示正确答案。 */ -(void)didChooseOption:(NSInteger)opt isRight:(BOOL)isRig { @weakify(self) CGPoint off = scroll.contentOffset; Question* q = questions[qIndex]; if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { RQYDTQuestionModel *ydtQuestionModel = questions[qIndex]; [RQ_YDT_USER_Question_Module doQuestionWithID:ydtQuestionModel.ID myAnswer:(ydtQuestionModel.Type == 3)? opt : opt/10000 trueAnswer:ydtQuestionModel.AnswerTrue.integerValue carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject exerciseType:RQExerciseType_Sequential]; } else { //标记做过的题 if ([defUser.car_type isEqualToString:@"2"]) { [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"4" State:1]; } else { RQYDTQuestionModel *ydtQuestionModel = questions[qIndex]; [RQ_YDT_USER_Question_Module doQuestionWithID:ydtQuestionModel.ID myAnswer:(ydtQuestionModel.Type == 3)? opt : opt/10000 trueAnswer:ydtQuestionModel.AnswerTrue.integerValue carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject exerciseType:RQExerciseType_Sequential]; } } // [DB_Que_Helper setMarkQuestionWithQuestion:[q._id integerValue] Type:@"4" State:1]; //计算分数 int mark = 1;//每题的分值 if ([defUser.car_type isEqualToString:@"1"] || [defUser.car_type isEqualToString:@"5"] || [defUser.car_type isEqualToString:@"6"]) { Question *q = questions[qIndex]; //q.option_type 0判断 1单选 2多选 if ([q.option_type intValue] == 2) { mark = 2; }else { mark = 1; } } else if ([defUser.car_type isEqualToString:@"2"]) { mark = 2; }else if ([defUser.car_type isEqualToString:@"3"] || [defUser.car_type isEqualToString:@"4"]) { mark = 1; }else if([defUser.car_type isEqualToString:@"D"]) { mark = 2; }else { if ([myDelegate.subject isEqualToString:@"1"]) {//C1 A1 A2 科一一题一分 mark = 1; }else {//C1 A1 A2 科四一题两分 mark = 2; } } if (isRig) { correctMark += mark; }else { faultMark += mark; } //记录做题状态 if (qIndex < answersLen) { answers[qIndex] = (int)opt; } if (isRig) { if (qIndex < correctLen ) { correct[qIndex] = CorrectTypeRignt; rigCnt ++; } //判断是否自动翻页 if (!isSkip) { if (!isExplain) { return; } /**非考试模式答对了在不自动翻页模式下就展示答案 不知道这样行不行--对之前用户反映的回馈 */ if(QuestionTypeExam != myDelegate.type.intValue) { showAnsw[qIndex] = YES; [self setShowAnsw]; } return; } /**已经到最后一题了。 */ if (qIndex >= questions.count -1) { [LoadingView showMsg:@"做完了!请交卷!"]; //这一句修复错题模式下 做完左后一题 数据库以及网络都没有请求的问题 修复1.0.2BUG [self faultExAction:isRig]; return; } [UIView animateWithDuration:.5 delay:.3 options:0 animations:^{ [scroll setContentOffset:CGPointMake(off.x + kSize.width, off.y)]; } completion:^(BOOL finished) { @strongify(self) [self nextExAction]; lastOffset = scroll.contentOffset; }]; } else { if (qIndex < correctLen) { faultCnt++; correct[qIndex] = CorrectTypeFault; } //如果是考试模式 要自动翻页 if (QuestionTypeExam == myDelegate.type.intValue) { /**已经到最后一题了 */ if (qIndex >= questions.count -1) { UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"考题已全部做完,考试结束" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil]; [alert show]; [self isUploadGrade]; return; } [UIView animateWithDuration:.5 delay:.3 options:0 animations:^{ [scroll setContentOffset:CGPointMake(off.x + kSize.width, off.y)]; } completion:^(BOOL finished) { @strongify(self) [self nextExAction]; lastOffset = scroll.contentOffset; }]; } //考试模式中 错太多自动结束 if (QuestionTypeExam == myDelegate.type.intValue && faultMark > _loseMark && !isContinue) { if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { NSString *msg = [NSString stringWithFormat: @"本次考试做错%d分,超过%d分,考试结束!",faultMark,_loseMark]; UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:msg preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { @strongify(self) if (myDelegate.timer) { [myDelegate.timer invalidate]; myDelegate.timer = nil; if (self.seconds < 60) { ShowMsg(@"学时未满一分钟不统计"); [self isUploadGrade]; return; } [self saveTrain]; [self upLoadTrainRecord]; } [self isUploadGrade]; }]; [alert addAction:saveAction]; [self presentViewController:alert animated:YES completion:nil]; } else { if ([defUser.car_type isEqualToString:@"2"]) { NSString *msg = [NSString stringWithFormat: @"本次考试做错%d分,超过%d分,考试失败!",faultMark,_loseMark]; UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:msg preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"重新开始" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { @strongify(self) [self.navigationController popViewControllerAnimated:NO]; }]; UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"继续考试" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { isContinue = YES; }]; [alert addAction:saveAction]; [alert addAction:cancleAction]; [self presentViewController:alert animated:YES completion:nil]; } else { NSString *msg = [NSString stringWithFormat: @"本次考试做错%d分,超过%d分,考试结束!",faultMark,_loseMark]; UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:msg preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { @strongify(self) if (myDelegate.timer) { [myDelegate.timer invalidate]; myDelegate.timer = nil; if (self.seconds < 60) { ShowMsg(@"学时未满一分钟不统计"); [self isUploadGrade]; return; } [self saveTrain]; [self upLoadTrainRecord]; } [self isUploadGrade]; }]; [alert addAction:saveAction]; [self presentViewController:alert animated:YES completion:nil]; } } } //判断 答错是否自动展示答案 if (!isExplain) { return; } /**非考试模式答错了就展示答案 */ if(QuestionTypeExam != myDelegate.type.intValue) { showAnsw[qIndex] = YES; [self setShowAnsw]; //[v setShowAnswer:YES]; } } [barRigLbl setText:[NSString stringWithFormat:@"对 %d",rigCnt]]; [barErrLbl setText:[NSString stringWithFormat:@"错 %d",faultCnt]]; //根据原本状态和本次对错判定现在是否移除状态 [self faultExAction:isRig]; } /**做章节练习,可以把listView加入进来。 **在listView里面设置好where。这里换成present好了。每次willAppear的时候,看是否已经选好了。 如果选好了。直接dismiss。 */ -(void)loadQuestion { @weakify(self) qIndex = 0; NSString* sql = [NSString string];//QuestionTypeOrdered QuestionTypeRecite QuestionTypeChapt QuestionTypeFault QuestionTypeStrenth QuestionTypeUndo NSInteger lastQid = 0; switch (myDelegate.type.intValue) { //顺序模式 case QuestionTypeOrdered: { questions = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Sequential] : ([defUser.car_type isEqualToString:@"2"]? [DB_Que_Helper queryGZPZ_EXAM_CYRYMarkQuestionWithType:@"5"] : [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Sequential]);//除去排除的所有当前学科当前车型的题目 //@"C1",@"A2",@"A1",@"D",@"4",@"1",@"2",@"3",@"5" defUser.car_type if ([defUser.car_type isEqualToString:@"4"]) { qIndex = defUser.coachIndex.intValue; lastQid = qIndex; } if ([defUser.car_type isEqualToString:@"1"]) { qIndex = defUser.A1Index.intValue; lastQid = qIndex; } if ([defUser.car_type isEqualToString:@"2"]) { qIndex = defUser.A2Index.intValue; lastQid = qIndex; } if ([defUser.car_type isEqualToString:@"3"]) { qIndex = defUser.dangerIndex.intValue; lastQid = qIndex; } if ([defUser.car_type isEqualToString:@"5"]) { qIndex = defUser.texiIndex.intValue; lastQid = qIndex; } if ([defUser.car_type isEqualToString:@"6"]) { qIndex = defUser.wycIndex.intValue; lastQid = qIndex; } if ([defUser.car_type isEqualToString:@"C1"]) { if (myDelegate.subject.intValue == 1) { qIndex = defUser.userSubj1Index.intValue; lastQid = qIndex; }else{ qIndex = defUser.userSubj4Index.intValue; lastQid = qIndex; } } if ([defUser.car_type isEqualToString:@"A2"]) { if (myDelegate.subject.intValue == 1) { qIndex = defUser.A2Subj1Index.intValue; lastQid = qIndex; }else{ qIndex = defUser.A2Subj4Index.intValue; lastQid = qIndex; } } if ([defUser.car_type isEqualToString:@"A1"]) { if (myDelegate.subject.intValue == 1) { qIndex = defUser.A1Subj1Index.intValue; lastQid = qIndex; }else{ qIndex = defUser.A1Subj4Index.intValue; lastQid = qIndex; } } if ([defUser.car_type isEqualToString:@"D"]) { if (myDelegate.subject.intValue == 1) { qIndex = defUser.DSubj1Index.intValue; lastQid = qIndex; }else{ qIndex = defUser.DSubj4Index.intValue; lastQid = qIndex; } } if (qIndex > questions.count-1) { qIndex = 0; } // 查找缺失那些数据库图片 // { // questions=[DB_Que_Helper queryQuestion:@"zhaobucunzai"]; // // NSLog(@"----><>%d",(int)questions.count); // // NSMutableArray *imgString = [NSMutableArray array]; // for (Question *q in questions) { // // UIImage *img = [UIImage imageNamed:q.media]; // if (!img) { // [imgString addObject:q.media]; // } // } // NSLog(@"imgString----><>%@",imgString); // } } break; //背题模式 case QuestionTypeRecite: questions = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Recitation] : ([defUser.car_type isEqualToString:@"2"]? [DB_Que_Helper queryGZPZ_EXAM_CYRYMarkQuestionWithType:@"5"] : [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Recitation]);//除去排除的所有当前学科当前车型的题目 if (myDelegate.subject.intValue == 1) { qIndex = defUser.user1Index.intValue; lastQid = qIndex; }else{ qIndex = defUser.user4Index.intValue; lastQid = qIndex; } if (qIndex > questions.count-1) { qIndex = 0; } break; //随机模式 case QuestionTypeRandom: questions = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Random] : ([defUser.car_type isEqualToString:@"2"]? [DB_Que_Helper queryGZPZ_EXAM_CYRYMarkQuestionWithType:@"5"] : [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Random]);//除去排除的所有当前学科当前车型的题目 if (questions && questions.count < 1) { return; } // qIndex = arc4random()%(questions.count - 1); break; //章节模式 章节模式 还用之前的方式 里边不涉及错题排错题的查询 case QuestionTypeChapt: { if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { questions=[RQ_YDTQuestion_Module getChapterQuestionWithChapterName:self.chapterName]; } else { if ([defUser.car_type isEqualToString:@"2"]) { sql=[NSString stringWithFormat:@"%@",myDelegate.where]; questions = [DB_Que_Helper queryGZPZ_EXAM_CYRYQuestion:sql]; } else { // sql=[NSString stringWithFormat:@"subject = '%@' and %@",myDelegate.subject,myDelegate.where]; questions=[RQ_YDTQuestion_Module getChapterQuestionWithChapterName:self.chapterName]; } } break; } //强化练习 强化练习 还用之前的方式 里边不涉及错题排错题的查询 case QuestionTypeStrenth: // sql=[NSString stringWithFormat:@"strong"]; // questions=[DB_Que_Helper queryQuestion:sql]; questions = [RQ_YDTQuestion_Module getPointQuestionWithPointID:self.pointId]; break; //我的错题 case QuestionTypeFault: questions = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Wrong] : ([defUser.car_type isEqualToString:@"2"]? [DB_Que_Helper queryGZPZ_EXAM_CYRYMarkQuestionWithType:@"1"] : [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Wrong]);//所有当前学科当前车型的错题 //NSLog(@"错题count = %d",(int)questions.count); break; //排除的题 case QuestionTypeUndo: questions = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Remove] : ([defUser.car_type isEqualToString:@"2"]? [DB_Que_Helper queryGZPZ_EXAM_CYRYMarkQuestionWithType:@"3"] : [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Remove]);//所有当前学科当前车型的排错题 //NSLog(@"排除count ==== %d",(int)questions.count); break; //我的收藏 case QuestionTypeFavorite: questions = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Collect] : ([defUser.car_type isEqualToString:@"2"]? [DB_Que_Helper queryGZPZ_EXAM_CYRYMarkQuestionWithType:@"2"] : [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Collect]);//所有当前学科当前车型的收藏题 //NSLog(@"收藏count = %d",(int)questions.count); break; //模拟考试 case QuestionTypeExam: if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { questions = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Exam]; } else { if ([defUser.car_type isEqualToString:@"2"]) { questions = [DB_Que_Helper queryGZPZ_EXAM_CYRYExamQuestion]; } else { questions = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Exam]; } } // NSLog(@"examCount = %d",(int)questions.count); break; //未做题 case QuestionTypeNotDo: questions = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_UnDo] : ([defUser.car_type isEqualToString:@"2"]? [DB_Que_Helper queryGZPZ_EXAM_CYRYMarkQuestionWithType:@"4"] : [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_UnDo]); // NSLog(@"未做count = %d",(int)questions.count); break; case QuestionTypeNewRule: questions = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_NewRule] : ([defUser.car_type isEqualToString:@"2"]? @[] : [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_NewRule]); break; case QuestionTypeMiOne: questions = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Mi_One]; break; case QuestionTypeMiTwo: questions = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Mi_Two]; break; default: break; } if (lastQid != 0) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:[NSString stringWithFormat:@"您上次已练习到%d题,是否继续答题",(int)lastQid + 1] delegate:self cancelButtonTitle:@"是" otherButtonTitles:@"否", nil]; alert.tag = 100; [alert show]; }else { //如果这个提示没有 就去看是否有未上传学时 NSString *pxkm = defUser.userDict[@"pxjd"]; if (pxkm.length < 1) { pxkm = @"1"; } NSArray* array = [DB_Helper quearyTrain:defUser.userStuId Subject:pxkm]; if (array.count > 0 && defUser.isycbd != 1) { UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"您本地有未上传学时,请确认上传!" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { @strongify(self) [self upLoadTrainRecord]; }]; [alert addAction:saveAction]; [self presentViewController:alert animated:YES completion:nil]; } } for(int i = 0;i=0; i--) { STButton* btn = navBtns[i]; UIBarButtonItem* bbi = [[UIBarButtonItem alloc] initWithCustomView:btn]; [bbiArr addObject:bbi]; } self.navigationItem.rightBarButtonItems = bbiArr; if (QuestionTypeExam == myDelegate.type.intValue) { [navBtns[0] addTarget:self action:@selector(pauseExamAction) forControlEvents:UIControlEventTouchUpInside]; [navBtns[2] addTarget:self action:@selector(submitExam) forControlEvents:UIControlEventTouchUpInside]; }else if (myDelegate.type.intValue == QuestionTypeRecite) { [navBtns[0] addTarget:self action:@selector(showChooseView) forControlEvents:UIControlEventTouchUpInside]; }else{ [navBtns[0] addTarget:self action:@selector(showChooseView) forControlEvents:UIControlEventTouchUpInside]; [navBtns[2] addTarget:self action:@selector(moveExAction) forControlEvents:UIControlEventTouchUpInside]; [navBtns[3] addTarget:self action:@selector(showAnswAction) forControlEvents:UIControlEventTouchUpInside]; } [navBtns[1] addTarget:self action:@selector(favAction) forControlEvents:UIControlEventTouchUpInside]; [[navBtns lastObject] addTarget:self action:@selector(settingBtn:) forControlEvents:UIControlEventTouchUpInside]; //除了随机 都要有 if (QuestionTypeRandom == myDelegate.type.intValue) { return; } chooseView = [[UIView alloc] initWithFrame:kFrame]; [chooseView setBackgroundColor:[UIColor colorWithWhite:.3 alpha:.3]]; contantV = [[UIView alloc] initWithFrame:CGRectMake(0, 100, kSize.width, kSize.height-100-kSafeAreaBottomHeight)]; [chooseView addSubview:contantV]; [contantV setBackgroundColor:[UIColor whiteColor]]; CGFloat x,y,wid,hei,bd; bd = 5; wid = hei = 40; x = kSize.width - wid - bd; y = bd; EXButton* btnn = [[EXButton alloc] initWithFrame:CGRectMake(x, y, wid, hei)]; [btnn addTarget:self action:@selector(hideChooseView) forControlEvents:UIControlEventTouchUpInside]; [btnn setImage:[[UIImage imageNamed:@"question_error.png"] tint:[UIColor grayColor]] forState:UIControlStateNormal]; [btnn setTitle:@"×" textColor:[UIColor whiteColor] font:30 fotState:UIControlStateNormal]; [contantV addSubview:btnn]; x = 20; wid = kSize.width-x-wid-bd-120; UITextField*tf = [[UITextField alloc]initWithFrame:CGRectMake(x, y, wid, hei)]; searchTf = tf; tf.delegate = self; tf.layer.masksToBounds = YES; tf.layer.cornerRadius = 5; tf.layer.borderWidth = 1; tf.layer.borderColor = [UIColor lightGrayColor].CGColor; tf.placeholder = @"请输入题号"; tf.textAlignment = NSTextAlignmentCenter; tf.keyboardType = UIKeyboardTypeNumberPad; tf.clearsOnBeginEditing = YES; [contantV addSubview:tf]; x += wid; wid = 80; UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeSystem]; sureBtn = searchBtn; searchBtn.frame = CGRectMake(x, y, wid, hei); [searchBtn setTitle:@"确定" textColor:defGreen font:NormalFont fotState:UIControlStateNormal]; searchBtn.titleLabel.font = [UIFont systemFontOfSize:Font17]; [searchBtn addTarget:self action:@selector(searchQuestion) forControlEvents:UIControlEventTouchUpInside]; [contantV addSubview:searchBtn]; x = 20; wid = 60; UILabel* label; label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, wid, hei)]; [label setText:@"text"]; [label setTextColor:defGreen]; [contantV addSubview:label]; rigLbl = label; x += wid + bd; label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, wid, hei)]; [label setText:@"text"]; [label setTextColor:[UIColor orangeColor]]; [contantV addSubview:label]; errorLbl = label; /**表示按钮的最小间距 可以做一个按钮的重用机制 不然 一千多个 很耗性能 */ y += hei + bd + bd; //用collection吧 自带缓存机制 CGFloat width = (kSize.width - 60)/5.0; UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; [layout setItemSize:CGSizeMake(width, width)]; [layout setSectionInset:UIEdgeInsetsMake(0, 20, 20, 20)]; UICollectionView *btnCollection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, y, kSize.width, contantV.height - y) collectionViewLayout:layout]; btnCollection.backgroundColor = [UIColor whiteColor]; btnCollection.delegate = self; btnCollection.dataSource = self; [contantV addSubview:btnCollection]; [btnCollection registerClass:[BtnCollectionViewCell class] forCellWithReuseIdentifier:@"btn"]; } -(void)goBackByNavigation{ @weakify(self) if (myDelegate.type.intValue == QuestionTypeExam) { // UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"退出后将不保存本次记录,是否继续退出?" delegate:self cancelButtonTitle:@"退出" otherButtonTitles:@"取消", nil]; // alert.tag = AlertTypeIsQuit; // [alert show]; [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"退出后将不保存本次记录,是否继续退出?" confirmTitle:@"退出" cancelTitle:@"取消" confirmAction:^{ @strongify(self) if (myDelegate.isUseriPhone) { [myDelegate.timer invalidate]; myDelegate.timer = nil; if (self.seconds < 60) { ShowMsg(@"学时未满一分钟不统计"); return; } [self saveTrain]; [self upLoadTrainRecord]; } [self.view endEditing:1]; [self.navigationController popToRootViewControllerAnimated:YES]; } cancelAction:^{ }]; }else{ if (myDelegate.timer) { UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"退出当前页面将结束理论计时,是否继续退出?" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"退出" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { @strongify(self) if (defUser.isycbd == 1) { [RQ_TIMING_VIEW stopTimingWithResultBlock:^(BOOL isSuccessed) { if (isSuccessed) { [RQ_TIMING_VIEW endTiming]; } }]; } else { [RQ_TIMING_VIEW stopTiming]; } // [myDelegate.timer invalidate]; // myDelegate.timer = nil; // // // if (self.seconds < 60) { // ShowMsg(@"学时未满一分钟不统计"); // return; // } // [self saveTrain]; // [self upLoadTrainRecord]; [self.view endEditing:1]; [self.navigationController popViewControllerAnimated:YES]; }]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]; [alert addAction:saveAction]; [alert addAction:cancelAction]; [self presentViewController:alert animated:YES completion:nil]; }else { [self.view endEditing:1]; [self.navigationController popViewControllerAnimated:YES]; } } } - (void)initTrainView { UIView *view = [[UIView alloc] initWithFrame:CGRectMake(kSize.width - 50, kSize.height - 350 - kSafeAreaBottomHeight, 60, 100)]; view.backgroundColor = [UIColor colorWithRed:35/255.0 green:160/255.0 blue:227/255.0 alpha:.44]; view.layer.masksToBounds = YES; view.layer.cornerRadius = 10; [self.view addSubview:view]; rightView = view; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, 50, 30)]; label.backgroundColor = [UIColor clearColor]; [label setText:@"00:00" Font:NormalFont TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentCenter]; [rightView addSubview:label]; timeLabel1 = label; label = [[UILabel alloc] initWithFrame:CGRectMake(0, 40, 50, 60)]; label.backgroundColor = [UIColor colorWithRed:35/255.0 green:160/255.0 blue:227/255.0 alpha:.5]; [label setText:@"点击\n计时" Font:NormalFont TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentCenter]; label.numberOfLines = 0; [rightView addSubview:label]; trainStateLabel = label; UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60, 100)]; btn.backgroundColor = [UIColor clearColor]; [btn addTarget:self action:@selector(showOrHide:) forControlEvents:UIControlEventTouchUpInside]; [rightView addSubview:btn]; view = [[UIView alloc] initWithFrame:rightView.frame]; view.backgroundColor = [UIColor colorWithRed:35/255.0 green:160/255.0 blue:227/255.0 alpha:.44]; view.layer.masksToBounds = YES; view.layer.cornerRadius = 10; view.hidden = YES; [self.view addSubview:view]; show_hideView = view; label = [[UILabel alloc] initWithFrame:CGRectMake(0, 2, kSize.width - 90, 23)]; label.backgroundColor = [UIColor clearColor]; [label setText:@"00:00:00" Font:FontTitle TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentCenter]; [show_hideView addSubview:label]; timeLabel2 = label; label = [[UILabel alloc] initWithFrame:CGRectMake(15, 25, kSize.width - 120, 40)]; label.backgroundColor = [UIColor clearColor]; [label setText:@"注:退出当前页面将结束计时,学时详情在“个人-我的学时”查看" Font:NormalFont TextColor:[UIColor whiteColor]]; label.numberOfLines = 0; [show_hideView addSubview:label]; btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 65, kSize.width - 90, 35)]; btn.backgroundColor = [UIColor colorWithRed:35/255.0 green:160/255.0 blue:227/255.0 alpha:.6]; [btn setTitle:@"开始计时" textColor:[UIColor whiteColor] font:FontTitle fotState:UIControlStateNormal]; [btn setTitle:@"结束计时" forState:UIControlStateSelected]; [btn addTarget:self action:@selector(beginOrEndTrain) forControlEvents:UIControlEventTouchUpInside]; [show_hideView addSubview:btn]; begin_endBtn = btn; } - (void)showOrHide:(UIButton *)sender { sender.selected = !sender.selected; if (sender.selected) { [UIView animateWithDuration:.4 animations:^{ show_hideView.hidden = NO; show_hideView.frame = CGRectMake(20, kSize.height - 300 - kSafeAreaBottomHeight, kSize.width - 90, 100); trainStateLabel.text = @"关闭\n弹窗"; }]; }else { [UIView animateWithDuration:.4 animations:^{ show_hideView.frame = rightView.frame; } completion:^(BOOL finished) { show_hideView.hidden = YES; if (myDelegate.isUseriPhone) { trainStateLabel.text = @"计\n时\n中"; }else { trainStateLabel.text = @"点击\n计时"; } }]; } } - (void)beginOrEndTrain { @weakify(self) if (!myDelegate.isLogin) { ShowMsg(@"请登录后再使用理论计时功能"); return; } NSInteger isNeed = 1; for (NSDictionary * dic in defUser.userDict[@"params"]) { if ([dic[@"KEY"] isEqualToString:@"SP_VERIFY_IMEI"]) { isNeed = [dic[@"VALUE"] integerValue]; } } NSString *IMEI = defUser.userDict[@"imei"]; if (IMEI.length > 0) { if (isNeed == 1) { if ([Tools getIDFAWithType:GetIDFAType_Default]) { @strongify(self) if (![IMEI isEqualToString:[Tools getIDFAWithType:GetIDFAType_Default]]) { ShowMsg(@"您当前手机与绑定手机不一致, 无法计时"); return; } else { if (!begin_endBtn.selected) { //开始计时 if (defUser.isycbd == 1) { [self startTimingWithResultBlock:^(BOOL isSuccess) { }]; } else { [self beginTime]; } }else {//结束计时 if (defUser.isycbd == 1) { [self stopTimingWithResultBlock:^(BOOL isSuccessed) { }]; } else { [self stopTiming]; } begin_endBtn.selected = !begin_endBtn.selected; } } } } else { [Tools saveNotBindImeiLogWithType:@"2" block:^(BOOL isSuccess) { @strongify(self) if (isSuccess) { if (!begin_endBtn.selected) { //开始计时 if (defUser.isycbd == 1) { [self startTimingWithResultBlock:^(BOOL isSuccess) { }]; } else { [self beginTime]; } }else {//结束计时 if (defUser.isycbd == 1) { [self stopTimingWithResultBlock:^(BOOL isSuccessed) { }]; } else { [self stopTiming]; } begin_endBtn.selected = !begin_endBtn.selected; } } }]; } } else { [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"您的账号暂未与该手机绑定,不能进行此操作,请通过“考试界面左上角点击头像-弹出左边侧栏-绑定账号”进行绑定" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil completion:nil]; } } -(void)stopTiming { [myDelegate.timer invalidate]; myDelegate.timer = nil; myDelegate.isUseriPhone = NO; myDelegate.isTrain = NO; timeLabel2.text = @"00:00:00"; timeLabel1.text = @"00:00"; // if (seconds < 60) { // ShowMsg(@"学时未满一分钟不统计"); // } [self saveTrain]; [self upLoadTrainRecord]; } - (void)beginTime { @weakify(self) if (![Util connectedToNetWork]) { ShowMsg(@"请检查网络连接。"); return; } NSMutableArray *arr=[NSMutableArray array]; [arr property:defUser.userDict[@"outId"] forKey:@"outId"]; [arr property:defUser.userDict[@"city"] forKey:@"dqbh"]; NSString* method = @"isUsePhone"; [MBProgressHUD showLoadToView:self.view]; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) { @strongify(self) [MBProgressHUD hideHUDForView:self.view]; if (!dict) { ShowMsgFailed(); return; } if ([dict[@"code"] isEqualToString:@"90"]) { UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:dict[@"msg"] preferredStyle:UIAlertControllerStyleAlert]; [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { @strongify(self) [LoginViewController loginFromVC:self]; }]]; [self presentViewController:alertFind animated:true completion:nil]; return; } if ([dict[@"code"] isEqualToString:@"0"]) { myDelegate.begin_Time = dict[@"body"]; [Tools playAudioWithString:@"操作成功,开始计时"]; self.seconds = 0; myDelegate.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES]; myDelegate.isUseriPhone = YES; myDelegate.isTrain = YES; begin_endBtn.selected = YES; //防止前五分钟内退出软件 造成理论无本地学时 无法签退的问题 [self saveTrain]; } else { NSString *msg = dict[@"msg"]; if (msg.length < 1) { msg = dict[@"body"]; } ShowMsg(msg); [Tools playAudioWithString:msg]; } }]; } - (void)timeFireMethod { @weakify(self) self.seconds++; [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]]; if (defUser.isycbd == 1) { NSString *pxkm = defUser.userDict[@"pxjd"]; if (pxkm.length < 1) { pxkm = @"1"; } if (([pxkm isEqualToString:@"2"] || [pxkm isEqualToString:@"3"])) { pxkm = @"4"; } int remainder1 = (int)(self.seconds)%900; if (remainder1 == 0) { [self.timer setFireDate:[NSDate distantFuture]]; SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindow]; alert.backgroundViewColor = backGroundColor; alert.customViewColor = RQ_MAIN_COLOR; [alert addButton:@"立即开始 " actionBlock:^(void) { dispatch_async(dispatch_get_main_queue(), ^{ @strongify(self) /// 1.本地活体检测 [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:0 completeBlock:^(BOOL success, NSDictionary * _Nullable dic) { @strongify(self) if (success) { /// 2.线上活体检测 [RQ_RemoteTheory_MANAGER edufaceTofaceWithPhotoStr:dic[@"normalImg"] loginFlagType:LoginFlagType_Process resultBlock:^(BOOL isSuccess, id dict) { @strongify(self) if (isSuccess) { NSString *timeStr = [self getTimes:self.seconds]; /// 3.2上传过程照片 if (dict) { NSDictionary *myDict = dict; NSString *imageUrlStr = myDict[@"body"]; if (RQStringIsEmpty(imageUrlStr)) { ShowMsg(@"路径为空"); } [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:imageUrlStr loginFlagType:LoginFlagType_Process resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) { @strongify(self) if (isSuccess) { [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"过程验证成功" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) { @strongify(self) [self.timer setFireDate:[NSDate distantPast]]; }]; } else { self.seconds--; [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]]; [self.timer setFireDate:[NSDate distantPast]]; } }]; } else { self.seconds--; [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]]; [self.timer setFireDate:[NSDate distantPast]]; } } else { self.seconds--; [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]]; [self.timer setFireDate:[NSDate distantPast]]; } }]; } else { self.seconds--; [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]]; [self.timer setFireDate:[NSDate distantPast]]; } }]; }); }]; [alert addTimerToButtonIndex:0 reverse:YES]; [alert showNotice:@"温馨提示" subTitle:@"即将开始活体检测,请做好准备" closeButtonTitle:nil duration:5.0f]; } } int hour = 0; int min = 0; int second = 0; int remainder = (int)self.seconds%60; if (remainder == 0) { //每1分钟保存一次 [self saveTrain]; } hour = (int)self.seconds / 3600; min = (int)self.seconds % 3600 / 60; second = (int)self.seconds % 3600 % 60; NSString *min_s; NSString *second_s; if (min<10) { min_s=[NSString stringWithFormat:@"0%d",min]; }else{ min_s=[NSString stringWithFormat:@"%d",min]; } if (second<10) { second_s=[NSString stringWithFormat:@"0%d",second]; }else{ second_s=[NSString stringWithFormat:@"%d",second]; } //更新UI上的时间 timeLabel2.text = [NSString stringWithFormat:@"0%d:%@:%@",hour,min_s,second_s]; timeLabel1.text = [NSString stringWithFormat:@"0%d:%@",hour,min_s]; } - (void)saveTrain { if (!formatter) { formatter = [NSDateFormatter rq_defaultDateFormatter]; } TrainRecord *train = [[TrainRecord alloc] init]; train.studentId = defUser.userStuId; train.beginTime = myDelegate.begin_Time; NSDate *date=[formatter dateFromString:myDelegate.begin_Time]; date=[date dateByAddingTimeInterval:self.seconds]; train.state = @"0"; train.endTime=[formatter stringFromDate:date]; NSInteger mins = self.seconds / 60; train.trainTime=[NSString stringWithFormat:@"%d",(int)mins]; train.subject = myDelegate.subject; train.classid = (self.classIdStr && ![self.classIdStr isEqualToString:@""])? self.classIdStr : @"0"; [DB_Helper saveTrain:train]; } - (void)upLoadTrainRecord { NSString *pxkm = defUser.userDict[@"pxjd"]; if (pxkm.length < 1) { pxkm = @"1"; } NSArray* array = [DB_Helper quearyTrain:defUser.userStuId Subject:myDelegate.subject]; if (array.count < 1) { ShowMsg(@"本地无学时明细!"); return; } //这里是对分段上传学时做的处理 如果学时上传有问题 查看这里 [self uploadMoreTrainRecordWithArray:array]; } - (void)uploadMoreTrainRecordWithArray:(NSArray *)trainArray { @weakify(self) if (![Util connectedToNetWork]) { showMsgUnconnect(); return; } NSString* str = @""; for (TrainRecord *record in trainArray) { str = [str stringByAppendingString:[NSString stringWithFormat:@"%@,%@,%@,%@;",record.studentId,record.beginTime,record.endTime,record.trainTime]]; } TrainRecord *record = [trainArray firstObject]; NSMutableArray *arr=[NSMutableArray array]; [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"ios",@"trainType", nil]]; [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:[DES3Util encrypt:str ],@"trainRecord", nil]]; [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:record.subject,@"pxkm", nil]]; [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:defUser.userDict[@"outId"],@"stuOutid", nil]]; NSString* method = @"uploadMoreTrainRecord"; [MBProgressHUD showLoadToView:self.view]; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) { [MBProgressHUD hideHUDForView:self.view]; @strongify(self) if (!dict) { ShowMsg(@"操作失败"); return; } if ([dict[@"code"] isEqualToString:@"90"]) { UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:dict[@"msg"] preferredStyle:UIAlertControllerStyleAlert]; [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { @strongify(self) [LoginViewController loginFromVC:self]; }]]; [self presentViewController:alertFind animated:true completion:nil]; return; } if ( [dict[@"code"] isEqualToString:@"1"]) { ShowMsg(dict[@"body"]); return; } if ( [dict[@"code"] isEqualToString:@"0"]) { for (TrainRecord *record in trainArray) { [DB_Helper updateTrainState:record]; } UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"上传学时成功!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil]; [alert show]; } }]; } #pragma mark collection delegate -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return questions.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { BtnCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"btn" forIndexPath:indexPath]; [cell.btn setTitle:[NSString stringWithFormat:@"%d",(int)indexPath.row + 1] textColor:contentTextColor font:22 fotState:UIControlStateNormal]; [cell.btn addTarget:self action:@selector(chooseBtn:) forControlEvents:UIControlEventTouchUpInside]; [cell.btn setTag:indexPath.row]; return cell; } -(void)chooseBtn:(UIButton*)sender { if (searchTf.isFirstResponder) { [searchTf resignFirstResponder]; return; } [self chooseQuestionWithQIndex:sender.tag]; } -(void)chooseQuestionWithQIndex:(NSInteger)questionIndex{ qIndex = questionIndex; [self setQueIndex]; [self hideChooseView]; //记录选择的位置 //顺序模式 if (QuestionTypeOrdered == myDelegate.type.intValue) { [self setIndexRecord]; } //背题模式 if (QuestionTypeRecite == myDelegate.type.intValue) { if ( 1==myDelegate.subject.intValue) { defUser.user1Index = [NSString stringWithFormat:@"%d",(int)qIndex]; }else{ defUser.user4Index = [NSString stringWithFormat:@"%d",(int)qIndex]; } } } -(void)setIndexRecord { if ([defUser.car_type isEqualToString:@"4"]) { defUser.coachIndex = [NSString stringWithFormat:@"%d",(int)qIndex]; } if ([defUser.car_type isEqualToString:@"1"]) { defUser.A1Index = [NSString stringWithFormat:@"%d",(int)qIndex]; } if ([defUser.car_type isEqualToString:@"2"]) { defUser.A2Index = [NSString stringWithFormat:@"%d",(int)qIndex]; } if ([defUser.car_type isEqualToString:@"3"]) { defUser.dangerIndex = [NSString stringWithFormat:@"%d",(int)qIndex]; } if ([defUser.car_type isEqualToString:@"5"]) { defUser.texiIndex = [NSString stringWithFormat:@"%d",(int)qIndex]; } if ([defUser.car_type isEqualToString:@"6"]) { defUser.wycIndex = [NSString stringWithFormat:@"%d",(int)qIndex]; } if ([defUser.car_type isEqualToString:@"C1"]) { if ( 1==myDelegate.subject.intValue) { defUser.userSubj1Index = [NSString stringWithFormat:@"%d",(int)qIndex]; }else{ defUser.userSubj4Index = [NSString stringWithFormat:@"%d",(int)qIndex]; } } if ([defUser.car_type isEqualToString:@"A2"]) { if ( 1==myDelegate.subject.intValue) { defUser.A2Subj1Index = [NSString stringWithFormat:@"%d",(int)qIndex]; }else{ defUser.A2Subj4Index = [NSString stringWithFormat:@"%d",(int)qIndex]; } } if ([defUser.car_type isEqualToString:@"A1"]) { if ( 1==myDelegate.subject.intValue) { defUser.A1Subj1Index = [NSString stringWithFormat:@"%d",(int)qIndex]; }else{ defUser.A1Subj4Index = [NSString stringWithFormat:@"%d",(int)qIndex]; } } if ([defUser.car_type isEqualToString:@"D"]) { if ( 1==myDelegate.subject.intValue) { defUser.DSubj1Index = [NSString stringWithFormat:@"%d",(int)qIndex]; }else{ defUser.DSubj4Index = [NSString stringWithFormat:@"%d",(int)qIndex]; } } } -(void)hideChooseView { [chooseView removeFromSuperview]; } -(void)showChooseView { if (myDelegate.type.intValue == QuestionTypeExam) { if (chooseView) { int rig = 0,fau =0; for (int i = 0; i< questions.count; i++) { if ( CorrectTypeFault == correct[i]) { fau++; [choBtns[i] setImage:[[UIImage imageNamed:@"question_error.png"] tint:[UIColor redColor]] withTitle:[NSString stringWithFormat:@"%d",i+1] Font:22 forState:UIControlStateNormal]; [choBtns[i] setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; } if ( CorrectTypeRignt == correct[i]) { rig++; [choBtns[i] setImage:[[UIImage imageNamed:@"question_error.png"] tint:defGreen] withTitle:[NSString stringWithFormat:@"%d",i+1] Font:22 forState:UIControlStateNormal]; [choBtns[i] setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; } } //NSLog(@"对的-->%d错的-->%d",rig,fau); [rigLbl setText:[NSString stringWithFormat:@"正确 %d",rig]]; [errorLbl setText:[NSString stringWithFormat:@"错误 %d",fau]]; searchTf.hidden = YES; sureBtn.hidden = YES; } }else{ [rigLbl setHidden:YES]; [errorLbl setHidden:YES]; } [[UIApplication sharedApplication].keyWindow addSubview:chooseView]; } //-(void)addQue //{ // Question *q=[questions objectAtIndex:qIndex]; // [DB_Que_Helper addToStrengthenQue:[q._id intValue]]; //} //-(void)removeQue //{ // Question *q=[questions objectAtIndex:qIndex]; // [DB_Que_Helper removeToStrengthenQue:[q._id intValue]]; //} #pragma mark - 输入题号搜索 -(void)searchQuestion{ NSInteger qNum = [searchTf.text integerValue]; if (qNum && qNum !=0 && qNum <= questions.count) { [self chooseQuestionWithQIndex:qNum-1]; }else{ ShowMsg(@"请输入正确题号"); } } -(void)preExAction{ if (questions.count < 1) { return; } qIndex --; if(qIndex<0){ qIndex = 0; } //顺序模式 if (QuestionTypeOrdered == myDelegate.type.intValue) { [self setIndexRecord]; } //背题模式 if (QuestionTypeRecite == myDelegate.type.intValue) { if ( 1==myDelegate.subject.intValue) { defUser.user1Index = [NSString stringWithFormat:@"%d",(int)qIndex]; }else{ defUser.user4Index = [NSString stringWithFormat:@"%d",(int)qIndex]; } } [self setQueIndex]; } //错题 -(void)faultExAction:(BOOL)isRight { /** 如果这次对 并且没有错的记录 可以不处理 若有错的记录 要将错改为对 如果这次错 并且没有错的记录 要标记错题 若有错的记录 可不做处理 */ Question* q = questions[qIndex]; //这个地方直接从库里边查 BOOL isOK; if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { RQ_SHARE_FUNCTION.myErorNum = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Wrong].count; if (isRight) { [self deleteState:@"2"]; } } else { if ([defUser.car_type isEqualToString:@"2"]) { isOK = [DB_Que_Helper queryGZPZ_EXAM_CYRYIsHaveWithQuestion:[q._id integerValue] Type:@"1"]; if (isOK) { q.state = @"1"; }else{ q.state = @"0"; } if (isRight == 1){ //NSLog(@"删除错题"); if (q.state.integerValue == 1) { q.state = @"0"; [self deleteState:@"2"]; if ([DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"1" State:[q.state integerValue]]) { RQ_SHARE_FUNCTION.myErorNum = [DB_Que_Helper queryGZPZ_EXAM_CYRYMarkQuestionWithMarkType:@"1"]; } } }else{ // NSLog(@"添加错题"); if (q.state.integerValue == 0) { q.state = @"1"; if ([DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"1" State:[q.state integerValue]]) { RQ_SHARE_FUNCTION.myErorNum = [DB_Que_Helper queryGZPZ_EXAM_CYRYMarkQuestionWithMarkType:@"1"]; } } } } else { RQ_SHARE_FUNCTION.myErorNum = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Wrong].count; if (isRight) { [self deleteState:@"2"]; } // isOK = [DB_Que_Helper queryIsHaveWithQuestion:[q._id integerValue] Type:@"1"];//错题1 } } } //排除 -(void)moveExAction { if (questions.count<1) { return; } // Question* q = questions[qIndex]; // if (q.move.intValue == 1) { // q.move = @"0"; // [self deleteState:@"3"]; // if ([defUser.car_type isEqualToString:@"2"]) { // [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"3" State:[q.state integerValue]]; // } else { // [DB_Que_Helper setMarkQuestionWithQuestion:[q._id integerValue] Type:@"3" State:[q.state integerValue]]; // } // }else{ // q.move = @"1"; // if ([defUser.car_type isEqualToString:@"2"]) { // [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"3" State:[q.state integerValue]]; // } else { // [DB_Que_Helper setMarkQuestionWithQuestion:[q._id integerValue] Type:@"3" State:[q.state integerValue]]; // } // } if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { RQYDTQuestionModel *ydtQuestionModel = questions[qIndex]; [RQ_YDT_USER_Question_Module removeQuestionWithID:ydtQuestionModel.ID carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject]; } else { if ([defUser.car_type isEqualToString:@"2"]) { Question* q = questions[qIndex]; if (q.move.intValue == 1) { q.move = @"0"; [self deleteState:@"3"]; [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"3" State:[q.state integerValue]]; }else{ q.move = @"1"; [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"3" State:[q.state integerValue]]; } } else { RQYDTQuestionModel *ydtQuestionModel = questions[qIndex]; [RQ_YDT_USER_Question_Module removeQuestionWithID:ydtQuestionModel.ID carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject]; if (![RQ_YDT_USER_Question_Module getRemoveRecordWithQuestionId:ydtQuestionModel.ID]) { [self deleteState:@"3"]; } } } // NSLog(@"------%@",q.move); [self setMoveTitle]; } //收藏 -(void)favAction{ // NSLog(@"收藏或取消收藏"); if (questions.count<1) { return; } // Question* q = questions[qIndex]; // if (q.favorite.intValue == 1) { // q.favorite = @"0"; // [self deleteState:@"1"]; // if ([defUser.car_type isEqualToString:@"2"]) { // [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"2" State:[q.state integerValue]]; // } else { // [DB_Que_Helper setMarkQuestionWithQuestion:[q._id integerValue] Type:@"2" State:[q.state integerValue]]; // } // }else{ // q.favorite = @"1"; // if ([defUser.car_type isEqualToString:@"2"]) { // [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"2" State:[q.state integerValue]]; // } else { // [DB_Que_Helper setMarkQuestionWithQuestion:[q._id integerValue] Type:@"2" State:[q.state integerValue]]; // } // } UIButton* favBtn = navBtns[1]; RQYDTQuestionModel *ydtQuestionModel = questions[qIndex]; if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { if (favBtn.selected) { [RQ_YDT_USER_Question_Module deleteCollectRecordWithQuestionId:ydtQuestionModel.ID carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject]; } else { [RQ_YDT_USER_Question_Module collectQuestionWithID:ydtQuestionModel.ID carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject]; } } else { if ([defUser.car_type isEqualToString:@"2"]) { Question* q = questions[qIndex]; if (q.favorite.intValue == 1) { q.favorite = @"0"; [self deleteState:@"1"]; [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"2" State:[q.state integerValue]]; }else{ q.favorite = @"1"; [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"2" State:[q.state integerValue]]; } } else { if (favBtn.selected) { [RQ_YDT_USER_Question_Module deleteCollectRecordWithQuestionId:ydtQuestionModel.ID carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject]; [self deleteState:@"1"]; } else { [RQ_YDT_USER_Question_Module collectQuestionWithID:ydtQuestionModel.ID carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject]; [self saveStateQuestion:@"1"]; } } } [self setFavTitle]; } //目前未发现调用 被弃用了吧 --markdanson //-(void)errorExAction //{ // if (questions.count<1) { // return; // } // Question* q = questions[qIndex]; // if (q.state.intValue > 0) { // q.state = @"0"; // [self removeQue]; // }else{ // q.state = @"1"; // [self addQue]; // } // //[self setFaultTitle]; //} /** 或者换个套路。每次滑动完毕。快速切换页面的内容和scroll的offset。 可以先切换中间的view的内容,然后修改offset,最后设置剩下2个的。 这样的话。在判断边界条件时值,只需要设置contenSize即可。 设置为一样的就可以了。给它弹提示框算了。 */ -(void)nextExAction { if (questions.count < 1) { return; } qIndex++; if(qIndex >= questions.count) { qIndex--; return; } if (QuestionTypeOrdered == myDelegate.type.intValue) { [self setIndexRecord]; } //背题模式 if (QuestionTypeRecite == myDelegate.type.intValue) { if ( 1==myDelegate.subject.intValue) { defUser.user1Index = [NSString stringWithFormat:@"%d",(int)qIndex]; }else{ defUser.user4Index = [NSString stringWithFormat:@"%d",(int)qIndex]; } } [self setQueIndex]; } -(void)showAnswAction { if (QuestionTypeRecite == myDelegate.type.intValue) { return; } STButton* btn = navBtns[3]; btn.selected = !btn.selected; showAnsw[qIndex] = btn.selected; [self setShowAnsw]; } - (void)pauseExamAction { if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { //关闭定时器 [self.timer setFireDate:[NSDate distantFuture]]; } else { if ([defUser.car_type isEqualToString:@"2"] && myDelegate.isLogin) { } else { //关闭定时器 [self.timer setFireDate:[NSDate distantFuture]]; } } [NSObject rq_showAlertViewWithTitle:@"暂停考试" message:@"已暂停考试,点击下面继续考试" confirmTitle:@"继续考试" confirmAction:^{ if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { [self.timer setFireDate:[NSDate distantPast]]; } else { if ([defUser.car_type isEqualToString:@"2"] && myDelegate.isLogin) { } else { [self.timer setFireDate:[NSDate distantPast]]; } } }]; // UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"暂停考试" message:@"已暂停考试,点击下面继续考试" delegate:self cancelButtonTitle:@"继续考试" otherButtonTitles: nil]; // [alert setTag:AlertTypePause]; // [alert show]; } - (void)submitExam { // NSLog(@"提交考试答卷"); @weakify(self) int undoCnt = 0; for (int i=0; i< questions.count; i++) { if (correct[i] == CorrectTypeUndo) { undoCnt ++ ; } } NSString* msg = [NSString stringWithFormat:@"还有%d道题没做,确定交卷?",undoCnt]; QMUIAlertController *alert = [QMUIAlertController alertControllerWithTitle:@"提交试卷" message:msg preferredStyle:QMUIAlertControllerStyleAlert]; [alert addAction:[QMUIAlertAction actionWithTitle:@"确定" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController * _Nonnull aAlertController, QMUIAlertAction * _Nonnull action) { @strongify(self) [self isUploadGrade]; }]]; [alert addAction:[QMUIAlertAction actionWithTitle:@"查看未做的题" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController * _Nonnull aAlertController, QMUIAlertAction * _Nonnull action) { @strongify(self) qIndex = 1; //遍历corecct,找到第一个未做的题目 for (int i = 0; i < questions.count; i++) { if (CorrectTypeUndo == correct[i]) { qIndex = i; break; } } [self setQueIndex]; }]]; [alert addAction:[QMUIAlertAction actionWithTitle:@"取消" style:QMUIAlertActionStyleCancel handler:nil]]; [alert showWithAnimated:YES]; } #pragma mark setting功能 /**专门给【设置】按钮。添加的函数 */ -(void)settingBtn:(STButton *)sender { //点击设置后 就要将模式改为夜间模式 for (ExerView* v in exVs) { [v setNightMode:YES]; } [self.view setBackgroundColor:nightColor]; [contantV setBackgroundColor:nightColor]; [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nightBg.png"] forBarMetrics:0]; //sender.tag为3为考试模式 为4是其他模式 NSMutableArray *setViewArray = [NSMutableArray array]; if (setViewArray.count > 0) { for (int i = 0; i < setViewArray.count; i ++) { ExerciseSetting *set = setViewArray[i]; [set removeFromSuperview]; } } if (sender.tag == 3) { setView = [[ExerciseSetting alloc] initWithExamFrame:CGRectMake(0, kSize.height-kNavOffSet-kSafeAreaBottomHeight-180, kSize.width, 180)]; isSkip = 1; isExplain = 0; } else { setView = [[ExerciseSetting alloc] initWithCustomFrame:CGRectMake(0, kSize.height-kNavOffSet-kSafeAreaBottomHeight-280, kSize.width, 280)]; } [setView.skipSwitch setOn:isSkip]; [setView.explainSwitch setOn:isExplain]; [setView.nightSwitch setOn:myDelegate.isNightMode]; [setView.voiceSwitch setOn:!myDelegate.isNotSoundMode]; [self.view addSubview:setView]; [setViewArray addObject:setView]; //添加setting用的方法 [setView.finishBtn addTarget:self action:@selector(setFinish) forControlEvents:UIControlEventTouchUpInside]; [setView.smallBtn addTarget:self action:@selector(setQuestionFont:) forControlEvents:UIControlEventTouchUpInside]; setView.smallBtn.tag = 100; [setView.bigBtn addTarget:self action:@selector(setQuestionFont:) forControlEvents:UIControlEventTouchUpInside]; setView.bigBtn.tag = 101; [setView.skipSwitch addTarget:self action:@selector(switchIsChanged:) forControlEvents:UIControlEventValueChanged]; setView.skipSwitch.tag = 11; [setView.explainSwitch addTarget:self action:@selector(switchIsChanged:) forControlEvents:UIControlEventValueChanged]; setView.explainSwitch.tag = 12; [setView.voiceSwitch addTarget:self action:@selector(switchIsChanged:) forControlEvents:UIControlEventValueChanged]; setView.voiceSwitch.tag = 13; [setView.nightSwitch addTarget:self action:@selector(switchIsChanged:) forControlEvents:UIControlEventValueChanged]; setView.nightSwitch.tag = 14; } -(void)switchIsChanged:(UISwitch *)aSwitch { switch (aSwitch.tag) { case 11: isSkip = aSwitch.on; break; case 12: isExplain = aSwitch.on; break; case 13: //是否无声模式 是否开启声音取反 默认开启声音 myDelegate.isNotSoundMode = !aSwitch.on; break; case 14: myDelegate.isNightMode = aSwitch.on; break; default: break; } } -(void)setFinish { //根据设置 按钮状态 [self checkIsNightMode]; [setView removeFromSuperview]; } -(void)setQuestionFont:(UIButton *)btn { //100小 101大 if (btn.tag == 100) { if (myDelegate.optionFont == 14) { return; } myDelegate.optionFont -= 1; } if (btn.tag == 101) { if (myDelegate.optionFont == 28) { return; } myDelegate.optionFont += 1; } setView.fontLabel.text = [NSString stringWithFormat:@"%d",(int)myDelegate.optionFont]; [exVs removeAllObjects]; //重新构建题目 [self configExerV:YES]; //将原来在后面的还放到后面 [self.view sendSubviewToBack:contantV]; for (ExerView* v in exVs) { [v setNightMode:YES]; } if (scroll) { [self.view sendSubviewToBack:scroll]; } //[self setFinish]; } //可以调用这个方法实现 夜间模式 只需要改myDelegate.isNightMode的值 然后调用checkIsNightMode即可 -(void)checkIsNightMode { if(myDelegate.isNightMode) { for (ExerView* v in exVs) { [v setNightMode:YES]; } [self.view setBackgroundColor:nightColor]; [contantV setBackgroundColor:nightColor]; [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nightBg.png"] forBarMetrics:0]; }else{ for (ExerView* v in exVs) { [v setNightMode:NO]; } [self.view setBackgroundColor:backGroundColor]; [contantV setBackgroundColor:[UIColor whiteColor]]; [self setNavBarNormalColor]; } } -(void)setNavBarNormalColor { [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"normalBg.png"] forBarMetrics:0]; } -(void)updateTime:(NSTimer*)tim { secCnt--; [self setFirstBbiTitle]; if (secCnt < 1) { @weakify(self); [NSObject rq_showAlertViewWithTitle:@"提示" message:@"考试时间到了,现在交卷!" confirmTitle:@"确定" confirmAction:^{ @strongify(self) [self isUploadGrade]; }]; // UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"考试时间到了,现在交卷!" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil]; // [alert setTag:AlertTypeTimeOut]; // [alert show]; [self.timer invalidate]; self.timer = nil; } } - (void)isUploadGrade { if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { [self endExamAndGotoResult]; } else { dispatch_async(dispatch_get_main_queue(), ^{ @weakify(self) if (myDelegate.isLogin) { if ([defUser.car_type isEqualToString:@"2"]) { NSInteger score = correctMark; if (score >= 80) { [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"考核通过,成绩即将上传!" confirmTitle:@"确定" confirmAction:^{ @strongify(self) grade.isUpdate = @"1"; [self endExamAndGotoResult]; }]; } else { [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"考核失败,是否重新开始考核!" confirmTitle:@"是" cancelTitle:@"否" confirmAction:^{ @strongify(self) [self.navigationController popViewControllerAnimated:NO]; } cancelAction:^{ @strongify(self) [self endExamAndGotoResult]; }]; } } else { grade.isUpdate = @"1"; [self endExamAndGotoResult]; // [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"是否允许上传本次成绩,成绩将在学霸排行榜中显示" confirmTitle:@"是" cancelTitle:@"否" confirmAction:^{ // @strongify(self) // grade.isUpdate = @"1"; // [self endExamAndGotoResult]; // } cancelAction:^{ // @strongify(self) // grade.isUpdate = @"0"; // [self endExamAndGotoResult]; // }]; } } else { //没登录 就不上传成绩 [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"您还未登录,成绩暂无法同步云平台" confirmTitle:@"确定" confirmAction:^{ @strongify(self) [self endExamAndGotoResult]; }]; } }); } } - (void)endExamAndGotoResult { dispatch_async(dispatch_get_main_queue(), ^{ if (!grade) { grade = [[Grade alloc] init]; } if (!honors) { honors = @[@"马路杀手",@"驾考标兵",@"驾考牛人",@"驾考神人",@"外星人",@"幸运儿"]; } NSInteger score = correctMark; NSInteger time = _testTime*60 - secCnt; NSDateFormatter *dateFormatter = [NSDateFormatter rq_defaultDateFormatter]; // formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]; [dateFormatter setDateFormat: @"MM-dd"]; grade.graDate = [dateFormatter stringFromDate:[NSDate date]]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; //如果有开始时间 那就根据时长来计算结束时间 如果没有开始时间 就根据当前时间计算出开始时间 这样就修复了 更改本地时间取得更好成绩的漏洞 grade.startDate = @""; if (grade.startDate.length > 10) { NSDate *beginDate = [dateFormatter dateFromString:grade.startDate]; NSDate *endDte = [NSDate dateWithTimeInterval:time sinceDate:beginDate]; grade.endDate = [dateFormatter stringFromDate:endDte]; }else{ grade.endDate = [dateFormatter stringFromDate:[NSDate date]]; NSDate *beginDate = [NSDate dateWithTimeIntervalSinceNow:-time]; grade.startDate = [dateFormatter stringFromDate:beginDate]; } //NSLog(@"开始--><>%@---结束---><>%@---时长-><>%d",grade.startDate,grade.endDate,(int)time); if (score < 60) { grade.graHonor = honors[0]; }else if (score < 90){ grade.graHonor = honors[1]; }else if (score < 93){ grade.graHonor = honors[2]; }else if (score < 96){ grade.graHonor = honors[3]; }else if (score < 98){ grade.graHonor = honors[4]; }else{ grade.graHonor = honors[5]; } //用min/sec获取占位符 确保时间格式为 00:00 NSString *min = @""; NSString* sec = @""; if (time/60<10) { min= @"0"; } if (time%60<10) { sec= @"0"; } if (score > 100) { //如果成绩大于100 置为100 score = 100; } grade.graTime = [NSString stringWithFormat:@"%@%d:%@%d",min,(int)time/60,sec,(int)time%60]; grade.graScore = [NSString stringWithFormat:@"%d",(int)score]; //NSLog(@"存入---><>%@--->%@----.%@----->%@--->%@----->%@",grade.graDate,grade.graHonor,grade.graScore,grade.graTime,grade.startDate,grade.endDate); [DB_Que_Helper insertGrade:grade]; ExamResultVC* vc = [[ExamResultVC alloc] init]; vc.grade = grade; vc.questions = questions; [self.navigationController qmui_pushViewController:vc animated:YES completion:nil]; }); } /**设置第一个导航栏按钮的标题。如果是普通练习。就显示题号。 否则显示时间。 */ - (void)setFirstBbiTitle { STButton* btn = navBtns[0]; NSString* title ; if (QuestionTypeExam == myDelegate.type.intValue){ int sec = secCnt%60; int min = secCnt/60; NSString* sec0,*min0; sec0 = sec<10 ? @"0" : @""; min0 = min<10 ? @"0" : @""; title = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? [NSString stringWithFormat:@"%@%d:%@%d",min0,min,sec0,sec] : ([defUser.car_type isEqualToString:@"2"]? @"00:00" : [NSString stringWithFormat:@"%@%d:%@%d",min0,min,sec0,sec]); }else{ title = [NSString stringWithFormat:@"%d/%d",(int)qIndex+1,(int)questions.count]; } [btn setTitle: title forState:UIControlStateNormal]; } - (void)setQueIndex { if (questions.count < 1) { return; } [self setFirstBbiTitle]; [self setMoveTitle]; [self setFavTitle]; [self setShowAnsw]; [indexLbl setText:[NSString stringWithFormat:@"%d/%d",(int)qIndex+1,(int)questions.count]]; NSInteger leeIndex = qIndex; if (questions.count>1) { if (qIndex == 0) { leeIndex += 1; }else if(qIndex == questions.count-1){ leeIndex -= 1; } } if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { [(ExerView*)exVs[1] setYdtQuestionModel:questions[leeIndex]]; } else { if ([defUser.car_type isEqualToString:@"2"]) { [(ExerView*)exVs[1] setQuestion:questions[leeIndex]]; } else { [(ExerView*)exVs[1] setYdtQuestionModel:questions[leeIndex]]; } } if (QuestionTypeRecite == myDelegate.type.intValue) { if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { NSInteger myAnswer = [[(RQYDTQuestionModel*)questions[leeIndex] AnswerTrue] intValue]; [(ExerView*)exVs[1] setAnswer:myAnswer]; [(ExerView*)exVs[1] setShowAnswer:YES]; } else { if ([defUser.car_type isEqualToString:@"2"]) { [(ExerView*)exVs[1] setAnswer:[[(Question*)questions[leeIndex] answer] intValue]]; [(ExerView*)exVs[1] setShowAnswer:![defUser.car_type isEqualToString:@"2"]]; } else { NSInteger myAnswer = [[(RQYDTQuestionModel*)questions[leeIndex] AnswerTrue] intValue]; [(ExerView*)exVs[1] setAnswer:myAnswer]; [(ExerView*)exVs[1] setShowAnswer:YES]; } } } else { [(ExerView*)exVs[1] setAnswer:answers[leeIndex]]; [(ExerView*)exVs[1] setShowAnswer:showAnsw[leeIndex]]; } /**设置偏移 */ //这里记录一个问题,第一次记录训练到4396题,如果我进来选择了否,不继续练习,所以跑到了第一题,但是我没有切换上下题,然后我退出界面再次进来(这里依旧保留旧的记录4396题,而不是点了否之后的第一题,如果你切换了其它题则会刷新记录) if (qIndex==0) { [scroll setContentOffset:CGPointMake(0, 0)]; lastOffset.x = 0; }else if(qIndex==questions.count-1){ [scroll setContentOffset:CGPointMake(kSize.width*2, 0)]; lastOffset.x = kSize.width*2; }else{ [scroll setContentOffset:CGPointMake(kSize.width, 0)]; lastOffset.x = kSize.width; } NSInteger qIndex0 = qIndex - 1; if (qIndex0 < 0) { qIndex0 = 0; } if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { [(ExerView*)exVs[0] setYdtQuestionModel:questions[qIndex0]]; } else { if ([defUser.car_type isEqualToString:@"2"]) { [(ExerView*)exVs[0] setQuestion:questions[qIndex0]]; } else { [(ExerView*)exVs[0] setYdtQuestionModel:questions[qIndex0]]; } } if (QuestionTypeRecite == myDelegate.type.intValue) { if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { [(ExerView*)exVs[0] setAnswer:[[(RQYDTQuestionModel*)questions[qIndex0] AnswerTrue] intValue]]; [(ExerView*)exVs[0] setShowAnswer:YES]; } else { if ([defUser.car_type isEqualToString:@"2"]) { [(ExerView*)exVs[0] setAnswer:[[(Question*)questions[qIndex0] answer] intValue]]; [(ExerView*)exVs[0] setShowAnswer:![defUser.car_type isEqualToString:@"2"]]; } else { [(ExerView*)exVs[0] setAnswer:[[(RQYDTQuestionModel*)questions[qIndex0] AnswerTrue] intValue]]; [(ExerView*)exVs[0] setShowAnswer:YES]; } } }else{ [(ExerView*)exVs[0] setAnswer:answers[qIndex0]]; [(ExerView*)exVs[0] setShowAnswer:showAnsw[qIndex0]]; } NSInteger qIndex2 = qIndex + 1; if (qIndex2 >= questions.count) { qIndex2 = (int)questions.count -1; } if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { [(ExerView*)exVs[2] setYdtQuestionModel:questions[qIndex2]]; } else { if ([defUser.car_type isEqualToString:@"2"]) { [(ExerView*)exVs[2] setQuestion:questions[qIndex2]]; } else { [(ExerView*)exVs[2] setYdtQuestionModel:questions[qIndex2]]; } } if (QuestionTypeRecite == myDelegate.type.intValue) { if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { [(ExerView*)exVs[2] setAnswer:[[(RQYDTQuestionModel*)questions[qIndex2] AnswerTrue] intValue]]; [(ExerView*)exVs[2] setShowAnswer:YES]; } else { if ([defUser.car_type isEqualToString:@"2"]) { [(ExerView*)exVs[2] setAnswer:[[(Question*)questions[qIndex2] answer] intValue]]; [(ExerView*)exVs[2] setShowAnswer:![defUser.car_type isEqualToString:@"2"]]; } else { [(ExerView*)exVs[2] setAnswer:[[(RQYDTQuestionModel*)questions[qIndex2] AnswerTrue] intValue]]; [(ExerView*)exVs[2] setShowAnswer:YES]; } } } else { [(ExerView*)exVs[2] setAnswer:answers[qIndex2]]; [(ExerView*)exVs[2] setShowAnswer:showAnsw[qIndex2]]; } //这个操作是为了视频题的视频可以正常播放 if (0 == qIndex) { [(ExerView*)exVs[0] playMovie]; } else if (questions.count-1 == qIndex){ [(ExerView*)exVs[2] playMovie]; } else { [(ExerView*)exVs[1] playMovie]; } [self.view bringSubviewToFront:rightView]; [self.view bringSubviewToFront:show_hideView]; } - (void)setShowAnsw { int vcInd = (int)(scroll.contentOffset.x / kSize.width); //先这样处理了,崩溃日志暗示这里等于3越界了@lee if (vcInd>=3) { vcInd = 2; } ExerView* v = exVs[vcInd]; [v setShowAnswer:RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? showAnsw[qIndex] : ([defUser.car_type isEqualToString:@"2"]? NO : showAnsw[qIndex])]; //根据设置按钮的内容来定义这一题是否显示答案 if (QuestionTypeRecite != myDelegate.type.intValue) { STButton* btn = navBtns[3]; [btn setSelected:showAnsw[qIndex]]; } } /**根据qIndex来设置是否收藏。 */ - (void)setFavTitle { UIButton* btn = navBtns[1]; if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { RQYDTQuestionModel *ydtQuestionModel = questions[qIndex]; [btn setSelected:[RQ_YDT_USER_Question_Module getCollectRecordWithQuestionId:ydtQuestionModel.ID]]; } else { if ([defUser.car_type isEqualToString:@"2"]) { if (qIndex < questions.count) { Question* q = questions[qIndex]; //这个地方直接从库里边查 BOOL isOK; isOK = [DB_Que_Helper queryGZPZ_EXAM_CYRYIsHaveWithQuestion:[q._id integerValue] Type:@"2"]; if (isOK) { q.favorite = @"1"; }else{ q.favorite = @"0"; } [btn setSelected:q.favorite.intValue]; //NSLog(@"favorite---><>%d",(int)q.favorite.integerValue); } } else { RQYDTQuestionModel *ydtQuestionModel = questions[qIndex]; [btn setSelected:[RQ_YDT_USER_Question_Module getCollectRecordWithQuestionId:ydtQuestionModel.ID]]; } } } /**根据qIndex来设置是否排除。 */ - (void)setMoveTitle { UIButton* btn = navBtns[2]; if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { RQYDTQuestionModel *ydtQuestionModel = questions[qIndex]; [btn setSelected:[RQ_YDT_USER_Question_Module getRemoveRecordWithQuestionId:ydtQuestionModel.ID]]; } else { if ([defUser.car_type isEqualToString:@"2"]) { Question* q = questions.count > qIndex? questions[qIndex] : nil; if (q) { //这个地方直接从库里边查 BOOL isOK; isOK = [DB_Que_Helper queryGZPZ_EXAM_CYRYIsHaveWithQuestion:[q._id integerValue] Type:@"3"]; if (isOK) { q.move = @"1"; }else{ q.move = @"0"; } [btn setSelected:q.move.intValue]; //NSLog(@"move--><>%d",(int)q.move.integerValue); } } else { RQYDTQuestionModel *ydtQuestionModel = questions[qIndex]; [btn setSelected:[RQ_YDT_USER_Question_Module getRemoveRecordWithQuestionId:ydtQuestionModel.ID]]; } } } /**type1是收藏,2是错题,3是排除的题。 废弃 dansonmark */ - (void)saveStateQuestion:(NSString*)type { if (!myDelegate.isLogin) { return; } if (![Util connectedToNetWork]) { return; } if (defUser.sfzmhm.length == 0) { return; } NSString *subjectString = [myDelegate.subject intValue] == 4?@"4":@"1"; NSMutableArray *arr=[NSMutableArray array]; if ([defUser.car_type isEqualToString:@"2"]) { Question* ques = questions[qIndex]; [arr addPro:@"qId" Value:ques._id]; } else { RQYDTQuestionModel *ydtQuestionModel = questions[qIndex]; [arr addPro:@"qId" Value:[NSString stringWithFormat:@"%@",[NSNumber numberWithInteger:ydtQuestionModel.ID]]]; } [arr addPro:@"userId" Value:defUser.userDict[@"id"]]; [arr addPro:@"type" Value:type]; [arr addPro:@"source" Value:@"2"]; [arr addPro:@"subject" Value:subjectString]; NSString* method = @"saveFavQuestion"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) { //NSLog(@"加入收排错---->%@---->%@",arr,root); if (!root || [root[@"code"] isEqualToString:@"1"]) { [LoadingView showMsg:@"操作失败"]; } }]; } /**删除错题、收藏、排错 */ - (void)deleteState:(NSString*)type { if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { } else { if (!myDelegate.isLogin) { return; } if (![Util connectedToNetWork]) { return; } if ([defUser.userDict[@"id"] length] == 0){ return; } NSMutableArray *arr=[NSMutableArray array]; if ([defUser.car_type isEqualToString:@"2"]) { Question* ques = questions[qIndex]; [arr addPro:@"id" Value:ques._id]; } else { RQYDTQuestionModel *ydtQuestionModel = questions[qIndex]; [arr addPro:@"id" Value:[NSString stringWithFormat:@"%@",[NSNumber numberWithInteger:ydtQuestionModel.ID]]]; } [arr addPro:@"user" Value:defUser.userDict[@"id"]]; [arr addPro:@"outId" Value:defUser.userStuId]; [arr addPro:@"type" Value:type]; NSString* method = @"deleteFav"; [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) { if (!root || [root[@"code"] isEqualToString:@"1"]) { ShowMsgFailed(); } }]; } } #pragma mark - 代理方法 - (void)removeRandomAD { [self removeAd:nil]; @weakify(adView) [UIView qmui_animateWithAnimated:YES duration:1 animations:^{ @strongify(adView) adView.hidden = YES; }]; } - (void)gotoAllCommentVC { if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { } else { AllCommentVC* vc = [[AllCommentVC alloc] init]; if ([defUser.car_type isEqualToString:@"2"]) { vc.quest = questions[qIndex]; } else { vc.ydtQuestionModel = questions[qIndex]; } [self navPushHideTabbarToVC:vc]; } } #pragma mark - alertViewDelegate - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { @weakify(self) if (AlertTypePause == alertView.tag) { if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) { [self.timer setFireDate:[NSDate distantPast]]; } else { if ([defUser.car_type isEqualToString:@"2"] && myDelegate.isLogin) { } else { [self.timer setFireDate:[NSDate distantPast]]; } } return; } if (AlertTypeTimeOut == alertView.tag) { [self isUploadGrade]; return; } if (AlertTypeSubmit == alertView.tag) { switch (buttonIndex) { case 0: [self isUploadGrade]; break; case 1: break; default: qIndex = 1; //遍历corecct,找到第一个未做的题目 for (int i = 0; i 0 && defUser.isycbd != 1) { UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"您本地有未上传学时,请确认上传!" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { @strongify(self) [self upLoadTrainRecord]; }]; [alert addAction:saveAction]; [self presentViewController:alert animated:YES completion:nil]; } } } - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { if ([scrollView isMemberOfClass:[UICollectionView class]]) { if (searchTf.isFirstResponder) { [searchTf resignFirstResponder]; } } } /**判断是否第一或最后一题 */ - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView { if ([scrollView isKindOfClass:[UICollectionView class]]) { return; } CGPoint off = scrollView.contentOffset; /**要加上后面的判断,否则容易误判。 */ if (off.x <= 0 && 0 == qIndex) { [LoadingView showMsg:@"已经是第一道题了!"]; } else if(off.x >= 2*kSize.width && questions.count-1 == qIndex){ [LoadingView showMsg:@"已经是最后一道题了!"]; } } - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { // NSLog(@"TTTT--: %f",scrollView.contentOffset.x) //这里因为设置了按页滚动为yes,以及preExAction/preExAction ==》setQueIndex 里面对scrool。contentoffset。x和lastoffset的改动; //lastoffset和scroll.contentoffset.x 会有 0,kize.width,kize.width*2 三种值 if (lastOffset.x > scroll.contentOffset.x) { [self preExAction]; }else if (lastOffset.x < scroll.contentOffset.x) { [self nextExAction]; } } #pragma mark - searchTf delegate - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSString *newStr = [textField.text stringByReplacingCharactersInRange:range withString:string]; if (newStr.length >4) {//限制输入至多4位 return NO; } return YES; } #pragma mark - LazyLoad - (CGFloat)adWidth { return RQ_SCREEN_WIDTH; } - (CGFloat)adHeight { return self.adWidth * (100.f / 640.f); } - (UIView *)bannerView { if (!_bannerView) { CGRect rect = {CGPointZero, CGSizeMake(self.adWidth, self.adHeight)}; _bannerView = [[UIView alloc] initWithFrame:rect]; } return _bannerView; } #pragma mark - TimeModule - (void)startTimingWithResultBlock:(void (^)(BOOL isSuccess))resultBlock { @weakify(self) if (defUser.isycbd == 1) { [RQ_RemoteTheory_MANAGER getTheoryStatusWithResultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull statusDict) { @strongify(self) if (isSuccess) { NSString *statusStr = statusDict[@"body"]; if (!statusStr && [statusStr isEqualToString:@""]) { ShowMsg(@"获取学员状态异常!"); !resultBlock? : resultBlock(NO); return; } BOOL statusIsSignIn = [statusStr isEqualToString:@"1"]; NSString *pxkm = defUser.userDict[@"pxjd"]; if (pxkm.length < 1) { pxkm = @"1"; } if (([pxkm isEqualToString:@"2"] || [pxkm isEqualToString:@"3"])) { pxkm = @"4"; } NSArray* array = [DB_Helper quearyTrain:RQStringIsNotEmpty(defUser.userStuId)? defUser.userStuId : @"" Subject:pxkm]; __block NSInteger trainTime = 0; [array.rac_sequence.signal subscribeNext:^(TrainRecord *record) { trainTime = trainTime + record.trainTime.integerValue; } completed:^{ dispatch_async(dispatch_get_main_queue(), ^{ @strongify(self) if (trainTime >= 30) { [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:statusIsSignIn? @"检测到上次未正常签退,请签退后再开始理论计时" : @"检测到学员已签退!本地存在异常学时,是否删除异常学时?" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"取消" otherButtonTitles:@[statusIsSignIn? @"签退" : @"删除"] otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) { @strongify(self) !resultBlock? : resultBlock(NO); if (selectedOtherButtonIndex == 0) { if (statusIsSignIn) { TrainRecord *lastRecord = [array lastObject]; /// 1.本地活体检测 [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:0 completeBlock:^(BOOL success, NSDictionary * _Nullable dic) { @strongify(self) if (success) { /// 2.线上活体检测 [RQ_RemoteTheory_MANAGER edufaceTofaceWithPhotoStr:dic[@"normalImg"] loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess, id dict) { @strongify(self) if (isSuccess) { if (dict) { NSDictionary *myDict = dict; NSString *imageUrlStr = myDict[@"body"]; if (RQStringIsEmpty(imageUrlStr)) { ShowMsg(@"路径为空"); } /// 3.签退 [RQ_RemoteTheory_MANAGER uploadEduSignOutWithArray:array resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signOutDict) { @strongify(self) if (success) { [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:nil]; /// 4.2上传签退照片 [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:lastRecord.classid timeStr:lastRecord.endTime actionPhotoStr:imageUrlStr loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) { @strongify(self) if (isSuccess) { NSLog(@"上传签退照片成功!"); [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:YES completion:nil]; } else { NSLog(@"上传签退照片失败!"); [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:^{ @strongify(self) [self reUploadPhotoWithClassidStr:self.classIdStr timeStr:lastRecord.endTime actionPhotoStr:imageUrlStr loginFlagType:LoginFlagType_SignOut]; }]; } }]; } !resultBlock? : resultBlock(NO); }]; } else { !resultBlock? : resultBlock(NO); [self.timer setFireDate:[NSDate distantPast]]; } } else { !resultBlock? : resultBlock(NO); } }]; } else { !resultBlock? : resultBlock(NO); } }]; } else { for (TrainRecord *record in array) { [DB_Helper deleteTrainRecord:record]; } } } }]; } else { if (statusIsSignIn) { [RQ_RemoteTheory_MANAGER uploadEduSignOutWithArray:@[] resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signOutDict) { @strongify(self) if (isSuccess) { [self signOutSuccessWithTrainArray:@[] signOutSuccess:YES uploadImageSuccess:NO completion:nil]; } !resultBlock? : resultBlock(isSuccess); }]; } else { /// 1.本地活体检测 [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:0 completeBlock:^(BOOL success, NSDictionary * _Nullable dic) { @strongify(self) if (success) { /// 2.线上活体检测 [RQ_RemoteTheory_MANAGER edufaceTofaceWithPhotoStr:dic[@"normalImg"] loginFlagType:LoginFlagType_SignIn resultBlock:^(BOOL isSuccess, id dict) { @strongify(self) if (isSuccess) { if (dict) { NSDictionary *myDict = dict; NSString *imageUrlStr = myDict[@"body"]; if (RQStringIsEmpty(imageUrlStr)) { ShowMsg(@"路径为空"); } /// 3.获取线上时间 [RQ_RemoteTheory_MANAGER getCurrentTimeWithResultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull timeDict) { @strongify(self) if (isSuccess) { // NSString *timeStr = @"2022-03-13 22:46:59"; NSDate *date = [NSDate rq_dateWithTimestamp:timeDict[@"body"]]; // NSDate *date = [NSDate rq_dateWithTimestamp:timeStr]; NSInteger timeStamp = [[NSNumber numberWithDouble:[date timeIntervalSince1970]] integerValue]; NSString *timeStampStr = [NSString stringWithFormat:@"%@",[NSNumber numberWithInteger:timeStamp]]; self.classIdStr = timeStampStr; if (self.classIdStr.length < 10) { /// 如果生成时间戳错误 用一个随机十位数代替 self.classIdStr = [NSString stringWithFormat:@"%@",[NSNumber numberWithInteger:[NSString rq_randomNumberWithFrom:1647311377 to:9999999999]]]; } /// 4.签到 [RQ_RemoteTheory_MANAGER uploadEduSignInWithClassidStr:self.classIdStr resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signInDict) { if (isSuccess) { @strongify(self) NSString *timeStr = signInDict[@"body"]; [self signInSuccessWithBeginTime:timeStr]; /// 5.上传照片 [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:imageUrlStr loginFlagType:LoginFlagType_SignIn resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) { // @strongify(self) }]; } !resultBlock? : resultBlock(isSuccess); }]; } else { !resultBlock? : resultBlock(NO); } }]; } else { !resultBlock? : resultBlock(NO); [self.timer setFireDate:[NSDate distantPast]]; } } else { !resultBlock? : resultBlock(NO); } }]; } else { !resultBlock? : resultBlock(NO); } }]; } } }); }]; } else { !resultBlock? : resultBlock(NO); } }]; } else { !resultBlock? : resultBlock(YES); [self beginTime]; } } - (void)stopTimingWithResultBlock:(void (^)(BOOL isSuccessed))resultBlock { @weakify(self) [self.timer setFireDate:[NSDate distantFuture]]; [self saveTrain]; if (defUser.isycbd == 1) { /// 1.本地活体检测 [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:0 completeBlock:^(BOOL success, NSDictionary * _Nullable dic) { @strongify(self) if (success) { /// 2.线上活体检测 [RQ_RemoteTheory_MANAGER edufaceTofaceWithPhotoStr:dic[@"normalImg"] loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess, id dict) { @strongify(self) if (isSuccess) { if (dict) { NSDictionary *myDict = dict; NSString *imageUrlStr = myDict[@"body"]; if (RQStringIsEmpty(imageUrlStr)) { ShowMsg(@"路径为空"); } /// 3.签退 NSString *pxkm = defUser.userDict[@"pxjd"]; if (pxkm.length < 1) { pxkm = @"1"; } if (([pxkm isEqualToString:@"2"] || [pxkm isEqualToString:@"3"])) { pxkm = @"4"; } NSArray* array = [DB_Helper quearyTrain:RQStringIsNotEmpty(defUser.userStuId)? defUser.userStuId : @"" Subject:pxkm]; if (array.count < 1) { !resultBlock? : resultBlock(YES); ShowMsg(@"本地无学时明细!"); return; } [RQ_RemoteTheory_MANAGER uploadEduSignOutWithArray:array resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signOutDict) { @strongify(self) if (isSuccess) { !resultBlock? : resultBlock(YES); [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:nil]; /// 4.2上传签退照片 NSString *timeStr = [self getTimes:self.seconds]; [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:imageUrlStr loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) { @strongify(self) if (isSuccess) { NSLog(@"上传签退照片成功!"); [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:YES completion:nil]; } else { NSLog(@"上传签退照片失败!"); [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:^{ [self reUploadPhotoWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:imageUrlStr loginFlagType:LoginFlagType_SignOut]; }]; } }]; } else { !resultBlock? : resultBlock(NO); [self.timer setFireDate:[NSDate distantPast]]; } }]; } else { !resultBlock? : resultBlock(NO); [self.timer setFireDate:[NSDate distantPast]]; } } else { !resultBlock? : resultBlock(NO); [self.timer setFireDate:[NSDate distantPast]]; } }]; } else { !resultBlock? : resultBlock(NO); [self.timer setFireDate:[NSDate distantPast]]; } }]; } else { !resultBlock? : resultBlock(YES); [self setSecondString:@"0"]; [self.timer setFireDate:[NSDate distantFuture]]; [self.timer invalidate]; self.timer = nil; myDelegate.timer = nil; // myDelegate.tPeriodVC = nil; myDelegate.isTrain = NO; timeLabel1.text = @"00:00"; timeLabel2.text = @"00:00:00"; // if (self.seconds < 60) { // ShowMsg(@"学时未满一分钟不统计"); // return; // } [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"结束计时,是否上传学时?" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"暂不上传" otherButtonTitles:@[@"确定"] otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) { @strongify(self) if (selectedOtherButtonIndex == 0) { [self upLoadTrainRecord]; }else if (selectedOtherButtonIndex == NSNotFound){ ShowMsg(@"学时已保存在本地"); } }]; } } //远程理论签到成功 - (void)signInSuccessWithBeginTime:(NSString *)beginTime { myDelegate.begin_Time = beginTime; [Tools playAudioWithString:@"操作成功,开始计时"]; self.seconds = 0; // [self.on_offBtn setTitle:@"结束计时" forState:UIControlStateNormal]; myDelegate.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES]; myDelegate.isUseriPhone = YES; myDelegate.isTrain = YES; self.timer = myDelegate.timer; begin_endBtn.selected = YES; //防止前五分钟内退出软件 造成理论无本地学时 无法签退的问题 [self saveTrain]; // myDelegate.tPeriodVC = self; ShowMsgSuc(); [RQ_COMMON_MANAGER keepIdleTimerDisabledisOpen:YES]; } //远程理论签退成功 - (void)signOutSuccessWithTrainArray:(NSArray *)trainArray signOutSuccess:(BOOL)signOutSuccess uploadImageSuccess:(BOOL)uploadImageSuccess completion:(void (^)(void))completion { for (TrainRecord *record in trainArray) { [DB_Helper updateTrainState:record]; } if (trainArray.count > 0) { if (signOutSuccess) { if (![_secondString isEqualToString:@"0"]) { [self setSecondString:@"0"]; } if (self.timer.isValid) { [self.timer invalidate]; } if (self.timer) { self.timer = nil; } if (myDelegate.timer) { myDelegate.timer = nil; } // if (myDelegate.tPeriodVC) { // myDelegate.tPeriodVC = nil; // } if (myDelegate.isTrain) { myDelegate.isTrain = NO; } if (![timeLabel1.text isEqualToString:@"00:00"]) { timeLabel1.text = @"00:00"; } if (![timeLabel2.text isEqualToString:@"00:00:00"]) { timeLabel2.text = @"00:00:00"; } } if (signOutSuccess && uploadImageSuccess) { [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"签退成功!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:nil]; } else if (signOutSuccess && !uploadImageSuccess && completion) { [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"上传照片失败!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"重新上传" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) { completion(); }]; } } else { // 强制签退后再去调签到 [self startTimingWithResultBlock:nil]; } [RQ_COMMON_MANAGER keepIdleTimerDisabledisOpen:NO]; } - (void)reUploadPhotoWithClassidStr:(NSString *)classidStr timeStr:(NSString *)timeStr actionPhotoStr:(NSString *)actionPhotoStr loginFlagType:(LoginFlagType)loginFlagType { __block BOOL reUploadSuccess = YES; __block BOOL isUploading = NO; int i = 0; do { if (i == 0) { if (!isUploading) { isUploading = YES; [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:classidStr timeStr:timeStr actionPhotoStr:actionPhotoStr loginFlagType:loginFlagType resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) { if (isSuccess) { ShowMsg(@"重新上传照片成功!"); reUploadSuccess = YES; } else { reUploadSuccess = NO; } isUploading = NO; }]; } } else { if (!isUploading) { isUploading = YES; [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"上传照片失败!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"重新上传" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) { [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:classidStr timeStr:timeStr actionPhotoStr:actionPhotoStr loginFlagType:loginFlagType resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) { if (isSuccess) { ShowMsg(@"重新上传照片成功!"); reUploadSuccess = YES; } else { reUploadSuccess = NO; } isUploading = NO; }]; }]; } } i ++; } while (reUploadSuccess == NO); } - (NSString *)getTimes:(int)second { NSDateFormatter *formatter=[[NSDateFormatter alloc]init]; [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSString *beginTimeStr = myDelegate.begin_Time; [formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]]; NSDate *beginDate = [formatter dateFromString:beginTimeStr]; NSDate *newDate = [NSDate dateWithTimeInterval:second sinceDate:beginDate]; NSString *nowString = [formatter stringFromDate:newDate]; return nowString; } @end