ExerciseVC.m 140 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499
  1. /**
  2. 先试一试循环滚动吧。
  3. */
  4. #import "ExerciseVC.h"
  5. #import "ExerView.h"
  6. #import "ExamResultVC.h"
  7. #import "Grade.h"
  8. #import "EXButton.h"
  9. #import "ExerciseSetting.h"
  10. #import "BtnCollectionViewCell.h"
  11. #import "ADLinkVC.h"
  12. #import "DES3Util.h"
  13. #import "ThirdLoginBindYunGuanVC.h"
  14. /**
  15. AlertTypeSubmit 提交
  16. AlertTypePause 暂停
  17. AlertTypeTimeOut 时间到
  18. */
  19. typedef NS_ENUM(NSInteger, AlertType){
  20. AlertTypeSubmit = 1,
  21. AlertTypePause,
  22. AlertTypeTimeOut,
  23. AlertTypeIsLoad,
  24. AlertTypeIsQuit
  25. };
  26. @interface ExerciseVC ()<UIScrollViewDelegate,ExerViewDelegate,UIAlertViewDelegate,UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,UITextFieldDelegate>
  27. //@property(nonatomic,strong)UIToolbar* toolBar;
  28. {
  29. // ExerView* exerV;
  30. //我的错题
  31. NSArray* questions;
  32. //0 到 (cont-1)
  33. NSInteger qIndex;
  34. /**就是考试时,用来选择题号的view。在页面底部
  35. */
  36. UIView * contantV;
  37. STButton* bbi0,*bbi1,*bbi2,*bbi3,*bbi4;
  38. UIScrollView* scroll;
  39. /**保存scroll主页面。最后一次滚动的offset
  40. */
  41. CGPoint lastOffset;
  42. #define answersLen 4000
  43. #define correctLen 100
  44. //#define sub1Minutes 45
  45. //#define sub4Minutes 30
  46. /**最大的错误分数
  47. */
  48. //#define faultCntMaxSub1 11
  49. //#define faultCntMaxSub4 6
  50. // NSInteger faultCntMax;
  51. /**用于保存用户的答题情况,默认值是0表示没答题
  52. */
  53. int answers[answersLen];
  54. /**表示这题是否展开解释。0是不展开,1是展开。
  55. */
  56. int showAnsw[answersLen];
  57. /**表示这题是否正确。1未答题,2正确,0错误。
  58. */
  59. int correct[correctLen];
  60. /**保存做错的题目数量
  61. */
  62. int faultCnt,rigCnt;
  63. /**保存做错的分数
  64. */
  65. int faultMark;
  66. /**保存做对的分数
  67. */
  68. int correctMark;
  69. /**保存剩余的秒数。
  70. */
  71. int secCnt;
  72. /**考试计时用的.
  73. */
  74. // NSTimer *timer;
  75. /**保存这次考试的信息。
  76. */
  77. Grade *grade;
  78. /**保存各种考试成绩的称号。例如,赛车之神
  79. */
  80. NSArray *honors;
  81. /**选择题目序号,view
  82. */
  83. UIView *chooseView;
  84. UILabel *rigLbl,*errorLbl,*indexLbl,*barRigLbl,*barErrLbl;
  85. /**选择题号的按钮
  86. */
  87. NSMutableArray *choBtns;
  88. /**是否自动翻页
  89. */
  90. BOOL isSkip;
  91. /**是否自动显示答案
  92. */
  93. BOOL isExplain;
  94. /**声音模式
  95. */
  96. /// 是否继续考试
  97. BOOL isContinue;
  98. UIView *adView;
  99. UIButton *adBtn;
  100. NSDictionary *adDic;
  101. //学时相关
  102. UIView *rightView;//右侧视图
  103. UIView *show_hideView;//左侧详情栏
  104. UILabel *trainStateLabel;//右侧计时状态展示
  105. UILabel *timeLabel1;//右侧按钮上 显示时分
  106. UILabel *timeLabel2;//弹出View上 显示时分秒
  107. UIButton *begin_endBtn;//开始结束按钮
  108. UITextField *searchTf;//搜索题目框
  109. UIButton *sureBtn;//搜索确定按钮
  110. // NSInteger seconds;//时间
  111. NSDateFormatter *formatter;
  112. }
  113. /**科一45分钟100题。
  114. 科四45分钟50题。
  115. */
  116. @property (nonatomic, readwrite, assign) CGFloat adWidth;
  117. @property (nonatomic, readwrite, assign) CGFloat adHeight;
  118. @property (nonatomic, readwrite, strong) UIView *bannerView;
  119. @property (assign, readwrite, nonatomic) NSInteger seconds;
  120. @property (strong, readwrite, nonatomic) NSTimer *timer;
  121. //@property (strong, readwrite, nonatomic) UIButton *on_offBtn;
  122. @property (nonatomic, copy) NSString *secondString;
  123. @end
  124. @implementation ExerciseVC
  125. {
  126. NSMutableArray *navBtns;
  127. ExerciseSetting *setView;
  128. /**用于滚动的练习题的页面,总共3个
  129. */
  130. NSMutableArray *exVs;
  131. }
  132. #pragma mark -
  133. - (void)viewDidLoad
  134. {
  135. [super viewDidLoad];
  136. RQ_COMMON_MANAGER.bannerOnVC = self;
  137. //关于模式选择
  138. [self loadQuestion];//==>设置qIndex 和 questions
  139. //通用导航栏
  140. [self configNavBar];
  141. //展示题目
  142. [self configExerV:NO];//==>setQueIndex
  143. //默认设置
  144. isSkip = YES;
  145. isExplain = YES;
  146. isContinue = NO;
  147. // //计时
  148. // [[RQ_HTTP_Service getIsUsePhone] subscribeNext:^(NSString *timeStr) {
  149. // if ([timeStr containsString:@"-"] || [timeStr containsString:@":"]) {
  150. // if ([timeStr componentsSeparatedByString:@"-"].firstObject.integerValue >= 2023) {
  151. // [self initTrainView];
  152. // }
  153. // }
  154. // } error:^(NSError * _Nullable error) {
  155. //// NSString *timeStr = @"2022-12-19 16:11:57";
  156. //
  157. // }];
  158. for (NSDictionary * dic in defUser.userDict[@"params"]) {
  159. if ([dic[@"KEY"] isEqualToString:@"SP_SHOW_YC"]) {
  160. BOOL isShow = [dic[@"VALUE"] boolValue];
  161. if (isShow) {
  162. // [self initTrainView];
  163. [self.view bringSubviewToFront:RQ_TIMING_VIEW];
  164. }
  165. }
  166. }
  167. }
  168. //页面将要进入前台,开启定时器
  169. -(void)viewWillAppear:(BOOL)animated
  170. {
  171. [super viewWillAppear:animated];
  172. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  173. //开启定时器
  174. [self.timer setFireDate:[NSDate distantPast]];
  175. } else {
  176. if ([defUser.car_type isEqualToString:@"2"] && myDelegate.isLogin) {
  177. } else {
  178. //开启定时器
  179. [self.timer setFireDate:[NSDate distantPast]];
  180. }
  181. }
  182. if (!adView) {
  183. if (QuestionTypeExam != myDelegate.type.intValue) {
  184. [self creatADView];
  185. }
  186. }
  187. for (NSDictionary * dic in defUser.userDict[@"params"]) {
  188. if ([dic[@"KEY"] isEqualToString:@"SP_SHOW_YC"]) {
  189. BOOL isShow = [dic[@"VALUE"] boolValue];
  190. if (isShow) {
  191. RQ_TIMING_VIEW.hidden = NO;
  192. }
  193. }
  194. }
  195. }
  196. -(void)viewWillDisappear:(BOOL)animated
  197. {
  198. [super viewWillDisappear:animated];
  199. [self setNavBarNormalColor];
  200. RQ_TIMING_VIEW.hidden = YES;
  201. }
  202. //页面消失,进入后台不显示该页面,关闭定时器
  203. -(void)viewDidDisappear:(BOOL)animated
  204. {
  205. [super viewDidDisappear:animated];
  206. for (ExerView* v in exVs) {
  207. [v stopMovie];
  208. }
  209. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  210. //关闭定时器
  211. [self.timer setFireDate:[NSDate distantFuture]];
  212. } else {
  213. if ([defUser.car_type isEqualToString:@"2"] && myDelegate.isLogin) {
  214. } else {
  215. //关闭定时器
  216. [self.timer setFireDate:[NSDate distantFuture]];
  217. }
  218. }
  219. if (myDelegate.timer) {
  220. [myDelegate.timer invalidate];
  221. myDelegate.timer = nil;
  222. }
  223. }
  224. - (void)didReceiveMemoryWarning {
  225. [super didReceiveMemoryWarning];
  226. }
  227. - (void)dealloc {
  228. }
  229. #pragma mark -
  230. -(void)configButtomBar
  231. {
  232. if (QuestionTypeExam == myDelegate.type.intValue){
  233. CGFloat h = 40 , w = 60;
  234. CGFloat topHeight = RQ_APPLICATION_TOP_BAR_HEIGHT;
  235. CGFloat height = RQ_SCREEN_HEIGHT;
  236. CGFloat buttomBarY = height - topHeight - h - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT;
  237. UIView *buttomBar = [[UIView alloc] initWithFrame:CGRectMake(0, buttomBarY, RQ_SCREEN_WIDTH, h)];
  238. [self.view addSubview:buttomBar];
  239. [buttomBar setBackgroundColor:KlineColor];
  240. UILabel* label;
  241. label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, w*2, h)];
  242. [label setTextAlignment:NSTextAlignmentCenter];
  243. [label setTextColor:subTitleColor];
  244. NSInteger examQuestionCount = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Exam].count;
  245. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  246. if (1 == myDelegate.subject.intValue) {
  247. [label setText:examQuestionCount > 0? [NSString stringWithFormat:@"1/%ld",examQuestionCount] : [defUser.car_type isEqualToString:@"D"]? @"1/50" : @"1/100"];
  248. }else{
  249. [label setText:examQuestionCount > 0? [NSString stringWithFormat:@"1/%ld",examQuestionCount] : @"1/50"];
  250. }
  251. } else {
  252. if ([defUser.car_type isEqualToString:@"2"]) {
  253. [label setText:@"1/50"];
  254. } else {
  255. if (1 == myDelegate.subject.intValue) {
  256. [label setText:examQuestionCount > 0? [NSString stringWithFormat:@"1/%ld",examQuestionCount] : [defUser.car_type isEqualToString:@"D"]? @"1/50" : @"1/100"];
  257. }else{
  258. [label setText:examQuestionCount > 0? [NSString stringWithFormat:@"1/%ld",examQuestionCount] : @"1/50"];
  259. }
  260. }
  261. }
  262. [buttomBar addSubview:label];
  263. indexLbl = label;
  264. label = [[UILabel alloc] initWithFrame:CGRectMake(kSize.width - w, 0, w, h)];
  265. [label setFont:[UIFont scaleSize:13]];
  266. [label setTextColor:[UIColor redColor]];
  267. [buttomBar addSubview:label];
  268. barErrLbl = label;
  269. label = [[UILabel alloc] initWithFrame:CGRectMake(kSize.width - 2*w, 0, w, h)];
  270. [label setFont:[UIFont scaleSize:13]];
  271. [label setTextColor:defGreen];
  272. [buttomBar addSubview:label];
  273. barRigLbl = label;
  274. UIButton* btn = [[UIButton alloc] initWithFrame:buttomBar.bounds];
  275. [btn addTarget:self action:@selector(showChooseView) forControlEvents:UIControlEventTouchUpInside];
  276. [buttomBar addSubview:btn];
  277. [barRigLbl setText:[NSString stringWithFormat:@"对 %d",rigCnt]];
  278. [barErrLbl setText:[NSString stringWithFormat:@"错 %d",faultCnt]];
  279. }else{
  280. // if (myDelegate.type.intValue != QuestionTypeRandom) {
  281. CGFloat h = 40;
  282. CGFloat topHeight = RQ_APPLICATION_TOP_BAR_HEIGHT;
  283. CGFloat height = RQ_SCREEN_HEIGHT;
  284. CGFloat buttomBarY = height - topHeight - h - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT;
  285. UIView *buttomBar = [[UIView alloc] initWithFrame:CGRectMake(0, buttomBarY, RQ_SCREEN_WIDTH, h + RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT)];
  286. [self.view addSubview:buttomBar];
  287. [buttomBar setBackgroundColor:backGroundColor];
  288. UILabel* label;
  289. label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kSize.width/3, h)];
  290. [label setTextAlignment:NSTextAlignmentCenter];
  291. [label setTextColor:subTitleColor];
  292. [label setText:[NSString stringWithFormat:@"1/%d",(int)questions.count]];
  293. [buttomBar addSubview:label];
  294. indexLbl = label;
  295. // label = [[UILabel alloc] initWithFrame:CGRectMake(w*2, 0, kSize.width - w*2 - 20, h)];
  296. // [label setTextAlignment:NSTextAlignmentRight];
  297. // [label setTextColor:subTitleColor];
  298. // [label setText:[NSString stringWithFormat:@"点我选择题号哦!"]];
  299. // [buttomBar addSubview:label];
  300. NSArray *arr = @[@"",@"上一题",@"下一题"];
  301. CGFloat wid = kSize.width/4;
  302. for (int i=0; i<arr.count; i++) {
  303. UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
  304. if (i==0) {
  305. btn.frame = CGRectMake(0, 0, wid*2, h);
  306. }else{
  307. btn.frame = CGRectMake(wid*(i+1), 0, wid, h);
  308. }
  309. [btn setTitle:arr[i] textColor:subTitleColor font:NormalFont fotState:UIControlStateNormal];
  310. [btn addTarget:self action:@selector(buttomBarClick:) forControlEvents:UIControlEventTouchUpInside];
  311. btn.tag = 1000+i;
  312. [buttomBar addSubview:btn];
  313. // }
  314. }
  315. }
  316. }
  317. -(void)buttomBarClick:(UIButton *)sender
  318. {
  319. switch (sender.tag) {
  320. case 1000:
  321. [self showChooseView];
  322. break;
  323. case 1001:
  324. if (0 == qIndex) {
  325. [LoadingView showMsg:@"已经是第一道题了!"];
  326. return;
  327. }
  328. [self preExAction];
  329. break;
  330. case 1002:
  331. if(questions.count-1 == qIndex){
  332. [LoadingView showMsg:@"已经是最后一道题了!"];
  333. return;
  334. }
  335. [self nextExAction];
  336. break;
  337. default:
  338. break;
  339. }
  340. }
  341. -(void)configExerV:(BOOL)isLoad
  342. {
  343. [self.view setBackgroundColor:backGroundColor];
  344. if (questions.count < 1)
  345. {
  346. //这个地方判断下是题库没导进来 还是无错题、收藏、排除
  347. switch (myDelegate.type.integerValue) {
  348. case QuestionTypeFault:
  349. [LoadingView showMsg:@"您还没有错题!"];
  350. break;
  351. case QuestionTypeFavorite:
  352. [LoadingView showMsg:@"您还没有收藏的题目!"];
  353. break;
  354. case QuestionTypeUndo:
  355. [LoadingView showMsg:@"您还没有排除的题目!"];
  356. break;
  357. default:
  358. [LoadingView showMsg:@"暂未找到相关题目!"];
  359. break;
  360. }
  361. return;
  362. }
  363. //放置题目和选项的scroll
  364. CGFloat bottomheight = RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT + 40;
  365. CGFloat topHeight = RQ_APPLICATION_TOP_BAR_HEIGHT;
  366. CGFloat height = RQ_SCREEN_HEIGHT;
  367. CGFloat scrollHeight = height - topHeight - bottomheight;
  368. if (!scroll) {
  369. scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH, scrollHeight)];//40 是bottombar 60是顶部隐藏的广告
  370. scroll.delegate = self;
  371. scroll.bounces = NO;
  372. scroll.showsHorizontalScrollIndicator = NO;
  373. [self.view addSubview:scroll];
  374. }
  375. //如果没值 要先设置一个默认值
  376. if (myDelegate.optionFont < 14 || myDelegate.optionFont > 28) {
  377. myDelegate.optionFont = 17;
  378. }
  379. exVs = [NSMutableArray array];
  380. for (int i =0; i<3; i++)
  381. {
  382. ExerView* exv = [[ExerView alloc] initWithFrame:CGRectMake(RQ_SCREEN_WIDTH * i, 0, RQ_SCREEN_WIDTH, scrollHeight)];//40 是bottombar 60是顶部隐藏的广告
  383. exv.index = i;
  384. exv.questions = questions;
  385. [scroll addSubview:exv];
  386. [exVs addObject:exv];
  387. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  388. [exv setYdtQuestionModel:questions[0]];
  389. if ( i>1 && questions.count > 1)
  390. {
  391. [exv setYdtQuestionModel:questions[1]];
  392. }
  393. } else {
  394. if ([defUser.car_type isEqualToString:@"2"]) {
  395. [exv setQuestion:questions[0]];
  396. if ( i>1 && questions.count > 1)
  397. {
  398. [exv setQuestion:questions[1]];
  399. }
  400. } else {
  401. [exv setYdtQuestionModel:questions[0]];
  402. if ( i>1 && questions.count > 1)
  403. {
  404. [exv setYdtQuestionModel:questions[1]];
  405. }
  406. }
  407. }
  408. exv.delegate2 = self;
  409. }
  410. //夜间模式
  411. [self checkIsNightMode];
  412. int pageCnt = (int)questions.count;
  413. if (pageCnt >3)
  414. {
  415. pageCnt = 3;
  416. }
  417. [scroll setContentSize:CGSizeMake(RQ_SCREEN_WIDTH*pageCnt, 0)];
  418. [scroll setPagingEnabled:YES];
  419. [self setQueIndex];
  420. if (!isLoad) {//isload:yes改变字体进来的(无须括号内操作),no初始化
  421. [self configButtomBar];
  422. }
  423. }
  424. - (void)creatADView {
  425. @weakify(self)
  426. //获取广告总数量 取一个随机数
  427. NSMutableArray *newAD = [NSMutableArray array];
  428. for (NSDictionary *dic in myDelegate.adArray) {
  429. if ([dic[@"LOCATION"] isEqualToString:@"3"]) {
  430. [newAD addObject:dic];
  431. }
  432. }
  433. CGFloat topHeight = RQ_APPLICATION_TOP_BAR_HEIGHT;
  434. CGFloat height = RQ_SCREEN_HEIGHT;
  435. adView = [[UIView alloc] initWithFrame:CGRectMake(0, height - topHeight - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT - 40 - self.adHeight, self.adWidth, self.adHeight)];
  436. [self.view addSubview:adView];
  437. [adView mas_remakeConstraints:^(MASConstraintMaker *make) {
  438. @strongify(self)
  439. make.left.mas_equalTo(self.view).mas_offset(0);
  440. make.bottom.mas_equalTo(self.view).mas_offset(- RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT - 40 - 8);
  441. make.size.mas_equalTo(CGSizeMake(self.adWidth, self.adHeight));
  442. }];
  443. UIImageView *adImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.adWidth, self.adHeight)];
  444. adImg.layer.cornerRadius = 0;
  445. adImg.contentMode = UIViewContentModeScaleAspectFill;
  446. [adImg setClipsToBounds:YES];
  447. [adView addSubview:adImg];
  448. adBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  449. adBtn.frame = CGRectMake(adView.frame.size.width - 40, 5, 30, 30);
  450. [adBtn setImage:[[UIImage imageNamed:@"community6"] tint:[UIColor redColor]] forState:UIControlStateNormal];
  451. [adBtn borderColor:[UIColor redColor] width:2 cornorRadios:15];
  452. [adBtn addTarget:self action:@selector(removeRandomAD) forControlEvents:UIControlEventTouchUpInside];
  453. [adView addSubview:adBtn];
  454. if (newAD.count < 1) {
  455. [adImg setImage:[UIImage imageNamed:@"subject_main_banner.jpg"]];
  456. }else{
  457. NSInteger rendomIndex = arc4random()%newAD.count;
  458. NSDictionary *dic = newAD[rendomIndex];
  459. adDic = [NSDictionary dictionaryWithDictionary:dic];
  460. NSString *path = dic[@"IMG"];
  461. [adImg sd_setImageWithURL:[NSURL URLWithString:path] placeholderImage:[UIImage imageNamed:@"subject_main_banner.jpg"]];
  462. //把手势添加到指定视图上
  463. [adImg setUserInteractionEnabled:YES];
  464. UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(skipToADLink:)];
  465. [adImg addGestureRecognizer:tapGesture];
  466. }
  467. // if (scroll.y < 10.0) {
  468. // scroll.y = adView.height;
  469. // }
  470. adView.hidden = NO;
  471. BOOL isShow1;
  472. BOOL isShow2;
  473. NSInteger begin1 = [RQ_COMMON_MANAGER.YYXC_AD_TIME1 componentsSeparatedByString:@"-"].firstObject.integerValue? : 23;
  474. NSInteger end1 = [RQ_COMMON_MANAGER.YYXC_AD_TIME1 componentsSeparatedByString:@"-"].lastObject.integerValue? :24;
  475. NSInteger begin2 = [RQ_COMMON_MANAGER.YYXC_AD_TIME2 componentsSeparatedByString:@"-"].firstObject.integerValue? : 0;
  476. NSInteger end2 = [RQ_COMMON_MANAGER.YYXC_AD_TIME2 componentsSeparatedByString:@"-"].lastObject.integerValue? : 6;
  477. isShow1 = [NSDate isBetweenFromHour:begin1 toHour:end1];
  478. isShow2 = [NSDate isBetweenFromHour:begin2 toHour:end2];
  479. if (RQ_COMMON_MANAGER.YYXC_AD_OPEN) {
  480. if (RQ_COMMON_MANAGER.YYXC_BANNER_AD_OPEN) {
  481. if (isShow1 || isShow2) {
  482. [self loadAdAndShow];
  483. }
  484. }
  485. }
  486. }
  487. - (void)loadAdAndShow {
  488. @weakify(self)
  489. [adView addSubview:self.bannerView];
  490. [RQ_AD_MODULE loadAdWithAdType:GromoreAdTypeBanner customView:self.bannerView];
  491. [RQ_AD_MODULE initADStatusChangeBlock:^(GromoreAdType adType, RQADDoType adDoType) {
  492. @strongify(self)
  493. if (adType == GromoreAdTypeBanner) {
  494. if (adDoType == RQADDoType_Close) {
  495. [self removeRandomAD];
  496. } else if (adDoType == RQADDoType_Success) {
  497. [adView bringSubviewToFront:adBtn];
  498. }
  499. }
  500. }];
  501. }
  502. - (void)removeAd:(id)sender {
  503. [RQ_AD_MODULE closeAdWithAdType:GromoreAdTypeBanner];
  504. [self.bannerView removeFromSuperview];
  505. self.bannerView = nil;
  506. }
  507. -(void)skipToADLink:(UITapGestureRecognizer *)gesture
  508. {
  509. //1是程序内 2是程序外
  510. NSString *skipType = adDic[@"OPENTYPE"];
  511. if ([skipType isEqualToString:@"1"]) {
  512. ADLinkVC *ad = [[ADLinkVC alloc] init];
  513. ad.title = adDic[@"TITLE"];
  514. ad.urlString = adDic[@"URL"];
  515. if (ad.urlString && ad.urlString.length != 0) {
  516. [self navPushHideTabbarToVC:ad];
  517. }
  518. }else{
  519. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:adDic[@"URL"]]];
  520. }
  521. }
  522. /**0,16,32,64,128
  523. 这里还要告诉是否答题正确,如果正确,自动翻页。否则显示正确答案。
  524. */
  525. -(void)didChooseOption:(NSInteger)opt isRight:(BOOL)isRig
  526. {
  527. @weakify(self)
  528. CGPoint off = scroll.contentOffset;
  529. Question* q = questions[qIndex];
  530. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  531. RQYDTQuestionModel *ydtQuestionModel = questions[qIndex];
  532. [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];
  533. } else {
  534. //标记做过的题
  535. if ([defUser.car_type isEqualToString:@"2"]) {
  536. [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"4" State:1];
  537. } else {
  538. RQYDTQuestionModel *ydtQuestionModel = questions[qIndex];
  539. [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];
  540. }
  541. }
  542. // [DB_Que_Helper setMarkQuestionWithQuestion:[q._id integerValue] Type:@"4" State:1];
  543. //计算分数
  544. int mark = 1;//每题的分值
  545. if ([defUser.car_type isEqualToString:@"1"] || [defUser.car_type isEqualToString:@"5"] || [defUser.car_type isEqualToString:@"6"]) {
  546. Question *q = questions[qIndex];
  547. //q.option_type 0判断 1单选 2多选
  548. if ([q.option_type intValue] == 2) {
  549. mark = 2;
  550. }else {
  551. mark = 1;
  552. }
  553. } else if ([defUser.car_type isEqualToString:@"2"]) {
  554. mark = 2;
  555. }else if ([defUser.car_type isEqualToString:@"3"] || [defUser.car_type isEqualToString:@"4"]) {
  556. mark = 1;
  557. }else if([defUser.car_type isEqualToString:@"D"]) {
  558. mark = 2;
  559. }else {
  560. if ([myDelegate.subject isEqualToString:@"1"]) {//C1 A1 A2 科一一题一分
  561. mark = 1;
  562. }else {//C1 A1 A2 科四一题两分
  563. mark = 2;
  564. }
  565. }
  566. if (isRig) {
  567. correctMark += mark;
  568. }else {
  569. faultMark += mark;
  570. }
  571. //记录做题状态
  572. if (qIndex < answersLen) {
  573. answers[qIndex] = (int)opt;
  574. }
  575. if (isRig)
  576. {
  577. if (qIndex < correctLen ) {
  578. correct[qIndex] = CorrectTypeRignt;
  579. rigCnt ++;
  580. }
  581. //判断是否自动翻页
  582. if (!isSkip)
  583. {
  584. if (!isExplain) {
  585. return;
  586. }
  587. /**非考试模式答对了在不自动翻页模式下就展示答案 不知道这样行不行--对之前用户反映的回馈
  588. */
  589. if(QuestionTypeExam != myDelegate.type.intValue) {
  590. showAnsw[qIndex] = YES;
  591. [self setShowAnsw];
  592. }
  593. return;
  594. }
  595. /**已经到最后一题了。
  596. */
  597. if (qIndex >= questions.count -1) {
  598. [LoadingView showMsg:@"做完了!请交卷!"];
  599. //这一句修复错题模式下 做完左后一题 数据库以及网络都没有请求的问题 修复1.0.2BUG
  600. [self faultExAction:isRig];
  601. return;
  602. }
  603. [UIView animateWithDuration:.5 delay:.3 options:0 animations:^{
  604. [scroll setContentOffset:CGPointMake(off.x + kSize.width, off.y)];
  605. } completion:^(BOOL finished) {
  606. @strongify(self)
  607. [self nextExAction];
  608. lastOffset = scroll.contentOffset;
  609. }];
  610. }
  611. else
  612. {
  613. if (qIndex < correctLen)
  614. {
  615. faultCnt++;
  616. correct[qIndex] = CorrectTypeFault;
  617. }
  618. //如果是考试模式 要自动翻页
  619. if (QuestionTypeExam == myDelegate.type.intValue)
  620. {
  621. /**已经到最后一题了
  622. */
  623. if (qIndex >= questions.count -1) {
  624. UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"考题已全部做完,考试结束" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
  625. [alert show];
  626. [self isUploadGrade];
  627. return;
  628. }
  629. [UIView animateWithDuration:.5 delay:.3 options:0 animations:^{
  630. [scroll setContentOffset:CGPointMake(off.x + kSize.width, off.y)];
  631. } completion:^(BOOL finished) {
  632. @strongify(self)
  633. [self nextExAction];
  634. lastOffset = scroll.contentOffset;
  635. }];
  636. }
  637. //考试模式中 错太多自动结束
  638. if (QuestionTypeExam == myDelegate.type.intValue && faultMark > _loseMark && !isContinue)
  639. {
  640. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  641. NSString *msg = [NSString stringWithFormat: @"本次考试做错%d分,超过%d分,考试结束!",faultMark,_loseMark];
  642. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
  643. UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  644. @strongify(self)
  645. if (myDelegate.timer) {
  646. [myDelegate.timer invalidate];
  647. myDelegate.timer = nil;
  648. if (self.seconds < 60) {
  649. ShowMsg(@"学时未满一分钟不统计");
  650. [self isUploadGrade];
  651. return;
  652. }
  653. [self saveTrain];
  654. [self upLoadTrainRecord];
  655. }
  656. [self isUploadGrade];
  657. }];
  658. [alert addAction:saveAction];
  659. [self presentViewController:alert animated:YES completion:nil];
  660. } else {
  661. if ([defUser.car_type isEqualToString:@"2"]) {
  662. NSString *msg = [NSString stringWithFormat: @"本次考试做错%d分,超过%d分,考试失败!",faultMark,_loseMark];
  663. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
  664. UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"重新开始" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  665. @strongify(self)
  666. [self.navigationController popViewControllerAnimated:NO];
  667. }];
  668. UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"继续考试" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  669. isContinue = YES;
  670. }];
  671. [alert addAction:saveAction];
  672. [alert addAction:cancleAction];
  673. [self presentViewController:alert animated:YES completion:nil];
  674. } else {
  675. NSString *msg = [NSString stringWithFormat: @"本次考试做错%d分,超过%d分,考试结束!",faultMark,_loseMark];
  676. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
  677. UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  678. @strongify(self)
  679. if (myDelegate.timer) {
  680. [myDelegate.timer invalidate];
  681. myDelegate.timer = nil;
  682. if (self.seconds < 60) {
  683. ShowMsg(@"学时未满一分钟不统计");
  684. [self isUploadGrade];
  685. return;
  686. }
  687. [self saveTrain];
  688. [self upLoadTrainRecord];
  689. }
  690. [self isUploadGrade];
  691. }];
  692. [alert addAction:saveAction];
  693. [self presentViewController:alert animated:YES completion:nil];
  694. }
  695. }
  696. }
  697. //判断 答错是否自动展示答案
  698. if (!isExplain)
  699. {
  700. return;
  701. }
  702. /**非考试模式答错了就展示答案
  703. */
  704. if(QuestionTypeExam != myDelegate.type.intValue)
  705. {
  706. showAnsw[qIndex] = YES;
  707. [self setShowAnsw];
  708. //[v setShowAnswer:YES];
  709. }
  710. }
  711. [barRigLbl setText:[NSString stringWithFormat:@"对 %d",rigCnt]];
  712. [barErrLbl setText:[NSString stringWithFormat:@"错 %d",faultCnt]];
  713. //根据原本状态和本次对错判定现在是否移除状态
  714. [self faultExAction:isRig];
  715. }
  716. /**做章节练习,可以把listView加入进来。
  717. **在listView里面设置好where。这里换成present好了。每次willAppear的时候,看是否已经选好了。
  718. 如果选好了。直接dismiss。
  719. */
  720. -(void)loadQuestion
  721. {
  722. @weakify(self)
  723. qIndex = 0;
  724. NSString* sql = [NSString string];//QuestionTypeOrdered QuestionTypeRecite QuestionTypeChapt QuestionTypeFault QuestionTypeStrenth QuestionTypeUndo
  725. NSInteger lastQid = 0;
  726. switch (myDelegate.type.intValue) {
  727. //顺序模式
  728. case QuestionTypeOrdered:
  729. {
  730. 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]);//除去排除的所有当前学科当前车型的题目
  731. //@"C1",@"A2",@"A1",@"D",@"4",@"1",@"2",@"3",@"5" defUser.car_type
  732. if ([defUser.car_type isEqualToString:@"4"]) {
  733. qIndex = defUser.coachIndex.intValue;
  734. lastQid = qIndex;
  735. }
  736. if ([defUser.car_type isEqualToString:@"1"]) {
  737. qIndex = defUser.A1Index.intValue;
  738. lastQid = qIndex;
  739. }
  740. if ([defUser.car_type isEqualToString:@"2"]) {
  741. qIndex = defUser.A2Index.intValue;
  742. lastQid = qIndex;
  743. }
  744. if ([defUser.car_type isEqualToString:@"3"]) {
  745. qIndex = defUser.dangerIndex.intValue;
  746. lastQid = qIndex;
  747. }
  748. if ([defUser.car_type isEqualToString:@"5"]) {
  749. qIndex = defUser.texiIndex.intValue;
  750. lastQid = qIndex;
  751. }
  752. if ([defUser.car_type isEqualToString:@"6"]) {
  753. qIndex = defUser.wycIndex.intValue;
  754. lastQid = qIndex;
  755. }
  756. if ([defUser.car_type isEqualToString:@"C1"]) {
  757. if (myDelegate.subject.intValue == 1) {
  758. qIndex = defUser.userSubj1Index.intValue;
  759. lastQid = qIndex;
  760. }else{
  761. qIndex = defUser.userSubj4Index.intValue;
  762. lastQid = qIndex;
  763. }
  764. }
  765. if ([defUser.car_type isEqualToString:@"A2"]) {
  766. if (myDelegate.subject.intValue == 1) {
  767. qIndex = defUser.A2Subj1Index.intValue;
  768. lastQid = qIndex;
  769. }else{
  770. qIndex = defUser.A2Subj4Index.intValue;
  771. lastQid = qIndex;
  772. }
  773. }
  774. if ([defUser.car_type isEqualToString:@"A1"]) {
  775. if (myDelegate.subject.intValue == 1) {
  776. qIndex = defUser.A1Subj1Index.intValue;
  777. lastQid = qIndex;
  778. }else{
  779. qIndex = defUser.A1Subj4Index.intValue;
  780. lastQid = qIndex;
  781. }
  782. }
  783. if ([defUser.car_type isEqualToString:@"D"]) {
  784. if (myDelegate.subject.intValue == 1) {
  785. qIndex = defUser.DSubj1Index.intValue;
  786. lastQid = qIndex;
  787. }else{
  788. qIndex = defUser.DSubj4Index.intValue;
  789. lastQid = qIndex;
  790. }
  791. }
  792. if (qIndex > questions.count-1) {
  793. qIndex = 0;
  794. }
  795. // 查找缺失那些数据库图片
  796. // {
  797. // questions=[DB_Que_Helper queryQuestion:@"zhaobucunzai"];
  798. //
  799. // NSLog(@"----><>%d",(int)questions.count);
  800. //
  801. // NSMutableArray *imgString = [NSMutableArray array];
  802. // for (Question *q in questions) {
  803. //
  804. // UIImage *img = [UIImage imageNamed:q.media];
  805. // if (!img) {
  806. // [imgString addObject:q.media];
  807. // }
  808. // }
  809. // NSLog(@"imgString----><>%@",imgString);
  810. // }
  811. }
  812. break;
  813. //背题模式
  814. case QuestionTypeRecite:
  815. 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]);//除去排除的所有当前学科当前车型的题目
  816. if (myDelegate.subject.intValue == 1) {
  817. qIndex = defUser.user1Index.intValue;
  818. lastQid = qIndex;
  819. }else{
  820. qIndex = defUser.user4Index.intValue;
  821. lastQid = qIndex;
  822. }
  823. if (qIndex > questions.count-1) {
  824. qIndex = 0;
  825. }
  826. break;
  827. //随机模式
  828. case QuestionTypeRandom:
  829. 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]);//除去排除的所有当前学科当前车型的题目
  830. if (questions && questions.count < 1)
  831. {
  832. return;
  833. }
  834. // qIndex = arc4random()%(questions.count - 1);
  835. break;
  836. //章节模式 章节模式 还用之前的方式 里边不涉及错题排错题的查询
  837. case QuestionTypeChapt: {
  838. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  839. questions=[RQ_YDTQuestion_Module getChapterQuestionWithChapterName:self.chapterName];
  840. } else {
  841. if ([defUser.car_type isEqualToString:@"2"]) {
  842. sql=[NSString stringWithFormat:@"%@",myDelegate.where];
  843. questions = [DB_Que_Helper queryGZPZ_EXAM_CYRYQuestion:sql];
  844. } else {
  845. // sql=[NSString stringWithFormat:@"subject = '%@' and %@",myDelegate.subject,myDelegate.where];
  846. questions=[RQ_YDTQuestion_Module getChapterQuestionWithChapterName:self.chapterName];
  847. }
  848. }
  849. break;
  850. }
  851. //强化练习 强化练习 还用之前的方式 里边不涉及错题排错题的查询
  852. case QuestionTypeStrenth:
  853. // sql=[NSString stringWithFormat:@"strong"];
  854. // questions=[DB_Que_Helper queryQuestion:sql];
  855. questions = [RQ_YDTQuestion_Module getPointQuestionWithPointID:self.pointId];
  856. break;
  857. //我的错题
  858. case QuestionTypeFault:
  859. 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]);//所有当前学科当前车型的错题
  860. //NSLog(@"错题count = %d",(int)questions.count);
  861. break;
  862. //排除的题
  863. case QuestionTypeUndo:
  864. 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]);//所有当前学科当前车型的排错题
  865. //NSLog(@"排除count ==== %d",(int)questions.count);
  866. break;
  867. //我的收藏
  868. case QuestionTypeFavorite:
  869. 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]);//所有当前学科当前车型的收藏题
  870. //NSLog(@"收藏count = %d",(int)questions.count);
  871. break;
  872. //模拟考试
  873. case QuestionTypeExam:
  874. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  875. questions = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Exam];
  876. } else {
  877. if ([defUser.car_type isEqualToString:@"2"]) {
  878. questions = [DB_Que_Helper queryGZPZ_EXAM_CYRYExamQuestion];
  879. } else {
  880. questions = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Exam];
  881. }
  882. }
  883. // NSLog(@"examCount = %d",(int)questions.count);
  884. break;
  885. //未做题
  886. case QuestionTypeNotDo:
  887. 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]);
  888. // NSLog(@"未做count = %d",(int)questions.count);
  889. break;
  890. case QuestionTypeNewRule:
  891. questions = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_NewRule] : ([defUser.car_type isEqualToString:@"2"]? @[] : [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_NewRule]);
  892. break;
  893. case QuestionTypeMiOne:
  894. questions = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Mi_One];
  895. break;
  896. case QuestionTypeMiTwo:
  897. questions = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Mi_Two];
  898. break;
  899. default:
  900. break;
  901. }
  902. if (lastQid != 0) {
  903. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:[NSString stringWithFormat:@"您上次已练习到%d题,是否继续答题",(int)lastQid + 1] delegate:self cancelButtonTitle:@"是" otherButtonTitles:@"否", nil];
  904. alert.tag = 100;
  905. [alert show];
  906. }else {
  907. //如果这个提示没有 就去看是否有未上传学时
  908. NSString *pxkm = defUser.userDict[@"pxjd"];
  909. if (pxkm.length < 1) {
  910. pxkm = @"1";
  911. }
  912. NSArray* array = [DB_Helper quearyTrain:defUser.userStuId Subject:pxkm];
  913. if (array.count > 0 && defUser.isycbd != 1) {
  914. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"您本地有未上传学时,请确认上传!" preferredStyle:UIAlertControllerStyleAlert];
  915. UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  916. @strongify(self)
  917. [self upLoadTrainRecord];
  918. }];
  919. [alert addAction:saveAction];
  920. [self presentViewController:alert animated:YES completion:nil];
  921. }
  922. }
  923. for(int i = 0;i<answersLen;i++)
  924. {
  925. answers[i] = 0;
  926. showAnsw[i]= 0;
  927. if (i< correctLen)
  928. {
  929. correct[i] = CorrectTypeUndo;
  930. }
  931. }
  932. faultCnt = 0;
  933. faultMark = 0;
  934. correctMark = 0;
  935. secCnt = _testTime*60;
  936. if (QuestionTypeExam == myDelegate.type.intValue) {
  937. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  938. self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTime:) userInfo:nil repeats:YES];
  939. } else {
  940. if ([defUser.car_type isEqualToString:@"2"] && myDelegate.isLogin) {
  941. } else {
  942. self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTime:) userInfo:nil repeats:YES];
  943. }
  944. }
  945. //每1秒运行一次function方法。
  946. grade = [[Grade alloc] init];
  947. NSDateFormatter *dateFormatter = [NSDateFormatter rq_defaultDateFormatter];
  948. grade.startDate = [dateFormatter stringFromDate:[NSDate date]];
  949. }
  950. }
  951. -(void)configNavBar
  952. {
  953. //通用导航栏设置
  954. UIBarButtonItem* backBbi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"question_pre_checked_icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(goBackByNavigation)];
  955. [backBbi setTintColor:defGreen];
  956. [self.navigationItem setLeftBarButtonItem:backBbi];
  957. self.navigationController.navigationBar.translucent = NO;
  958. navBtns = [NSMutableArray array];
  959. NSArray* titles1;
  960. NSArray* titles2;
  961. NSArray* imagesN;
  962. NSArray* imagesS;
  963. if (myDelegate.type.intValue == QuestionTypeExam)
  964. {
  965. titles1 = @[@"00/0000",@"收藏本题",@"交卷",@"设置"];
  966. titles2 = @[@"00/0000",@"取消收藏",@"交卷",@"设置"];
  967. //最后一张图是title_setting_ico.png。 但是60X60尺寸太大。无法显示
  968. imagesN = @[@"exerise_top1",@"exerise_top2",@"exerise_top3",@"exerise_top5.png"];
  969. imagesS = @[@"exerise_topH1",@"exerise_topH2",@"exerise_topH3",@"exerise_top5.png"];
  970. }
  971. else if(myDelegate.type.intValue == QuestionTypeRecite){
  972. titles1 = @[@"00/0000",@"收藏本题",@"设置"];
  973. titles2 = @[@"00/0000",@"取消收藏",@"设置"];
  974. imagesN = @[@"exerise_top1",@"exerise_top2",@"exerise_top5.png"];
  975. imagesS = @[@"exerise_topH1",@"exerise_topH2",@"exerise_top5.png"];
  976. }
  977. else
  978. {
  979. titles1 = @[@"00/0000",@"收藏本题",@"排除本题",@"展开解释",@"设置"];
  980. titles2 = @[@"00/0000",@"取消收藏",@"取消排除",@"收起解释",@"设置"];
  981. imagesN = @[@"exerise_top1",@"exerise_top2",@"exerise_top3",@"exerise_top4",@"exerise_top5.png"];
  982. imagesS = @[@"exerise_topH1",@"exerise_topH2",@"exerise_topH3",@"exerise_topH4",@"exerise_top5.png"];
  983. }
  984. CGFloat barBtnH = self.navigationController.navigationBar.frame.size.height;
  985. CGFloat barBtnW = kSize.width / (titles1.count + 3);
  986. for (int i = 0; i < titles1.count && i< titles2.count; i++) {
  987. STButton* btn = [[STButton alloc] initWithFrame:CGRectMake(0, 0, barBtnW, barBtnH) ];
  988. if (IOS11) {
  989. NSLayoutConstraint *widthConstraint = [btn.widthAnchor constraintEqualToConstant:barBtnW];
  990. NSLayoutConstraint *heightConstraint = [btn.heightAnchor constraintEqualToConstant:barBtnH];
  991. [heightConstraint setActive:YES];
  992. [widthConstraint setActive:YES];
  993. }
  994. [btn setImage:[UIImage imageNamed:imagesN[i]] withTitle:titles1[i] Font:SmallFont forState:UIControlStateNormal];
  995. [btn setImage:[UIImage imageNamed:imagesS[i]] withTitle:titles2[i] Font:SmallFont forState:UIControlStateSelected];
  996. [btn setTitleColor:subTitleColor forState:UIControlStateNormal];
  997. [btn setTitleColor:defGreen forState:UIControlStateHighlighted];
  998. [btn setTitleColor:defGreen forState:UIControlStateSelected];
  999. [btn setTag:i];
  1000. [navBtns addObject:btn];
  1001. }
  1002. [[navBtns lastObject] setImage:[[UIImage imageNamed:[imagesS lastObject]] tint:[UIColor colorWithWhite:135.0/255 alpha:1]] forState:UIControlStateNormal];
  1003. /**这里要倒序加入。
  1004. */
  1005. NSMutableArray* bbiArr = [NSMutableArray array];
  1006. for (int i = (int)titles1.count - 1 ; i>=0; i--) {
  1007. STButton* btn = navBtns[i];
  1008. UIBarButtonItem* bbi = [[UIBarButtonItem alloc] initWithCustomView:btn];
  1009. [bbiArr addObject:bbi];
  1010. }
  1011. self.navigationItem.rightBarButtonItems = bbiArr;
  1012. if (QuestionTypeExam == myDelegate.type.intValue)
  1013. {
  1014. [navBtns[0] addTarget:self action:@selector(pauseExamAction) forControlEvents:UIControlEventTouchUpInside];
  1015. [navBtns[2] addTarget:self action:@selector(submitExam) forControlEvents:UIControlEventTouchUpInside];
  1016. }else if (myDelegate.type.intValue == QuestionTypeRecite) {
  1017. [navBtns[0] addTarget:self action:@selector(showChooseView) forControlEvents:UIControlEventTouchUpInside];
  1018. }else{
  1019. [navBtns[0] addTarget:self action:@selector(showChooseView) forControlEvents:UIControlEventTouchUpInside];
  1020. [navBtns[2] addTarget:self action:@selector(moveExAction) forControlEvents:UIControlEventTouchUpInside];
  1021. [navBtns[3] addTarget:self action:@selector(showAnswAction) forControlEvents:UIControlEventTouchUpInside];
  1022. }
  1023. [navBtns[1] addTarget:self action:@selector(favAction) forControlEvents:UIControlEventTouchUpInside];
  1024. [[navBtns lastObject] addTarget:self action:@selector(settingBtn:) forControlEvents:UIControlEventTouchUpInside];
  1025. //除了随机 都要有
  1026. if (QuestionTypeRandom == myDelegate.type.intValue) {
  1027. return;
  1028. }
  1029. chooseView = [[UIView alloc] initWithFrame:kFrame];
  1030. [chooseView setBackgroundColor:[UIColor colorWithWhite:.3 alpha:.3]];
  1031. contantV = [[UIView alloc] initWithFrame:CGRectMake(0, 100, kSize.width, kSize.height-100-kSafeAreaBottomHeight)];
  1032. [chooseView addSubview:contantV];
  1033. [contantV setBackgroundColor:[UIColor whiteColor]];
  1034. CGFloat x,y,wid,hei,bd;
  1035. bd = 5;
  1036. wid = hei = 40;
  1037. x = kSize.width - wid - bd;
  1038. y = bd;
  1039. EXButton* btnn = [[EXButton alloc] initWithFrame:CGRectMake(x, y, wid, hei)];
  1040. [btnn addTarget:self action:@selector(hideChooseView) forControlEvents:UIControlEventTouchUpInside];
  1041. [btnn setImage:[[UIImage imageNamed:@"question_error.png"] tint:[UIColor grayColor]] forState:UIControlStateNormal];
  1042. [btnn setTitle:@"×" textColor:[UIColor whiteColor] font:30 fotState:UIControlStateNormal];
  1043. [contantV addSubview:btnn];
  1044. x = 20;
  1045. wid = kSize.width-x-wid-bd-120;
  1046. UITextField*tf = [[UITextField alloc]initWithFrame:CGRectMake(x, y, wid, hei)];
  1047. searchTf = tf;
  1048. tf.delegate = self;
  1049. tf.layer.masksToBounds = YES;
  1050. tf.layer.cornerRadius = 5;
  1051. tf.layer.borderWidth = 1;
  1052. tf.layer.borderColor = [UIColor lightGrayColor].CGColor;
  1053. tf.placeholder = @"请输入题号";
  1054. tf.textAlignment = NSTextAlignmentCenter;
  1055. tf.keyboardType = UIKeyboardTypeNumberPad;
  1056. tf.clearsOnBeginEditing = YES;
  1057. [contantV addSubview:tf];
  1058. x += wid;
  1059. wid = 80;
  1060. UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeSystem];
  1061. sureBtn = searchBtn;
  1062. searchBtn.frame = CGRectMake(x, y, wid, hei);
  1063. [searchBtn setTitle:@"确定" textColor:defGreen font:NormalFont fotState:UIControlStateNormal];
  1064. searchBtn.titleLabel.font = [UIFont systemFontOfSize:Font17];
  1065. [searchBtn addTarget:self action:@selector(searchQuestion) forControlEvents:UIControlEventTouchUpInside];
  1066. [contantV addSubview:searchBtn];
  1067. x = 20;
  1068. wid = 60;
  1069. UILabel* label;
  1070. label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, wid, hei)];
  1071. [label setText:@"text"];
  1072. [label setTextColor:defGreen];
  1073. [contantV addSubview:label];
  1074. rigLbl = label;
  1075. x += wid + bd;
  1076. label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, wid, hei)];
  1077. [label setText:@"text"];
  1078. [label setTextColor:[UIColor orangeColor]];
  1079. [contantV addSubview:label];
  1080. errorLbl = label;
  1081. /**表示按钮的最小间距 可以做一个按钮的重用机制 不然 一千多个 很耗性能
  1082. */
  1083. y += hei + bd + bd;
  1084. //用collection吧 自带缓存机制
  1085. CGFloat width = (kSize.width - 60)/5.0;
  1086. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  1087. [layout setItemSize:CGSizeMake(width, width)];
  1088. [layout setSectionInset:UIEdgeInsetsMake(0, 20, 20, 20)];
  1089. UICollectionView *btnCollection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, y, kSize.width, contantV.height - y) collectionViewLayout:layout];
  1090. btnCollection.backgroundColor = [UIColor whiteColor];
  1091. btnCollection.delegate = self;
  1092. btnCollection.dataSource = self;
  1093. [contantV addSubview:btnCollection];
  1094. [btnCollection registerClass:[BtnCollectionViewCell class] forCellWithReuseIdentifier:@"btn"];
  1095. }
  1096. -(void)goBackByNavigation{
  1097. @weakify(self)
  1098. if (myDelegate.type.intValue == QuestionTypeExam)
  1099. {
  1100. // UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"退出后将不保存本次记录,是否继续退出?" delegate:self cancelButtonTitle:@"退出" otherButtonTitles:@"取消", nil];
  1101. // alert.tag = AlertTypeIsQuit;
  1102. // [alert show];
  1103. [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"退出后将不保存本次记录,是否继续退出?" confirmTitle:@"退出" cancelTitle:@"取消" confirmAction:^{
  1104. @strongify(self)
  1105. if (myDelegate.isUseriPhone) {
  1106. [myDelegate.timer invalidate];
  1107. myDelegate.timer = nil;
  1108. if (self.seconds < 60) {
  1109. ShowMsg(@"学时未满一分钟不统计");
  1110. return;
  1111. }
  1112. [self saveTrain];
  1113. [self upLoadTrainRecord];
  1114. }
  1115. [self.view endEditing:1];
  1116. [self.navigationController popToRootViewControllerAnimated:YES];
  1117. } cancelAction:^{
  1118. }];
  1119. }else{
  1120. if (myDelegate.timer) {
  1121. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"退出当前页面将结束理论计时,是否继续退出?" preferredStyle:UIAlertControllerStyleAlert];
  1122. UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"退出" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1123. @strongify(self)
  1124. if (defUser.isycbd == 1) {
  1125. [RQ_TIMING_VIEW stopTimingWithResultBlock:^(BOOL isSuccessed) {
  1126. if (isSuccessed) {
  1127. [RQ_TIMING_VIEW endTiming];
  1128. }
  1129. }];
  1130. } else {
  1131. [RQ_TIMING_VIEW stopTiming];
  1132. }
  1133. // [myDelegate.timer invalidate];
  1134. // myDelegate.timer = nil;
  1135. //
  1136. //
  1137. // if (self.seconds < 60) {
  1138. // ShowMsg(@"学时未满一分钟不统计");
  1139. // return;
  1140. // }
  1141. // [self saveTrain];
  1142. // [self upLoadTrainRecord];
  1143. [self.view endEditing:1];
  1144. [self.navigationController popViewControllerAnimated:YES];
  1145. }];
  1146. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
  1147. [alert addAction:saveAction];
  1148. [alert addAction:cancelAction];
  1149. [self presentViewController:alert animated:YES completion:nil];
  1150. }else {
  1151. [self.view endEditing:1];
  1152. [self.navigationController popViewControllerAnimated:YES];
  1153. }
  1154. }
  1155. }
  1156. - (void)initTrainView {
  1157. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(kSize.width - 50, kSize.height - 350 - kSafeAreaBottomHeight, 60, 100)];
  1158. view.backgroundColor = [UIColor colorWithRed:35/255.0 green:160/255.0 blue:227/255.0 alpha:.44];
  1159. view.layer.masksToBounds = YES;
  1160. view.layer.cornerRadius = 10;
  1161. [self.view addSubview:view];
  1162. rightView = view;
  1163. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, 50, 30)];
  1164. label.backgroundColor = [UIColor clearColor];
  1165. [label setText:@"00:00" Font:NormalFont TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentCenter];
  1166. [rightView addSubview:label];
  1167. timeLabel1 = label;
  1168. label = [[UILabel alloc] initWithFrame:CGRectMake(0, 40, 50, 60)];
  1169. label.backgroundColor = [UIColor colorWithRed:35/255.0 green:160/255.0 blue:227/255.0 alpha:.5];
  1170. [label setText:@"点击\n计时" Font:NormalFont TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentCenter];
  1171. label.numberOfLines = 0;
  1172. [rightView addSubview:label];
  1173. trainStateLabel = label;
  1174. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60, 100)];
  1175. btn.backgroundColor = [UIColor clearColor];
  1176. [btn addTarget:self action:@selector(showOrHide:) forControlEvents:UIControlEventTouchUpInside];
  1177. [rightView addSubview:btn];
  1178. view = [[UIView alloc] initWithFrame:rightView.frame];
  1179. view.backgroundColor = [UIColor colorWithRed:35/255.0 green:160/255.0 blue:227/255.0 alpha:.44];
  1180. view.layer.masksToBounds = YES;
  1181. view.layer.cornerRadius = 10;
  1182. view.hidden = YES;
  1183. [self.view addSubview:view];
  1184. show_hideView = view;
  1185. label = [[UILabel alloc] initWithFrame:CGRectMake(0, 2, kSize.width - 90, 23)];
  1186. label.backgroundColor = [UIColor clearColor];
  1187. [label setText:@"00:00:00" Font:FontTitle TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentCenter];
  1188. [show_hideView addSubview:label];
  1189. timeLabel2 = label;
  1190. label = [[UILabel alloc] initWithFrame:CGRectMake(15, 25, kSize.width - 120, 40)];
  1191. label.backgroundColor = [UIColor clearColor];
  1192. [label setText:@"注:退出当前页面将结束计时,学时详情在“个人-我的学时”查看" Font:NormalFont TextColor:[UIColor whiteColor]];
  1193. label.numberOfLines = 0;
  1194. [show_hideView addSubview:label];
  1195. btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 65, kSize.width - 90, 35)];
  1196. btn.backgroundColor = [UIColor colorWithRed:35/255.0 green:160/255.0 blue:227/255.0 alpha:.6];
  1197. [btn setTitle:@"开始计时" textColor:[UIColor whiteColor] font:FontTitle fotState:UIControlStateNormal];
  1198. [btn setTitle:@"结束计时" forState:UIControlStateSelected];
  1199. [btn addTarget:self action:@selector(beginOrEndTrain) forControlEvents:UIControlEventTouchUpInside];
  1200. [show_hideView addSubview:btn];
  1201. begin_endBtn = btn;
  1202. }
  1203. - (void)showOrHide:(UIButton *)sender {
  1204. sender.selected = !sender.selected;
  1205. if (sender.selected) {
  1206. [UIView animateWithDuration:.4 animations:^{
  1207. show_hideView.hidden = NO;
  1208. show_hideView.frame = CGRectMake(20, kSize.height - 300 - kSafeAreaBottomHeight, kSize.width - 90, 100);
  1209. trainStateLabel.text = @"关闭\n弹窗";
  1210. }];
  1211. }else {
  1212. [UIView animateWithDuration:.4 animations:^{
  1213. show_hideView.frame = rightView.frame;
  1214. } completion:^(BOOL finished) {
  1215. show_hideView.hidden = YES;
  1216. if (myDelegate.isUseriPhone) {
  1217. trainStateLabel.text = @"计\n时\n中";
  1218. }else {
  1219. trainStateLabel.text = @"点击\n计时";
  1220. }
  1221. }];
  1222. }
  1223. }
  1224. - (void)beginOrEndTrain {
  1225. @weakify(self)
  1226. if (!myDelegate.isLogin) {
  1227. ShowMsg(@"请登录后再使用理论计时功能");
  1228. return;
  1229. }
  1230. NSInteger isNeed = 1;
  1231. for (NSDictionary * dic in defUser.userDict[@"params"]) {
  1232. if ([dic[@"KEY"] isEqualToString:@"SP_VERIFY_IMEI"]) {
  1233. isNeed = [dic[@"VALUE"] integerValue];
  1234. }
  1235. }
  1236. NSString *IMEI = defUser.userDict[@"imei"];
  1237. if (IMEI.length > 0) {
  1238. if (isNeed == 1) {
  1239. if ([Tools getIDFAWithType:GetIDFAType_Default]) {
  1240. @strongify(self)
  1241. if (![IMEI isEqualToString:[Tools getIDFAWithType:GetIDFAType_Default]]) {
  1242. ShowMsg(@"您当前手机与绑定手机不一致, 无法计时");
  1243. return;
  1244. } else {
  1245. if (!begin_endBtn.selected) {
  1246. //开始计时
  1247. if (defUser.isycbd == 1) {
  1248. [self startTimingWithResultBlock:^(BOOL isSuccess) {
  1249. }];
  1250. } else {
  1251. [self beginTime];
  1252. }
  1253. }else {//结束计时
  1254. if (defUser.isycbd == 1) {
  1255. [self stopTimingWithResultBlock:^(BOOL isSuccessed) {
  1256. }];
  1257. } else {
  1258. [self stopTiming];
  1259. }
  1260. begin_endBtn.selected = !begin_endBtn.selected;
  1261. }
  1262. }
  1263. }
  1264. } else {
  1265. [Tools saveNotBindImeiLogWithType:@"2" block:^(BOOL isSuccess) {
  1266. @strongify(self)
  1267. if (isSuccess) {
  1268. if (!begin_endBtn.selected) {
  1269. //开始计时
  1270. if (defUser.isycbd == 1) {
  1271. [self startTimingWithResultBlock:^(BOOL isSuccess) {
  1272. }];
  1273. } else {
  1274. [self beginTime];
  1275. }
  1276. }else {//结束计时
  1277. if (defUser.isycbd == 1) {
  1278. [self stopTimingWithResultBlock:^(BOOL isSuccessed) {
  1279. }];
  1280. } else {
  1281. [self stopTiming];
  1282. }
  1283. begin_endBtn.selected = !begin_endBtn.selected;
  1284. }
  1285. }
  1286. }];
  1287. }
  1288. } else {
  1289. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"您的账号暂未与该手机绑定,不能进行此操作,请通过“考试界面左上角点击头像-弹出左边侧栏-绑定账号”进行绑定" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil completion:nil];
  1290. }
  1291. }
  1292. -(void)stopTiming
  1293. {
  1294. [myDelegate.timer invalidate];
  1295. myDelegate.timer = nil;
  1296. myDelegate.isUseriPhone = NO;
  1297. myDelegate.isTrain = NO;
  1298. timeLabel2.text = @"00:00:00";
  1299. timeLabel1.text = @"00:00";
  1300. // if (seconds < 60) {
  1301. // ShowMsg(@"学时未满一分钟不统计");
  1302. // }
  1303. [self saveTrain];
  1304. [self upLoadTrainRecord];
  1305. }
  1306. - (void)beginTime {
  1307. @weakify(self)
  1308. if (![Util connectedToNetWork])
  1309. {
  1310. ShowMsg(@"请检查网络连接。");
  1311. return;
  1312. }
  1313. NSMutableArray *arr=[NSMutableArray array];
  1314. [arr property:defUser.userDict[@"outId"] forKey:@"outId"];
  1315. [arr property:defUser.userDict[@"city"] forKey:@"dqbh"];
  1316. NSString* method = @"isUsePhone";
  1317. [MBProgressHUD showLoadToView:self.view];
  1318. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  1319. @strongify(self)
  1320. [MBProgressHUD hideHUDForView:self.view];
  1321. if (!dict) {
  1322. ShowMsgFailed();
  1323. return;
  1324. }
  1325. if ([dict[@"code"] isEqualToString:@"90"]) {
  1326. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:dict[@"msg"] preferredStyle:UIAlertControllerStyleAlert];
  1327. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  1328. @strongify(self)
  1329. [LoginViewController loginFromVC:self];
  1330. }]];
  1331. [self presentViewController:alertFind animated:true completion:nil];
  1332. return;
  1333. }
  1334. if ([dict[@"code"] isEqualToString:@"0"]) {
  1335. myDelegate.begin_Time = dict[@"body"];
  1336. [Tools playAudioWithString:@"操作成功,开始计时"];
  1337. self.seconds = 0;
  1338. myDelegate.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES];
  1339. myDelegate.isUseriPhone = YES;
  1340. myDelegate.isTrain = YES;
  1341. begin_endBtn.selected = YES;
  1342. //防止前五分钟内退出软件 造成理论无本地学时 无法签退的问题
  1343. [self saveTrain];
  1344. } else {
  1345. NSString *msg = dict[@"msg"];
  1346. if (msg.length < 1) {
  1347. msg = dict[@"body"];
  1348. }
  1349. ShowMsg(msg);
  1350. [Tools playAudioWithString:msg];
  1351. }
  1352. }];
  1353. }
  1354. - (void)timeFireMethod {
  1355. @weakify(self)
  1356. self.seconds++;
  1357. [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]];
  1358. if (defUser.isycbd == 1) {
  1359. NSString *pxkm = defUser.userDict[@"pxjd"];
  1360. if (pxkm.length < 1) {
  1361. pxkm = @"1";
  1362. }
  1363. if (([pxkm isEqualToString:@"2"] || [pxkm isEqualToString:@"3"])) {
  1364. pxkm = @"4";
  1365. }
  1366. int remainder1 = (int)(self.seconds)%900;
  1367. if (remainder1 == 0) {
  1368. [self.timer setFireDate:[NSDate distantFuture]];
  1369. SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindow];
  1370. alert.backgroundViewColor = backGroundColor;
  1371. alert.customViewColor = RQ_MAIN_COLOR;
  1372. [alert addButton:@"立即开始 " actionBlock:^(void) {
  1373. dispatch_async(dispatch_get_main_queue(), ^{
  1374. @strongify(self)
  1375. /// 1.本地活体检测
  1376. [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:0 completeBlock:^(BOOL success, NSDictionary * _Nullable dic) {
  1377. @strongify(self)
  1378. if (success) {
  1379. /// 2.线上活体检测
  1380. [RQ_RemoteTheory_MANAGER edufaceTofaceWithPhotoStr:dic[@"normalImg"] loginFlagType:LoginFlagType_Process resultBlock:^(BOOL isSuccess, id dict) {
  1381. @strongify(self)
  1382. if (isSuccess) {
  1383. NSString *timeStr = [self getTimes:self.seconds];
  1384. /// 3.2上传过程照片
  1385. if (dict) {
  1386. NSDictionary *myDict = dict;
  1387. NSString *imageUrlStr = myDict[@"body"];
  1388. if (RQStringIsEmpty(imageUrlStr)) {
  1389. ShowMsg(@"路径为空");
  1390. }
  1391. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:imageUrlStr loginFlagType:LoginFlagType_Process resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  1392. @strongify(self)
  1393. if (isSuccess) {
  1394. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"过程验证成功" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  1395. @strongify(self)
  1396. [self.timer setFireDate:[NSDate distantPast]];
  1397. }];
  1398. } else {
  1399. self.seconds--;
  1400. [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]];
  1401. [self.timer setFireDate:[NSDate distantPast]];
  1402. }
  1403. }];
  1404. } else {
  1405. self.seconds--;
  1406. [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]];
  1407. [self.timer setFireDate:[NSDate distantPast]];
  1408. }
  1409. } else {
  1410. self.seconds--;
  1411. [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]];
  1412. [self.timer setFireDate:[NSDate distantPast]];
  1413. }
  1414. }];
  1415. } else {
  1416. self.seconds--;
  1417. [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]];
  1418. [self.timer setFireDate:[NSDate distantPast]];
  1419. }
  1420. }];
  1421. });
  1422. }];
  1423. [alert addTimerToButtonIndex:0 reverse:YES];
  1424. [alert showNotice:@"温馨提示" subTitle:@"即将开始活体检测,请做好准备" closeButtonTitle:nil duration:5.0f];
  1425. }
  1426. }
  1427. int hour = 0;
  1428. int min = 0;
  1429. int second = 0;
  1430. int remainder = (int)self.seconds%60;
  1431. if (remainder == 0)
  1432. {
  1433. //每1分钟保存一次
  1434. [self saveTrain];
  1435. }
  1436. hour = (int)self.seconds / 3600;
  1437. min = (int)self.seconds % 3600 / 60;
  1438. second = (int)self.seconds % 3600 % 60;
  1439. NSString *min_s;
  1440. NSString *second_s;
  1441. if (min<10) {
  1442. min_s=[NSString stringWithFormat:@"0%d",min];
  1443. }else{
  1444. min_s=[NSString stringWithFormat:@"%d",min];
  1445. }
  1446. if (second<10) {
  1447. second_s=[NSString stringWithFormat:@"0%d",second];
  1448. }else{
  1449. second_s=[NSString stringWithFormat:@"%d",second];
  1450. }
  1451. //更新UI上的时间
  1452. timeLabel2.text = [NSString stringWithFormat:@"0%d:%@:%@",hour,min_s,second_s];
  1453. timeLabel1.text = [NSString stringWithFormat:@"0%d:%@",hour,min_s];
  1454. }
  1455. - (void)saveTrain {
  1456. if (!formatter) {
  1457. formatter = [NSDateFormatter rq_defaultDateFormatter];
  1458. }
  1459. TrainRecord *train = [[TrainRecord alloc] init];
  1460. train.studentId = defUser.userStuId;
  1461. train.beginTime = myDelegate.begin_Time;
  1462. NSDate *date=[formatter dateFromString:myDelegate.begin_Time];
  1463. date=[date dateByAddingTimeInterval:self.seconds];
  1464. train.state = @"0";
  1465. train.endTime=[formatter stringFromDate:date];
  1466. NSInteger mins = self.seconds / 60;
  1467. train.trainTime=[NSString stringWithFormat:@"%d",(int)mins];
  1468. train.subject = myDelegate.subject;
  1469. train.classid = (self.classIdStr && ![self.classIdStr isEqualToString:@""])? self.classIdStr : @"0";
  1470. [DB_Helper saveTrain:train];
  1471. }
  1472. - (void)upLoadTrainRecord {
  1473. NSString *pxkm = defUser.userDict[@"pxjd"];
  1474. if (pxkm.length < 1) {
  1475. pxkm = @"1";
  1476. }
  1477. NSArray* array = [DB_Helper quearyTrain:defUser.userStuId Subject:myDelegate.subject];
  1478. if (array.count < 1) {
  1479. ShowMsg(@"本地无学时明细!");
  1480. return;
  1481. }
  1482. //这里是对分段上传学时做的处理 如果学时上传有问题 查看这里
  1483. [self uploadMoreTrainRecordWithArray:array];
  1484. }
  1485. - (void)uploadMoreTrainRecordWithArray:(NSArray *)trainArray {
  1486. @weakify(self)
  1487. if (![Util connectedToNetWork]) {
  1488. showMsgUnconnect();
  1489. return;
  1490. }
  1491. NSString* str = @"";
  1492. for (TrainRecord *record in trainArray) {
  1493. str = [str stringByAppendingString:[NSString stringWithFormat:@"%@,%@,%@,%@;",record.studentId,record.beginTime,record.endTime,record.trainTime]];
  1494. }
  1495. TrainRecord *record = [trainArray firstObject];
  1496. NSMutableArray *arr=[NSMutableArray array];
  1497. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"ios",@"trainType", nil]];
  1498. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:[DES3Util encrypt:str ],@"trainRecord", nil]];
  1499. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:record.subject,@"pxkm", nil]];
  1500. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:defUser.userDict[@"outId"],@"stuOutid", nil]];
  1501. NSString* method = @"uploadMoreTrainRecord";
  1502. [MBProgressHUD showLoadToView:self.view];
  1503. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  1504. [MBProgressHUD hideHUDForView:self.view];
  1505. @strongify(self)
  1506. if (!dict) {
  1507. ShowMsg(@"操作失败");
  1508. return;
  1509. }
  1510. if ([dict[@"code"] isEqualToString:@"90"]) {
  1511. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:dict[@"msg"] preferredStyle:UIAlertControllerStyleAlert];
  1512. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  1513. @strongify(self)
  1514. [LoginViewController loginFromVC:self];
  1515. }]];
  1516. [self presentViewController:alertFind animated:true completion:nil];
  1517. return;
  1518. }
  1519. if ( [dict[@"code"] isEqualToString:@"1"]) {
  1520. ShowMsg(dict[@"body"]);
  1521. return;
  1522. }
  1523. if ( [dict[@"code"] isEqualToString:@"0"]) {
  1524. for (TrainRecord *record in trainArray) {
  1525. [DB_Helper updateTrainState:record];
  1526. }
  1527. UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"上传学时成功!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
  1528. [alert show];
  1529. }
  1530. }];
  1531. }
  1532. #pragma mark collection delegate
  1533. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  1534. {
  1535. return questions.count;
  1536. }
  1537. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  1538. {
  1539. BtnCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"btn" forIndexPath:indexPath];
  1540. [cell.btn setTitle:[NSString stringWithFormat:@"%d",(int)indexPath.row + 1] textColor:contentTextColor font:22 fotState:UIControlStateNormal];
  1541. [cell.btn addTarget:self action:@selector(chooseBtn:) forControlEvents:UIControlEventTouchUpInside];
  1542. [cell.btn setTag:indexPath.row];
  1543. return cell;
  1544. }
  1545. -(void)chooseBtn:(UIButton*)sender
  1546. {
  1547. if (searchTf.isFirstResponder) {
  1548. [searchTf resignFirstResponder];
  1549. return;
  1550. }
  1551. [self chooseQuestionWithQIndex:sender.tag];
  1552. }
  1553. -(void)chooseQuestionWithQIndex:(NSInteger)questionIndex{
  1554. qIndex = questionIndex;
  1555. [self setQueIndex];
  1556. [self hideChooseView];
  1557. //记录选择的位置
  1558. //顺序模式
  1559. if (QuestionTypeOrdered == myDelegate.type.intValue) {
  1560. [self setIndexRecord];
  1561. }
  1562. //背题模式
  1563. if (QuestionTypeRecite == myDelegate.type.intValue) {
  1564. if ( 1==myDelegate.subject.intValue) {
  1565. defUser.user1Index = [NSString stringWithFormat:@"%d",(int)qIndex];
  1566. }else{
  1567. defUser.user4Index = [NSString stringWithFormat:@"%d",(int)qIndex];
  1568. }
  1569. }
  1570. }
  1571. -(void)setIndexRecord
  1572. {
  1573. if ([defUser.car_type isEqualToString:@"4"]) {
  1574. defUser.coachIndex = [NSString stringWithFormat:@"%d",(int)qIndex];
  1575. }
  1576. if ([defUser.car_type isEqualToString:@"1"]) {
  1577. defUser.A1Index = [NSString stringWithFormat:@"%d",(int)qIndex];
  1578. }
  1579. if ([defUser.car_type isEqualToString:@"2"]) {
  1580. defUser.A2Index = [NSString stringWithFormat:@"%d",(int)qIndex];
  1581. }
  1582. if ([defUser.car_type isEqualToString:@"3"]) {
  1583. defUser.dangerIndex = [NSString stringWithFormat:@"%d",(int)qIndex];
  1584. }
  1585. if ([defUser.car_type isEqualToString:@"5"]) {
  1586. defUser.texiIndex = [NSString stringWithFormat:@"%d",(int)qIndex];
  1587. }
  1588. if ([defUser.car_type isEqualToString:@"6"]) {
  1589. defUser.wycIndex = [NSString stringWithFormat:@"%d",(int)qIndex];
  1590. }
  1591. if ([defUser.car_type isEqualToString:@"C1"]) {
  1592. if ( 1==myDelegate.subject.intValue) {
  1593. defUser.userSubj1Index = [NSString stringWithFormat:@"%d",(int)qIndex];
  1594. }else{
  1595. defUser.userSubj4Index = [NSString stringWithFormat:@"%d",(int)qIndex];
  1596. }
  1597. }
  1598. if ([defUser.car_type isEqualToString:@"A2"]) {
  1599. if ( 1==myDelegate.subject.intValue) {
  1600. defUser.A2Subj1Index = [NSString stringWithFormat:@"%d",(int)qIndex];
  1601. }else{
  1602. defUser.A2Subj4Index = [NSString stringWithFormat:@"%d",(int)qIndex];
  1603. }
  1604. }
  1605. if ([defUser.car_type isEqualToString:@"A1"]) {
  1606. if ( 1==myDelegate.subject.intValue) {
  1607. defUser.A1Subj1Index = [NSString stringWithFormat:@"%d",(int)qIndex];
  1608. }else{
  1609. defUser.A1Subj4Index = [NSString stringWithFormat:@"%d",(int)qIndex];
  1610. }
  1611. }
  1612. if ([defUser.car_type isEqualToString:@"D"]) {
  1613. if ( 1==myDelegate.subject.intValue) {
  1614. defUser.DSubj1Index = [NSString stringWithFormat:@"%d",(int)qIndex];
  1615. }else{
  1616. defUser.DSubj4Index = [NSString stringWithFormat:@"%d",(int)qIndex];
  1617. }
  1618. }
  1619. }
  1620. -(void)hideChooseView
  1621. {
  1622. [chooseView removeFromSuperview];
  1623. }
  1624. -(void)showChooseView
  1625. {
  1626. if (myDelegate.type.intValue == QuestionTypeExam) {
  1627. if (chooseView)
  1628. {
  1629. int rig = 0,fau =0;
  1630. for (int i = 0; i< questions.count; i++)
  1631. {
  1632. if ( CorrectTypeFault == correct[i])
  1633. {
  1634. fau++;
  1635. [choBtns[i] setImage:[[UIImage imageNamed:@"question_error.png"] tint:[UIColor redColor]] withTitle:[NSString stringWithFormat:@"%d",i+1] Font:22 forState:UIControlStateNormal];
  1636. [choBtns[i] setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  1637. }
  1638. if ( CorrectTypeRignt == correct[i])
  1639. {
  1640. rig++;
  1641. [choBtns[i] setImage:[[UIImage imageNamed:@"question_error.png"] tint:defGreen] withTitle:[NSString stringWithFormat:@"%d",i+1] Font:22 forState:UIControlStateNormal];
  1642. [choBtns[i] setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  1643. }
  1644. }
  1645. //NSLog(@"对的-->%d错的-->%d",rig,fau);
  1646. [rigLbl setText:[NSString stringWithFormat:@"正确 %d",rig]];
  1647. [errorLbl setText:[NSString stringWithFormat:@"错误 %d",fau]];
  1648. searchTf.hidden = YES;
  1649. sureBtn.hidden = YES;
  1650. }
  1651. }else{
  1652. [rigLbl setHidden:YES];
  1653. [errorLbl setHidden:YES];
  1654. }
  1655. [[UIApplication sharedApplication].keyWindow addSubview:chooseView];
  1656. }
  1657. //-(void)addQue
  1658. //{
  1659. // Question *q=[questions objectAtIndex:qIndex];
  1660. // [DB_Que_Helper addToStrengthenQue:[q._id intValue]];
  1661. //}
  1662. //-(void)removeQue
  1663. //{
  1664. // Question *q=[questions objectAtIndex:qIndex];
  1665. // [DB_Que_Helper removeToStrengthenQue:[q._id intValue]];
  1666. //}
  1667. #pragma mark - 输入题号搜索
  1668. -(void)searchQuestion{
  1669. NSInteger qNum = [searchTf.text integerValue];
  1670. if (qNum && qNum !=0 && qNum <= questions.count) {
  1671. [self chooseQuestionWithQIndex:qNum-1];
  1672. }else{
  1673. ShowMsg(@"请输入正确题号");
  1674. }
  1675. }
  1676. -(void)preExAction{
  1677. if (questions.count < 1) {
  1678. return;
  1679. }
  1680. qIndex --;
  1681. if(qIndex<0){
  1682. qIndex = 0;
  1683. }
  1684. //顺序模式
  1685. if (QuestionTypeOrdered == myDelegate.type.intValue) {
  1686. [self setIndexRecord];
  1687. }
  1688. //背题模式
  1689. if (QuestionTypeRecite == myDelegate.type.intValue) {
  1690. if ( 1==myDelegate.subject.intValue) {
  1691. defUser.user1Index = [NSString stringWithFormat:@"%d",(int)qIndex];
  1692. }else{
  1693. defUser.user4Index = [NSString stringWithFormat:@"%d",(int)qIndex];
  1694. }
  1695. }
  1696. [self setQueIndex];
  1697. }
  1698. //错题
  1699. -(void)faultExAction:(BOOL)isRight
  1700. {
  1701. /**
  1702. 如果这次对 并且没有错的记录 可以不处理 若有错的记录 要将错改为对
  1703. 如果这次错 并且没有错的记录 要标记错题 若有错的记录 可不做处理
  1704. */
  1705. Question* q = questions[qIndex];
  1706. //这个地方直接从库里边查
  1707. BOOL isOK;
  1708. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  1709. RQ_SHARE_FUNCTION.myErorNum = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Wrong].count;
  1710. if (isRight) {
  1711. [self deleteState:@"2"];
  1712. }
  1713. } else {
  1714. if ([defUser.car_type isEqualToString:@"2"]) {
  1715. isOK = [DB_Que_Helper queryGZPZ_EXAM_CYRYIsHaveWithQuestion:[q._id integerValue] Type:@"1"];
  1716. if (isOK) {
  1717. q.state = @"1";
  1718. }else{
  1719. q.state = @"0";
  1720. }
  1721. if (isRight == 1){
  1722. //NSLog(@"删除错题");
  1723. if (q.state.integerValue == 1)
  1724. {
  1725. q.state = @"0";
  1726. [self deleteState:@"2"];
  1727. if ([DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"1" State:[q.state integerValue]]) {
  1728. RQ_SHARE_FUNCTION.myErorNum = [DB_Que_Helper queryGZPZ_EXAM_CYRYMarkQuestionWithMarkType:@"1"];
  1729. }
  1730. }
  1731. }else{
  1732. // NSLog(@"添加错题");
  1733. if (q.state.integerValue == 0)
  1734. {
  1735. q.state = @"1";
  1736. if ([DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"1" State:[q.state integerValue]]) {
  1737. RQ_SHARE_FUNCTION.myErorNum = [DB_Que_Helper queryGZPZ_EXAM_CYRYMarkQuestionWithMarkType:@"1"];
  1738. }
  1739. }
  1740. }
  1741. } else {
  1742. RQ_SHARE_FUNCTION.myErorNum = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Wrong].count;
  1743. if (isRight) {
  1744. [self deleteState:@"2"];
  1745. }
  1746. // isOK = [DB_Que_Helper queryIsHaveWithQuestion:[q._id integerValue] Type:@"1"];//错题1
  1747. }
  1748. }
  1749. }
  1750. //排除
  1751. -(void)moveExAction
  1752. {
  1753. if (questions.count<1) {
  1754. return;
  1755. }
  1756. // Question* q = questions[qIndex];
  1757. // if (q.move.intValue == 1) {
  1758. // q.move = @"0";
  1759. // [self deleteState:@"3"];
  1760. // if ([defUser.car_type isEqualToString:@"2"]) {
  1761. // [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"3" State:[q.state integerValue]];
  1762. // } else {
  1763. // [DB_Que_Helper setMarkQuestionWithQuestion:[q._id integerValue] Type:@"3" State:[q.state integerValue]];
  1764. // }
  1765. // }else{
  1766. // q.move = @"1";
  1767. // if ([defUser.car_type isEqualToString:@"2"]) {
  1768. // [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"3" State:[q.state integerValue]];
  1769. // } else {
  1770. // [DB_Que_Helper setMarkQuestionWithQuestion:[q._id integerValue] Type:@"3" State:[q.state integerValue]];
  1771. // }
  1772. // }
  1773. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  1774. RQYDTQuestionModel *ydtQuestionModel = questions[qIndex];
  1775. [RQ_YDT_USER_Question_Module removeQuestionWithID:ydtQuestionModel.ID carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject];
  1776. } else {
  1777. if ([defUser.car_type isEqualToString:@"2"]) {
  1778. Question* q = questions[qIndex];
  1779. if (q.move.intValue == 1) {
  1780. q.move = @"0";
  1781. [self deleteState:@"3"];
  1782. [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"3" State:[q.state integerValue]];
  1783. }else{
  1784. q.move = @"1";
  1785. [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"3" State:[q.state integerValue]];
  1786. }
  1787. } else {
  1788. RQYDTQuestionModel *ydtQuestionModel = questions[qIndex];
  1789. [RQ_YDT_USER_Question_Module removeQuestionWithID:ydtQuestionModel.ID carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject];
  1790. if (![RQ_YDT_USER_Question_Module getRemoveRecordWithQuestionId:ydtQuestionModel.ID]) {
  1791. [self deleteState:@"3"];
  1792. }
  1793. }
  1794. }
  1795. // NSLog(@"------%@",q.move);
  1796. [self setMoveTitle];
  1797. }
  1798. //收藏
  1799. -(void)favAction{
  1800. // NSLog(@"收藏或取消收藏");
  1801. if (questions.count<1) {
  1802. return;
  1803. }
  1804. // Question* q = questions[qIndex];
  1805. // if (q.favorite.intValue == 1) {
  1806. // q.favorite = @"0";
  1807. // [self deleteState:@"1"];
  1808. // if ([defUser.car_type isEqualToString:@"2"]) {
  1809. // [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"2" State:[q.state integerValue]];
  1810. // } else {
  1811. // [DB_Que_Helper setMarkQuestionWithQuestion:[q._id integerValue] Type:@"2" State:[q.state integerValue]];
  1812. // }
  1813. // }else{
  1814. // q.favorite = @"1";
  1815. // if ([defUser.car_type isEqualToString:@"2"]) {
  1816. // [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"2" State:[q.state integerValue]];
  1817. // } else {
  1818. // [DB_Que_Helper setMarkQuestionWithQuestion:[q._id integerValue] Type:@"2" State:[q.state integerValue]];
  1819. // }
  1820. // }
  1821. UIButton* favBtn = navBtns[1];
  1822. RQYDTQuestionModel *ydtQuestionModel = questions[qIndex];
  1823. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  1824. if (favBtn.selected) {
  1825. [RQ_YDT_USER_Question_Module deleteCollectRecordWithQuestionId:ydtQuestionModel.ID carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject];
  1826. } else {
  1827. [RQ_YDT_USER_Question_Module collectQuestionWithID:ydtQuestionModel.ID carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject];
  1828. }
  1829. } else {
  1830. if ([defUser.car_type isEqualToString:@"2"]) {
  1831. Question* q = questions[qIndex];
  1832. if (q.favorite.intValue == 1) {
  1833. q.favorite = @"0";
  1834. [self deleteState:@"1"];
  1835. [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"2" State:[q.state integerValue]];
  1836. }else{
  1837. q.favorite = @"1";
  1838. [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"2" State:[q.state integerValue]];
  1839. }
  1840. } else {
  1841. if (favBtn.selected) {
  1842. [RQ_YDT_USER_Question_Module deleteCollectRecordWithQuestionId:ydtQuestionModel.ID carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject];
  1843. [self deleteState:@"1"];
  1844. } else {
  1845. [RQ_YDT_USER_Question_Module collectQuestionWithID:ydtQuestionModel.ID carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject];
  1846. [self saveStateQuestion:@"1"];
  1847. }
  1848. }
  1849. }
  1850. [self setFavTitle];
  1851. }
  1852. //目前未发现调用 被弃用了吧 --markdanson
  1853. //-(void)errorExAction
  1854. //{
  1855. // if (questions.count<1) {
  1856. // return;
  1857. // }
  1858. // Question* q = questions[qIndex];
  1859. // if (q.state.intValue > 0) {
  1860. // q.state = @"0";
  1861. // [self removeQue];
  1862. // }else{
  1863. // q.state = @"1";
  1864. // [self addQue];
  1865. // }
  1866. // //[self setFaultTitle];
  1867. //}
  1868. /**
  1869. 或者换个套路。每次滑动完毕。快速切换页面的内容和scroll的offset。
  1870. 可以先切换中间的view的内容,然后修改offset,最后设置剩下2个的。
  1871. 这样的话。在判断边界条件时值,只需要设置contenSize即可。
  1872. 设置为一样的就可以了。给它弹提示框算了。
  1873. */
  1874. -(void)nextExAction
  1875. {
  1876. if (questions.count < 1) {
  1877. return;
  1878. }
  1879. qIndex++;
  1880. if(qIndex >= questions.count)
  1881. {
  1882. qIndex--;
  1883. return;
  1884. }
  1885. if (QuestionTypeOrdered == myDelegate.type.intValue) {
  1886. [self setIndexRecord];
  1887. }
  1888. //背题模式
  1889. if (QuestionTypeRecite == myDelegate.type.intValue) {
  1890. if ( 1==myDelegate.subject.intValue) {
  1891. defUser.user1Index = [NSString stringWithFormat:@"%d",(int)qIndex];
  1892. }else{
  1893. defUser.user4Index = [NSString stringWithFormat:@"%d",(int)qIndex];
  1894. }
  1895. }
  1896. [self setQueIndex];
  1897. }
  1898. -(void)showAnswAction
  1899. {
  1900. if (QuestionTypeRecite == myDelegate.type.intValue) {
  1901. return;
  1902. }
  1903. STButton* btn = navBtns[3];
  1904. btn.selected = !btn.selected;
  1905. showAnsw[qIndex] = btn.selected;
  1906. [self setShowAnsw];
  1907. }
  1908. - (void)pauseExamAction
  1909. {
  1910. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  1911. //关闭定时器
  1912. [self.timer setFireDate:[NSDate distantFuture]];
  1913. } else {
  1914. if ([defUser.car_type isEqualToString:@"2"] && myDelegate.isLogin) {
  1915. } else {
  1916. //关闭定时器
  1917. [self.timer setFireDate:[NSDate distantFuture]];
  1918. }
  1919. }
  1920. [NSObject rq_showAlertViewWithTitle:@"暂停考试" message:@"已暂停考试,点击下面继续考试" confirmTitle:@"继续考试" confirmAction:^{
  1921. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  1922. [self.timer setFireDate:[NSDate distantPast]];
  1923. } else {
  1924. if ([defUser.car_type isEqualToString:@"2"] && myDelegate.isLogin) {
  1925. } else {
  1926. [self.timer setFireDate:[NSDate distantPast]];
  1927. }
  1928. }
  1929. }];
  1930. // UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"暂停考试" message:@"已暂停考试,点击下面继续考试" delegate:self cancelButtonTitle:@"继续考试" otherButtonTitles: nil];
  1931. // [alert setTag:AlertTypePause];
  1932. // [alert show];
  1933. }
  1934. - (void)submitExam {
  1935. // NSLog(@"提交考试答卷");
  1936. @weakify(self)
  1937. int undoCnt = 0;
  1938. for (int i=0; i< questions.count; i++)
  1939. {
  1940. if (correct[i] == CorrectTypeUndo)
  1941. {
  1942. undoCnt ++ ;
  1943. }
  1944. }
  1945. NSString* msg = [NSString stringWithFormat:@"还有%d道题没做,确定交卷?",undoCnt];
  1946. QMUIAlertController *alert = [QMUIAlertController alertControllerWithTitle:@"提交试卷" message:msg preferredStyle:QMUIAlertControllerStyleAlert];
  1947. [alert addAction:[QMUIAlertAction actionWithTitle:@"确定" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController * _Nonnull aAlertController, QMUIAlertAction * _Nonnull action) {
  1948. @strongify(self)
  1949. [self isUploadGrade];
  1950. }]];
  1951. [alert addAction:[QMUIAlertAction actionWithTitle:@"查看未做的题" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController * _Nonnull aAlertController, QMUIAlertAction * _Nonnull action) {
  1952. @strongify(self)
  1953. qIndex = 1;
  1954. //遍历corecct,找到第一个未做的题目
  1955. for (int i = 0; i < questions.count; i++) {
  1956. if (CorrectTypeUndo == correct[i]) {
  1957. qIndex = i;
  1958. break;
  1959. }
  1960. }
  1961. [self setQueIndex];
  1962. }]];
  1963. [alert addAction:[QMUIAlertAction actionWithTitle:@"取消" style:QMUIAlertActionStyleCancel handler:nil]];
  1964. [alert showWithAnimated:YES];
  1965. }
  1966. #pragma mark setting功能
  1967. /**专门给【设置】按钮。添加的函数
  1968. */
  1969. -(void)settingBtn:(STButton *)sender
  1970. {
  1971. //点击设置后 就要将模式改为夜间模式
  1972. for (ExerView* v in exVs)
  1973. {
  1974. [v setNightMode:YES];
  1975. }
  1976. [self.view setBackgroundColor:nightColor];
  1977. [contantV setBackgroundColor:nightColor];
  1978. [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nightBg.png"] forBarMetrics:0];
  1979. //sender.tag为3为考试模式 为4是其他模式
  1980. NSMutableArray *setViewArray = [NSMutableArray array];
  1981. if (setViewArray.count > 0)
  1982. {
  1983. for (int i = 0; i < setViewArray.count; i ++)
  1984. {
  1985. ExerciseSetting *set = setViewArray[i];
  1986. [set removeFromSuperview];
  1987. }
  1988. }
  1989. if (sender.tag == 3)
  1990. {
  1991. setView = [[ExerciseSetting alloc] initWithExamFrame:CGRectMake(0, kSize.height-kNavOffSet-kSafeAreaBottomHeight-180, kSize.width, 180)];
  1992. isSkip = 1;
  1993. isExplain = 0;
  1994. }
  1995. else
  1996. {
  1997. setView = [[ExerciseSetting alloc] initWithCustomFrame:CGRectMake(0, kSize.height-kNavOffSet-kSafeAreaBottomHeight-280, kSize.width, 280)];
  1998. }
  1999. [setView.skipSwitch setOn:isSkip];
  2000. [setView.explainSwitch setOn:isExplain];
  2001. [setView.nightSwitch setOn:myDelegate.isNightMode];
  2002. [setView.voiceSwitch setOn:!myDelegate.isNotSoundMode];
  2003. [self.view addSubview:setView];
  2004. [setViewArray addObject:setView];
  2005. //添加setting用的方法
  2006. [setView.finishBtn addTarget:self action:@selector(setFinish) forControlEvents:UIControlEventTouchUpInside];
  2007. [setView.smallBtn addTarget:self action:@selector(setQuestionFont:) forControlEvents:UIControlEventTouchUpInside];
  2008. setView.smallBtn.tag = 100;
  2009. [setView.bigBtn addTarget:self action:@selector(setQuestionFont:) forControlEvents:UIControlEventTouchUpInside];
  2010. setView.bigBtn.tag = 101;
  2011. [setView.skipSwitch addTarget:self action:@selector(switchIsChanged:) forControlEvents:UIControlEventValueChanged];
  2012. setView.skipSwitch.tag = 11;
  2013. [setView.explainSwitch addTarget:self action:@selector(switchIsChanged:) forControlEvents:UIControlEventValueChanged];
  2014. setView.explainSwitch.tag = 12;
  2015. [setView.voiceSwitch addTarget:self action:@selector(switchIsChanged:) forControlEvents:UIControlEventValueChanged];
  2016. setView.voiceSwitch.tag = 13;
  2017. [setView.nightSwitch addTarget:self action:@selector(switchIsChanged:) forControlEvents:UIControlEventValueChanged];
  2018. setView.nightSwitch.tag = 14;
  2019. }
  2020. -(void)switchIsChanged:(UISwitch *)aSwitch
  2021. {
  2022. switch (aSwitch.tag) {
  2023. case 11:
  2024. isSkip = aSwitch.on;
  2025. break;
  2026. case 12:
  2027. isExplain = aSwitch.on;
  2028. break;
  2029. case 13:
  2030. //是否无声模式 是否开启声音取反 默认开启声音
  2031. myDelegate.isNotSoundMode = !aSwitch.on;
  2032. break;
  2033. case 14:
  2034. myDelegate.isNightMode = aSwitch.on;
  2035. break;
  2036. default:
  2037. break;
  2038. }
  2039. }
  2040. -(void)setFinish
  2041. {
  2042. //根据设置 按钮状态
  2043. [self checkIsNightMode];
  2044. [setView removeFromSuperview];
  2045. }
  2046. -(void)setQuestionFont:(UIButton *)btn
  2047. {
  2048. //100小 101大
  2049. if (btn.tag == 100) {
  2050. if (myDelegate.optionFont == 14) {
  2051. return;
  2052. }
  2053. myDelegate.optionFont -= 1;
  2054. }
  2055. if (btn.tag == 101) {
  2056. if (myDelegate.optionFont == 28) {
  2057. return;
  2058. }
  2059. myDelegate.optionFont += 1;
  2060. }
  2061. setView.fontLabel.text = [NSString stringWithFormat:@"%d",(int)myDelegate.optionFont];
  2062. [exVs removeAllObjects];
  2063. //重新构建题目
  2064. [self configExerV:YES];
  2065. //将原来在后面的还放到后面
  2066. [self.view sendSubviewToBack:contantV];
  2067. for (ExerView* v in exVs)
  2068. {
  2069. [v setNightMode:YES];
  2070. }
  2071. if (scroll) {
  2072. [self.view sendSubviewToBack:scroll];
  2073. }
  2074. //[self setFinish];
  2075. }
  2076. //可以调用这个方法实现 夜间模式 只需要改myDelegate.isNightMode的值 然后调用checkIsNightMode即可
  2077. -(void)checkIsNightMode
  2078. {
  2079. if(myDelegate.isNightMode)
  2080. {
  2081. for (ExerView* v in exVs)
  2082. {
  2083. [v setNightMode:YES];
  2084. }
  2085. [self.view setBackgroundColor:nightColor];
  2086. [contantV setBackgroundColor:nightColor];
  2087. [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nightBg.png"] forBarMetrics:0];
  2088. }else{
  2089. for (ExerView* v in exVs)
  2090. {
  2091. [v setNightMode:NO];
  2092. }
  2093. [self.view setBackgroundColor:backGroundColor];
  2094. [contantV setBackgroundColor:[UIColor whiteColor]];
  2095. [self setNavBarNormalColor];
  2096. }
  2097. }
  2098. -(void)setNavBarNormalColor
  2099. {
  2100. [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"normalBg.png"] forBarMetrics:0];
  2101. }
  2102. -(void)updateTime:(NSTimer*)tim
  2103. {
  2104. secCnt--;
  2105. [self setFirstBbiTitle];
  2106. if (secCnt < 1) {
  2107. @weakify(self);
  2108. [NSObject rq_showAlertViewWithTitle:@"提示" message:@"考试时间到了,现在交卷!" confirmTitle:@"确定" confirmAction:^{
  2109. @strongify(self)
  2110. [self isUploadGrade];
  2111. }];
  2112. // UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"考试时间到了,现在交卷!" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
  2113. // [alert setTag:AlertTypeTimeOut];
  2114. // [alert show];
  2115. [self.timer invalidate];
  2116. self.timer = nil;
  2117. }
  2118. }
  2119. - (void)isUploadGrade {
  2120. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  2121. [self endExamAndGotoResult];
  2122. } else {
  2123. dispatch_async(dispatch_get_main_queue(), ^{
  2124. @weakify(self)
  2125. if (myDelegate.isLogin) {
  2126. if ([defUser.car_type isEqualToString:@"2"]) {
  2127. NSInteger score = correctMark;
  2128. if (score >= 80) {
  2129. [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"考核通过,成绩即将上传!" confirmTitle:@"确定" confirmAction:^{
  2130. @strongify(self)
  2131. grade.isUpdate = @"1";
  2132. [self endExamAndGotoResult];
  2133. }];
  2134. } else {
  2135. [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"考核失败,是否重新开始考核!" confirmTitle:@"是" cancelTitle:@"否" confirmAction:^{
  2136. @strongify(self)
  2137. [self.navigationController popViewControllerAnimated:NO];
  2138. } cancelAction:^{
  2139. @strongify(self)
  2140. [self endExamAndGotoResult];
  2141. }];
  2142. }
  2143. } else {
  2144. grade.isUpdate = @"1";
  2145. [self endExamAndGotoResult];
  2146. // [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"是否允许上传本次成绩,成绩将在学霸排行榜中显示" confirmTitle:@"是" cancelTitle:@"否" confirmAction:^{
  2147. // @strongify(self)
  2148. // grade.isUpdate = @"1";
  2149. // [self endExamAndGotoResult];
  2150. // } cancelAction:^{
  2151. // @strongify(self)
  2152. // grade.isUpdate = @"0";
  2153. // [self endExamAndGotoResult];
  2154. // }];
  2155. }
  2156. } else {
  2157. //没登录 就不上传成绩
  2158. [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"您还未登录,成绩暂无法同步云平台" confirmTitle:@"确定" confirmAction:^{
  2159. @strongify(self)
  2160. [self endExamAndGotoResult];
  2161. }];
  2162. }
  2163. });
  2164. }
  2165. }
  2166. - (void)endExamAndGotoResult {
  2167. dispatch_async(dispatch_get_main_queue(), ^{
  2168. if (!grade) {
  2169. grade = [[Grade alloc] init];
  2170. }
  2171. if (!honors) {
  2172. honors = @[@"马路杀手",@"驾考标兵",@"驾考牛人",@"驾考神人",@"外星人",@"幸运儿"];
  2173. }
  2174. NSInteger score = correctMark;
  2175. NSInteger time = _testTime*60 - secCnt;
  2176. NSDateFormatter *dateFormatter = [NSDateFormatter rq_defaultDateFormatter];
  2177. // formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
  2178. [dateFormatter setDateFormat: @"MM-dd"];
  2179. grade.graDate = [dateFormatter stringFromDate:[NSDate date]];
  2180. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  2181. //如果有开始时间 那就根据时长来计算结束时间 如果没有开始时间 就根据当前时间计算出开始时间 这样就修复了 更改本地时间取得更好成绩的漏洞
  2182. grade.startDate = @"";
  2183. if (grade.startDate.length > 10) {
  2184. NSDate *beginDate = [dateFormatter dateFromString:grade.startDate];
  2185. NSDate *endDte = [NSDate dateWithTimeInterval:time sinceDate:beginDate];
  2186. grade.endDate = [dateFormatter stringFromDate:endDte];
  2187. }else{
  2188. grade.endDate = [dateFormatter stringFromDate:[NSDate date]];
  2189. NSDate *beginDate = [NSDate dateWithTimeIntervalSinceNow:-time];
  2190. grade.startDate = [dateFormatter stringFromDate:beginDate];
  2191. }
  2192. //NSLog(@"开始--><>%@---结束---><>%@---时长-><>%d",grade.startDate,grade.endDate,(int)time);
  2193. if (score < 60) {
  2194. grade.graHonor = honors[0];
  2195. }else if (score < 90){
  2196. grade.graHonor = honors[1];
  2197. }else if (score < 93){
  2198. grade.graHonor = honors[2];
  2199. }else if (score < 96){
  2200. grade.graHonor = honors[3];
  2201. }else if (score < 98){
  2202. grade.graHonor = honors[4];
  2203. }else{
  2204. grade.graHonor = honors[5];
  2205. }
  2206. //用min/sec获取占位符 确保时间格式为 00:00
  2207. NSString *min = @"";
  2208. NSString* sec = @"";
  2209. if (time/60<10) {
  2210. min= @"0";
  2211. }
  2212. if (time%60<10) {
  2213. sec= @"0";
  2214. }
  2215. if (score > 100) {
  2216. //如果成绩大于100 置为100
  2217. score = 100;
  2218. }
  2219. grade.graTime = [NSString stringWithFormat:@"%@%d:%@%d",min,(int)time/60,sec,(int)time%60];
  2220. grade.graScore = [NSString stringWithFormat:@"%d",(int)score];
  2221. //NSLog(@"存入---><>%@--->%@----.%@----->%@--->%@----->%@",grade.graDate,grade.graHonor,grade.graScore,grade.graTime,grade.startDate,grade.endDate);
  2222. [DB_Que_Helper insertGrade:grade];
  2223. ExamResultVC* vc = [[ExamResultVC alloc] init];
  2224. vc.grade = grade;
  2225. vc.questions = questions;
  2226. [self.navigationController qmui_pushViewController:vc animated:YES completion:nil];
  2227. });
  2228. }
  2229. /**设置第一个导航栏按钮的标题。如果是普通练习。就显示题号。
  2230. 否则显示时间。
  2231. */
  2232. - (void)setFirstBbiTitle {
  2233. STButton* btn = navBtns[0];
  2234. NSString* title ;
  2235. if (QuestionTypeExam == myDelegate.type.intValue){
  2236. int sec = secCnt%60;
  2237. int min = secCnt/60;
  2238. NSString* sec0,*min0;
  2239. sec0 = sec<10 ? @"0" : @"";
  2240. min0 = min<10 ? @"0" : @"";
  2241. 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]);
  2242. }else{
  2243. title = [NSString stringWithFormat:@"%d/%d",(int)qIndex+1,(int)questions.count];
  2244. }
  2245. [btn setTitle: title forState:UIControlStateNormal];
  2246. }
  2247. - (void)setQueIndex {
  2248. if (questions.count < 1) {
  2249. return;
  2250. }
  2251. [self setFirstBbiTitle];
  2252. [self setMoveTitle];
  2253. [self setFavTitle];
  2254. [self setShowAnsw];
  2255. [indexLbl setText:[NSString stringWithFormat:@"%d/%d",(int)qIndex+1,(int)questions.count]];
  2256. NSInteger leeIndex = qIndex;
  2257. if (questions.count>1) {
  2258. if (qIndex == 0) {
  2259. leeIndex += 1;
  2260. }else if(qIndex == questions.count-1){
  2261. leeIndex -= 1;
  2262. }
  2263. }
  2264. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  2265. [(ExerView*)exVs[1] setYdtQuestionModel:questions[leeIndex]];
  2266. } else {
  2267. if ([defUser.car_type isEqualToString:@"2"]) {
  2268. [(ExerView*)exVs[1] setQuestion:questions[leeIndex]];
  2269. } else {
  2270. [(ExerView*)exVs[1] setYdtQuestionModel:questions[leeIndex]];
  2271. }
  2272. }
  2273. if (QuestionTypeRecite == myDelegate.type.intValue)
  2274. {
  2275. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  2276. NSInteger myAnswer = [[(RQYDTQuestionModel*)questions[leeIndex] AnswerTrue] intValue];
  2277. [(ExerView*)exVs[1] setAnswer:myAnswer];
  2278. [(ExerView*)exVs[1] setShowAnswer:YES];
  2279. } else {
  2280. if ([defUser.car_type isEqualToString:@"2"]) {
  2281. [(ExerView*)exVs[1] setAnswer:[[(Question*)questions[leeIndex] answer] intValue]];
  2282. [(ExerView*)exVs[1] setShowAnswer:![defUser.car_type isEqualToString:@"2"]];
  2283. } else {
  2284. NSInteger myAnswer = [[(RQYDTQuestionModel*)questions[leeIndex] AnswerTrue] intValue];
  2285. [(ExerView*)exVs[1] setAnswer:myAnswer];
  2286. [(ExerView*)exVs[1] setShowAnswer:YES];
  2287. }
  2288. }
  2289. }
  2290. else
  2291. {
  2292. [(ExerView*)exVs[1] setAnswer:answers[leeIndex]];
  2293. [(ExerView*)exVs[1] setShowAnswer:showAnsw[leeIndex]];
  2294. }
  2295. /**设置偏移
  2296. */
  2297. //这里记录一个问题,第一次记录训练到4396题,如果我进来选择了否,不继续练习,所以跑到了第一题,但是我没有切换上下题,然后我退出界面再次进来(这里依旧保留旧的记录4396题,而不是点了否之后的第一题,如果你切换了其它题则会刷新记录)
  2298. if (qIndex==0) {
  2299. [scroll setContentOffset:CGPointMake(0, 0)];
  2300. lastOffset.x = 0;
  2301. }else if(qIndex==questions.count-1){
  2302. [scroll setContentOffset:CGPointMake(kSize.width*2, 0)];
  2303. lastOffset.x = kSize.width*2;
  2304. }else{
  2305. [scroll setContentOffset:CGPointMake(kSize.width, 0)];
  2306. lastOffset.x = kSize.width;
  2307. }
  2308. NSInteger qIndex0 = qIndex - 1;
  2309. if (qIndex0 < 0) {
  2310. qIndex0 = 0;
  2311. }
  2312. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  2313. [(ExerView*)exVs[0] setYdtQuestionModel:questions[qIndex0]];
  2314. } else {
  2315. if ([defUser.car_type isEqualToString:@"2"]) {
  2316. [(ExerView*)exVs[0] setQuestion:questions[qIndex0]];
  2317. } else {
  2318. [(ExerView*)exVs[0] setYdtQuestionModel:questions[qIndex0]];
  2319. }
  2320. }
  2321. if (QuestionTypeRecite == myDelegate.type.intValue) {
  2322. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  2323. [(ExerView*)exVs[0] setAnswer:[[(RQYDTQuestionModel*)questions[qIndex0] AnswerTrue] intValue]];
  2324. [(ExerView*)exVs[0] setShowAnswer:YES];
  2325. } else {
  2326. if ([defUser.car_type isEqualToString:@"2"]) {
  2327. [(ExerView*)exVs[0] setAnswer:[[(Question*)questions[qIndex0] answer] intValue]];
  2328. [(ExerView*)exVs[0] setShowAnswer:![defUser.car_type isEqualToString:@"2"]];
  2329. } else {
  2330. [(ExerView*)exVs[0] setAnswer:[[(RQYDTQuestionModel*)questions[qIndex0] AnswerTrue] intValue]];
  2331. [(ExerView*)exVs[0] setShowAnswer:YES];
  2332. }
  2333. }
  2334. }else{
  2335. [(ExerView*)exVs[0] setAnswer:answers[qIndex0]];
  2336. [(ExerView*)exVs[0] setShowAnswer:showAnsw[qIndex0]];
  2337. }
  2338. NSInteger qIndex2 = qIndex + 1;
  2339. if (qIndex2 >= questions.count) {
  2340. qIndex2 = (int)questions.count -1;
  2341. }
  2342. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  2343. [(ExerView*)exVs[2] setYdtQuestionModel:questions[qIndex2]];
  2344. } else {
  2345. if ([defUser.car_type isEqualToString:@"2"]) {
  2346. [(ExerView*)exVs[2] setQuestion:questions[qIndex2]];
  2347. } else {
  2348. [(ExerView*)exVs[2] setYdtQuestionModel:questions[qIndex2]];
  2349. }
  2350. }
  2351. if (QuestionTypeRecite == myDelegate.type.intValue) {
  2352. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  2353. [(ExerView*)exVs[2] setAnswer:[[(RQYDTQuestionModel*)questions[qIndex2] AnswerTrue] intValue]];
  2354. [(ExerView*)exVs[2] setShowAnswer:YES];
  2355. } else {
  2356. if ([defUser.car_type isEqualToString:@"2"]) {
  2357. [(ExerView*)exVs[2] setAnswer:[[(Question*)questions[qIndex2] answer] intValue]];
  2358. [(ExerView*)exVs[2] setShowAnswer:![defUser.car_type isEqualToString:@"2"]];
  2359. } else {
  2360. [(ExerView*)exVs[2] setAnswer:[[(RQYDTQuestionModel*)questions[qIndex2] AnswerTrue] intValue]];
  2361. [(ExerView*)exVs[2] setShowAnswer:YES];
  2362. }
  2363. }
  2364. } else {
  2365. [(ExerView*)exVs[2] setAnswer:answers[qIndex2]];
  2366. [(ExerView*)exVs[2] setShowAnswer:showAnsw[qIndex2]];
  2367. }
  2368. //这个操作是为了视频题的视频可以正常播放
  2369. if (0 == qIndex) {
  2370. [(ExerView*)exVs[0] playMovie];
  2371. } else if (questions.count-1 == qIndex){
  2372. [(ExerView*)exVs[2] playMovie];
  2373. } else {
  2374. [(ExerView*)exVs[1] playMovie];
  2375. }
  2376. [self.view bringSubviewToFront:rightView];
  2377. [self.view bringSubviewToFront:show_hideView];
  2378. }
  2379. - (void)setShowAnsw {
  2380. int vcInd = (int)(scroll.contentOffset.x / kSize.width);
  2381. //先这样处理了,崩溃日志暗示这里等于3越界了@lee
  2382. if (vcInd>=3) {
  2383. vcInd = 2;
  2384. }
  2385. ExerView* v = exVs[vcInd];
  2386. [v setShowAnswer:RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? showAnsw[qIndex] : ([defUser.car_type isEqualToString:@"2"]? NO : showAnsw[qIndex])];
  2387. //根据设置按钮的内容来定义这一题是否显示答案
  2388. if (QuestionTypeRecite != myDelegate.type.intValue) {
  2389. STButton* btn = navBtns[3];
  2390. [btn setSelected:showAnsw[qIndex]];
  2391. }
  2392. }
  2393. /**根据qIndex来设置是否收藏。
  2394. */
  2395. - (void)setFavTitle {
  2396. UIButton* btn = navBtns[1];
  2397. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  2398. RQYDTQuestionModel *ydtQuestionModel = questions[qIndex];
  2399. [btn setSelected:[RQ_YDT_USER_Question_Module getCollectRecordWithQuestionId:ydtQuestionModel.ID]];
  2400. } else {
  2401. if ([defUser.car_type isEqualToString:@"2"]) {
  2402. if (qIndex < questions.count) {
  2403. Question* q = questions[qIndex];
  2404. //这个地方直接从库里边查
  2405. BOOL isOK;
  2406. isOK = [DB_Que_Helper queryGZPZ_EXAM_CYRYIsHaveWithQuestion:[q._id integerValue] Type:@"2"];
  2407. if (isOK) {
  2408. q.favorite = @"1";
  2409. }else{
  2410. q.favorite = @"0";
  2411. }
  2412. [btn setSelected:q.favorite.intValue];
  2413. //NSLog(@"favorite---><>%d",(int)q.favorite.integerValue);
  2414. }
  2415. } else {
  2416. RQYDTQuestionModel *ydtQuestionModel = questions[qIndex];
  2417. [btn setSelected:[RQ_YDT_USER_Question_Module getCollectRecordWithQuestionId:ydtQuestionModel.ID]];
  2418. }
  2419. }
  2420. }
  2421. /**根据qIndex来设置是否排除。
  2422. */
  2423. - (void)setMoveTitle {
  2424. UIButton* btn = navBtns[2];
  2425. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  2426. RQYDTQuestionModel *ydtQuestionModel = questions[qIndex];
  2427. [btn setSelected:[RQ_YDT_USER_Question_Module getRemoveRecordWithQuestionId:ydtQuestionModel.ID]];
  2428. } else {
  2429. if ([defUser.car_type isEqualToString:@"2"]) {
  2430. Question* q = questions.count > qIndex? questions[qIndex] : nil;
  2431. if (q) {
  2432. //这个地方直接从库里边查
  2433. BOOL isOK;
  2434. isOK = [DB_Que_Helper queryGZPZ_EXAM_CYRYIsHaveWithQuestion:[q._id integerValue] Type:@"3"];
  2435. if (isOK) {
  2436. q.move = @"1";
  2437. }else{
  2438. q.move = @"0";
  2439. }
  2440. [btn setSelected:q.move.intValue];
  2441. //NSLog(@"move--><>%d",(int)q.move.integerValue);
  2442. }
  2443. } else {
  2444. RQYDTQuestionModel *ydtQuestionModel = questions[qIndex];
  2445. [btn setSelected:[RQ_YDT_USER_Question_Module getRemoveRecordWithQuestionId:ydtQuestionModel.ID]];
  2446. }
  2447. }
  2448. }
  2449. /**type1是收藏,2是错题,3是排除的题。 废弃 dansonmark
  2450. */
  2451. - (void)saveStateQuestion:(NSString*)type {
  2452. if (!myDelegate.isLogin) {
  2453. return;
  2454. }
  2455. if (![Util connectedToNetWork]) {
  2456. return;
  2457. }
  2458. if (defUser.sfzmhm.length == 0)
  2459. {
  2460. return;
  2461. }
  2462. NSString *subjectString = [myDelegate.subject intValue] == 4?@"4":@"1";
  2463. NSMutableArray *arr=[NSMutableArray array];
  2464. if ([defUser.car_type isEqualToString:@"2"]) {
  2465. Question* ques = questions[qIndex];
  2466. [arr addPro:@"qId" Value:ques._id];
  2467. } else {
  2468. RQYDTQuestionModel *ydtQuestionModel = questions[qIndex];
  2469. [arr addPro:@"qId" Value:[NSString stringWithFormat:@"%@",[NSNumber numberWithInteger:ydtQuestionModel.ID]]];
  2470. }
  2471. [arr addPro:@"userId" Value:defUser.userDict[@"id"]];
  2472. [arr addPro:@"type" Value:type];
  2473. [arr addPro:@"source" Value:@"2"];
  2474. [arr addPro:@"subject" Value:subjectString];
  2475. NSString* method = @"saveFavQuestion";
  2476. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  2477. //NSLog(@"加入收排错---->%@---->%@",arr,root);
  2478. if (!root || [root[@"code"] isEqualToString:@"1"])
  2479. {
  2480. [LoadingView showMsg:@"操作失败"];
  2481. }
  2482. }];
  2483. }
  2484. /**删除错题、收藏、排错
  2485. */
  2486. - (void)deleteState:(NSString*)type {
  2487. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  2488. } else {
  2489. if (!myDelegate.isLogin) {
  2490. return;
  2491. }
  2492. if (![Util connectedToNetWork]) {
  2493. return;
  2494. }
  2495. if ([defUser.userDict[@"id"] length] == 0){
  2496. return;
  2497. }
  2498. NSMutableArray *arr=[NSMutableArray array];
  2499. if ([defUser.car_type isEqualToString:@"2"]) {
  2500. Question* ques = questions[qIndex];
  2501. [arr addPro:@"id" Value:ques._id];
  2502. } else {
  2503. RQYDTQuestionModel *ydtQuestionModel = questions[qIndex];
  2504. [arr addPro:@"id" Value:[NSString stringWithFormat:@"%@",[NSNumber numberWithInteger:ydtQuestionModel.ID]]];
  2505. }
  2506. [arr addPro:@"user" Value:defUser.userDict[@"id"]];
  2507. [arr addPro:@"outId" Value:defUser.userStuId];
  2508. [arr addPro:@"type" Value:type];
  2509. NSString* method = @"deleteFav";
  2510. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  2511. if (!root || [root[@"code"] isEqualToString:@"1"]) {
  2512. ShowMsgFailed();
  2513. }
  2514. }];
  2515. }
  2516. }
  2517. #pragma mark - 代理方法
  2518. - (void)removeRandomAD {
  2519. [self removeAd:nil];
  2520. @weakify(adView)
  2521. [UIView qmui_animateWithAnimated:YES duration:1 animations:^{
  2522. @strongify(adView)
  2523. adView.hidden = YES;
  2524. }];
  2525. }
  2526. - (void)gotoAllCommentVC {
  2527. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  2528. } else {
  2529. AllCommentVC* vc = [[AllCommentVC alloc] init];
  2530. if ([defUser.car_type isEqualToString:@"2"]) {
  2531. vc.quest = questions[qIndex];
  2532. } else {
  2533. vc.ydtQuestionModel = questions[qIndex];
  2534. }
  2535. [self navPushHideTabbarToVC:vc];
  2536. }
  2537. }
  2538. #pragma mark - alertViewDelegate
  2539. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
  2540. @weakify(self)
  2541. if (AlertTypePause == alertView.tag) {
  2542. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  2543. [self.timer setFireDate:[NSDate distantPast]];
  2544. } else {
  2545. if ([defUser.car_type isEqualToString:@"2"] && myDelegate.isLogin) {
  2546. } else {
  2547. [self.timer setFireDate:[NSDate distantPast]];
  2548. }
  2549. }
  2550. return;
  2551. }
  2552. if (AlertTypeTimeOut == alertView.tag) {
  2553. [self isUploadGrade];
  2554. return;
  2555. }
  2556. if (AlertTypeSubmit == alertView.tag) {
  2557. switch (buttonIndex) {
  2558. case 0:
  2559. [self isUploadGrade];
  2560. break;
  2561. case 1:
  2562. break;
  2563. default:
  2564. qIndex = 1;
  2565. //遍历corecct,找到第一个未做的题目
  2566. for (int i = 0; i<questions.count; i++) {
  2567. if (CorrectTypeUndo == correct[i]) {
  2568. qIndex = i;
  2569. break;
  2570. }
  2571. }
  2572. [self setQueIndex];
  2573. break;
  2574. }
  2575. }
  2576. if (AlertTypeIsLoad == alertView.tag) {
  2577. if (buttonIndex == alertView.cancelButtonIndex){
  2578. grade.isUpdate = @"0";
  2579. }else{
  2580. grade.isUpdate = @"1";
  2581. }
  2582. [self endExamAndGotoResult];
  2583. }
  2584. if (AlertTypeIsQuit == alertView.tag) {
  2585. if (buttonIndex == 0) {
  2586. if (myDelegate.isUseriPhone) {
  2587. [myDelegate.timer invalidate];
  2588. myDelegate.timer = nil;
  2589. if (self.seconds < 60) {
  2590. ShowMsg(@"学时未满一分钟不统计");
  2591. return;
  2592. }
  2593. [self saveTrain];
  2594. [self upLoadTrainRecord];
  2595. }
  2596. [self.view endEditing:1];
  2597. [self.navigationController popViewControllerAnimated:YES];
  2598. }
  2599. }
  2600. if (alertView.tag == 100) {
  2601. if (buttonIndex == alertView.cancelButtonIndex){
  2602. //是
  2603. [indexLbl setText:[NSString stringWithFormat:@"%d/%d",(int)qIndex+1,(int)questions.count]];
  2604. } else {
  2605. //否
  2606. qIndex = 0;
  2607. [self configExerV:YES];
  2608. }
  2609. NSString *pxkm = defUser.userDict[@"pxjd"];
  2610. if (pxkm.length < 1) {
  2611. pxkm = @"1";
  2612. }
  2613. NSArray* array = [DB_Helper quearyTrain:defUser.userStuId Subject:pxkm];
  2614. if (array.count > 0 && defUser.isycbd != 1) {
  2615. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"您本地有未上传学时,请确认上传!" preferredStyle:UIAlertControllerStyleAlert];
  2616. UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  2617. @strongify(self)
  2618. [self upLoadTrainRecord];
  2619. }];
  2620. [alert addAction:saveAction];
  2621. [self presentViewController:alert animated:YES completion:nil];
  2622. }
  2623. }
  2624. }
  2625. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
  2626. if ([scrollView isMemberOfClass:[UICollectionView class]]) {
  2627. if (searchTf.isFirstResponder) {
  2628. [searchTf resignFirstResponder];
  2629. }
  2630. }
  2631. }
  2632. /**判断是否第一或最后一题
  2633. */
  2634. - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {
  2635. if ([scrollView isKindOfClass:[UICollectionView class]]) {
  2636. return;
  2637. }
  2638. CGPoint off = scrollView.contentOffset;
  2639. /**要加上后面的判断,否则容易误判。
  2640. */
  2641. if (off.x <= 0 && 0 == qIndex) {
  2642. [LoadingView showMsg:@"已经是第一道题了!"];
  2643. } else if(off.x >= 2*kSize.width && questions.count-1 == qIndex){
  2644. [LoadingView showMsg:@"已经是最后一道题了!"];
  2645. }
  2646. }
  2647. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
  2648. // NSLog(@"TTTT--: %f",scrollView.contentOffset.x)
  2649. //这里因为设置了按页滚动为yes,以及preExAction/preExAction ==》setQueIndex 里面对scrool。contentoffset。x和lastoffset的改动;
  2650. //lastoffset和scroll.contentoffset.x 会有 0,kize.width,kize.width*2 三种值
  2651. if (lastOffset.x > scroll.contentOffset.x) {
  2652. [self preExAction];
  2653. }else if (lastOffset.x < scroll.contentOffset.x) {
  2654. [self nextExAction];
  2655. }
  2656. }
  2657. #pragma mark - searchTf delegate
  2658. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  2659. NSString *newStr = [textField.text stringByReplacingCharactersInRange:range withString:string];
  2660. if (newStr.length >4) {//限制输入至多4位
  2661. return NO;
  2662. }
  2663. return YES;
  2664. }
  2665. #pragma mark - LazyLoad
  2666. - (CGFloat)adWidth {
  2667. return RQ_SCREEN_WIDTH;
  2668. }
  2669. - (CGFloat)adHeight {
  2670. return self.adWidth * (100.f / 640.f);
  2671. }
  2672. - (UIView *)bannerView {
  2673. if (!_bannerView) {
  2674. CGRect rect = {CGPointZero, CGSizeMake(self.adWidth, self.adHeight)};
  2675. _bannerView = [[UIView alloc]
  2676. initWithFrame:rect];
  2677. }
  2678. return _bannerView;
  2679. }
  2680. #pragma mark - TimeModule
  2681. - (void)startTimingWithResultBlock:(void (^)(BOOL isSuccess))resultBlock {
  2682. @weakify(self)
  2683. if (defUser.isycbd == 1) {
  2684. [RQ_RemoteTheory_MANAGER getTheoryStatusWithResultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull statusDict) {
  2685. @strongify(self)
  2686. if (isSuccess) {
  2687. NSString *statusStr = statusDict[@"body"];
  2688. if (!statusStr && [statusStr isEqualToString:@""]) {
  2689. ShowMsg(@"获取学员状态异常!");
  2690. !resultBlock? : resultBlock(NO);
  2691. return;
  2692. }
  2693. BOOL statusIsSignIn = [statusStr isEqualToString:@"1"];
  2694. NSString *pxkm = defUser.userDict[@"pxjd"];
  2695. if (pxkm.length < 1) {
  2696. pxkm = @"1";
  2697. }
  2698. if (([pxkm isEqualToString:@"2"] || [pxkm isEqualToString:@"3"])) {
  2699. pxkm = @"4";
  2700. }
  2701. NSArray* array = [DB_Helper quearyTrain:RQStringIsNotEmpty(defUser.userStuId)? defUser.userStuId : @"" Subject:pxkm];
  2702. __block NSInteger trainTime = 0;
  2703. [array.rac_sequence.signal subscribeNext:^(TrainRecord *record) {
  2704. trainTime = trainTime + record.trainTime.integerValue;
  2705. } completed:^{
  2706. dispatch_async(dispatch_get_main_queue(), ^{
  2707. @strongify(self)
  2708. if (trainTime >= 30) {
  2709. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:statusIsSignIn? @"检测到上次未正常签退,请签退后再开始理论计时" : @"检测到学员已签退!本地存在异常学时,是否删除异常学时?" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"取消" otherButtonTitles:@[statusIsSignIn? @"签退" : @"删除"] otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  2710. @strongify(self)
  2711. !resultBlock? : resultBlock(NO);
  2712. if (selectedOtherButtonIndex == 0) {
  2713. if (statusIsSignIn) {
  2714. TrainRecord *lastRecord = [array lastObject];
  2715. /// 1.本地活体检测
  2716. [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:0 completeBlock:^(BOOL success, NSDictionary * _Nullable dic) {
  2717. @strongify(self)
  2718. if (success) {
  2719. /// 2.线上活体检测
  2720. [RQ_RemoteTheory_MANAGER edufaceTofaceWithPhotoStr:dic[@"normalImg"] loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess, id dict) {
  2721. @strongify(self)
  2722. if (isSuccess) {
  2723. if (dict) {
  2724. NSDictionary *myDict = dict;
  2725. NSString *imageUrlStr = myDict[@"body"];
  2726. if (RQStringIsEmpty(imageUrlStr)) {
  2727. ShowMsg(@"路径为空");
  2728. }
  2729. /// 3.签退
  2730. [RQ_RemoteTheory_MANAGER uploadEduSignOutWithArray:array resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signOutDict) {
  2731. @strongify(self)
  2732. if (success) {
  2733. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:nil];
  2734. /// 4.2上传签退照片
  2735. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:lastRecord.classid timeStr:lastRecord.endTime actionPhotoStr:imageUrlStr loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  2736. @strongify(self)
  2737. if (isSuccess) {
  2738. NSLog(@"上传签退照片成功!");
  2739. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:YES completion:nil];
  2740. } else {
  2741. NSLog(@"上传签退照片失败!");
  2742. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:^{
  2743. @strongify(self)
  2744. [self reUploadPhotoWithClassidStr:self.classIdStr timeStr:lastRecord.endTime actionPhotoStr:imageUrlStr loginFlagType:LoginFlagType_SignOut];
  2745. }];
  2746. }
  2747. }];
  2748. }
  2749. !resultBlock? : resultBlock(NO);
  2750. }];
  2751. } else {
  2752. !resultBlock? : resultBlock(NO);
  2753. [self.timer setFireDate:[NSDate distantPast]];
  2754. }
  2755. } else {
  2756. !resultBlock? : resultBlock(NO);
  2757. }
  2758. }];
  2759. } else {
  2760. !resultBlock? : resultBlock(NO);
  2761. }
  2762. }];
  2763. } else {
  2764. for (TrainRecord *record in array) {
  2765. [DB_Helper deleteTrainRecord:record];
  2766. }
  2767. }
  2768. }
  2769. }];
  2770. } else {
  2771. if (statusIsSignIn) {
  2772. [RQ_RemoteTheory_MANAGER uploadEduSignOutWithArray:@[] resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signOutDict) {
  2773. @strongify(self)
  2774. if (isSuccess) {
  2775. [self signOutSuccessWithTrainArray:@[] signOutSuccess:YES uploadImageSuccess:NO completion:nil];
  2776. }
  2777. !resultBlock? : resultBlock(isSuccess);
  2778. }];
  2779. } else {
  2780. /// 1.本地活体检测
  2781. [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:0 completeBlock:^(BOOL success, NSDictionary * _Nullable dic) {
  2782. @strongify(self)
  2783. if (success) {
  2784. /// 2.线上活体检测
  2785. [RQ_RemoteTheory_MANAGER edufaceTofaceWithPhotoStr:dic[@"normalImg"] loginFlagType:LoginFlagType_SignIn resultBlock:^(BOOL isSuccess, id dict) {
  2786. @strongify(self)
  2787. if (isSuccess) {
  2788. if (dict) {
  2789. NSDictionary *myDict = dict;
  2790. NSString *imageUrlStr = myDict[@"body"];
  2791. if (RQStringIsEmpty(imageUrlStr)) {
  2792. ShowMsg(@"路径为空");
  2793. }
  2794. /// 3.获取线上时间
  2795. [RQ_RemoteTheory_MANAGER getCurrentTimeWithResultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull timeDict) {
  2796. @strongify(self)
  2797. if (isSuccess) {
  2798. // NSString *timeStr = @"2022-03-13 22:46:59";
  2799. NSDate *date = [NSDate rq_dateWithTimestamp:timeDict[@"body"]];
  2800. // NSDate *date = [NSDate rq_dateWithTimestamp:timeStr];
  2801. NSInteger timeStamp = [[NSNumber numberWithDouble:[date timeIntervalSince1970]] integerValue];
  2802. NSString *timeStampStr = [NSString stringWithFormat:@"%@",[NSNumber numberWithInteger:timeStamp]];
  2803. self.classIdStr = timeStampStr;
  2804. if (self.classIdStr.length < 10) {
  2805. /// 如果生成时间戳错误 用一个随机十位数代替
  2806. self.classIdStr = [NSString stringWithFormat:@"%@",[NSNumber numberWithInteger:[NSString rq_randomNumberWithFrom:1647311377 to:9999999999]]];
  2807. }
  2808. /// 4.签到
  2809. [RQ_RemoteTheory_MANAGER uploadEduSignInWithClassidStr:self.classIdStr resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signInDict) {
  2810. if (isSuccess) {
  2811. @strongify(self)
  2812. NSString *timeStr = signInDict[@"body"];
  2813. [self signInSuccessWithBeginTime:timeStr];
  2814. /// 5.上传照片
  2815. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:imageUrlStr loginFlagType:LoginFlagType_SignIn resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  2816. // @strongify(self)
  2817. }];
  2818. }
  2819. !resultBlock? : resultBlock(isSuccess);
  2820. }];
  2821. } else {
  2822. !resultBlock? : resultBlock(NO);
  2823. }
  2824. }];
  2825. } else {
  2826. !resultBlock? : resultBlock(NO);
  2827. [self.timer setFireDate:[NSDate distantPast]];
  2828. }
  2829. } else {
  2830. !resultBlock? : resultBlock(NO);
  2831. }
  2832. }];
  2833. } else {
  2834. !resultBlock? : resultBlock(NO);
  2835. }
  2836. }];
  2837. }
  2838. }
  2839. });
  2840. }];
  2841. } else {
  2842. !resultBlock? : resultBlock(NO);
  2843. }
  2844. }];
  2845. } else {
  2846. !resultBlock? : resultBlock(YES);
  2847. [self beginTime];
  2848. }
  2849. }
  2850. - (void)stopTimingWithResultBlock:(void (^)(BOOL isSuccessed))resultBlock {
  2851. @weakify(self)
  2852. [self.timer setFireDate:[NSDate distantFuture]];
  2853. [self saveTrain];
  2854. if (defUser.isycbd == 1) {
  2855. /// 1.本地活体检测
  2856. [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:0 completeBlock:^(BOOL success, NSDictionary * _Nullable dic) {
  2857. @strongify(self)
  2858. if (success) {
  2859. /// 2.线上活体检测
  2860. [RQ_RemoteTheory_MANAGER edufaceTofaceWithPhotoStr:dic[@"normalImg"] loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess, id dict) {
  2861. @strongify(self)
  2862. if (isSuccess) {
  2863. if (dict) {
  2864. NSDictionary *myDict = dict;
  2865. NSString *imageUrlStr = myDict[@"body"];
  2866. if (RQStringIsEmpty(imageUrlStr)) {
  2867. ShowMsg(@"路径为空");
  2868. }
  2869. /// 3.签退
  2870. NSString *pxkm = defUser.userDict[@"pxjd"];
  2871. if (pxkm.length < 1) {
  2872. pxkm = @"1";
  2873. }
  2874. if (([pxkm isEqualToString:@"2"] || [pxkm isEqualToString:@"3"])) {
  2875. pxkm = @"4";
  2876. }
  2877. NSArray* array = [DB_Helper quearyTrain:RQStringIsNotEmpty(defUser.userStuId)? defUser.userStuId : @"" Subject:pxkm];
  2878. if (array.count < 1) {
  2879. !resultBlock? : resultBlock(YES);
  2880. ShowMsg(@"本地无学时明细!");
  2881. return;
  2882. }
  2883. [RQ_RemoteTheory_MANAGER uploadEduSignOutWithArray:array resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signOutDict) {
  2884. @strongify(self)
  2885. if (isSuccess) {
  2886. !resultBlock? : resultBlock(YES);
  2887. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:nil];
  2888. /// 4.2上传签退照片
  2889. NSString *timeStr = [self getTimes:self.seconds];
  2890. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:imageUrlStr loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  2891. @strongify(self)
  2892. if (isSuccess) {
  2893. NSLog(@"上传签退照片成功!");
  2894. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:YES completion:nil];
  2895. } else {
  2896. NSLog(@"上传签退照片失败!");
  2897. [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:^{
  2898. [self reUploadPhotoWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:imageUrlStr loginFlagType:LoginFlagType_SignOut];
  2899. }];
  2900. }
  2901. }];
  2902. } else {
  2903. !resultBlock? : resultBlock(NO);
  2904. [self.timer setFireDate:[NSDate distantPast]];
  2905. }
  2906. }];
  2907. } else {
  2908. !resultBlock? : resultBlock(NO);
  2909. [self.timer setFireDate:[NSDate distantPast]];
  2910. }
  2911. } else {
  2912. !resultBlock? : resultBlock(NO);
  2913. [self.timer setFireDate:[NSDate distantPast]];
  2914. }
  2915. }];
  2916. } else {
  2917. !resultBlock? : resultBlock(NO);
  2918. [self.timer setFireDate:[NSDate distantPast]];
  2919. }
  2920. }];
  2921. } else {
  2922. !resultBlock? : resultBlock(YES);
  2923. [self setSecondString:@"0"];
  2924. [self.timer setFireDate:[NSDate distantFuture]];
  2925. [self.timer invalidate];
  2926. self.timer = nil;
  2927. myDelegate.timer = nil;
  2928. // myDelegate.tPeriodVC = nil;
  2929. myDelegate.isTrain = NO;
  2930. timeLabel1.text = @"00:00";
  2931. timeLabel2.text = @"00:00:00";
  2932. // if (self.seconds < 60) {
  2933. // ShowMsg(@"学时未满一分钟不统计");
  2934. // return;
  2935. // }
  2936. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"结束计时,是否上传学时?" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"暂不上传" otherButtonTitles:@[@"确定"] otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  2937. @strongify(self)
  2938. if (selectedOtherButtonIndex == 0) {
  2939. [self upLoadTrainRecord];
  2940. }else if (selectedOtherButtonIndex == NSNotFound){
  2941. ShowMsg(@"学时已保存在本地");
  2942. }
  2943. }];
  2944. }
  2945. }
  2946. //远程理论签到成功
  2947. - (void)signInSuccessWithBeginTime:(NSString *)beginTime {
  2948. myDelegate.begin_Time = beginTime;
  2949. [Tools playAudioWithString:@"操作成功,开始计时"];
  2950. self.seconds = 0;
  2951. // [self.on_offBtn setTitle:@"结束计时" forState:UIControlStateNormal];
  2952. myDelegate.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES];
  2953. myDelegate.isUseriPhone = YES;
  2954. myDelegate.isTrain = YES;
  2955. self.timer = myDelegate.timer;
  2956. begin_endBtn.selected = YES;
  2957. //防止前五分钟内退出软件 造成理论无本地学时 无法签退的问题
  2958. [self saveTrain];
  2959. // myDelegate.tPeriodVC = self;
  2960. ShowMsgSuc();
  2961. [RQ_COMMON_MANAGER keepIdleTimerDisabledisOpen:YES];
  2962. }
  2963. //远程理论签退成功
  2964. - (void)signOutSuccessWithTrainArray:(NSArray *)trainArray signOutSuccess:(BOOL)signOutSuccess uploadImageSuccess:(BOOL)uploadImageSuccess completion:(void (^)(void))completion {
  2965. for (TrainRecord *record in trainArray) {
  2966. [DB_Helper updateTrainState:record];
  2967. }
  2968. if (trainArray.count > 0) {
  2969. if (signOutSuccess) {
  2970. if (![_secondString isEqualToString:@"0"]) {
  2971. [self setSecondString:@"0"];
  2972. }
  2973. if (self.timer.isValid) {
  2974. [self.timer invalidate];
  2975. }
  2976. if (self.timer) {
  2977. self.timer = nil;
  2978. }
  2979. if (myDelegate.timer) {
  2980. myDelegate.timer = nil;
  2981. }
  2982. // if (myDelegate.tPeriodVC) {
  2983. // myDelegate.tPeriodVC = nil;
  2984. // }
  2985. if (myDelegate.isTrain) {
  2986. myDelegate.isTrain = NO;
  2987. }
  2988. if (![timeLabel1.text isEqualToString:@"00:00"]) {
  2989. timeLabel1.text = @"00:00";
  2990. }
  2991. if (![timeLabel2.text isEqualToString:@"00:00:00"]) {
  2992. timeLabel2.text = @"00:00:00";
  2993. }
  2994. }
  2995. if (signOutSuccess && uploadImageSuccess) {
  2996. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"签退成功!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:nil];
  2997. } else if (signOutSuccess && !uploadImageSuccess && completion) {
  2998. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"上传照片失败!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"重新上传" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  2999. completion();
  3000. }];
  3001. }
  3002. } else {
  3003. // 强制签退后再去调签到
  3004. [self startTimingWithResultBlock:nil];
  3005. }
  3006. [RQ_COMMON_MANAGER keepIdleTimerDisabledisOpen:NO];
  3007. }
  3008. - (void)reUploadPhotoWithClassidStr:(NSString *)classidStr timeStr:(NSString *)timeStr actionPhotoStr:(NSString *)actionPhotoStr loginFlagType:(LoginFlagType)loginFlagType {
  3009. __block BOOL reUploadSuccess = YES;
  3010. __block BOOL isUploading = NO;
  3011. int i = 0;
  3012. do {
  3013. if (i == 0) {
  3014. if (!isUploading) {
  3015. isUploading = YES;
  3016. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:classidStr timeStr:timeStr actionPhotoStr:actionPhotoStr loginFlagType:loginFlagType resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  3017. if (isSuccess) {
  3018. ShowMsg(@"重新上传照片成功!");
  3019. reUploadSuccess = YES;
  3020. } else {
  3021. reUploadSuccess = NO;
  3022. }
  3023. isUploading = NO;
  3024. }];
  3025. }
  3026. } else {
  3027. if (!isUploading) {
  3028. isUploading = YES;
  3029. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"上传照片失败!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"重新上传" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
  3030. [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:classidStr timeStr:timeStr actionPhotoStr:actionPhotoStr loginFlagType:loginFlagType resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
  3031. if (isSuccess) {
  3032. ShowMsg(@"重新上传照片成功!");
  3033. reUploadSuccess = YES;
  3034. } else {
  3035. reUploadSuccess = NO;
  3036. }
  3037. isUploading = NO;
  3038. }];
  3039. }];
  3040. }
  3041. }
  3042. i ++;
  3043. } while (reUploadSuccess == NO);
  3044. }
  3045. - (NSString *)getTimes:(int)second {
  3046. NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
  3047. [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  3048. NSString *beginTimeStr = myDelegate.begin_Time;
  3049. [formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
  3050. NSDate *beginDate = [formatter dateFromString:beginTimeStr];
  3051. NSDate *newDate = [NSDate dateWithTimeInterval:second sinceDate:beginDate];
  3052. NSString *nowString = [formatter stringFromDate:newDate];
  3053. return nowString;
  3054. }
  3055. @end