HomeBaseVC.m 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075
  1. /**设置循环滚动
  2. */
  3. #import "HomeBaseVC.h"
  4. #import "HmV0.h"
  5. #import "HmV1.h"
  6. #import "HmV2.h"
  7. #import "HmV3.h"
  8. #import "HmV4.h"
  9. #import "HmV5.h"
  10. #import "ScanVC.h"
  11. #import "Tools.h"
  12. #import "ThirdLoginBindYunGuanVC.h"
  13. #import "DistenceTooLongMapVC.h"
  14. #import "DES3Util.h"
  15. #import "TheoryTrainVC.h"
  16. #import <BMKLocationkit/BMKLocationComponent.h>//引入定位功能所有的头文件(新)
  17. #import "OliveappLivenessDetectionViewController.h"
  18. #import "OliveappCameraPreviewController.h"
  19. #import "OliveappDetectedFrame.h"
  20. #import "OliveappBase64Helper.h"
  21. @interface HomeBaseVC ()<UIScrollViewDelegate,BMKLocationManagerDelegate,OliveappLivenessResultDelegate,FaceDetectorsDelegate>
  22. {
  23. /** 分段选择器下方的滚动条。*/
  24. UIView *btnBar;
  25. /** 保存scroll主页面。最后一次滚动的offset */
  26. CGPoint lastOffset;
  27. /** 左上角的头像 */
  28. UIImageView *headIv;
  29. NSString *headerImgPath;
  30. /** 这个值决定是否隐藏segment */
  31. CGFloat _segmenHeight;
  32. /** 下面几个全局是为了隐藏选择科目条 */
  33. UIView *barBg;
  34. //同步错题
  35. UILabel *bgLabel;
  36. //集中式理论
  37. BOOL isNeedTest;
  38. BOOL isCloseAudio;
  39. NSInteger maxTime;
  40. NSString *scanType;
  41. NSString *scanData;
  42. CLLocationCoordinate2D myLocation;
  43. }
  44. @property(nonatomic,strong)UIScrollView* scroll;
  45. /**分段选择器的按钮
  46. */
  47. @property(nonatomic,strong)NSMutableArray* btns;
  48. /**用于使scroll和按钮联动
  49. */
  50. @property(nonatomic,assign)NSInteger pageIndex;
  51. @property (strong, readwrite, nonatomic) NSString *faceIdStr;
  52. @end
  53. @implementation HomeBaseVC
  54. - (void)dealloc{
  55. //移除指定的通知,不然会造成内存泄露
  56. [[NSNotificationCenter defaultCenter] removeObserver:self name:@"Tiku_Change" object:nil];
  57. }
  58. - (void)viewDidLoad
  59. {
  60. [super viewDidLoad];
  61. [self myInit];
  62. self.pageIndex = 1;
  63. headerImgPath = @"";//头像初始地址为空
  64. // 移动question已做题到markQuestion
  65. // if (myDelegate.isSyn) {
  66. // myDelegate.isSyn = NO;
  67. // [DB_Que_Helper moveIsDoneToMarkQuestion];//移动已做题
  68. // if (myDelegate.isLogin)//更新版本 先做一次同步
  69. // {
  70. // [self syncQuestion];
  71. // }
  72. // }
  73. }
  74. -(void)viewWillAppear:(BOOL)animated
  75. {
  76. [super viewWillAppear:animated];
  77. //用户数据监控,实时更新头像。
  78. [RACObserve(defUser, userDict) subscribeNext:^(NSDictionary *dic) {
  79. //更新头像 这样做的好处是 如果有更新就会立刻更新上,如果没有 就不用重新获取头像 节省流量
  80. NSString *str = defUser.userDict[@"photo"];
  81. if (str && ![str hasPrefix:@"http"]){
  82. str = [imgPreFix stringByAppendingString:str];
  83. }
  84. if (!str || str.length < 1) {
  85. str = @"";
  86. }
  87. if (![str isEqualToString:headerImgPath]) {
  88. [headIv sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"drawer_head.png"]];
  89. headerImgPath = str;
  90. }
  91. }];
  92. //判断是否理论计时
  93. if (myDelegate.isLogin) {
  94. [self getStuSignFlag];
  95. }
  96. }
  97. -(void)viewWillDisappear:(BOOL)animated{
  98. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  99. } else {
  100. [self setHidesBottomBarWhenPushed:NO];
  101. }
  102. [super viewWillDisappear:animated];
  103. }
  104. -(void)viewDidAppear:(BOOL)animated{
  105. [super viewDidAppear:animated];
  106. if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
  107. } else {
  108. self.tabBarController.tabBar.hidden = NO;
  109. }
  110. }
  111. #pragma mark -
  112. -(void)myInit
  113. {
  114. //导航栏遮盖问题
  115. self.navigationController.navigationBar.translucent = NO;
  116. self.navigationItem.title = @"优易学车";
  117. self.view.backgroundColor = backGroundColor;
  118. [self.navigationItem.leftBarButtonItem setTintColor:defGreen];
  119. //二维码扫描登陆网页
  120. UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"erWeiMa.png"] originImageScaleToSize:CGSizeMake(22.5, 22.5)] style:UIBarButtonItemStyleDone target:self action:@selector(clickToScan)];
  121. item.tintColor = defGreen;
  122. [self.navigationItem setRightBarButtonItem:item];
  123. CGFloat sBoader = (kNavBarHeight - 35)/2.0;
  124. UIButton *sideBtn = [[UIButton alloc] initWithFrame:CGRectMake(sBoader, kStatusHeight + sBoader, kNavBarHeight - sBoader*2, kNavBarHeight - sBoader*2)];
  125. [self.view addSubview:sideBtn];
  126. UIImageView *iv = [[UIImageView alloc] initWithFrame:sideBtn.bounds];
  127. [iv setBoardWid:1 Color:defGreen];
  128. [iv setRound];
  129. headIv = iv;
  130. [sideBtn addSubview:iv];
  131. [sideBtn addTarget:self action:@selector(showLeftViewAction) forControlEvents:UIControlEventTouchUpInside];
  132. UIBarButtonItem* bbi0 = [[UIBarButtonItem alloc] initWithCustomView:sideBtn];
  133. self.navigationItem.leftBarButtonItem = bbi0;
  134. //顶部滚动条
  135. CGFloat barHeight = 2;
  136. CGFloat segmenHeight = kSegmenHeight-barHeight;
  137. NSArray *segItems = @[@"报名",@"科一",@"科二",@"科三",@"科四",@"下证"];
  138. CGFloat segW = kSize.width/(segItems.count);
  139. _btns = [NSMutableArray array];
  140. for (int i = 0; i<segItems.count; i ++)
  141. {
  142. UIButton * button = [[UIButton alloc]initWithFrame:CGRectMake(segW*i,0,segW,segmenHeight)];
  143. [button setTitle:[segItems objectAtIndex:i] forState:UIControlStateNormal];
  144. [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
  145. [button setTitleColor:defGreen forState:UIControlStateSelected];
  146. [button.titleLabel setFont:[UIFont scaleSize:15]];
  147. [button addTarget:self action:@selector(segSelected:) forControlEvents:UIControlEventTouchUpInside];
  148. [button setBackgroundColor:[UIColor whiteColor]];
  149. [button setTag:i];
  150. [self.view addSubview:button];
  151. [_btns addObject:button];
  152. }
  153. barBg = [[UIView alloc] initWithFrame:CGRectMake(0, segmenHeight, kSize.width, barHeight)];
  154. [barBg setBackgroundColor:backGroundColor];
  155. [self.view addSubview:barBg];
  156. btnBar = [[UIView alloc] initWithFrame:CGRectMake(segW, segmenHeight, segW, barHeight)];
  157. [btnBar setBackgroundColor:defGreen];
  158. [self.view addSubview:btnBar];
  159. //1 addSubView(1+6+1)
  160. _scroll = [[UIScrollView alloc]init];
  161. [self.view addSubview:_scroll];
  162. __block CGFloat scroolY;
  163. [RACObserve(defUser, isZhiGeZheng) subscribeNext:^(id _Nullable x) {
  164. if ([defUser.isZhiGeZheng isEqualToString:@"YES"]){
  165. //在这里用——scroll将报名、科一、科二...那栏挡住
  166. scroolY = 0;
  167. [_scroll setScrollEnabled:NO];
  168. }else{
  169. scroolY = kSegmenHeight;
  170. [_scroll setScrollEnabled:YES];
  171. }
  172. _scroll.frame = CGRectMake(0, scroolY, kSize.width, kSize.height- kNavOffSet - scroolY - kTabBarHeight);
  173. _scroll.pagingEnabled = YES;
  174. _scroll.decelerationRate = .2;//用于使scroll快速完成减速。--dansongood
  175. _scroll.showsHorizontalScrollIndicator = NO;
  176. _scroll.delegate = self;
  177. }];
  178. /**为了实现页面连滚。
  179. */
  180. HmV5* vc05 = [[HmV5 alloc] init];
  181. vc05.viewH = _scroll.height;
  182. [self addChildViewController:vc05];
  183. [_scroll addSubview:vc05.view];
  184. //子页面初始化
  185. HmV0* vc0 = [[HmV0 alloc] init];
  186. vc0.viewH = _scroll.height;
  187. [self addChildViewController:vc0];
  188. [_scroll addSubview:vc0.view];
  189. //设置Subject不能在添加之后 因为初始化要用到这个属性
  190. HmV1* vc1 = [[HmV1 alloc] init];
  191. vc1.subject = 1;
  192. vc1.viewH = _scroll.height;
  193. [self addChildViewController:vc1];
  194. [_scroll addSubview:vc1.view];
  195. HmV2* vc2 = [[HmV2 alloc] init];
  196. vc2.viewH = _scroll.height;
  197. [self addChildViewController:vc2];
  198. [_scroll addSubview:vc2.view];
  199. HmV3* vc3 = [[HmV3 alloc] init];
  200. vc3.viewH = _scroll.height;
  201. [self addChildViewController:vc3];
  202. [_scroll addSubview:vc3.view];
  203. HmV4* vc4 = [[HmV4 alloc] init];
  204. vc4.subject = 4;
  205. vc4.viewH = _scroll.height;
  206. [self addChildViewController:vc4];
  207. [_scroll addSubview:vc4.view];
  208. HmV5* vc5 = [[HmV5 alloc] init];
  209. vc5.viewH = _scroll.height;
  210. [self addChildViewController:vc5];
  211. [_scroll addSubview:vc5.view];
  212. /**为了实现页面连滚。
  213. */
  214. HmV0* vc00 = [[HmV0 alloc] initWithFake:YES];
  215. vc00.viewH = _scroll.height;
  216. [self addChildViewController:vc00];
  217. [_scroll addSubview:vc00.view];
  218. int i = 0;
  219. for (UIView* v in _scroll.subviews)
  220. {
  221. //只需要修改X值,即可
  222. v.frame = CGRectMake(kSize.width*i++, 0, kSize.width, _scroll.height);
  223. }
  224. /**考虑到首页VC需要,
  225. */
  226. [_scroll setContentSize:CGSizeMake(kSize.height*_scroll.subviews.count, 0)];
  227. //监听题库变化
  228. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationAction:) name:@"Tiku_Change" object:nil];
  229. //查看是否在进行集中式理论学习
  230. isNeedTest = NO;
  231. maxTime = 0;
  232. //检测本地是否有学时未上传 如果有不能进行任何操作
  233. if (myDelegate.isLogin && defUser.isycbd != 1) {
  234. NSString *pxkm = defUser.userDict[@"pxjd"];
  235. if (pxkm.length < 1) {
  236. pxkm = @"1";
  237. }
  238. NSArray* trainArray = [DB_Helper quearyTrain:defUser.userStuId Subject:pxkm];
  239. if (trainArray.count > 0) {
  240. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"您本地有未上传学时,请确认上传!" preferredStyle:UIAlertControllerStyleAlert];
  241. UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  242. [self uploadMoreTrainRecordWithArray:trainArray];
  243. }];
  244. [alert addAction:saveAction];
  245. [self presentViewController:alert animated:YES completion:nil];
  246. }
  247. }
  248. }
  249. - (void)uploadMoreTrainRecordWithArray:(NSArray *)trainArray
  250. {
  251. if (![Util connectedToNetWork]) {
  252. showMsgUnconnect();
  253. return;
  254. }
  255. NSString* str = @"";
  256. for (TrainRecord *record in trainArray) {
  257. str = [str stringByAppendingString:[NSString stringWithFormat:@"%@,%@,%@,%@;",record.studentId,record.beginTime,record.endTime,record.trainTime]];
  258. }
  259. TrainRecord *record = [trainArray firstObject];
  260. NSMutableArray *arr=[NSMutableArray array];
  261. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"ios",@"trainType", nil]];
  262. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:[DES3Util encrypt:str ],@"trainRecord", nil]];
  263. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:record.subject,@"pxkm", nil]];
  264. [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:defUser.userDict[@"outId"],@"stuOutid", nil]];
  265. NSString* method = @"uploadMoreTrainRecord";
  266. [MBProgressHUD showLoadToView:self.view];
  267. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
  268. [MBProgressHUD hideHUDForView:self.view];
  269. if (!dict) {
  270. ShowMsg(@"上传学时失败!");
  271. return;
  272. }
  273. if ([dict[@"code"] isEqualToString:@"90"]) {
  274. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:dict[@"msg"] preferredStyle:UIAlertControllerStyleAlert];
  275. [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  276. [LoginViewController loginFromVC:self];
  277. }]];
  278. [self presentViewController:alertFind animated:true completion:nil];
  279. return;
  280. }
  281. if ([dict[@"code"] isEqualToString:@"1"]) {
  282. ShowMsg(dict[@"body"]);
  283. return;
  284. }
  285. if ( [dict[@"code"] isEqualToString:@"0"]) {
  286. for (TrainRecord *record in trainArray) {
  287. [DB_Helper updateTrainState:record];
  288. }
  289. UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"上传学时成功!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
  290. [alert show];
  291. }
  292. }];
  293. }
  294. - (void)notificationAction:(NSNotification *)notification{
  295. self.pageIndex = 1;//目的是回滚到科一的界面,只要切换了题库类型(上下/左右)
  296. if ([notification.userInfo[@"zhigezhengChanged"] isEqualToString:@"NO"]) {
  297. return;
  298. }
  299. CGFloat scroolY;
  300. if ([defUser.isZhiGeZheng isEqualToString:@"YES"]){
  301. //在这里用——scroll将报名、科一、科二...那栏挡住
  302. scroolY = 0;
  303. [_scroll setScrollEnabled:NO];
  304. }else{
  305. scroolY = kSegmenHeight;
  306. [_scroll setScrollEnabled:YES];
  307. }
  308. _scroll.frame = CGRectMake(0, scroolY, kSize.width, kSize.height- kNavOffSet - scroolY - kTabBarHeight);
  309. }
  310. /**显示左边抽屉
  311. */
  312. -(void)showLeftViewAction
  313. {
  314. [self.sideVC showLeftViewController:true];
  315. }
  316. -(void)clickToScan
  317. {
  318. if (!myDelegate.isLogin) {
  319. [LoadingView showMsg:@"请登录后操作"];
  320. [LoginViewController loginFromVC:self];
  321. return;
  322. }
  323. ScanVC *scan = [[ScanVC alloc] init];
  324. scan.type = @"1";
  325. [scan scanBlock:^(NSDictionary *dic) {
  326. //模拟
  327. if ([dic[@"scanType"] isEqualToString:@"MNQTrain"]) {
  328. // 成功
  329. //根据是否存在mnTrainType判断本地记录的学时编号等数据是否与服务器同步过(即登录完调的状态接口成功与否)
  330. if (myDelegate.mnTrainType) {
  331. myDelegate.mnTrainType = @"2";//已经登录未人脸验证
  332. UINavigationController *nav = [LoginViewController getPeriodVCWithName:@"MNQtTrainVC"];
  333. if (nav) {
  334. nav.modalPresentationStyle = UIModalPresentationFullScreen;
  335. [self presentViewController:nav animated:YES completion:nil];
  336. }
  337. }else{
  338. [MBProgressHUD showMessage:@"正在获取当前训练状态" toView:self.view];
  339. //这个主要目的是为了更新本地学时编号等数据
  340. [LoginViewController getCurrentStateWithCompleteBlock:^(NSDictionary *root) {
  341. [MBProgressHUD hideHUDForView:self.view animated:NO];
  342. if (!root) {
  343. ShowMsg(@"请求失败");
  344. return;
  345. }
  346. if ([root[@"code"] isEqualToString:@"0"]) {
  347. UINavigationController *nav = [LoginViewController getPeriodVCWithName:@"MNQtTrainVC"];
  348. if (nav) {
  349. nav.modalPresentationStyle = UIModalPresentationFullScreen;
  350. [self presentViewController:nav animated:YES completion:nil];
  351. }
  352. }else{
  353. ShowMsg(root[@"msg"]);
  354. }
  355. }];
  356. }
  357. return;
  358. }
  359. //理论扫码
  360. NSInteger isNeed = 1;
  361. for (NSDictionary * dic in defUser.userDict[@"params"]) {
  362. if ([dic[@"KEY"] isEqualToString:@"SP_VERIFY_IMEI"]) {
  363. isNeed = [dic[@"VALUE"] integerValue];
  364. }
  365. }
  366. NSString *IMEI = defUser.userDict[@"imei"];
  367. if (IMEI.length > 0) {
  368. if (isNeed == 1) {
  369. if ([Tools getIDFAWithType:GetIDFAType_Default]) {
  370. if (![IMEI isEqualToString:[Tools getIDFAWithType:GetIDFAType_Default]]) {
  371. ShowMsg(@"请用本人手机进行理论计时");
  372. return;
  373. }
  374. }
  375. }else{
  376. [Tools saveNotBindImeiLogWithType:@"1" block:^(BOOL isSuccess) {
  377. }];//操作类型(1理论设备扫码,2远程计时,3模拟终端,4大车)

  378. }
  379. }else {
  380. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:@"您暂未绑定学员账号,是否绑定?" preferredStyle:UIAlertControllerStyleAlert];
  381. [alertFind addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
  382. [alertFind addAction:[UIAlertAction actionWithTitle:@"去绑定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  383. ThirdLoginBindYunGuanVC *vc = [[ThirdLoginBindYunGuanVC alloc] init];
  384. [self navPushHideTabbarToVC:vc];
  385. }]];
  386. [self presentViewController:alertFind animated:true completion:nil];
  387. return;
  388. }
  389. isCloseAudio = YES;
  390. scanType = dic[@"scanType"];
  391. scanData = dic[@"dataString"];
  392. if ([dic[@"scanType"] intValue] == 2) {
  393. UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:@"是否结束理论学习?" preferredStyle:UIAlertControllerStyleAlert];
  394. [alertFind addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
  395. [alertFind addAction:[UIAlertAction actionWithTitle:@"结束计时" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  396. [self getMyLocation];
  397. }]];
  398. [self presentViewController:alertFind animated:true completion:nil];
  399. }else {
  400. [self getMyLocation];
  401. }
  402. }];
  403. [self navPushHideTabbarToVC:scan];
  404. [MBProgressHUD showMessage:@"正在获取当前位置..." toView:self.view];
  405. [[MapManager sharedManager] updateLocationWithCompleteBlock:^(BOOL success, CLLocation *location) {
  406. [MBProgressHUD hideHUDForView:self.view animated:YES];
  407. if (success) {
  408. self->myLocation = location.coordinate;
  409. // [self takePhoto];
  410. [self getQgCode];
  411. }
  412. }];
  413. }
  414. #pragma mark -
  415. //0,1,2,3,4,5,6,7
  416. -(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
  417. lastOffset = scrollView.contentOffset;
  418. NSInteger pInd = (int)(lastOffset.x / kSize.width);
  419. {//为了实现循环滚动
  420. if (pInd < 1) {
  421. pInd = 6;
  422. }
  423. if (pInd > 6) {
  424. pInd = 1;
  425. }
  426. pInd--;
  427. }
  428. if (pInd != self.pageIndex) {
  429. self.pageIndex = pInd;
  430. }
  431. }
  432. /**分段按钮,和scroll联动*/
  433. -(void)segSelected:(UIButton*)sender
  434. {
  435. if (sender.tag == self.pageIndex) {
  436. return;
  437. }
  438. self.pageIndex = sender.tag;
  439. }
  440. /**0-5
  441. */
  442. -(void)setPageIndex:(NSInteger)pageIndex{
  443. //刷新错题提示
  444. if (pageIndex==1) {
  445. myDelegate.subject = @"1";
  446. HmV1 *vc = (HmV1 *)self.childViewControllers[2];
  447. [vc getFaultCntNew];
  448. }else if(pageIndex==4){
  449. myDelegate.subject = @"4";
  450. HmV4 *vc = (HmV4 *)self.childViewControllers[5];
  451. [vc getFaultCntNew];
  452. }
  453. [_btns[_pageIndex] setSelected:NO];
  454. _pageIndex = pageIndex;
  455. [_btns[_pageIndex] setSelected:YES];
  456. //为了实现循环滚动
  457. [_scroll setContentOffset:CGPointMake(kSize.width*(pageIndex+1), _scroll.contentOffset.y) animated:NO];
  458. //这里设置每次进入某一类型回滚到顶部
  459. UIView *view = _scroll.subviews[pageIndex+1];
  460. HmvBase *vc = (HmvBase *)view.nextResponder;
  461. [vc.zzScrollV setContentOffset:CGPointZero animated:NO];
  462. CGSize size = btnBar.frame.size;
  463. [UIView animateWithDuration:.2 animations:^{
  464. btnBar.frame = CGRectMake(size.width * _pageIndex, btnBar.frame.origin.y, size.width, size.height);
  465. }];
  466. myDelegate.subject = [NSString stringWithFormat:@"%d",(int)pageIndex];
  467. RQ_YDTQuestion_Module.subject = (pageIndex > 0 && pageIndex < 5)? pageIndex : 1;
  468. }
  469. #pragma mark 更新第一次进入同步数据
  470. -(void)syncQuestion
  471. {
  472. if (![Util connectedToNetWork]) {
  473. return;
  474. }
  475. self.view.userInteractionEnabled = NO;
  476. bgLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, (kSize.height - 80)/2.0, kSize.width - 60, 70)];
  477. bgLabel.backgroundColor = backGroundColor;
  478. [bgLabel setBoardWid:5 Color:contentTextColor];
  479. [bgLabel setText:@"收藏、错题同步中,请稍后..." Font:24 TextColor:kTitleColor Alignment:NSTextAlignmentCenter];
  480. [[UIApplication sharedApplication].keyWindow addSubview:bgLabel];
  481. [self getMyQuestionType:@"" Subject:@""];
  482. }
  483. -(void)getMyQuestionType:(NSString*)type Subject:(NSString*)subject;
  484. {
  485. NSMutableArray *arr = [NSMutableArray array];
  486. [arr addPro:@"user" Value:defUser.userDict[@"id"]];
  487. [arr addPro:@"outId" Value:defUser.userStuId];
  488. [arr addPro:@"type" Value:type];
  489. [arr addPro:@"subject" Value:subject];
  490. [arr addPro:@"carType" Value:defUser.car_type];
  491. [arr addPro:@"isPage" Value:@"0"];
  492. [arr addPro:@"pageSize" Value:@"0"];
  493. [arr addPro:@"currentPage" Value:@"0"];
  494. NSString *method = @"getMyQuestionFavs";
  495. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  496. //NSLog(@"同步错题收藏---->%@--->%@",arr,root);
  497. if (!root || [root[@"code"] isEqualToString:@"1"]) {
  498. [self removebgLabel];
  499. ShowMsg(@"题库错题、收藏、排除同步失败,请在侧栏手动同步");
  500. return;
  501. }
  502. NSArray* body = [root objectForKey:@"body"];
  503. if (body.count > 0) {
  504. if ([defUser.car_type isEqualToString:@"2"]) {
  505. if ([DB_Que_Helper deleteGZPZ_EXAM_CYRYAllMarkQuestion]) {
  506. [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithArray:body];
  507. }
  508. } else {
  509. if ([DB_Que_Helper deleteAllMarkQuestion]) {
  510. [DB_Que_Helper setMarkQuestionWithArray:body];
  511. }
  512. }
  513. }
  514. [self removebgLabel];
  515. ShowMsg(@"题库错题、收藏、排除已同步完毕");
  516. }];
  517. }
  518. -(void)removebgLabel
  519. {
  520. if (bgLabel) {
  521. [bgLabel removeFromSuperview];
  522. bgLabel = nil;
  523. }
  524. self.view.userInteractionEnabled = YES;
  525. }
  526. //获取当前学员计时状态
  527. - (void)getStuSignFlag {
  528. if (![Util connectedToNetWork]) {
  529. return;
  530. }
  531. NSString *stuId = defUser.userDict[@"outId"];
  532. if (!stuId || stuId.length == 0) {
  533. return;
  534. }
  535. NSMutableArray *arr=[NSMutableArray array];
  536. [arr addPro:@"stuId" Value:stuId];
  537. [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]];
  538. NSString* method = @"getStuSignFlag";
  539. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  540. if (!root || [root[@"code"] integerValue] == 1) {
  541. return;
  542. }
  543. //这里接收服务器返回状态 当前训练培训训练状态 0 未签到 4集中理论签到中
  544. // if ([[root[@"body"] objectForKey:@"status"] integerValue] == 0) {
  545. // //还没开始集中式理论
  546. //
  547. // }
  548. // if ([[root[@"body"] objectForKey:@"status"] integerValue] == 4) {
  549. // //集中式理论学习中
  550. // }
  551. if ([[root[@"body"] objectForKey:@"theoryVerify"] integerValue] == 1) {
  552. //开启过程验证
  553. isNeedTest = YES;
  554. }else {
  555. //关闭过程验证
  556. isNeedTest = NO;
  557. }
  558. NSInteger newTime = [[root[@"body"] objectForKey:@"timre"] integerValue];
  559. maxTime = [[root[@"body"] objectForKey:@"theoryTime"] integerValue];
  560. if ([[root[@"body"] objectForKey:@"status"] integerValue] == 4) {//已经签到 集中式计时中
  561. myDelegate.trainStateLabel.text = @"理论学习中...";
  562. if (isNeedTest) {
  563. if (maxTime > newTime) {
  564. [self setNotificationWithFireTime:maxTime - newTime withType:LocalNotificationTypeTheory];
  565. }else {
  566. myDelegate.trainStateLabel.text = @"请扫描过程验证二维码";
  567. if (isCloseAudio) {
  568. isCloseAudio = NO;
  569. }else {
  570. [Tools playAudioWithString:@"请扫描过程验证二维码"];
  571. }
  572. }
  573. }
  574. }else {
  575. myDelegate.trainStateLabel.text = @"";
  576. }
  577. }];
  578. }
  579. //语音播报或者推送
  580. - (void)setNotificationWithFireTime:(NSInteger)fireTime withType:(LocalNotificationType)localNotificationType{
  581. switch (localNotificationType) {
  582. /// 课堂
  583. case LocalNotificationTypeTheory: {
  584. NSString *identifierStr = @"Theory";
  585. /// 间隔时间大于5分钟(300秒)
  586. if (fireTime >= 300) {
  587. NSInteger timeInterval = fireTime - 300;
  588. // if (DEBUG) {
  589. // timeInterval = 120;
  590. // }
  591. [RQ_LocalNoti_Manager removeNotificationWithIdentifierID:identifierStr];
  592. [RQ_LocalNoti_Manager addLocalNotificationWithTitle:@"优易学车提醒您" subTitle:@"5分钟后将超过验证时间,请提前扫码验证" body:[RQ_SHARE_FUNCTION getCurrentTimeStringWithTimeStamp:timeInterval] timeInterval:timeInterval identifier:identifierStr userInfo:@{@"identifier" : identifierStr , @"message" : @"即将超过验证时间,请提前扫码验证"} repeats:0];
  593. } else {
  594. [RQ_LocalNoti_Manager removeNotificationWithIdentifierID:identifierStr];
  595. [RQ_LocalNoti_Manager addLocalNotificationWithTitle:@"优易学车提醒您" subTitle:@"即将超过验证时间,请提前扫码验证" body:[RQ_SHARE_FUNCTION getCurrentTimeStringWithTimeStamp:0] timeInterval:0 identifier:identifierStr userInfo:@{@"identifier" : identifierStr , @"message" : @"即将超过验证时间,请提前扫码验证"} repeats:0];
  596. }
  597. break;
  598. }
  599. /// 模拟
  600. case LocalNotificationTypSsimulation: {
  601. //移除旧的通知
  602. if ([[[UIApplication sharedApplication] scheduledLocalNotifications] count] > 0) {
  603. [[UIApplication sharedApplication] cancelAllLocalNotifications];
  604. }
  605. //定义本地通知对象
  606. UILocalNotification *notification = [[UILocalNotification alloc]init];
  607. //设置调用时间
  608. notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:fireTime];
  609. //设置通知属性
  610. notification.alertBody = @"优易学车提醒您"; //通知主体
  611. notification.applicationIconBadgeNumber = 1;//应用程序图标右上角显示的消息数
  612. notification.alertAction = @"打开应用"; //待机界面的滑动动作提示
  613. notification.soundName = @"TrainTest.mp3";//收到通知时播放的声音,默认消息声音
  614. // 通知参数
  615. NSDictionary *userDict = [NSDictionary dictionaryWithObjectsAndKeys:@"nothing",@"ShiCaoPeriodVC_reTakePhoto", nil];
  616. notification.userInfo = userDict;
  617. //调用通知
  618. [[UIApplication sharedApplication] scheduleLocalNotification:notification];
  619. break;
  620. }
  621. default:
  622. break;
  623. }
  624. }
  625. - (void)cancelLocalNotificationWithType:(LocalNotificationType)localNotificationType {
  626. switch (localNotificationType) {
  627. /// 课堂
  628. case LocalNotificationTypeTheory: {
  629. NSString *identifierStr = @"Theory";
  630. [RQ_LocalNoti_Manager removeNotificationWithIdentifierID:identifierStr];
  631. break;
  632. }
  633. /// 模拟
  634. case LocalNotificationTypSsimulation: {
  635. //移除旧的通知
  636. if ([[[UIApplication sharedApplication] scheduledLocalNotifications] count] > 0) {
  637. [[UIApplication sharedApplication] cancelAllLocalNotifications];
  638. }
  639. break;
  640. }
  641. default:
  642. break;
  643. }
  644. }
  645. - (void)getMyLocation {
  646. //定位功能
  647. [MBProgressHUD showMessage:@"正在获取当前位置..." toView:self.view];
  648. [[MapManager sharedManager] updateLocationWithCompleteBlock:^(BOOL success, CLLocation *location) {
  649. [MBProgressHUD hideHUDForView:self.view animated:YES];
  650. if (success) {
  651. self->myLocation = location.coordinate;
  652. [self studentQrcode];
  653. }
  654. }];
  655. }
  656. /** 扫描二维码调取接口 */
  657. - (void)studentQrcode {
  658. if (![Util connectedToNetWork]) {
  659. showMsgUnconnect();
  660. return;
  661. }
  662. if (myLocation.longitude == 0.0) {
  663. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"位置获取失败,请重新扫描二维码!" message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
  664. [alert show];
  665. return;
  666. }
  667. NSMutableArray *arr = [NSMutableArray array];
  668. [arr addPro:@"studentOutid" Value:defUser.userDict[@"outId"]];
  669. [arr addPro:@"qrcode" Value:scanData];
  670. [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]];
  671. [arr addPro:@"lng" Value:[NSString stringWithFormat:@"%f",myLocation.longitude]];
  672. [arr addPro:@"lat" Value:[NSString stringWithFormat:@"%f",myLocation.latitude]];
  673. // [arr addPro:@"lng" Value:@"123.907972"];
  674. // [arr addPro:@"lat" Value:@"41.887931"];
  675. [arr addPro:@"type" Value:scanType];
  676. [arr addPro:@"telType" Value:@"ios"];
  677. if (_faceIdStr && ![_faceIdStr isEqualToString:@""]) {
  678. [arr addPro:@"faceId" Value:_faceIdStr];
  679. _faceIdStr = @"";
  680. }
  681. NSString *method = @"studentQrcode";
  682. NSString *str = [scanType isEqualToString: @"1"] ? @"签到中...":@"签退中...";
  683. if ([scanType isEqualToString: @"1"] ) {
  684. str = @"签到中...";
  685. }else if ([scanType isEqualToString: @"2"]) {
  686. str = @"签退中...";
  687. }else if ([scanType isEqualToString: @"3"]) {
  688. str = @"验证中...";
  689. }
  690. [MBProgressHUD showMessage:str toView:self.view];
  691. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  692. [MBProgressHUD hideHUDForView:self.view];
  693. if (!root) {
  694. ShowMsg(@"操作失败,请重试!");
  695. [Tools playAudioWithString:@"操作失败,请重试!"];
  696. return;
  697. }
  698. if ([root[@"code"] integerValue] == 0) {//代表操作成功
  699. if ([scanType isEqualToString:@"1"] || [scanType isEqualToString:@"3"]) {
  700. myDelegate.trainStateLabel.text = @"理论学习中...";
  701. }
  702. if ([scanType isEqualToString:@"2"]) {
  703. myDelegate.trainStateLabel.text = @"";
  704. }
  705. // if (DEBUG) {
  706. // isNeedTest = YES;
  707. // }
  708. if (isNeedTest) {
  709. switch ([scanType integerValue]) { //1、签到 2、签退 3、过程验证
  710. case 1://签到成功
  711. if (maxTime > 0) {
  712. [self setNotificationWithFireTime:maxTime withType:LocalNotificationTypeTheory];
  713. }
  714. break;
  715. case 2://签退
  716. [self cancelLocalNotificationWithType:LocalNotificationTypeTheory];
  717. break;
  718. case 3://验证成功
  719. if (maxTime > 0) {
  720. [self setNotificationWithFireTime:maxTime withType:LocalNotificationTypeTheory];
  721. }
  722. break;
  723. default:
  724. break;
  725. }
  726. }
  727. }
  728. if ([root[@"code"] integerValue] == 2) {//距离理论教室位置较远
  729. NSString *str = root[@"msg"];
  730. if (str.length < 1) {
  731. return;
  732. }
  733. NSArray *mapArray = [str componentsSeparatedByString:@";"];
  734. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:[mapArray lastObject] preferredStyle:UIAlertControllerStyleAlert];
  735. [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]];
  736. [alert addAction:[UIAlertAction actionWithTitle:@"查看位置详情" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  737. //进入地图页面 传入两个点 一个距离 lng lat len
  738. if (mapArray.count > 3) {
  739. // lng = 123.467129,
  740. // lat = 41.813997
  741. //122.769684;41.515881;66822;您当前距离理论教室位置66822米,请到理论教室扫码!
  742. DistenceTooLongMapVC *mapVC = [[DistenceTooLongMapVC alloc] init];
  743. mapVC.lat1 = myLocation.latitude;
  744. mapVC.lng1 = myLocation.longitude;
  745. mapVC.lat2 = [mapArray[1] floatValue];
  746. mapVC.lng2 = [mapArray[0] floatValue];
  747. mapVC.distence = mapArray[2];
  748. mapVC.skipMspBlock = ^{
  749. myLocation.longitude = 0.0;
  750. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"位置已重置,请重新扫描二维码!" message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
  751. [alert show];
  752. };
  753. [self navPushHideTabbarToVC:mapVC];
  754. }
  755. }]];
  756. [self presentViewController:alert animated:true completion:nil];
  757. return;
  758. }
  759. // 需要进行人脸比对
  760. if ([root[@"code"] integerValue] == 99) {
  761. [self takePhoto];
  762. return;
  763. }
  764. [Tools playAudioWithString:root[@"msg"]];
  765. ShowMsg(root[@"msg"]);
  766. }];
  767. }
  768. // 人脸比对
  769. - (void)takePhoto {
  770. UIStoryboard * board = [UIStoryboard storyboardWithName:@"LivenessDetection" bundle:nil];
  771. OliveappLivenessDetectionViewController * livenessDetectionViewController;
  772. livenessDetectionViewController = (OliveappLivenessDetectionViewController *)[ board instantiateViewControllerWithIdentifier:@"LivenessDetectionStoryboard"];
  773. livenessDetectionViewController.modalPresentationStyle = 0;
  774. livenessDetectionViewController.faceDelegate = self;
  775. OliveappSessionManagerConfig* config = [OliveappSessionManagerConfig new];
  776. // config.timeoutMs = 100000;
  777. [config usePredefinedConfig: 4]; // 这里配置检测步骤
  778. livenessDetectionViewController.cusConfig = config;
  779. NSError *error;
  780. BOOL isSuccess = [livenessDetectionViewController setConfigLivenessDetection:self withError: &error];
  781. if (isSuccess){
  782. [self presentViewController:livenessDetectionViewController animated:YES completion:nil];
  783. }
  784. }
  785. - (void)onLivenessSuccess:(OliveappDetectedFrame *)detectedFrame{
  786. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  787. [self dismissViewControllerAnimated:YES completion:nil];
  788. });
  789. }
  790. - (void)onLivenessFail:(int)sessionState withDetectedFrame:(OliveappDetectedFrame *)detectedFrame{
  791. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  792. [self dismissViewControllerAnimated:YES completion:nil];
  793. UIAlertController *actionsheet = [UIAlertController alertControllerWithTitle:@"提示" message:@"获取人脸失败,是否重新进行人脸比对" preferredStyle:UIAlertControllerStyleAlert];
  794. UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"是" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  795. [self takePhoto];
  796. }];
  797. UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"否" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  798. }];
  799. [actionsheet addAction:action1];
  800. [actionsheet addAction:action2];
  801. [self presentViewController:actionsheet animated:YES completion:nil];
  802. });
  803. }
  804. - (void)onLivenessCancel{
  805. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  806. [self dismissViewControllerAnimated:YES completion:nil];
  807. });
  808. }
  809. - (void)sendFaceImage:(UIImage *)faceImage {
  810. UIImage *normalImage = [UIImage fixOrientation:faceImage];
  811. NSData *imgData = UIImageJPEGRepresentation(normalImage, .2f);
  812. NSString *backString = [NSString stringWithFormat:@"%@",[OliveappBase64Helper encode:imgData]];
  813. [self face2faceTheoryWithPhotoStr:backString ResultBlock:^(NSString *faceId) {
  814. if (![faceId isEqualToString:@""]) {
  815. _faceIdStr = faceId;
  816. [self studentQrcode];
  817. }
  818. }];
  819. }
  820. - (void)sendFaceImageError {
  821. }
  822. - (void)face2faceTheoryWithPhotoStr:(NSString *)photoStr ResultBlock:(void (^)(NSString *faceId))resultBlock {
  823. if (![Util connectedToNetWork]) {
  824. showMsgUnconnect();
  825. return;
  826. }
  827. if (myLocation.longitude == 0.0) {
  828. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"位置获取失败,请重新扫描二维码!" message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
  829. [alert show];
  830. return;
  831. }
  832. NSMutableArray *arr=[NSMutableArray array];
  833. [arr addPro:@"stunum" Value:defUser.userDict[@"stuNum"]];
  834. [arr addPro:@"dqbh" Value:defUser.userDict[@"city"]];
  835. [arr addPro:@"outId" Value:defUser.userDict[@"outId"]];
  836. [arr addPro:@"lng" Value:[NSString stringWithFormat:@"%f",myLocation.longitude]];
  837. [arr addPro:@"lat" Value:[NSString stringWithFormat:@"%f",myLocation.latitude]];
  838. [arr addPro:@"photo" Value:photoStr];
  839. NSString *method = @"face2faceTheory";
  840. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  841. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  842. [MBProgressHUD hideHUDForView:self.view];
  843. if (!root) {
  844. ShowMsg(@"操作失败,请重试!");
  845. [Tools playAudioWithString:@"操作失败,请重试!"];
  846. return;
  847. }
  848. if ([root[@"code"] integerValue] == 0) {//代表操作成功
  849. if (resultBlock && root[@"data"][@"faceId"]) {
  850. resultBlock(root[@"data"][@"faceId"]);
  851. }
  852. }
  853. [Tools playAudioWithString:root[@"msg"]];
  854. ShowMsg(root[@"msg"]);
  855. }];
  856. }
  857. - (void)getQgCode {
  858. if (![Util connectedToNetWork]) {
  859. showMsgUnconnect();
  860. return;
  861. }
  862. NSMutableArray *arr=[NSMutableArray array];
  863. [arr addPro:@"dqbh" Value:@"2101"];
  864. [arr addPro:@"sim" Value:@"12101000042"];
  865. [arr addPro:@"roomId" Value:@"343"];
  866. [arr addPro:@"coachNum" Value:@"3623240296803372"];
  867. [arr addPro:@"type" Value:@"3"];
  868. NSString *method = @"getQgCode";
  869. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  870. }];
  871. }
  872. @end